Education onlyNot investment adviceFutures trading involves substantial risk of loss
Guide 08 · Indicator

What is MACD? The calculation, divergence, crosses and default settings

Two moving averages, their gap, and a smoothed line of that gap. Here is how it is built.

A trader points her pen at a histogram panel under a candlestick chart on her monitor

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.

Mechanics diagram
zeroMACD line (EMA 12 - EMA 26)signal line (EMA 9 of MACD)histogram = MACD - signal
The histogram is the MACD line minus the signal line. Bars above zero mean the MACD line is above its signal; below zero, under it.

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 - signal

08.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.