Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-timeframe script halt - index value out of range

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

    Multi-timeframe script halt - index value out of range

    Hi guys,

    I'm having an issue running my script on a backtest dataset. I'm not sure if there is an issue with the script (most likely) or with my downloaded data.

    I'd like to run a year worth of backtest to analyze the data and I'm just not able to run the script on MES 06-22 (the month of May and the month of July). The script halts with the following message:

    Code:
    Strategy 'MyCoolStrategy233': Error on calling 'OnBarUpdate' method on bar 211: 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.
    The script works fine through most of June 2022.

    I have worked with Multi-timeframe strategies before and I was required to add the following as pretty much the start of my script (which I have done)

    Code:
    if (CurrentBars[0] < 201)
    {
    return;
    }
    What I'm confused about is so far the script ran through 9 1/2 months of backtest data without a problem. Is it possible that my MES 06-22 data is corrupt somehow or maybe I need to tweak my script to handle something else?

    I don't even know a starting point to address this. Hoping you have something that can point me in the right direction.

    Thanks!​

    #2
    Hello Bluebeep,

    Thank you for your post.

    You are correct that usually adding a CurrentBar (or CurrentBars for a multi-series script) is one of the ways to prevent this error from happening. We have a tip page in the help guide about making sure there are enough bars in the series you are accessing here:
    I know this may be a simple suggestion, though the error mentions the error happened on bar 211; if you change your check to see if there are at least 211 instead of 201 bars do you still get the error on the backtest?
    if (CurrentBars[0] < 211)
    {
    return;
    }
    Otherwise, you will likely need to add prints to your script to further debug which part of your script is throwing the error so you may adjust it. For example, you could add a print statement that tells you the BarsInProgress to help narrow down which series is calling OnBarUpdate() when the error occurs. It is possible that maybe it's not related to CurrentBars[0] and perhaps it's an added timeframe that is causing the error. For more info about using prints to debug your scripts:Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    76 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    146 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    79 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    50 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    54 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X