Download MetaTrader 5
To add comments, please log in or register
Use searching on MQL5.community. It is easy!
maindoor
120
maindoor 2014.05.28 12:27 

Hi,

I get incorrect series array using (error 4054) in the sleep below, most of the time.

Am I doing the return handling correctly ? I have code like this:

MqlRates rates[];
int copied;
ArraySetAsSeries(rates, true);     

for(int j=50; j>0; j--) {  
  ResetLastError();
  copied = CopyRates(EURUSD, PERIOD_M15, 1, 20, rates);
  int lastError = GetLastError();
  if (lastError == ERR_NO_MQLERROR ||
  lastError == ERR_NO_ERROR) {
      break;
  } else if (lastError == ERR_HISTORY_WILL_UPDATED ||
             lastError == ERR_INCORRECT_SERIESARRAY_USING ) {
      Print("Sleeping ", lastError, " ", j);                 
      Sleep(250);
  } else {
      Alert("Fatal Error ", lastError, ":", ErrorDescription(lastError));   
      return 0;
  }
}

Thanks.

Alain Verleyen
Moderator
28701
Alain Verleyen 2014.05.28 19:42  
maindoor:

Hi,

I get incorrect series array using (error 4054) in the sleep below, most of the time.

Am I doing the return handling correctly ? I have code like this:

MqlRates rates[];
int copied;
ArraySetAsSeries(rates, true);     

for(int j=50; j>0; j--) {  
  ResetLastError();
  copied = CopyRates(EURUSD, PERIOD_M15, 1, 20, rates);
  int lastError = GetLastError();
  if (lastError == ERR_NO_MQLERROR ||
  lastError == ERR_NO_ERROR) {
      break;
  } else if (lastError == ERR_HISTORY_WILL_UPDATED ||
             lastError == ERR_INCORRECT_SERIESARRAY_USING ) {
      Print("Sleeping ", lastError, " ", j);                 
      Sleep(250);
  } else {
      Alert("Fatal Error ", lastError, ":", ErrorDescription(lastError));   
      return 0;
  }
}

Thanks.

Don't check for error when there is not. See CopyRates() documentation :

Return Value

Returns the number of copied elements or -1 in case of  an error.

maindoor
120
maindoor 2014.05.28 21:48  
angevoyageur:

Don't check for error when there is not. See CopyRates() documentation :




Thank you for your reply. I will try it out.
/
To add comments, please log in or register