Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling 'OnBarUpdate' method

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

    Error on calling 'OnBarUpdate' method

    Hello,

    I get 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."

    I thought that, like in NT7, this error should solved with the code

    if(CurrentBar < MinNumBars)
    return;

    But in NT8 it continues appering. Trying to fix it MinNumBars is bigger than the highest BarsAgo period. But no success.

    #2
    Hello guillembm,

    Thank you for your post.

    This error message indicates that you are trying to access an invalid index in your script. Do you still see the indexing error occur if you set your CurrentBar check to be

    if (CurrentBar < 0)
    return;

    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 to 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 an index 1 bar ago.

    Indexing errors can also occur when using an invalid index with arrays or collections. Below is a public link 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.


    Ultimately, debugging steps should be taken to monitor the strategy to determine why an action has been taken or has not been taken. Prints need to be added above each index that is being used in the same scope to determine which line contains the indexing error in your script.

    If you have further questions, please attach an exported script example demonstrating the behavior you are seeing so we may further investigate.

    I've included some tips for debugging below.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    Debugging in the Strategy Builder - https://drive.google.com/file/d/1mTq...w?usp=drivesdk

    Debugging Demo - https://drive.google.com/file/d/1rOz...w?usp=drivesdk

    Please let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by inanazsocial, Today, 01:15 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    10 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    2 views
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Working...
    X