MACD
Moving Average Convergence Divergence
A trend-momentum indicator built from the difference between two EMAs, plus a signal line and histogram that visualise momentum shifts.
MACD is a trend-momentum indicator built from the difference between a 12-bar and 26-bar EMA, plus a 9-bar signal line and a histogram. The signal-line cross marks momentum shifts; the zero line marks the trend regime. Default settings: 12, 26, 9.
MACD is the difference between a fast EMA (default 12) and a slow EMA (default 26). A third EMA of that difference (default 9) becomes the signal line, and the gap between MACD and signal is plotted as a histogram.
The three classic reading lenses are: the MACD/signal cross (momentum shift), the zero-line position (regime: above zero bullish, below zero bearish), and the histogram slope (acceleration or deceleration of momentum). MACD behaves poorly in choppy markets because the EMAs whip around — pair it with a regime filter for usable results.
How do I read MACD?
- MACD line above zero = the fast EMA is above the slow EMA = the recent trend regime is bullish.
- MACD line below zero = bearish regime.
- MACD crosses above signal line = momentum shifting bullish (long trigger). Cross below = bearish trigger.
- Histogram growing positive = bullish momentum accelerating. Histogram shrinking = momentum weakening, often before a cross fires.
- Bearish divergence: price makes a higher high but MACD makes a lower high — signals weakening upside momentum.
How is MACD calculated?
MACD measures the relationship between two exponential moving averages of different lengths, then smooths that relationship into a signal line and visualises the gap as a histogram.
- 1.Compute a 12-bar exponential moving average (EMA) of close — the fast EMA.
- 2.Compute a 26-bar EMA of close — the slow EMA.
- 3.Subtract slow from fast: MACD line = EMA(12) − EMA(26).
- 4.Compute a 9-bar EMA of the MACD line — the signal line.
- 5.Plot the histogram: MACD line − signal line. Above zero = bullish momentum, below = bearish.
What are the default MACD settings?
| Parameter | Default | When to adjust |
|---|---|---|
| Fast EMA length | 12 | Gerald Appel's original setting. Drop to 8 for faster signals on crypto/intraday; raise to 19 for less noise on weekly charts. |
| Slow EMA length | 26 | Original setting. Keep paired with fast EMA at roughly 2× the fast length. |
| Signal length | 9 | EMA smoothing of the MACD line. Tighter (5) gives earlier signals with more whipsaws; wider (14) is smoother but later. |
| Source | Close | Most common. HLC3 produces smoother readings on volatile assets. |
How do I plot MACD in Pine Script?
//@version=5
indicator("MACD Example", overlay=false)
fastLen = input.int(12, title="Fast Length", minval=1)
slowLen = input.int(26, title="Slow Length", minval=1)
signalLen = input.int(9, title="Signal Length", minval=1)
src = input.source(close, title="Source")
[macdLine, signalLine, hist] = ta.macd(src, fastLen, slowLen, signalLen)
plot(macdLine, title="MACD", color=color.blue)
plot(signalLine, title="Signal", color=color.orange)
plot(hist, title="Histogram", color=hist >= 0 ? color.green : color.red, style=plot.style_columns)
hline(0, "Zero", color=color.gray)Pine's ta.macd() returns three values in one call: the MACD line, signal line, and histogram. Plotting the histogram as columns (green when positive, red when negative) makes momentum acceleration visually obvious. Wire all three lengths to inputs so users can tune without touching code. The hline at zero anchors the regime read at a glance.
Continue exploring
Related indicators
EMA
Exponential Moving Average
A weighted moving average that gives more influence to recent prices, making it more responsive to new information than a simple moving average.
View EMAMomentumRSI
Relative Strength Index
A momentum oscillator that measures the speed and magnitude of recent price changes on a bounded 0–100 scale.
View RSIVolatilityBB
Bollinger Bands
A volatility envelope built from a moving average and ±2 standard deviations, expanding and contracting as volatility changes.
View BBAbout this reference
This page is an educational reference explaining what MACD is, how it is calculated, its default settings, and how to plot it in Pine Script. It is compiled from established trading literature and public technical documentation. Last review: .
Educational content. Not financial advice.