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

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!
    BertrandNinjaTrader Customer Service

    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.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ETFVoyageur, Today, 10:13 PM
                0 responses
                2 views
                0 likes
                Last Post ETFVoyageur  
                Started by guyonabuffalo, Today, 10:01 PM
                0 responses
                2 views
                0 likes
                Last Post guyonabuffalo  
                Started by cre8able, 05-09-2024, 09:15 PM
                3 responses
                21 views
                0 likes
                Last Post cre8able  
                Started by jpeep, 08-16-2020, 08:31 AM
                17 responses
                502 views
                0 likes
                Last Post notenufftime  
                Started by ETFVoyageur, 05-07-2024, 07:05 PM
                15 responses
                124 views
                0 likes
                Last Post ETFVoyageur  
                Working...
                X