ArrayCopyRates used in mql4 library

 

Hello,


I have this code that works fine if called from the same script.

But if it is stored in a mq4 library ( mqr file library and a header). It does not copy the rates.

How should I use or modified this function or declare the array in the calling script in order to

get copied rates correctly. Thanks in advance.



bool copy(string symbol, int timeframe, double &array1[][6]){
int error=0;


int numberOfCopiedCandles=0;
int sleepTime=500;
numberOfCopiedCandles=ArrayCopyRates(array1,symbol, timeframe);

error=GetLastError();
if(error==4066)
{

numberOfCopiedCandles=0;
for(int i=0;i<3; i++)
{
Sleep(sleepTime);
numberOfCopiedCandles=ArrayCopyRates(array1,symbol, timeframe);
error=GetLastError();
if(error==4066)
{
numberOfCopiedCandles=0;
Sleep(sleepTime);
numberOfCopiedCandles=ArrayCopyRates(array1,symbol, timeframe);
}
}
if(i>=3 && error==4066){
return(false);
}

}

return (true);

}

 
havingfun:

Hello,


I have this code that works fine if called from the same script.

But if it is stored in a mq4 library ( mqr file library and a header). It does not copy the rates.

How should I use or modified this function or declare the array in the calling script in order to

get copied rates correctly. Thanks in advance.


Didn't u already post the exact same post? Anyway, maybe this helps (from: https://docs.mql4.com/basis/variables/formal):

MQL4-library functions imported within other modules cannot have parameters initialized by default values.

Parameters are passed by value, i.e., modifications of the corresponding local variable inside the called function will not be shown in the calling function in any way. It is possible to pass arrays as parameters. However, for an array passed as parameter, it is impossible to change values of its elements.

In the future please use the SRC button for code...