Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

No Trades in SystemPerformance.AllTrades

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    No Trades in SystemPerformance.AllTrades

    Sir,

    I am running several strategies on NinjaTrader 8 in RealTime for testing purposes. Each strategy is assigned to one simulation account. Further, each strategy trades in one data series with only one instrument either "ES 03-21", "YM 03-21", or "MYM 03-21" (index futures).

    Most aspects of real-time trading are working fine, i.e. each strategy can open and close positions. On closing a position, all account items are updated properly.

    But there is one problem with SystemPerformance.AllTrades because this collection is empty for all strategies and at all times during trading.

    Code:
    protected override void OnPositionUpdate( ... ) {
    ...
    Log( "Number of Trades: " + SystemPerformance.AllTrades.Count, .... );        // Prints "Number of Trades: 0"
    Log( "Number of Trades: " + SystemPerformance.AllTrades.TradesCount, .... );  // Prints "Number of Trades: 4"  i.e. the number of trades made by ALL strategies.
    ...
    The property SystemPerformance.AllTrades.Count returns zero always and for all strategies. The property SystemPerformance.AllTrades.TradesCount returns the total number of trades made by all active strategies. Moreover, It is not possible to access any single trade by index, i.e. SystemPerformance.Alltrades[ ...Count - 1]. Using index-based access to the AllTrades collection causes an exception.

    I searched this community for answers to my problem. For instance, one thread suggested setting the parameter IncludeTradeHistoryInBacktest = True. But it won't help either.

    Can you assist me to correct this problem? I would like to analyze the trades for each strategy in the method OnPositionUpdate().

    Many thanks in advance.


    #2
    Hello ubrand,

    Thanks for your post.

    Please see the attached example script which demonstrates reading information from SystemPerformance.AllTrades.

    The code to print out all trades made by a strategy would look something like this, for example.

    Code:
    // Print out the number of trades
    Print("The strategy has taken " + SystemPerformance.AllTrades.Count + " trades.");
    See the help guide documentation below for more information.
    SystemPerformance: https://ninjatrader.com/support/help...erformance.htm
    AllTrades: https://ninjatrader.com/support/help.../alltrades.htm
    TradeCollection: https://ninjatrader.com/support/help...collection.htm
    OnPositionUpdate: https://ninjatrader.com/support/help...tionupdate.htm

    Let us know if we may assist further.
    Attached Files
    Last edited by NinjaTrader_BrandonH; 01-11-2022, 08:47 AM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      You may have to set
      Code:
      IncludeTradeHistoryInBacktest = true;
      in
      Code:
      State.Configure
      Documentation: https://ninjatrader.com/support/help...inbacktest.htm
      Last edited by nathanfranke; 04-01-2023, 01:22 AM.

      Comment


        #4
        I was having the same issue posted here and have discovered that the SystemPerformance.AllTrades.Count does NOT always return the correct response.

        Print("OnPositionUpdate: The strategy has taken " + SystemPerformance.AllTrades.Count + " trades.");
        Print("The strategy has taken " + SystemPerformance.LongTrades.TradesCount + " long trades.");
        Print("The strategy has taken " + SystemPerformance.ShortTrades.TradesCount + " short trades.");
        Print("The strategy has taken " + SystemPerformance.AllTrades.TradesCount + " total trades.");​

        I added the following code and noticed that the first line was always showing zero. While the other lines incremented as expected specifically for longs, shorts, and the TradesCount var not the Count var.

        Something to note for others.

        Also, a trade is not counted until it's actually completed.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X