Announcement

Collapse
No announcement yet.

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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      134 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      67 views
      0 likes
      Last Post PaulMohn  
      Working...
      X