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

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

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

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DayTradingDEMON, Today, 09:28 AM
            3 responses
            19 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Stanfillirenfro, Today, 07:23 AM
            9 responses
            23 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by George21, Today, 10:07 AM
            0 responses
            8 views
            0 likes
            Last Post George21  
            Started by navyguy06, Today, 09:28 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            8 responses
            32 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X