MACD (Moving Average Convergence Divergence)
MACD compares two exponential moving averages to show a trend's direction and momentum; it is both a trend tool and an oscillator.
What it is
MACD was introduced by Gerald Appel in the 1970s. It measures the gap between a fast and a slow exponential moving average. When the fast average pulls away from the slow one, the trend is strengthening; when it closes in, momentum is fading.
How it's calculated
- MACD line = 12-period EMA − 26-period EMA
- Signal line = 9-period EMA of the MACD line
- Histogram = MACD line − signal line
How traders read it
- The MACD line crossing the signal line upward is bullish, downward bearish.
- Above or below zero shows the overall direction of the trend.
- A shrinking histogram means momentum is fading, even before the lines cross.
- Divergence between price and MACD, as with RSI, warns of a weakening trend.
Settings
The classic settings are 12, 26 and 9. Some traders try smaller values on short timeframes and larger ones on daily and weekly charts; measure any change with a backtest.
Where it misleads
- MACD is built on moving averages, so its signals lag by nature.
- In a ranging market, repeated crossovers produce many false signals.
Its Pine Script on Vlevel
This is the script the chart runs. In the chart's indicators window you can open it, change it and save your own copy.
MACD · Pine Script v6
//@version=6
indicator("MACD", format = format.price, precision = 4)
fastLength = input.int(12, "Fast Length", minval = 1)
slowLength = input.int(26, "Slow Length", minval = 1)
src = input.source(close, "Source")
signalLength = input.int(9, "Signal Smoothing", minval = 1, maxval = 50)
oscKind = input.string("EMA", "Oscillator MA Type", options = ["SMA", "EMA"])
sigKind = input.string("EMA", "Signal Line MA Type", options = ["SMA", "EMA"])
fast = oscKind == "SMA" ? ta.sma(src, fastLength) : ta.ema(src, fastLength)
slow = oscKind == "SMA" ? ta.sma(src, slowLength) : ta.ema(src, slowLength)
macd = fast - slow
signal = sigKind == "SMA" ? ta.sma(macd, signalLength) : ta.ema(macd, signalLength)
hist = macd - signal
plot(hist, "Histogram", style = plot.style_columns, color = hist >= 0 ? (hist[1] < hist ? #26a69a : #b2dfdb) : (hist[1] < hist ? #ffcdd2 : #ff5252))
plot(macd, "MACD", color = #1fb8ff)
plot(signal, "Signal", color = #f5a742)
hline(0, "Zero Line", color = color.new(color.white, 75), linestyle = hline.style_dotted)Indicators describe past prices; none predicts the future. For education, not investment advice.