Array out of range - unique

To add comments, please log in or register
Ernest Klokow
1201
Ernest Klokow  

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);

Marco vd Heijden
Moderator
12404
Marco vd Heijden  
Incomplete code.
Mehrdad Jeddi
27935
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:

ArrayResize(WPRArray,WPR_MAPeriod);
 

Regards.

Ernest Klokow
1201
Ernest Klokow  
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!!!

Mehrdad Jeddi
27935
Mehrdad Jeddi  
Ernest Klokow:

That's it! Now it works!

THANK YOU so much!!!

You're welcome.

To add comments, please log in or register