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

Error on calling 'OnBarUpdate' method for indicator on bar...

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

    Error on calling 'OnBarUpdate' method for indicator on bar...

    Hi,

    I very often get this error while compiling an indicator and I don't know what to do. Any idea what I'm doing wrong?

    Error on calling 'OnBarUpdate' method for indicator 'MyIndicator' on bar x: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    Thanks.

    #2
    Hello,

    Thank you for the question.

    The error:
    Error on calling 'OnBarUpdate' method for indicator 'MyIndicator' on bar x: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    is fairly specific to using a BarsAgo before that number of bars has been processed or is on the chart.

    An example could be checking the close of 2 bars ago Close[2], this is valid but if this is used on bar 0 or bar 1, it will produce an error. This is because on bar 0 and 1, 2 bars ago would be -2 and -1 which are not valid or above 0 the first bar.

    To correct this, the most simple way is to look through the code and find the largest number of BarsAgo you used and prevent the script from processing until that many bars has been processed.

    An example would be if you had used 5 bars ago, you could use:

    Code:
    if(CurrentBar < 5) return;
    and place this right in the top of the OnBarUpdate method.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,607 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    9 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    19 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    6 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    15 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X