Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Still looking for strategy enabled status

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

    Still looking for strategy enabled status

    Hello,

    I would like to perform some actions only when the strategy is enabled (e.g. sound alerts, I would like not to generate sounds as the strategy is loading, or when it's in the strategy analyzer.

    How can I determine that the strategy is enabled? I can already determine it is live realtime by checking for State.Realtime in OnStateChange().

    Ideally I would check that the strategy is both calculating realtime and enabled.

    Many Thanks, Caesar.

    #2
    Hello Caesar,

    Once a strategy reached State.Configure in OnStateChange(), the strategy has been enabled. For actions you want to trigger once at the start when a script is enabled, add the code to State.DataLoaded.


    There is no difference in the NinjaScript lifecycle between a strategy being backtested in the Strategy Analyzer and being enabled on a chart. The only difference is that the strategy will reach State.Terminated once the historical data has been processed.
    https://ninjatrader.com/support/help...fecycle_of.htm

    Should you want to know if a strategy is in the Strategy Analyzer, compare if IsInStrategyAnalyzer is true.
    https://ninjatrader.com/support/help...gyanalyzer.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Perfect, Many Thanks, Caesar.

      Comment


        #4
        Hello Chelsea,

        I ran a quick test and none of Realtime, Transition, Dataloaded runs last and the only one before the strategy starts. Those three are called multiple times. I took the log from just launching NT8 as it opened a chart.

        Something that delineates the strategy has started to run is needed. Otherwise there isn't a way to do specific things in strategy running mode vs. not.

        The log is attached.

        Many Thanks, Caesar.
        Attached Files

        Comment


          #5
          Hello Caesar,

          State.SetDefaults and State.Terminated are also called for instances used to populate the windows.

          Are you printing an instance ID to know which instance you are viewing the state of.

          See the thread below.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello Chelsea,

            Are you saying to handle Termination as that is the last event that occurred?

            Many Thanks, Caesar.

            Comment


              #7
              Hello Caesar,

              State.Terminated is the last state that a script will reach in the lifecycle.

              Many users confuse which instance is actually reaching each state.
              There will be instances that immediately become State.Terminated that are not enabled. They are used for constructing the UI.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello Chelsea,

                I did a test script and Terminated happens at the start of a Reload. I need to know when the Reload ends and realtime trade begins.

                Best, Caesar.

                Comment


                  #9
                  Hello Caesar,

                  Real-time trading begins when State is State.Realtime in OnStateChange().

                  The only way you would know a script is being reloaded and not being first enabled, is if the State becomes State.Terminated and then becomes State.Configure again.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Chelsea,

                    Many Thanks! Caesar.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    71 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    143 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    76 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    47 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    51 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X