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.
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!
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
NinjaTrader
Indicator not workiing
Collapse
X
-
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.Tags: None
-
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.htmPaul H.NinjaTrader Customer Service
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
4 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
46 views
0 likes
|
Last Post Today, 12:28 AM |
Comment