MQL5 Custom indicator, error 4806

 

Hi guys,


I wrote a test indicator and every start I got an error message (CopyBuffer 4806 error), I don't know why and hope, You can help me to solve it.


The code:

int macd_handle_m5, macd_handle_m10;
double macd_values_m5[], macd_values_m10[];

int OnInit()
  {

   ArraySetAsSeries(macd_values_m5, true);
   ArraySetAsSeries(macd_values_m10, true);
   
   ResetLastError();
   macd_handle_m5 = iCustom(_Symbol, PERIOD_M5, "Examples\\MACD", 12, 26, 9, PRICE_CLOSE);
   if(macd_handle_m5 < 0){
      Print("M5 handle error:" + IntegerToString(GetLastError()));
   }
   
   ResetLastError();
   macd_handle_m10 = iCustom(_Symbol, PERIOD_M10, "Examples\\MACD", 12, 26, 9, PRICE_CLOSE);
   if(macd_handle_m10 < 0){
      Print("M10 handle error:" + IntegerToString(GetLastError()));
   }

   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]){
   
   
   ResetLastError();
   if(CopyBuffer(macd_handle_m5, 0, 0, 10, macd_values_m5) < 0){
      Print("M5 CopyBuffer error: " + IntegerToString(GetLastError()) + " handle: " + IntegerToString(macd_handle_m5));
   }else{
      Print("M5 value[0]: " + DoubleToString(macd_values_m5[0] ,_Digits));
   }
   
   
   
   ResetLastError();
   if(CopyBuffer(macd_handle_m10, 0, 0, 10, macd_values_m10) < 0){
      Print("M10 CopyBuffer error: " + IntegerToString(GetLastError()) + " handle: " + IntegerToString(macd_handle_m10));
   }else{
      Print("M10 value[0]: " + DoubleToString(macd_values_m10[0] ,_Digits));
   }
   
   
   return(rates_total);
}


Any idea?

 

do not use if(CopyBuffer(.....) < 0)

try the code:

if(!CopyBuffer( etc etc...))

 
JacintoBelgium:

do not use if(CopyBuffer(.....) < 0)

try the code:

if(!CopyBuffer( etc etc...))

Why?!
CopyBuffer returns an int value and what he did is right.

Despite of the error (that I guess that happens on first OnCalculate call) the indicator is working fine, right?
 
i realise that this is an old thread, but have same issue sometimes. Am i right in thinking that the code should say "<= 0", with the =? and that the error 4806 will go away?