Here is the method that I use: ref: this post http://www.ninjatrader.com/support/f...gun#post245553 in this thread: http://www.ninjatrader.com/support/f...gun#post245458, which unsurprisingly is about that exact error.
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 bars error "index was out of bounds of the array"
Collapse
X
-
Originally posted by CSharpTrader View Post
Here is the method that I use: ref: this post http://www.ninjatrader.com/support/f...gun#post245553 in this thread: http://www.ninjatrader.com/support/f...gun#post245458, which unsurprisingly is about that exact error.
-
I have visual studio... I'll turn there first, as annoying it can be to try to debug live indicators. I'm hoping Joydeep has additional insight, too. Print statements.... 80's debugging, the horror!! Thanks though.
Comment
-
Originally posted by CSharpTrader View PostI have visual studio... I'll turn there first, as annoying it can be to try to debug live indicators. I'm hoping Joydeep has additional insight, too. Print statements.... 80's debugging, the horror!! Thanks though.
Comment
-
Joydeep, Koganam... I've got the error line.
3rd line down after if (BarsInProgress==0):
double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025;
Hope this helps. It's more specific but I'm still at a loss..
Comment
-
Originally posted by CSharpTrader View PostJoydeep, Koganam... I've got the error line.
3rd line down after if (BarsInProgress==0):
double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025;
Hope this helps. It's more specific but I'm still at a loss..
You are trying to access BarsArray[1] (i.e., Closes[1])from a tick triggered in BarsArray[0] (i.e., BarsInProgress 0). You may simply not have enough bars in BarsArray[1] at the time of access. You may want to double check the value of BarsArray[1] at the time of the access.
Comment
-
Btw I had been struggling to get it sync'd with VS2010 the whole time, thanks for the patience..
Comment
-
I thought that's what the original check CurrentBars[1] < slowMA + 12 addressed... don't we have enough bars if that returns true?
Comment
-
Originally posted by CSharpTrader View PostI thought that's what the original check CurrentBars[1] < slowMA + 12 addressed... don't we have enough bars if that returns true?
I do not mean to be patronizing, but I have made this mistake so often myself, that I sometimes just ask to make sure: "Are you sure that you recompiled after you made the edit?"
Comment
-
No problem. Here it is in the latest form, below. Yup, recompiled (I too tend to make mistakes that are more absent- minded than higher- level). I attached the process to visual studio debug, and that line was the one that threw the out of bounds index error (despite passing the test in the initial check for # bars). I'll restart now per your suggestion. Fingers crossed. Thanks again.
Code:protected override void OnBarUpdate() { for (int index = 0; index < BarsArray.Length; index++) { if (CurrentBars[index] < (slowMA+12)) return; } if(BarsInProgress==0) { //Check for uptrend int uptrendCheckCount = 0; int countOfClosesOverSlowEma = 0; double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025; double keyPriceViolationLevelToday = EMA(Closes[1],slowMA)[0] + Math.Abs(EMA(Closes[1],slowMA)[0] - EMA(Closes[1],slowMA)[1]); for(int i=0;i<10;i++) { if((EMA(Closes[1],fastMA)[i] >= EMA(Closes[1],medMA)[i]) && (EMA(Closes[1],medMA)[i] >= EMA(Closes[1],slowMA)[i])) { uptrendCheckCount++; } if(Closes[1][i+1] >= EMA(Closes[1],slowMA)[i+1]) { countOfClosesOverSlowEma++; } } if((countOfClosesOverSlowEma==10)&&(uptrendCheckCount==10)) { if(Lows[1][0] <= keyPriceViolationLevelPriorDay) { if((Close[0] > Open[0])&&(Close[0] > keyPriceViolationLevelToday)) { Plot0.Set(1); } } } } }
Comment
-
Originally posted by CSharpTrader View PostNo problem. Here it is in the latest form, below. Yup, recompiled (I too tend to make mistakes that are more absent- minded than higher- level). I attached the process to visual studio debug, and that line was the one that threw the out of bounds index error (despite passing the test in the initial check for # bars). I'll restart now per your suggestion. Fingers crossed. Thanks again.
Code:protected override void OnBarUpdate() { for (int index = 0; index < BarsArray.Length; index++) { if (CurrentBars[index] < (slowMA+12)) return; } if(BarsInProgress==0) { //Check for uptrend int uptrendCheckCount = 0; int countOfClosesOverSlowEma = 0; double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025; double keyPriceViolationLevelToday = EMA(Closes[1],slowMA)[0] + Math.Abs(EMA(Closes[1],slowMA)[0] - EMA(Closes[1],slowMA)[1]); for(int i=0;i<10;i++) { if((EMA(Closes[1],fastMA)[i] >= EMA(Closes[1],medMA)[i]) && (EMA(Closes[1],medMA)[i] >= EMA(Closes[1],slowMA)[i])) { uptrendCheckCount++; } if(Closes[1][i+1] >= EMA(Closes[1],slowMA)[i+1]) { countOfClosesOverSlowEma++; } } if((countOfClosesOverSlowEma==10)&&(uptrendCheckCount==10)) { if(Lows[1][0] <= keyPriceViolationLevelPriorDay) { if((Close[0] > Open[0])&&(Close[0] > keyPriceViolationLevelToday)) { Plot0.Set(1); } } } } }
Comment
-
*Gulp* It's me. As per my earlier comment on stupid mistakes (aren't they all?) I didn't have the 2nd data series added in the initialize method. Sorry. I had developed this as a strategy first, and just copied over OnBarUpdate(). Big waste of time.
We're running now, with a nice new issue. Getting alerts in the alerts window that don't match my conditions expressed in the code. The Plot0.Set(1) has a breakpoint, and the instrument that hits it doesn't generate an alert, but matches my conditions, and the one that does generate an alert, doesn't match the conditions, nor does it hit the breakpoint. Glad I love writing code.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cre8able, Yesterday, 07:24 PM
|
1 response
13 views
0 likes
|
Last Post Today, 06:55 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
6 responses
939 views
0 likes
|
Last Post
by Jquiroz1975
Today, 06:51 AM
|
||
Started by gbourque, Today, 06:39 AM
|
1 response
4 views
0 likes
|
Last Post Today, 06:50 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
1 response
17 views
0 likes
|
Last Post Today, 06:16 AM | ||
Started by benmarkal, Yesterday, 12:52 PM
|
3 responses
23 views
0 likes
|
Last Post Today, 05:22 AM |
Comment