Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index out of range with longer span of data

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

    Index out of range with longer span of data

    I get this error:
    Code:
    Strategy 'AIT_NIDFS_EO_210718': Error on calling 'OnBarUpdate' method on bar 42435: 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.
    But ONLY when running with longer span of data. What I mean.
    My generic backtest is from 1st of June, 2019 to 1st of June, 2021 (2 years).

    At exactly 14th of March, 2020 it gives me the error posted above. I used prints, but still unable to find, where the problem lies. What is weird, that I tested the following:
    1) 13th of March, 2020 - 15th of March, 2020 (1 day before and 1 day after error) - no error.
    2) 1st of January, 2020 - 1st of July, 2020 (Half a year, in between of which the error supposedly should occur) - no error.

    So what can be wrong?

    #2
    What is even more interesting.

    I continued on trying to 'catch' an error with Prints and basically insert Print code at first before every new region in OnBarUpdate method, and then, after I caught where it stops printing - after every line within that region.

    And you know what? That action of adding lines of Print code (without any other code alteration) got the script to work without an error? So it's double weird. What could cause that?

    Comment


      #3
      Hello UltraNIX,

      Thank you for your note.

      Are you sure you didn't modify anything other than adding prints?

      Does your script use any try/catch statements?

      Without further detail it'd be hard for us to say why adding prints appears to be letting the script work properly.

      Thanks in advance; I look forward to assisting you further.

      Comment


        #4
        Originally posted by NinjaTrader_Kate View Post
        Hello UltraNIX,

        Are you sure you didn't modify anything other than adding prints?
        Yes. That was also weird to me. By the way, it's with modification of IntradayFlags strategy. And again, it's just before bse (barssinceentryexecution) code I struggled to get to work before.

        Also, in order not to slow backtesting performance, I added if (CurrentBar > 30000), then add Print. And, as expected, it worked. I tested on 3 different periods and all worked fine just with one line of Print in correct place. Again, it's still weird.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X