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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    36 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    14 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    22 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X