Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator not workiing

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

    Indicator not workiing

    I have a simple indicator that requires 5 or more bars. however when i add indicator nothing happens(no plot) and get the below error in the output window. The same exact window works very fine on some other charts. I did verify the current chart has many bars, infact more days worth of 30min bars. please help.

    Indicator 'jBar': 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.

    #2
    Hello chakriare,

    Thanks for your post.

    What happens when you load an indicator is that it will start processing, on a bar by bar basis, from the very beginning of data that is loaded in the dataseries of the chart, so if you have 5 days of data the indicator will start on the first bar 5 days ago.

    If the code logic looks for a previous bar it will fail on the first bar (count starts at 0) as there is no previous bar. An example of looking at a prior bar would be: if (Close[0] > Close[1]) where 1 represents a prior bar.

    To work around the initial loading you can use a check of the current bar number as the first statement in the OnBarUpdate() method. for example:

    if (CurrentBar < 5) return; // do not process until 5 bars loaded

    It is possible, depending on the code logic you may need more or less than 5.

    Please review: http://ninjatrader.com/support/helpG...currentbar.htm

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    599 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    344 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    557 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X