Hello forum, good day.
I need help identifying why am I getting an Array Out of Range error so I can solve this. What I'm trying to do is to move right and left 'N' number of bars from a certain point in a Moving Average. The problem occurs 10 bars or so after starting the Strategy Tester. I have tested the code that moves to the right from a certain point in the MA(7) (commented the code that moves to the left) and the Strategy Tester runs without any problem, but when I test the code that moves to the left is when the error happens. Your help will be much appreciated.
The coloured line is the one that triggers the Array Out of Range error. So far, I assume that the error has to do with the limit I'm setting for that loop. Here is the code:
Best regards and thank you in advance,
Gerardo
I always solve these things like so:
But you might want to re write some stuff in a way that you have two blocks that cover two directions in stead of trying to use one block to cover two directions.
Thanks a lot for the tips Marco, I'll give it a try.
Well i removed it since it was not the correct solution it will still first hit the out of range and then try to reset the value so that does not work it only works for counts without array.
You could at least try
ArrayResize( MA_Value, Bars);
But if it is trying to read negative value it will still give the error so you have to make sure the value exists before trying to read it.
// Move left from the valley for ( j = i_valley; j < wave_limit; j++ ) { if(j<0){j=0;}if(i_valley<0){i_valley=0;} Range_Left = NormalizeDouble( ( MA_Value[j] - MA_Valley[i_valley] ) / Point, Digits ) / PipFactor; // Print( "i: ", i, ". j: ", j ); // Print( "Range Left: ", Range_Left ); if ( Range_Left >= Threshold ) { fnDrawDot( "Wave range left " + j, Time[j], MA_Value[j], 159, 20, "Wingdings", clrBlack ); break; } }
But that also can not work since you are using j in a loop... so if you modify j you infect the loop.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello forum, good day.
I need help identifying why am I getting an Array Out of Range error so I can solve this. What I'm trying to do is to move right and left 'N' number of bars from a certain point in a Moving Average. The problem occurs 10 bars or so after starting the Strategy Tester. I have tested the code that moves to the right from a certain point in the MA(7) (commented the code that moves to the left) and the Strategy Tester runs without any problem, but when I test the code that moves to the left is when the error happens. Your help will be much appreciated.
The coloured line is the one that triggers the Array Out of Range error. So far, I assume that the error has to do with the limit I'm setting for that loop. Here is the code:
Best regards and thank you in advance,
Gerardo