Finally, I looked at bar 44 but didn't find anything wrong with it.
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 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:
Error on calling 'OnBarUpdate' method on bar 44: Index was outside the bounds of the array.MaximumBarsLookBack = MaximumBarsLookBack.Infinite;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.Brandon H.NinjaTrader Customer Service
-
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.htmBrandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cre8able, Yesterday, 01:16 PM
|
3 responses
11 views
0 likes
|
Last Post
by cre8able
Today, 08:28 AM
|
||
Started by ChartTourist, Today, 08:22 AM
|
0 responses
5 views
0 likes
|
Last Post
by ChartTourist
Today, 08:22 AM
|
||
Started by LiamTwine, Today, 08:10 AM
|
0 responses
2 views
0 likes
|
Last Post
by LiamTwine
Today, 08:10 AM
|
||
Started by Balage0922, Today, 07:38 AM
|
0 responses
5 views
0 likes
|
Last Post
by Balage0922
Today, 07:38 AM
|
||
Started by JoMoon2024, Today, 06:56 AM
|
0 responses
6 views
0 likes
|
Last Post
by JoMoon2024
Today, 06:56 AM
|
Comment