error 4806

 

CopyBuffer unexpected results!!

this seemingly sound code gives a reading error

 double CMyTemplate:: MACDGet(const int buffer, const int index)
     {
      double MACD_buffer[];
 ArraySetAsSeries(MACD_buffer,true);
//--- reset error code 
   ResetLastError();
//--- fill a part of the MACD array with values from the indicator buffer that has 0 index 
   if(!CopyBuffer(handle_MACD,buffer,index,1,MACD_buffer))
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the MACD indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(222.2);
     }
   return(MACD_buffer[0]);

 MACD  =432932703 

MACD Signal 1 =-816387384 

 
First, fix your broken code; CopyBuffer does not return a boolean. Your test will not show a failure.
 
William Roeder:
First, fix your broken code; CopyBuffer does not return a boolean. Your test will not show a failure.
   double CMyClass::MACDGet(const int buffer, const int index)
     {
      double MACD_buffer[];
 ArraySetAsSeries(MACD_buffer,true);
//--- reset error code 
   ResetLastError();
//--- fill a part of the MACD array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle_MACD,buffer,index,1,MACD_buffer)<0)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the MACD indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(222);
     }
   return(MACD_buffer[0]);
  
  } 

it returns "int" ...sorry about that !

yet still returns the same error 4806

what perplexes me is that the same function if I take it outside the class performs correctly as expected.... 

I am using it in OnTick event ...I suspect the tick frequency has something to do with the error ! 

 
justinmcridge: yet still returns the same error 4806

You keep saying that, but your original code would not have printed anything, therefor your error must be elsewhere.

 

Forum on trading, automated trading systems and testing trading strategies

strategy tester error

Alain Verleyen, 2020.04.23 03:11

That's a Justin Mcridge issue.

PrintFormat(" Point :%d",m_symbol.Point());

Read the documentation please. You are using %d all over to print double value. %d is for an INT !

Possible you have the same issue.

And even in your other topic https://www.mql5.com/en/forum/338056

unexplained return of a simple function
unexplained return of a simple function
  • 2020.04.20
  • www.mql5.com
Hello community the unexpected return I am getting is : the highest High is -977190959 could someone Plz figure this out...
Reason: