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.
| Output | Definition |
|---|---|
macd | Fast EMA of the close minus slow EMA |
signal | EMA of the MACD line (9 bars by default) |
histogram | MACD 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
| Input | Type | Default | Range |
|---|---|---|---|
fast_period | integer | 12 | 2 – 300 |
slow_period | integer | 26 | 3 – 500 |
signal_period | integer | 9 | 2 – 300 |
Outputs
macd, signal, histogram
