Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index was outside the bounds of the array

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

    Index was outside the bounds of the array

    I'm getting this error after an update or out of the blues!
    How do I get rid of it!

    Log: "Error on calling 'OnBarUpdate' method on bar 136691: Index was outside the bounds of the array"

    #2
    Hello johnnybegoode,

    This means an invalid index was used.

    With the error:
    "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"
    This message indicates an invalid index was used.

    As one example, calling Close[1] when CurrentBar is 0 (the very first bar) will cause this error.
    The reason for this is because there will not be a bar ago; essentially there is not enough data at bar 0 look back one bar.
    The script will start from the far left of the chart at the very beginning where the CurrentBar will equal 0 and then start working to the right, calling OnBarUpdate() for each bar.
    In this specific example, it would be needed to wait for the second bar to be built (from all series if there are multiple series added), to ensure that you have enough data to call a index 1 bar ago.
    This is especially important when multiple series are added to a single script as the data for all series may not start at the same time.
    Below is a link to the help guide on this specific example of an indexing error.

    Also, below are links to the help guide on CurrentBar and CurrentBars.



    Indexing errors can also occur when using an invalid index with arrays or collections.
    Below are public links to 3rd party educational sites on arrays and index out of range errors.



    What was the exact index you tried to use that was invalid?

    Did you ensure the Count of that object is equal to or greater than the index used?
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    560 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    325 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X