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

Error only for Optimization, Accessing an index out of range

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

    Error only for Optimization, Accessing an index out of range

    Hi, I keep getting this error running the Backtest type "Optimizer" on my strategy, however a "Standard" run works just fine.

    Indicator 'ATR': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    Strategy 'Algo1': Error on calling 'OnBarUpdate' method on bar 145: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    I am using " if (CurrentBar < X) { return;} " in OnBarUpdate(). Note that the 145 in the output/error log is +1 the value I use for X. I am running the most recent version of NT8 and have tried running this particular strategy on multiple PCs and have the same problem.

    Was there an update recently to the ATR indicator maybe or something else because this code used to be able to run the Optimizer without an issue. Or maybe it there some variable persistence issue with the optimizer? I am able to get

    Any help diagnosing would be greatly appreciated!

    Thanks,
    John

    #2
    Solved. Had to check "Optimize Data Series" box for some reason it works even though I'm not using it as a variable to iterate over

    Comment


      #3
      Hello John,

      Thanks for your posts.

      I do not think those issues would be fixed by checking "Optimize Data Series." Those errors are more related to an indexing issue where you are trying to access something that is not there. Typically this is seen when a calculation is made looking back so many bars before those bars have been processed. (This is where we make CurrentBar checks.)

      There could have been an issue where the strategy was not compiled to include this check, or the issue may have been due to another type of indexing issue. For example, referencing an array or dictionary that does not have an element at the index being accessed. If the issue is unrelated to needing a certain number of bars, I may suggest adding debugging prints to find out which line is throwing the error to learn more about the issue.

      More information relating to CurrentBar checks and indexing errors relating to not enough bars being available can be found here - https://ninjatrader.com/support/help...nough_bars.htm

      Debugging tips can be found here - https://ninjatrader.com/support/help...script_cod.htm

      If there is anything else we can do to help, please let us know.
      JimNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      4 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Started by alifarahani, Today, 09:40 AM
      6 responses
      40 views
      0 likes
      Last Post alifarahani  
      Started by Waxavi, Today, 02:10 AM
      1 response
      18 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by Kaledus, Today, 01:29 PM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X