TradeCollection

View as Markdown

Definition

A collection of Trade objects. You can access a trade object by providing an index value. Trades are indexed sequentially meaning the oldest trade taken in a strategy will be at an index value of zero. The most recent trade taken will be at an index value of the total trades in the collection minus 1.

Methods and Properties

PropertyDescription
TradesCountAn int value representing the number of trades in the collection
EvenTradesGets a TradeCollection object of even trades
GetTrades()Gets a TradeCollection object representing a specified position
LosingTradesGets a TradeCollection object of losing trades
TradesPerformanceGets a TradesPerformance object
WinningTradesGets a TradeCollection object of winning trades

Examples

1protected override void OnBarUpdate()
2{
3 // Accesses the first/last trade in the strategy (oldest trade is at index 0)
4 // and prints out the profit as a percentage to the output window
5 if (SystemPerformance.AllTrades.Count > 1)
6 {
7 Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
8 Trade firstTrade = SystemPerformance.AllTrades[0];
9
10 Print("The last trade profit is " + lastTrade.ProfitPercent);
11 Print("The first trade profit is " + firstTrade.ProfitPercent);
12 }
13}
1protected override void OnBarUpdate()
2{
3 // Once the strategy has executed 20 trades loop through the losing trades
4 // collection and print out the PnL on only long trades
5 if (SystemPerformance.AllTrades.Count == 20)
6 {
7 Print("There are " + SystemPerformance.AllTrades.LosingTrades.Count + " losing trades.");
8 foreach (Trade myTrade in SystemPerformance.AllTrades.LosingTrades)
9 {
10 if (myTrade.Entry.MarketPosition == MarketPosition.Long)
11 Print(myTrade.ProfitCurrency);
12 }
13 }
14}