Array out of range - unique

 

I know this error has been discussed many times but the ones I saw dealt with indicators and did not really address my problem.

Can anybody tell me why the following code in my EA gives an "Array out of range" error?

for (int j = 0; j < WPR_MAPeriod; j++)
         {
            WPRArray[j] = iWPR(NULL, WPR_Timeframe, WPR_Period, j);
         }
         double WPR_Average = iMAOnArray(WPRArray, 0, WPR_MAPeriod, 0, WPR_MAMethod, 0);
         
         Text = DoubleToString(WPR_Average, 0);

According to the journal the error is on this line double WPR_Average = iMAOnArray(WPRArray, 0, WPR_MAPeriod, 0, WPR_MAMethod, 0);

 
Incomplete code.
 

Hi,

The code is incomplete,

So i think the problem is this variable that you should resize it first before passing it to For loop:

ArrayResize(WPRArray,WPR_MAPeriod);
 

Regards.

 
Mehrdad Jeddi:

Hi,

The code is incomplete,

So i think the problem is this variable that you should resize it first before passing it to For loop:

Regards.

That's it! Now it works!

THANK YOU so much!!!

 
Ernest Klokow:

That's it! Now it works!

THANK YOU so much!!!

You're welcome.

Reason: