Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SystemPerformance.AllTrades.Count always returns 0

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

    SystemPerformance.AllTrades.Count always returns 0

    I've recently upgraded NT to the latest version. And I noticed something stopped working.

    I have the following code:

    protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
    {
    Print(SystemPerformance.AllTrades.Count.ToString() );
    }

    After a trade is closed, I call this method to do something with the trade data. For example: SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].Exit.Quantity to call the exit quantity.

    Has this feature stopped working? Or changed in any way?

    Thanks​
    Last edited by siroki; 01-28-2023, 08:20 AM.

    #2
    Hello siroki,

    Thanks for your post.

    SystemPerformance.AllTrades.Count has not been modified in the latest version release of NinjaTrader (8.0.27.1). This could be seen in the Release Notes section of the help guide.

    Release Notes: https://ninjatrader.com/support/help...8/8_0_27_1.htm

    OnPositionUpdate will only trigger each time a PositionUpdate is received for the strategy. A trade is considered an entry order and an exit order. For example, if an entry order is placed and an exit order is placed to exit the position, the trade count will be 1.

    See this screenshot demonstrating that 2 entry orders were placed and 2 exit orders were placed to exit. When a third entry order is placed and OnPositionUpdate() fires, we see a '2' in the Output window from Print(SystemPerformance.AllTrades.Count.ToString() ); indicating that two trades were placed (two entries and two exits).

    OnPositionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm

    See the help guide documentation below for more information.

    OnPositionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm
    SystemPerformance.AllTrades: https://ninjatrader.com/support/help.../alltrades.htm

    I have also attached the strategy used to test this.

    Please let me know if I may assist further.​
    Attached Files
    <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
      Thanks for your reply.

      I did further investigation. The issue seems to be related when strategy is run over an instrument list holding 2 or more tickers.

      When running the strategy over a single ticker, the trade count returns a value
      When running the strategy over an instrument list holding a single ticker, the trade count returns a value

      When running the strategy over an instrument list holding 2 or more tickers, the trade count always returns 0!

      Any help is greatly appreciated. This was not an issue in a prior version of NT.

      Perhaps you can replicate this issue?
      Last edited by siroki; 02-12-2023, 03:10 AM.

      Comment


        #4
        Hello siroki,

        Thanks for your note.

        To clarify, in the Strategies tab of the Control Center you are adding a strategy to an Instrument List containing two or more instruments and see a value of 0 in the Ouput window for a print in OnPositionUpdate() that prints out SystemPerformance.AllTrades.Count.ToString(). Is that correct?

        If so, you could set IncludeTradeHistoryInBacktest = true; in the State.SetDefaults section of code in your script. This property determines if the strategy will save orders, trades, and execution history. This property is always defaulted to true, except when the strategy is running on the Strategies tab, then it is set to false by default.

        When you set this property to true in State.SetDefaults, add a strategy to an Instrument List containing two or more instruments, and enable it, you should see values print to the Output window. See the attached screenshot.

        See this help guide page for more information about IncludeTradeHistoryInBacktest: https://ninjatrader.com/support/help...inbacktest.htm

        Please let me know if I may asssit further.
        Attached Files
        <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


          #5
          Actually, I'm encountering the issue while backtesting using the Strategy Analyzer.

          Comment


            #6
            Hello siroki,

            Thanks for the clarification.

            Since you are backtesting the strategy in the Strategy Analyzer on an Instrument List containing multiple instruments, you could set IncludeTradeHistoryInBacktest = true; in the State == State.Configure.

            Code:
            else if (State == State.Configure)
            {
                    IncludeTradeHistoryInBacktest = true;
            }​
            See the attached screenshot demonstrating this.

            IncludeTradeHistoryInBacktest: https://ninjatrader.com/support/help...inbacktest.htm

            Please let me know if I may assist further.
            Attached Files
            <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

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            630 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            566 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X