Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT loads strategy before interval change

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

    NT loads strategy before interval change

    create a strategy with the following code only

    Print("Current strategy chart is a "+BarsPeriod.Value+" "+BarsPeriod.Id);

    load the cs to a 1 min chart

    it will print 'Current strategy chart is a 1 Minute'

    change the interval to a 1000 volume

    it will print 'Current strategy chart is a 1 Minute'

    change the interval to a 60 second

    it will print 'Current strategy chart is a 1000 volume'

    Clearly NT runs the strategy BEFORE it changes the interval

    so what? well if you are checking the BarsPeriod.Value and BarsPeriod.Id before adding a barseries, you will get the wrong information and add or not add the barseries

    Obviously the fix is to F5 refresh the chart after changing the interval to make sure you are adding the barseries

    Question: why does NT not add the strategy AFTER changing the interval? Seems to me if the user wants to change the interval then the user wants the strategy run on the new interval and not on the old interval

    #2
    Hi ATI user, the Initialize() can be called several times, so that's why you see old values...do you see this after moving the code in the OnBarUpdate()? Thanks!

    Comment


      #3
      no point checking in OnBarUpdate method since I can not add a barseries from there

      Comment


        #4
        I also note that, in a blank chart, when I right click and select Strategies, NT runs the last strategy that was in the chart before I even select one in the list

        Why?

        Comment


          #5
          the problem is worse than I thought

          if you open a workspace that has a 60 second chart and

          1. right click in the chart and select Strategies....it prints '1 min...'

          2. select your strat from the list....it prints '1 min...'

          3. click OK/load your cs...it prints '1 min...'

          4. refresh the chart....it prints '60 sec...'

          if you forget to do the refresh, you are trading a different cs than you thought you were

          Comment


            #6
            ATI user,

            You should never drive any logic from Initialize(). Prints from there will be executed several times. This is expected.

            If you change the period, and run the strategy it will be running on the correct series. Just print from OnBarUpdate.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              ATI user,

              You should never drive any logic from Initialize().
              thanks Josh

              moved the prints

              when you say "...any logic...." I assume you do not mean logic that checks BarsPeriod.Id in order to add barseries??

              I thought Add needed to be done in Initialize

              Comment


                #8
                Correct, as the Initialize() is just for configuring settings like adding plots, series and for example the CalculateOnBarClose setting...so with the Add() there and the Print / BarsPeriod logic in the OnBarUpdate() it should work as expected.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                633 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                364 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                567 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                568 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X