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

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.
    Create and loop over a string array. Access array Length and get elements at indexes.



    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 andrewtrades, Today, 04:57 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    5 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    7 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X