Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Brandon H.NinjaTrader Customer Service

    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

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      191 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,230 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X