Namespace: WealthLab.Backtest
Parent: Object

The Transaction class represents the result of an order (buy, sell, sell short, or cover short) that was placed either during a simulated backtest, or in the WealthLab Order Manager.

When developing a C# Coded Strategy, you obtain a Transaction instance as a result of the PlaceTrade method. You can modify certain properties of the Transaction, such as Quantity, to implement customized position sizing in your trading Strategy.

Backtest Related
public double Commission

The commission that was applied to the order. In WealthLab, you establish commission in the Backtest Settings interface.

public DateTime EntryDate

The signal entry date of the transaction. Corresponds to the price bar on which the trading signal was issued.

public DateTime ExecutionDate

The date that the backtester filled the order during the simulation.

public double ExecutionPrice

The price at which the backtester filled the order during the simulation.

public bool MarginOverride

Set this property to true to cause the backtester to fill the transaction even if there is not enough simulated capital.

public int PositionTag

This integer value is used internally by WealthLab to track which Building Block a particular Transaction belongs to. Avoid using this yourself. Instead, you can use the Tag property to store information in a Transaction.

public double Weight

Specifies a weight value to use for determining which transactions the backtester should fill in cases where there are more candidate transactions than available simulated capital. Transactions are sorted by this value during the backtest process, so higher values here will result in a higher priority.

Example Code
using WealthLab.Backtest;
using WealthLab.Core;
using WealthLab.Indicators;

namespace WealthScript2
	public class MyStrategy : UserStrategyBase
		public override void Initialize(BarHistory bars)
			_sma1 = SMA.Series(bars.Close, 8);
			_sma2 = SMA.Series(bars.Close, 20);
			_rsi = RSI.Series(bars.Close, 10);


		public override void Execute(BarHistory bars, int idx)
			if (!HasOpenPosition(bars, PositionType.Long))
				Transaction t = null;
				if (_sma1.CrossesOver(_sma2, idx))
					t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market);

				// Assign the highest priority to the lowest rsi (most oversold) by negation
				if (t != null)
					t.Weight = -_rsi[idx];
				if (_sma1.CrossesUnder(_sma2, idx))
					PlaceTrade(bars, TransactionType.Sell, OrderType.Market);

		//private variables
		SMA _sma1;
		SMA _sma2;
		RSI _rsi;

public BarHistory Bars

The BarHistory instance that the transaction was placed on.

public bool IsEntry

Returns true if this is an entry (Buy or Short) transaction.

public bool IsExit

Returns true if this is an exit (Sell or Cover) transaction.

public double OrderPrice

The order price of the transaction. Does not apply for Market orders.

public OrderType OrderType

Contains the order type of the transaction. Possible values are OrderType.Market, OrderType.Limit, OrderType.Stop and OrderType.FixedPrice. Market, Limit, and Stop simulate their corresponding broker order types, while FixedPrice is a theoretical order type intended to support situations where you want to establish a fixed price of an order.

public PositionType PositionType

Returns the position type of the transaction, PositionType.Long for Buy and Sell orders, and PositionType.Short for Short and Cover orders.

public double Quantity

Contains the number of shares or contracts in the transaction.

public string SignalName

Allows you to save an optional signal name string along with the Transaction. This eventually gets passed to the EntrySignalName property of the resulting Position object.

public string Symbol

The symbol that the transaction was placed on.

public object Tag

If you assign a value to the Tag property of a Transaction instance that opened a new position (a Buy or Short TransactionTypes), that value will be assigned to the Tag property of the Position instance that is created.

public TransactionType TransactionType

Contains the type of transaction, possible values are TransactionType.Buy, TransactionType.Sell, TransactionType.Short or TransactionType.Cover.