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 algospoke, 04-17-2024, 06:40 PM
      6 responses
      49 views
      0 likes
      Last Post algospoke  
      Started by arvidvanstaey, Today, 02:19 PM
      4 responses
      11 views
      0 likes
      Last Post arvidvanstaey  
      Started by samish18, 04-17-2024, 08:57 AM
      16 responses
      61 views
      0 likes
      Last Post samish18  
      Started by jordanq2, Today, 03:10 PM
      2 responses
      11 views
      0 likes
      Last Post jordanq2  
      Started by traderqz, Today, 12:06 AM
      10 responses
      21 views
      0 likes
      Last Post traderqz  
      Working...
      X