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

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.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by lightsun47, Today, 03:51 PM
    0 responses
    5 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    8 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    44 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    13 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    9 views
    0 likes
    Last Post port119
    by port119
     
    Working...
    X