&& VOLMA(14)[0] < 20
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Index was outside the bounds of the array
Collapse
X
-
Baseheadz,
I don't see any reason why that would produce out of range message. It's likely some other part of the script or related to the VOLMA() indicator.
If you want help isolating which line is causing it, you can use try-catch blocks.
The most common reasons for running into this are explained here:
Ryan M.NinjaTrader Customer Service
-
It compiles fine and then when I set the strategy to true, it comes up with an error in the log.
It says:
Strategy Error on calling 'OnBarUpdate' method for strategy 'TestStrategy/ea0e7bb49a544162938e052ef65625d2': Index was outside the bounds of the array.
Comment
-
Dear Ryan,
I've the same error when trying to plot the DMIndex on a chart inside a custom strategy
There is clearly something NT doesn't like but I've no idea what!Code:DMIndex(3).Panel = 1; DMIndex(3).Lines[0].Value = Vleveldown; DMIndex(3).Lines[1].Value = Vlevelup; Add(DMIndex(3));
Cheers,
Chris
Comment
-
Hi Chris,
For this type of error, you can use try-catch to identify what is contributing.
What if you switch the order of your Initialize() statements so that the Add() is before the others.
Code:Add(DMIndex(3)); DMIndex(3).Panel = 1; DMIndex(3).Lines[0].Value = 3; DMIndex(3).Lines[1].Value = 3;
Last edited by NinjaTrader_RyanM1; 11-15-2011, 09:21 AM.Ryan M.NinjaTrader Customer Service
Comment
-
Hi Ryan,
Indeed I always wondered why the add came at the end and not at the beginning of the statement.
I took my cue from here http://www.ninjatrader.com/support/f...ead.php?t=3228 but I prefer your logic of starting with the add.
I'll test because the DMIndex generates out of memory exception in my custom strategy (and not the RSI which is strange because the DMIndex is very close to the RSI).
Cheers,
Chris
Comment
-
preventing index out of range problems
One approach that often works is to make sure that the DataSeries or other type of array contains enough elements so that what you are trying to do can actually happen. For example, if you are using if(Risng(Values[0])) as a condition, don't do it unless Values[0].Count >=2, because if an array has less than 2 elements, Rising and Falling are meaningless.
Sometimes the errror occurs during startup when your array is empty, ie contains no elements and has a Count property of zero.. So for anything that accesses an array called MyArray, using if(MyArray.Count>3) as an enabling condition before trying to access a value of the array will take care of that condition.
Or before accessing the value for b bars back , check that MyArray.ContainsValue(b) is True.
If b is negative you can have problems. Unless you take special precautions and are more than b bars back from the CurrentBar, the value you are looking for will not exist. Avoid doing this.Last edited by Ricam; 11-15-2011, 12:21 PM.
Comment
-
Thank you Ricam, I am truly a newbee and I don't think I am using array in my custom strategy, just some basics indicators like RSI or MACD.
In any case thank you for your advice, I need to pay closer attention to some of my conditions to avoid some of the loopholes re failing, crossabove, etc.
cheers, chris
Comment
-
A related problem sometimes happens when you don't exclude some opening bars that produce invalid values. This is the unstable period of the indicator. An example would be looking for the value of a 14 period MA when the CurrentBar is less than 14.
So, let's say you have an indicator that uses two moving averages with periods Fast and Slow. A generally safe approach is to avoid those bars by starting OnBarUpdate with
Sometimes there will be errors only when CurrentBar is -1 or 0, and only those values need to be excluded. It's good to have your catch block print out the CurrentBar value as well as the error message to help narrow this down.Code:if(CurrentBar < Math.Max(Fast,Slow) ) return;
Last edited by Ricam; 11-16-2011, 07:22 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by sjsj2732, Yesterday, 04:31 AM
|
0 responses
36 views
0 likes
|
Last Post
by sjsj2732
Yesterday, 04:31 AM
|
||
|
Started by NullPointStrategies, 03-13-2026, 05:17 AM
|
0 responses
287 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
287 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
133 views
1 like
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
95 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|

Comment