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 not incrementing

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

    SystemPerformance.AllTrades.Count not incrementing

    Hello,

    I've been using the following code (and the NT7 equivalent before NT8) as part of my money management strategy for years now. It works perfectly as long as a strategy is only applied to a single currency pair. However, a strategy that I am currently testing was profitable on four different currency pairs; for the sake of simplicity, I started forward-testing on only two.

    When a strategy is applied to more than one currency pair in real-time (sim101 account for starters), it appears that SystemPerformance.AllTrades.Count never increments, even if both instances of the strategy have opened and closed multiple trades. I have applied the strategy in question to a single currency pair and the following code works as expected. Also, I have set IncludeTradeHistoryInBacktest = true.

    With that in mind - is there a way to tweak the following code to retrieve a count of trades for that strategy for a particular symbol/currency pair? If not, or if that isn't the cause - any ideas why it might not be counting?

    Here is the basic code layout:
    if (SystemPerformance.AllTrades.Count > 0)
    {
    Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];

    double lastProfit = lastTrade.ProfitCurrency;
    //Use this value to calculate lot sizing - if profit was >= 0, do something, else do another thing
    }
    else
    {
    //Default lot size here --> THIS SECTION ALWAYS TRIGGERS
    }

    Thank you.

    #2
    Hello UglyHack,

    Thanks for your post.

    Strategies run separate instances of each other so you will not see SystemPerformance.AllTrades.Count increase for trades made with a separate instance of that strategy.

    If you would like to share information between NinjaScripts, you could consider reading/writing that information to/from file, or you may wish to use static variables in the AddOn namespace that your strategy instances can use. These approaches will allow the strategies to "share information" with each other.

    Some publicly available examples can be found below.

    Using a StreamReader - https://ninjatrader.com/support/help...o_read_fro.htm

    Using a StreamWriter - https://ninjatrader.com/support/help...o_write_to.htm

    Writing to static variables in the AddOn namespace (User Defined Methods for NT8) - https://ninjatrader.com/support/foru...ument-backtest

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,

      While interesting and likely useful in the future (likely VERY useful), that actually is the opposite of what I want right now.

      What I'm currently seeing: when a strategy is applied to two different currency pairs at the same time, SystemPerformance.AllTrades.Count does NOT increment.
      When the same strategy is applied to only one currency pair, SystemPerformance.AllTrades.Count DOES increment as expected.

      So my question is: why doesn't this increment when running the strategy on two different currency pairs at the same time? It sounds like that isn't expected, so maybe I found a bug... But I'm hoping that a minor adjustment to my code will clear it up.

      Thank you.

      Comment


        #4
        Hello UglyHack,

        So I understand correctly, you are saying that when you apply instances of your strategy to other instruments (have multiple instances of the strategy running) the strategies do not increment SystemPerformance.AllTrades.Count?

        I may suspect an issue where the strategy is not making trades if this is the case. Can you confirm that you are able to reach your order submission methods using prints and that you see order feedback with TraceOrders enabled?

        Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

        Trace Orders - https://ninjatrader.com/support/help...aceorders2.htm

        I have attached a demonstration and a sample script which is a clone of the SampleMACrossover strategy that prints SystemPerformance.AllTrades.Count. I do not have an issue with this test script.

        Demo - https://drive.google.com/file/d/1O8z...w?usp=drivesdk

        Let me know if you are seeing ill behavior with the test script or if you have any questions on the debug output.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello Jim,

          I have tried implementing the strategy you uploaded on the Sim101 account on two currency pairs. The problem persists - after a successful open/close/open, the SystemPerformance.AllTrades.Count printout remains zero.

          My original strategy successfully opened trades and managed stops (including trailing) and profit levels as well. The only issue was that it didn't increment this counter.

          So if you, on your system, apply this strategy during real-time trading (Sim101 account, NOT backtesting) to both EURUSD and, say, GBPJPY - it increments the counter after a trade is completed? I'm on version 8.0.15.1 64-bit. Do you have a newer version?

          Comment


            #6
            Hello UglyHack,

            When I enable the strategy against the Sim101 account, SystemPerformance.AllTrades.Count increments with each historical trade and then continues to update with each realtime trade made.

            The current release is 8.0.16.3. If you are having issues with the test script, I may be suspect of an issue involving the installation or the connection.

            Please make sure you are on the latest version, and if you do not see the behavior in my demo when running the test script, please send me a message at platformsupport [at] ninjatrader [dot] com so we can arrange a time to get connected and investigate further.

            New installers can be downloaded here.

            I look forward to being of further assistance.
            JimNinjaTrader Customer Service

            Comment


              #7
              Where did the "thank you" button go?
              Anyway, for anyone else who has a similar issue: it looks like this was caused by a bug or glitch in a saved workspace. Removing that workspace and re-applying the strategy from a clean start appears to have resolved it.

              Comment


                #8
                Thanks for the comment UglyHack. The "Thank you" button is replaced with a "Like" button in this version of vBulletin.

                I'm glad you are back up and running. If you have any other issues please don't hesitate to open a new thread.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                26 views
                0 likes
                Last Post wzgy0920  
                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
                192 views
                0 likes
                Last Post Hasadafa  
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,235 views
                0 likes
                Last Post xiinteractive  
                Working...
                X