Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Accessing an index with a value that is invalid
Collapse
X
-
Accessing an index with a value that is invalid
So i ran this strategy in market play back just 2 days ago and everything was working fine. Since then the only thing i've done is downloaded more days of market data. Anything you can think of that would cause this error now when i try to start the strategy in market replay? I haven't changed any of the code at all.
Tags: None
-
Here is a bit more information... this is what i'm finding on debugging
Here is the code snippets
I am getting the error on the last line of code that there for the isFirstCandleRed. I dont understand why the strategy worked yesterday though.Code:protected override void OnBarUpdate() { if (CurrentBars[0] < 2 && CurrentBar >= ema.Period/*|| CurrentBars[1] < 2*/) return; double emaValue = ema[0]; //Entry Criteria for Longs bool isFirstCandleRed = Close[2] < Open[2]; // Check if the first candle is red[/COLOR]
The strategy is basically trying to look at the prior two candles, and then entry is on the third candle.Last edited by sofortune; 06-08-2024, 12:15 PM.
-
Hello sofortune,
The condition you have to return looks strange, if you need 2 barsago your condition should look like this assuming you used AddDataSeries to add a secondary series:
if (CurrentBars[0] < 2 | CurrentBars[1] < 2)
return;
That makes sure both series have at least 2 bars which would be needed because the code you are using will be executed for both series. If you did not use AddDataSeries and this is a single series script it would be:
if(CurrentBar < 2) return;
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
87 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
132 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
65 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
118 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
67 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|

Comment