Signal Line MACD, how to calculate EMA of it?

 

Hi all, what to use as "Close" in the calculation below to find out SignalLine EMA of MACD???


I've been googling around to find how to calculate the SignalLine in a MACD-calculation.

I know the following to calculate EMA of something but the last part with close is not clear to me in regards to SignalLine of MACD: 

Initial SMA: 10-period sum / 10 

Multiplier: (2 / (Time periods + 1) ) = (2 / (10 + 1) ) = 0.1818 (18.18%)

EMA: {Close - EMA(previous day)} x multiplier + EMA(previous day). 

I first add upp all MACD points for a 10-period sum / 10

I do the multiplier calculation

Now how does this last part apply to the SigalLine as the SignalLine won't have any close price???

Should "Close" just be the closing price of the current bar or should it be the EMA of the MACD for the current bar?

 
Johan Strandberg:

Hi all, what to use as "Close" in the calculation below to find out SignalLine EMA of MACD???

I've been googling around to find how to calculate the SignalLine in a MACD-calculation.

I know the following to calculate EMA of something but the last part with close is not clear to me in regards to SignalLine of MACD: 

I first add upp all MACD points for a 10-period sum / 10

I do the multiplier calculation

Now how does this last part apply to the SigalLine as the SignalLine won't have any close price???

Should "Close" just be the closing price of the current bar or should it be the EMA of the MACD for the current bar?


The "close" is the Close Price of the Bar in question, or any of the other Price arguments commonly used (such as Typical Price, Median Price, etc.), and the calculation is as follows:

Calculation (on MetaTrader)

The MACD is calculated by subtracting the value of a 26-period exponential moving average from a 12-period exponential moving average. A 9-period dotted simple moving average of the MACD (the signal line) is then plotted on top of the MACD.

MACD = EMA(CLOSE, 12) - EMA(CLOSE, 26)

SIGNAL = SMA(MACD, 9) (Please note that MetaTrader uses SMA, while other sources use EMA)

Where:

EMA — Exponential Moving Average;
SMA — Simple Moving Average;
SIGNAL — the signal line of the indicator

What is the 'Moving Average Convergence Divergence - MACD'

Moving average convergence divergence (MACD) is a trend-following momentum indicator that shows the relationship between two moving averages of prices. The MACD is calculated by subtracting the 26-day exponential moving average (EMA) from the 12-day EMA. A nine-day EMA of the MACD, called the "signal line", is then plotted on top of the MACD, functioning as a trigger for buy and sell signals.

MACD-Histogram

MACD: (12-day EMA - 26-day EMA)
Signal Line: 9-day EMA of MACD (This one is using EMA instead of SMA)
MACD Histogram: MACD - Signal Line
 
Fernando Carreiro:


The "close" is the Close Price of the Bar in question, or any of the other Price arguments commonly used (such as Typical Price, Median Price, etc.), and the calculation is as follows:


Thank you Fernando for excellent help despite the fact that I was a total jerk to you in previous threads. Thanks not only for your help here with the MACD but also in humbling me to realize I shouldn't react like I do sometimes and try to be less of a jerk to people whos intention are well meant. 

SIGNAL = SMA(MACD, 9) (Please note that MetaTrader uses SMA, while other sources use EMA)

This I find very interesting, don't really understand why MT4 doesn't use the "standard" way of calculating (if there is a standard way). 

 

Still not 100% sure about the calculation so anybody who know if the following is correct or wrong feel free to answer. 

Is the EMA of MACD used for calculating 9-period signal line calculated correctly below?


Calculating Signal Line of MACD with EMA:

Initial SMA: 10-period sum / 10 

Multiplier: (2 / (Time periods + 1) ) = (2 / (10 + 1) ) = 0.1818 (18.18%)

EMA: {Close - EMA(previous day)} x multiplier + EMA(previous day). 

  • Temp = The 9-period signal line is supposed to be based on MACD. So first Initial SMA = sum of MACDs over a 10-period sum / 10. This give us the SMA of signal line of MACD for the first value. This feels right to me but needed to double check that its the MACD's values I should add.


  • Mulitplier (2 / 10 + 1) = 0.1818


  • EMA of 9-period signal line of MACD = (ClosePrice Current Bar - Temp(SMA of MACD from the first bullet point)) * 0-1818 + Temp(SMA of MACD from the first bullet point)


Next calculation of EMA of 9-period signal line of MACD should then be:

  • EMA of 9-period signle line of MACD = (ClosePrice Current Bar - previous 9period EMA of MACD) * 0.1818 + previous 9period EMA of MACD
Thanks

 
Johan Strandberg: Thank you Fernando for excellent help despite the fact that I was a total jerk to you in previous threads. Thanks not only for your help here with the MACD but also in humbling me to realize I shouldn't react like I do sometimes and try to be less of a jerk to people whos intention are well meant.
You are welcome!
 
Johan Strandberg:

Still not 100% sure about the calculation so anybody who know if the following is correct or wrong feel free to answer. 

Is the EMA of MACD used for calculating 9-period signal line calculated correctly below?

Calculating Signal Line of MACD with EMA:

  • Temp = The 9-period signal line is supposed to be based on MACD. So first Initial SMA = sum of MACDs over a 10-period sum / 10. This give us the SMA of signal line of MACD for the first value. This feels right to me but needed to double check that its the MACD's values I should add.

  • Mulitplier (2 / 10 + 1) = 0.1818
  • EMA of 9-period signal line of MACD = (ClosePrice Current Bar - Temp(SMA of MACD from the first bullet point)) * 0-1818 + Temp(SMA of MACD from the first bullet point)

Next calculation of EMA of 9-period signal line of MACD should then be:

  • EMA of 9-period signle line of MACD = (ClosePrice Current Bar - previous 9period EMA of MACD) * 0.1818 + previous 9period EMA of MACD
Thanks

The following paper by Tony Finch, explains how to calculate an Exponential Moving Average incrementally (especially pages 7-8, but read the entire paper for clarification).

To calculate the alpha weight/constant for a certain period, use the following:
  • EMA (Exponential Moving Average): 2 / (Period + 1)
  • SMMA (Smoothed Moving Average): 1 / Period

So for the alpha weights/constants you need, are 12 period and 26 period for the MACD itself, and a 9 period for the signal:

  • 2 / ( 12 + 1 ) = 2 / 13 = 0.15384615384615384615384615384615
  • 2 / ( 26 + 1 ) = 2 / 27 = 0.07407407407407407407407407407407
  • 2 / (  9 + 1 ) = 2 / 10 = 0.2

EDIT: The are several ways to "seed" an incremental EMA calculation:

  1. Use the first value as the "seed" and then continue as normal. This is the preferred and most appropriate method, as it is independent of how the alpha weight/constant is calculated.
  2. Calculate the SMA (Simple Mean) of the first "n" elements of the period. So if period is 9, then use the SMA(9) = (x1+x2+x3+x4+x5+x6+x7+x8+x9) / 9 and then continue with incremental EMA on the 10th element.
    Although this method is used by many, it is not the best option, especially because of how the alpha weights/constants are calculated for EMA, SMMA and other variations. It also breaks the normal flow of an incremental online calculation.

PS! Alternatively, just show your code and it will be easier for us to identify the problem areas.

 
Fernando Carreiro:

The following paper by Tony Finch, explains how to calculate an Exponential Moving Average incrementally (especially pages 7-8, but read the entire paper for clarification).

To calculate the alpha weight/constant for a certain period, use the following:
  • EMA (Exponential Moving Average): 2 / (Period + 1)
  • SMMA (Smoothed Moving Average): 1 / Period

So for the alpha weights/constants you need, are 12 period and 26 period for the MACD itself, and a 9 period for the signal:

  • 2 / ( 12 + 1 ) = 2 / 13 = 0.15384615384615384615384615384615
  • 2 / ( 26 + 1 ) = 2 / 27 = 0.07407407407407407407407407407407
  • 2 / (  9 + 1 ) = 2 / 10 = 0.2

EDIT: The are several ways to "seed" an incremental EMA calculation:

  1. Use the first value as the "seed" and then continue as normal. This is the preferred and most appropriate method, as it is independent of how the alpha weight/constant is calculated.
  2. Calculate the SMA (Simple Mean) of the first "n" elements of the period. So if period is 9, then use the SMA(9) = (x1+x2+x3+x4+x5+x6+x7+x8+x9) / 9 and then continue with incremental EMA on the 10th element.
    Although this method is used by many, it is not the best option, especially because of how the alpha weights/constants are calculated for EMA, SMMA and other variations. It also breaks the normal flow of an incremental online calculation.

PS! Alternatively, just show your code and it will be easier for us to identify the problem areas.


My earlier calculations seems to be off, after some re-thinking I finally solved it. 


My thought is this is after some more thinking on the formula: 


As the sigal line's EMA is based on MACD and not closing price of a certain time period/bar (this is only for EMA's based on price, not EMA's based on MACD).

 

The EMA-calculation of signalLine based on MACD should be:

Intital value which will be a SMA is: n number of MACDs value added up / n

this will be the first signalLineEMA even though it is in fact a SMA. 


After the initial above value EMA will be:  signalLineEMA = (MACDvalue currentbar - previous day signalLineEMA) * multiplier + previous day signalLineEMA. 


Basically by using MACDvalue of current bar as "Close" it will be right and be a calculation of just MACD which is what the signal Line is instead of a closing price. 

Reason: