Finally, I looked at bar 44 but didn't find anything wrong with it.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Indicator error "outside the bounds of the array"
Collapse
X
-
Indicator error "outside the bounds of the array"
I'm writing an indicator. When I apply it to a price chart, I get this error:
Which array does it refer to? Setting:Error on calling 'OnBarUpdate' method on bar 44: Index was outside the bounds of the array.inMaximumBarsLookBack = MaximumBarsLookBack.Infinite;does not solve this issue.State.SetDefaults
Finally, I looked at bar 44 but didn't find anything wrong with it.Tags: None
-
Hello Gianpiero,
Thanks for your post.
This means an invalid index was used somewhere in your script.
For example, with the error:
"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"
This message also indicates an invalid index was used.
As one example, calling Close[1] when CurrentBar is 0 (the very first bar) will cause this error.
The reason for this is because there will not be a bar ago; essentially there is not enough data at bar 0 look back one bar.
The script will start from the far left of the chart at the very beginning where the CurrentBar will equal 0 and then start working to the right, calling OnBarUpdate() for each bar.
In this specific example, it would be needed to wait for the second bar to be built (from all series if there are multiple series added), to ensure that you have enough data to call a index 1 bar ago.
This is especially important when multiple series are added to a single script as the data for all series may not start at the same time.
Below is a link to the help guide on this specific example of an indexing error.
https://ninjatrader.com/support/helpGuides/nt8/make_sure_you_have_enough_bars.htm
Also, below are links to the help guide on CurrentBar and CurrentBars.
https://ninjatrader.com/support/helpGuides/nt8/currentbar.htm
https://ninjatrader.com/support/helpGuides/nt8/currentbars.htm
Indexing errors can also occur when using an invalid index with arrays or collections.
Below are public links to 3rd party educational sites on arrays and index out of range errors.
Ultimately, debugging prints would have to be added to your script that prints out each index you are accessing in your script along with the CurrentBar to find the exact line of code in your script causing the error. Note that CurrentBar must be greater than or equal to the index you are accessing in the script and negative indexes cannot be accessed.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121Last edited by NinjaTrader_BrandonH; 10-30-2023, 07:35 AM.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Hello Gianpiero,
Thanks for your notes.
I have updated the links in post # 2 and also shared the link below.
Below is a link to the help guide on this specific example of an indexing error.
https://ninjatrader.com/support/helpGuides/nt8/make_sure_you_have_enough_bars.htm
Also, below are links to the help guide on CurrentBar and CurrentBars.
https://ninjatrader.com/support/helpGuides/nt8/currentbar.htm
https://ninjatrader.com/support/helpGuides/nt8/currentbars.htm<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
344 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
557 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment