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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    82 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    43 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Working...
    X