A momentum indicator built from the difference between two moving averages, plus a signal line and histogram.
MACD (Moving Average Convergence Divergence) is a momentum and trend-following indicator developed by Gerald Appel in the late 1970s. It measures the relationship between two exponential moving averages (EMAs) of price. It has three parts: the MACD line (the fast EMA minus the slow EMA), a signal line (an EMA of the MACD line), and a histogram (the gap between the MACD line and the signal line). It is shown in a separate pane below the price chart rather than directly on price. MACD is purely a calculation derived from past prices; it describes momentum that has already occurred and does not predict the future. No indicator is predictive, and all trading carries risk of loss.
MACD starts with two exponential moving averages of the closing price — a faster one (default 12 periods) and a slower one (default 26 periods). Subtracting the slow EMA from the fast EMA gives the MACD line. When the fast average pulls further above the slow average, the MACD line rises; when they converge or the fast average drops below the slow one, it falls toward and below zero. The signal line is a 9-period EMA of the MACD line, which smooths it and acts as a slower reference. The histogram plots the distance between the MACD line and the signal line as vertical bars, making it easier to see when those two lines are converging or diverging. All three components react to recent price changes, which is why MACD is described as a momentum measure layered on top of a trend calculation.
The classic defaults are 12 (fast EMA), 26 (slow EMA), and 9 (signal EMA), applied to the closing price — often written as MACD(12,26,9). Some traders use faster settings such as 5,35,5 for more sensitivity, or slower settings on higher timeframes to reduce noise. Changing the inputs or the chart timeframe changes every crossover and histogram reading, so settings are something to test and understand rather than assume.
//@version=6
indicator("MACD Example", overlay = false)
fastLen = input.int(12, "Fast Length")
slowLen = input.int(26, "Slow Length")
sigLen = input.int(9, "Signal Length")
[macdLine, signalLine, histLine] = ta.macd(close, fastLen, slowLen, sigLen)
plot(macdLine, "MACD", color = color.blue)
plot(signalLine, "Signal", color = color.orange)
plot(histLine, "Histogram", color = color.gray, style = plot.style_histogram)
hline(0, "Zero", color = color.gray)Pro tip: Treat the histogram and the zero line as context, not triggers. Many traders note that a crossover occurring while the MACD line is on the same side of zero as the prevailing trend looks more consistent with that trend, whereas crossovers near zero in a flat market are the ones most prone to whipsaw. Pair MACD with broader price context and sound risk management. This is educational information only, not advice — no indicator is predictive, and all trading carries risk of loss.
Educational only — not financial advice, not a recommendation to trade. No indicator is predictive; trading involves substantial risk of loss.