Indicators/Momentum

Moving Average Convergence Divergence (MACD)

The gap between a fast and a slow moving average of price, with a signal line and a histogram showing whether momentum is building or fading.

MACD 12 26 9AMZN · daily
MACD on a daily AMZN chart in StockVyze

What it measures

MACD subtracts a slow exponential moving average (26 bars by default) from a fast one (12 bars). When the fast average pulls away above the slow one, the MACD line rises; when the two converge, it falls toward zero.

OutputDefinition
macdFast EMA of the close minus slow EMA
signalEMA of the MACD line (9 bars by default)
histogramMACD line minus signal line

How to read it

  • Signal crossover. The MACD line crossing above its signal line is a common bullish signal; crossing below, bearish.
  • Zero line. MACD above zero means the fast average is above the slow one, a sign of an uptrend.
  • Histogram. A positive histogram means the MACD line is above its signal line. Bars growing taller above zero are conventionally read as bullish momentum building, bars growing deeper below zero as bearish momentum building; bars shrinking toward zero often precede a crossover.

Common mistakes

  • Trading every crossover. In sideways markets MACD crosses its signal line constantly. Crossovers aligned with the zero line and the larger trend are more meaningful.
  • Comparing raw values across stocks. MACD is in price units, so a MACD of 2 means very different things for a $20 stock and a $500 stock.

Use it in a scan

A bullish crossover in a stock above its 200-day average:

cross_up(macd_line(12, 26), macd_signal(12, 26, 9)) and c > sma(200)

Inputs

InputTypeDefaultRange
fast_periodinteger122 – 300
slow_periodinteger263 – 500
signal_periodinteger92 – 300

Outputs

macd, signal, histogram

References