how to get the value of iMACD for a given bar in mql5?

 

Hi

I searched for a simple way to calc the macd (iMACD) for the last bar (or for a given bar number) but couldn't find a clear solution for that. The documentation got me confused.

Can someone show me one simple example please?

thanks
 
int handle;
double MACD[1];

int OnInit()
  {
   handle=iMACD(NULL,0,12,26,9,PRICE_CLOSE);
   
   
void OnTick()
  {
   if(CopyBuffer(handle,0,5,1,MACD)>0)
      printf("Value of iMACD index[5] = %f",MACD[0]);
Reason: