Getting an EMA value for the MACD

 

can anyone help me with this bit of coding...


From what i understand... i can use the  ExponentialMAOnBuffer() but im not so clear as to how

 
Tomisin Osasona:

can anyone help me with this bit of coding...


From what i understand... i can use the  ExponentialMAOnBuffer() but im not so clear as to how

I really don't understand what you want or need. The link of ExponentialMAOnBuffer() points to MathExp(value) which calculate e^value.

But the MACD is the difference of two ema and the ema of that difference.

You can find the code of the MACD already on your pc here:  ...\MQL5\Indicators\Examples\MACD.mq5.

BTW an ema is simple to calculate it yourself: newEma =  ((newValue-prvEma)*c + prvEma) ; and c = 2/(n+1) with n being the periods on the moving average.

To get that values on any indicator use iCustom() - there is an example.

Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
[in]  Custom indicator name. If the name starts with the reverse slash '\', the EX5 indicator file is searched for relative to the MQL5\Indicators indicator root directory. Thus, when calling FirstIndicator"...), the indicator is downloaded as MQL5\Indicators\FirstIndicator.ex5. If the path contains no file, the error 4802...
 
Carl Schreiber:

I really don't understand what you want or need. The link of ExponentialMAOnBuffer() points to MathExp(value) which calculate e^value.

But the MACD is the difference of two ema and the ema of that difference.

You can find the code of the MACD already on your pc here:  ...\MQL5\Indicators\Examples\MACD.mq5.

BTW an ema is simple to calculate it yourself: newEma =  ((newValue-prvEma)*c + prvEma) ; and c = 2/(n+1) with n being the periods on the moving average.

To get that values on any indicator use iCustom() - there is an example.

Im trying to calculate for an EMA signal line... even if i cant get the line, just the values would do

i check the MACD code and i found this

/---
   int limit;
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
//--- calculate MACD
   for(int i=limit;i<rates_total && !IsStopped();i++)
      ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
//--- calculate Signal
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);

would it just do the change the last line of coding

//--- calculate Signal
   ExponentialMAOnBuffer(rates_total,prev_calculated,1,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);