Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy enable/disable event

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

    strategy enable/disable event

    hi all,

    I need to keep state of some variables starting from the point in which a strategy is enabled during which I need to initialize/reset these variables. I am not sure if this code should go in the Initialize method as I am not sure exactly on what user events does the initialized method get called.

    Onn

    #2
    The Initialize() method is called during various times, even if the indicator/strategy you're using is not being called.

    For Variables you wish to calculate at start up, we suggest using the OnStartUp() method for these values as this will only be called when that instance of the strategy is called:

    MatthewNinjaTrader Product Management

    Comment


      #3
      So if the user does the following:

      1. Enable strategy
      2. Disable strategy
      3. Enable strategy

      Will On StartUp will be called twice (1 and 3)?
      Onn

      Comment


        #4
        Correct - it would be called each time the strategy was Enabled.
        MatthewNinjaTrader Product Management

        Comment


          #5
          sweet - and I assume I would have the Bars object available/ready with OnStartUp where as with Initialize it is not available yet.

          Onn

          Comment


            #6
            Yes, indeed. It's called on CurrentBar(s) = 0
            MatthewNinjaTrader Product Management

            Comment


              #7
              Originally posted by onnb1 View Post
              So if the user does the following:

              1. Enable strategy
              2. Disable strategy
              3. Enable strategy

              Will On StartUp will be called twice (1 and 3)?
              Onn
              These are very simple things to determine:

              Code:
              //Variables
              public int startup_cnt = 0;
              public int init_cnt = 0;
              
              
              	protected override void OnStartUp()
                      {
                            startup_cnt ++;
                            Print ( "OnStartUp() Called!  cnt=' + startup_cnt );
                     }

              Comment


                #8
                true
                I just like to know what is the expected behavior and see that the actual behavior is the same.

                Onn

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X