Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 Bug? Object loosing reference after reload strategy

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

    NT8 Bug? Object loosing reference after reload strategy

    Object loosing reference after reload strategy - please load the attached test indicator (MyTestIndicator.cs) to a chart, then add/enable the test strategy (MyTestStrategy.cs).
    It all works without an error - so far so good.

    Then please see the attached video (gif) - I simply do a change in a print code line and recompile (shouldn't change anything for the functionality).
    After that re-enabling/disabling the test strategy forces an error (see output window)!
    Attached Files

    #2
    Why not use AddChartIndicator?

    Comment


      #3
      Hi bltdavid - using AddChartIndicator here is unfortunately not an option.

      Comment


        #4
        What is happening here is that when you recompile, it recompiles EVERYTHING including all the strategies and indicators. What you have done is you have an indicator running in the "old universe" on the chart, but then you recompiled both the indicator and the strategy, and then statused JUST THE STRATEGY off and back on (you did not refresh the indicator), so the strategy is trying to read the indicators on the chart but the TYPE of the old indicator on the chart (still running from before the recompile) is not a match to the NEW TYPE of the indicator after recompiling because the newly recompiled indicator is in a different custom assembly (just re-generated) than the old one was (still running, but since replaced).

        When you recompile, you must refresh the chart so the indicators running on the chart will be the new ones, the ones after the recompile.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          "When you recompile, you must refresh the chart so the indicators running on the chart will be the new ones, the ones after the recompile."


          Remove and re-add indicator(s) and strategies?
          So new Chart and add indicator(s) and strategies?

          Restart of Ninja appeared to work but that is more than I prefer.

          Comment


            #6
            No, just hit F5 on the chart and that will reload both the indicator and the strategies for that chart.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #7
              F5 was not sufficient

              Comment


                #8
                It was sufficient here when I ran your example just like in the video. You have to do it AFTER you recompile, on the chart in question. You do not have to disable your strategy first, but you need to answer yes to the prompt that asks about restarting the running strategy.

                You should assume that when you have recompiled, nothing that was running before the recompile will be accessible.
                Last edited by QuantKey_Bruce; 05-08-2023, 05:27 PM.
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #9
                  that was @1729-heart's sample.


                  My issue was subscription to event was moved from

                  (State == State.DataLoaded) ///We may not be realtime just yet
                  to
                  (State == State.Realtime)

                  Further there are several globals set between indicator, strategy and AddOn

                  Globals Declaration(ownership) was moved to the AddOn





                  Snippet
                  else if (State == State.Realtime)
                  {
                  Print("Strategy InstanceID " + InstanceId + " State:" + State);

                  BartGlobals.SetStrategy(InstrumentName, this);

                  PrintStatic = Print;

                  Account.ExecutionUpdate -= AccountOnExecutionUpdateStatic;
                  Account.OrderUpdate -= AccountOnOrderUpdateStatic;

                  Account.ExecutionUpdate += AccountOnExecutionUpdateStatic;
                  Account.OrderUpdate += AccountOnOrderUpdateStatic;
                  }
                  else if (State == State.Terminated)
                  {
                  if (sw != null)
                  {
                  sw.Close();
                  sw.Dispose();
                  sw = null;
                  }

                  Account.ExecutionUpdate -= AccountOnExecutionUpdateStatic;
                  Account.OrderUpdate -= AccountOnOrderUpdateStatic;
                  }​






                  Comment


                    #10
                    Okay, or if I could suggest, you might want to use State.Transition instead of State.Realtime because if you start it up outside of trading hours e.g. you start it on Sunday at Noon, it won't reach State.Realtime yet.
                    Bruce DeVault
                    QuantKey Trading Vendor Services
                    NinjaTrader Ecosystem Vendor - QuantKey

                    Comment


                      #11
                      Wow, Great catch/call on Transition.

                      Thank You.

                      Comment


                        #12
                        Hello Heart,

                        Thanks for your post.

                        QuantKey_Bruce is correct. When a compile is made all NinjaScripts on the platform will be compiled (indicators, strategies, etc), not just the individual script that you edited.

                        Once you made changes to a script and recompile, you should reload the NinjaScripts on the Chart by pressing the F5 key on your keyboard or by right-clicking on the Chart window and selecting the 'Reload NinjaScript" option. The 'Reload NinjaScript' option will remove the existing instance of the indicator or strategy and add a new instance of the indicator or strategy in the chart.
                        Brandon H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by sofortune, 06-13-2024, 02:31 AM
                        3 responses
                        23 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by GodAtum, Today, 09:52 AM
                        11 responses
                        25 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by TheTechnician86, Yesterday, 10:44 PM
                        2 responses
                        13 views
                        0 likes
                        Last Post TheTechnician86  
                        Started by flonkle, Today, 01:19 AM
                        4 responses
                        29 views
                        0 likes
                        Last Post flonkle
                        by flonkle
                         
                        Started by WHICKED, 06-27-2023, 12:07 PM
                        83 responses
                        864 views
                        1 like
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X