Error 4806 while using CopyBuffer()

Hi,

I would like to just get the value of a custom indicator in an Expert Advisor, here is my code :

double   IndicatorBuffer[]; 
int      HandleIndicator = 0;

int OnInit()
{
   HandleIndicator = iCustom(Symbol(),PERIOD_CURRENT,"MAindicator","EURUSD",PERIOD_CURRENT);
   
   Print("iCustom HANDLE "+HandleIndicator+" ERR? "+GetLastError());
   
   if(HandleIndicator > 0)
 
      int CpyHandle = CopyBuffer(HandleIndicator,0,0,3,CorrelationBuffer);
      
      Print("Cpy HANDLE "+CpyHandle+" ERR? "+GetLastError());
   }
}

53

Is it the correct way to get a value of a iCustom indicator ?

Why do I get this error ?

Get the handle in OnInit , the indicator hasn’t yet run. Get the data in OnCalculate / OnTick after it has.

ERR_INDICATOR_DATA_NOT_FOUND 4806 Requested data not found

Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Runtime Errors - Reference on algorithmic/automated trading language for MetaTrader 5

First, I would like to thank you for your answer.

I tryed to put then to put the CopyBuffer in OnTick() as this code :

double   IndicatorBuffer[]; 
int      HandleIndicator = 0;

int OnInit()
{
   HandleIndicator = iCustom(Symbol(),PERIOD_CURRENT,"correlation","EURUSD",PERIOD_CURRENT);
   
   Print("iCustom HANDLE "+HandleIndicator+" ERR? "+GetLastError());

   return(INIT_SUCCEEDED);
}
void OnTick()
{ 
   if(HandleIndicator > 0)
   {
      int CpyHandle = CopyBuffer(HandleIndicator,0,0,3,IndicatorBuffer);
      
      Print("Cpy HANDLE "+CpyHandle+" ERR? "+GetLastError());
   }
   
   Print("First value "+IndicatorBuffer[0]);
}

But it still an error “Not all data of MA is calculated. Error 4806.” :

54

Call the iCustom in OnTick()

Don’t call iCustom in OnTick, it’s the best way to have problems. Also Don’t check for error when there is no error. What is this message “Not all data of MA…”, it’s not in the code you posted. Show you real code.

This is exactly all the code I did in the Expert, this is the real code.

And I am calling the indicator “correlation” with iCustom,
55