NinjaScript > Language Reference > Strategy > TradeCollection >

WinningTrades

Print this Topic Previous pageReturn to chapter overviewNext page

Definition

A subcollection of Trade objects consisting of only the winning trades in a TradeCollection. 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

Count

An int value representing the number of trades in the collection

GetTrades()

Gets a TradeCollection object representing a specified position

TradesPerformance

Gets a TradesPerformance object

 

Syntax
<TradeCollection>.WinningTrades

 

 

Examples

protected override void OnBarUpdate()
{
    // Accesses the first/last winning trade in the strategy (oldest trade is at index 0)
    // and prints out the profit as a percentage to the output window

    if (Performance.AllTrades.WinningTrades.Count > 1)

    {

         Trade lastTrade = Performance.AllTrades.WinningTrades[Performance.AllTrades.Count - 1];
        Trade firstTrade = Performance.AllTrades.WinningTrades[0];

 
        Print("The last winning trade's profit was " + lastTrade.ProfitPercent);
        Print("The first winning trade's profit was " + firstTrade.ProfitPercent);

    }
}