Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    579 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 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
    554 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X