Error 4054, what is wrong with the following code

 

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.

 
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.

 
angevoyageur:

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




Thank you for your reply. I will try it out.