Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy behavior with BarsRequired = 0

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

    Strategy behavior with BarsRequired = 0

    BarsRequired = 0 apparently doesn't mean what it says, which causes me a bit of a problem. I'd like OnBarUpdate to be called for every bar of every instrument, but that's not what it does.

    Right now, OnBarUpdate isn't called until there is data available for every instrument. Suppose I have a 10-instrument strategy with 24 months of historical data for 9 instruments, and 3 months of data for 1 instrument. I call my strategy with "BarsRequired=0" with a starting date 24 months ago. The first call to OnBarUpdate will be 3 months ago (not 24 like I want), NT7 does not call OnBarUpdate for the 21-month period where it has data for 9 instruments but not the 10th.

    I'd like "BarsRequired=0" to mean exactly that; i.e. OnBarUpdate will be called for every bar of every instrument, without regard to whether the other instruments have data available. If there is some reason you think you need to retain the current behavior, please consider a special "BarsRequired= -1" which behaves this way.

    This would also affect multitimeframe strategies. Right now, if I have a strategy which uses 1-minute and 30-minute data, OnBarUpdate is not called for the first 29-minutes of the 1-minute series, even if BarsRequired=0. This is also undesireable, it means that the first day's backtest results are impacted because the 1-minute series didn't see the entire day.

    I have strategies with a lot of instruments (i.e. 100 instruments with 1-minute bars). The strategies can handle missing data. When running with a new set of instruments, if I use an instrument which has less data available than the others, then OnBarUpdate is never called for a lot of the desired period, and it's tedious to debug because I have to inspect each instrument's historical data to figure out which instrument(s) are causing the problem.

    Thanks,
    Kevin

    #2
    Hello Kevin,

    Thank you for the comments and suggestions. Can you please share a sample script that demonstrates issues with the the current approach? If it requires a particular data set, include the details or files of this as well.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Sorry for the delayed responses.

      This is easy to replicate. I've attached a strategy TestBarsReq0 which simply prints the date & time of each call to OnBarUpdate.

      To Replicate:

      1) choose 2 symbols, one of which has data which starts after the other. I chose SPY (which always has data) and BGZ (data starts on 11/5/08).

      2) open an output window.

      3) open a new strategy analyzer window and select SPY as the primary instrument, 1-day period. Time period should cover the start date of the second instrument (I used 10/1/08 to 12/31/08). Enter the symbol of the second instrument as parameter "Symbol2" ("BGZ). Verify "Min Bars Required" = 0.

      4) Start the backtest and observe that the first call to OnBarUpdate is the start of the second instrument (11/5/08). OnBarUpdate was not called for the first instrument even though data existed and "BarsRequired" was set to 0.


      This is highly undesirable behavior. I have been working with strategies that use a lot of instruments (i.e. 100). They are designed to deal with missing bars. But nothing is called until every instrument has data, so if I add a instrument that is missing data at the beginning of the period, nothing runs until data starts for the latest-starting instrument.

      There is a similar issue when using multiple timeframes on a single instrument. If 1 timeframe is 1 min, and the other timeframe is 60 min, the first call to OnBarUpdate will be 1 hour into the first day. Definitely not what you want if you specified BarsRequired=0.

      BarsRequired=0 should mean exactly that - I want to see every bar.

      Thanks,

      Kevin
      Attached Files

      Comment


        #4
        Hello,

        This is Brett further assisting.

        Before I test this, a setting I could forsee causing your issues is when you first start the strategy what is Maximum Bars Lookback set too? If it is 256 if you set this to infinit does this resolve the issue?
        BrettNinjaTrader Product Management

        Comment


          #5
          No, that makes no difference. I'm running with MaximumBarsLookBack=256, but setting to Infinite make no difference with this issue.

          Comment


            #6
            Hello,

            I am looking into if this is expected or not expected.

            Thanks for posting the further information.
            BrettNinjaTrader Product Management

            Comment


              #7
              Hello,

              This is expected.


              All series must complete the MinBarsRequired before anything is processed. This is currently how NinjaTraders bar processing logic is designed as any other design method would cause undue errors for users accessing Closes[2][0] for example to a BarsArray that does not exist yet.

              Therefor as it stands all MarsArrays must at least have 1 value before a OnBarUpdate() is processed. There will be no change to this going forward at this time.

              Let me know if I can be of further assistance.
              BrettNinjaTrader Product Management

              Comment


                #8
                There really should be a way to get NT7 to call OnBarUpdate for every bar without regard to what other data series are doing.

                How about allowing "BarsRequired = -1" to enable that?

                Comment


                  #9
                  Hello,

                  I will submit this to development for development to possibly add in a future version of NinjaTrader.

                  Thanks again!
                  BrettNinjaTrader Product Management

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  608 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  355 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
                  560 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  561 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X