Getting a EMA out of a data instead of the iMA function

 

hi,


I am trying to make a EA that needs a standard MACD, not the one that is available with the iMACD function.


I know that the MACD line is made by subtracting the 26EMA from the 12EMA, this can be easily done with the iMA function. But after that there needs to be a EMA made out of the MACD line. But to get there I simply get lost... 


How do I code the MACD signal line out of the MACD line?


Calculation for the MACD and a standard EMA are in the attached files.

My code so far (I know it is basicaly nothing for the MACD signal line...):

   double twelveDayEma = iMA(Symbol(),NULL,12,0,MODE_EMA,PRICE_CLOSE,0);
   double twentysixDayEma = iMA(Symbol(),NULL,26,0,MODE_EMA,PRICE_CLOSE,0);
   
   double calculatedMACDLine = twelveDayEma - twentysixDayEma;
   
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
Files:
1.png  56 kb
 
You can't do it with a variable. You need to calculate all differences for all bars so you can compute the EMA(i) from EMA(i+1) and the difference(i)
double      EMAl(double aPrevEMA, double aValue, double anLength){
   return EMAa( aPrevEMA, aValue, 2.0 / (anLength + 1.0) );
}
double      EMAa(double aPrevEMA, double aValue, double aAlpha){
   return aPrevEMA + aAlpha * (aValue - aPrevEMA);
}
Remember it take 3.45 × Length values before you have a valid EMA
 
William Roeder:
You can't do it with a variable. You need to calculate all differences for all bars so you can compute the EMA(i) from EMA(i+1) and the difference(i)
Remember it take 3.45 × Length values before you have a valid EMA

@William Roeder

What do the variables mean?

For the calculation of EMA1:

- aPrevEMA (is this for the first calculation 0?)

- aValue(is this the MACDline?)

- anLength(is this the length of the EMA? so in case for a standard macdsignal line it should be a 9?)

For the calculation of the EMAa:

- aPrevEMA (is this for the first calculation 0?)

- aValue (is this the MACDline?)

- aAlpha(is this the weighted multiplier?)


For as far I understand, I do not need any extra code except for the MACDline calulation to let this work?


I hope that you can help me with these questions, thanks in advance!

 

Do not double post!

I have deleted your duplicated topic.

 
Keith Watford:

Do not double post!

I have deleted your duplicated topic.

Why? Thats a whole other topic on how to calculate an ema... 
 
DaanKouwen_SF:
Why? Thats a whole other topic on how to calculate an ema... 

It was not a whole other topic.

It was a development of the same code.

Reason: