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 NullPointStrategies, Today, 05:17 AM
|
0 responses
44 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
65 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment