MACD, the moving average convergence divergence, was developed by Gerald Appel in the late 1970s. It shows the gap between a fast and a slow exponential moving average of price, and how that gap is changing. When the averages pull apart the gap widens; when they come together it narrows.
MACD is built entirely from past prices, so it always lags. It is useful as a description of trend and momentum, and as an input in written rules, such as a trend filter or a stop that exits when momentum turns.
08.1How to calculate MACD
Take a 12-period and a 26-period exponential moving average of the close. The MACD line is the 12 minus the 26. The signal line is a 9-period exponential moving average of the MACD line. The histogram is the MACD line minus the signal line.
macd = EMA(close, 12) - EMA(close, 26)
signal = EMA(macd, 9)
histogram = macd - signal08.2Default MACD settings
The 12, 26, 9 settings come from Appel's original work and are the default in nearly every platform. Day traders sometimes use faster settings, and some strategies use a second, faster MACD as an exit. Changing the settings changes what the indicator measures; tuning them to fit past data is a common way to overfit a strategy.
08.3Crosses and the golden cross
A cross happens when the MACD line moves above or below its signal line, which is the same moment the histogram changes sign. A zero-line cross is when the MACD line itself crosses zero, which means the fast average has crossed the slow one. People sometimes call an upward cross a golden cross, borrowing the name from the 50-day and 200-day moving average cross on daily stock charts.
08.4MACD divergence
Divergence is when price and MACD disagree: price makes a higher high while MACD makes a lower high, or price makes a lower low while MACD makes a higher low. It shows that momentum is fading relative to price. It does not say when, or whether, price will turn, and divergences can persist through long trends.
08.5Using MACD for day trading, mechanically
On intraday charts, MACD is most often used as a filter rather than a trigger: take long setups from another rule only while the MACD line is above its signal, for example. If you write it into a strategy, state the bar period, the settings, and whether the reading is taken on the bar close or intrabar, because each choice changes the result.
Where it usually goes wrong
- Treating every cross as an entry without any other rule.
- Calling a divergence a reversal before price confirms anything.
- Tuning the three settings until a backtest looks good.
