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.

    https://www.dotnetperls.com/array

    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 sambathraj, Today, 07:46 PM
    0 responses
    4 views
    0 likes
    Last Post sambathraj  
    Started by topa11, Today, 12:52 PM
    2 responses
    32 views
    0 likes
    Last Post topa11
    by topa11
     
    Started by torento, Yesterday, 05:43 PM
    4 responses
    82 views
    0 likes
    Last Post torento
    by torento
     
    Started by sprks7979, Today, 05:59 PM
    0 responses
    25 views
    0 likes
    Last Post sprks7979  
    Started by intelligenttrader, 09-11-2022, 06:02 PM
    8 responses
    230 views
    0 likes
    Last Post Lance El Camino  
    Working...
    X