Skip to content
Indicators 10 min read

MACD explained: calculation, crossovers and divergence

How MACD is built from 12- and 26-session EMAs, a worked example with the signal line and histogram, crossovers, divergence, PPO and limitations.

Hypothetical daily chart: price falls to a low, rebounds, falls to a lower low and then recovers, with the MACD line, its signal line and histogram in the pane below.Lower lowABSignal crossZero cross0MACD(12, 26, 9)
Daily candles on hypothetical data with MACD(12, 26, 9): the MACD line, its dashed signal line and the histogram. Price makes a lower low at B than at A, but MACD’s low at B is higher (-1.23 against -2.11): a bullish divergence. The first signal-line crossover comes between the two lows and is followed by the lower low; the zero-line crossover arrives 13 sessions after B, well into the rebound.

MACD measures the gap between a fast and a slow exponential moving average of the close. Its crossovers and divergences describe changes in trend momentum after they happen; they do not forecast the next move.

What MACD measures

MACD, short for moving average convergence divergence, is a trend-following momentum indicator developed by Gerald Appel in the 1970s. It subtracts a slower exponential moving average (EMA) of the close from a faster one. When the fast average pulls away above the slow one, MACD rises; when the two converge, MACD moves back toward zero; when the fast average drops below the slow one, MACD turns negative.

MACD at a glance
PropertyMACD
InputClosing prices
Standard settings12, 26 and 9 periods
ComponentsMACD line, signal line and histogram
ScaleUnbounded, in the stock’s price units
MidlineZero, where the two EMAs are equal
First valuesMACD line after 26 closes; signal line after 34 with the seeding used below

The three numbers in MACD(12, 26, 9) are the fast EMA period, the slow EMA period and the period of the signal line, an EMA of MACD itself. They are the common default on daily charts, but nothing in the formula requires them, and other settings change every value.

How MACD is calculated

MACD uses three exponential moving averages: two of the close and one of MACD itself. Each EMA moves a fixed fraction of the way from its previous value toward the newest input.

k = 2 ÷ (n + 1)
EMA today = EMA yesterday + k × (input today − EMA yesterday)
MACD line = EMA(12) of the close − EMA(26) of the close
signal line = EMA(9) of the MACD line
histogram = MACD line − signal line
n
The EMA period: 12, 26 or 9.
k
The smoothing factor: 0.1538 for 12, 0.0741 for 26 and 0.2 for 9.

An EMA needs a starting value. A common convention, used in the worked example, seeds each EMA with the simple average of its first n inputs: EMA(12) starts at session 12, EMA(26) at session 26 and the signal line at the ninth MACD value, session 34. Other software starts from the first close or from a longer history. Early values then differ between platforms, but the gap shrinks every session, because each new EMA value keeps only part of the old one.

MACD is a difference of two prices, so for a US stock it is in dollars. Its formula divides by nothing, so it has no zero-denominator case; each line simply starts once its averages have their first values.

A worked MACD example

The example uses 50 hypothetical daily closes: a slow decline into session 35 followed by a recovery. All closes are listed so that every average can be recomputed.

Hypothetical daily closes ($), sessions 1–50
SessionsCloses ($)
1–1060.00, 60.20, 60.05, 60.30, 60.20, 60.35, 60.15, 60.25, 60.30, 60.15
11–2060.25, 60.05, 60.20, 59.95, 59.85, 59.90, 59.60, 59.45, 59.55, 59.30
21–3059.10, 59.15, 58.85, 58.60, 58.70, 58.35, 58.20, 57.90, 58.05, 57.65
31–4057.30, 57.40, 56.95, 56.65, 56.45, 56.80, 57.20, 57.10, 57.60, 58.05
41–5058.35, 58.20, 58.75, 59.15, 59.50, 59.45, 59.95, 60.40, 60.70, 61.10

EMA(12) starts at session 12 as the average of the first 12 closes, 60.1875. EMA(26) starts at session 26 as the average of the first 26 closes, 59.7231, so the first MACD value is 59.1055 − 59.7231 = -0.6176. The signal line starts at session 34 as the average of the nine MACD values from sessions 26 to 34, -0.7341.

EMAs, MACD line, signal line and histogram, sessions 26–50
SessionClose ($)EMA(12)EMA(26)MACD lineSignal lineHistogram
2658.3559.105559.7231-0.6176
2758.2058.966259.6103-0.6441
2857.9058.802159.4836-0.6814
2958.0558.686459.3774-0.6909
3057.6558.527059.2494-0.7224
3157.3058.338259.1050-0.7668
3257.4058.193958.9787-0.7849
3356.9558.002558.8285-0.8259
3456.6557.794458.6671-0.8727-0.7341-0.1386
3556.4557.587658.5029-0.9153-0.7703-0.1449
3656.8057.466458.3767-0.9103-0.7983-0.1120
3757.2057.425458.2896-0.8641-0.8115-0.0526
3857.1057.375458.2014-0.8261-0.8144-0.0117
3957.6057.409958.1569-0.7470-0.80090.0539
4058.0557.508458.1490-0.6406-0.76880.1283
4158.3557.637958.1639-0.5260-0.72030.1943
4258.2057.724458.1665-0.4422-0.66470.2225
4358.7557.882158.2098-0.3276-0.59720.2696
4459.1558.077258.2794-0.2022-0.51820.3160
4559.5058.296158.3698-0.0737-0.42930.3556
4659.4558.473658.44980.0238-0.33870.3625
4759.9558.700858.56100.1398-0.24300.3828
4860.4058.962258.69720.2650-0.14140.4064
4960.7059.229558.84550.3840-0.03630.4203
5061.1059.517359.01250.50480.07190.4329

Read the histogram from session 34. It is most negative at session 35, the lowest close in the series, then shrinks for 3 sessions before turning positive at session 39: the MACD line has crossed above its signal line. The MACD line itself stays below zero until session 46, when EMA(12) moves back above EMA(26), and the signal line follows at session 50.

Values are rounded to four decimals for display; each step uses the unrounded figures.

How to read MACD on a stock chart

MACD is drawn in a pane below price: the MACD line, the signal line and the histogram around a zero line. Read it in layers, from the slowest information to the fastest.

  1. Zero line. Above zero, the 12-session EMA is above the 26-session EMA; below zero, it is beneath. This is the broad direction of the shorter-term trend.
  2. Slope of the MACD line. A rising line means the fast EMA is gaining on the slow one, whether MACD is above or below zero.
  3. MACD against its signal line. The histogram shows this gap, and it changes sign at every signal-line crossover.
  4. Swings against price. Compare MACD peaks and troughs with price peaks and troughs to find divergence.
  5. Scale. The values are in dollars, so compare the size of swings within one chart, not across stocks.

In TradeClever, open Stock Charts and add the MACD pane. The fast, slow and signal periods are configurable, with 12, 26 and 9 as defaults. For the basics of candles, ranges and volume, see reading a stock chart.

Signal-line and zero-line crossovers explained

MACD has two kinds of crossover. They answer different questions and arrive at different times.

The two MACD crossovers
CrossoverWhat crossesWhat it describesTiming
Signal-line crossoverThe MACD line crosses its 9-session EMAMACD has turned relative to its own recent pathEarlier and more frequent
Zero-line crossoverThe MACD line crosses zeroEMA(12) has crossed EMA(26): a moving-average crossoverLater and less frequent

In the worked example, the signal-line crossover comes at session 39, 4 sessions after the lowest close and while MACD is still negative. It records that the decline’s momentum has faded relative to its recent average, not that the decline has ended. The zero-line crossover at session 46 is the moment EMA(12) moves above EMA(26). It comes later because MACD has to climb all the way back from its low; by then the close was $3.00 above the lowest close.

In sideways markets the two EMAs stay close together, and the lines can cross back and forth repeatedly. A crossover describes two averages; it is not an instruction.

MACD histogram interpretation

The histogram plots MACD minus its signal line. It is zero when the two lines cross, positive when MACD is above the signal line and negative when it is below.

Because the signal line is an average of MACD, the histogram measures how far MACD has moved away from its own recent path. That makes it the fastest of the three components: it can turn while MACD and the signal line are still moving the old way. In the worked example the histogram is at its most negative at session 35 and starts shrinking at session 36, 3 sessions before the crossover.

Histogram versus signal line
AspectSignal lineHistogram
What it isA 9-session EMA of the MACD lineThe MACD line minus the signal line
How it is drawnA second line over MACDBars above and below zero
Main readingCrossovers with the MACD lineBars growing or shrinking
SpeedSmoothed, slowerThe fastest of the three components

Shrinking bars mean MACD is converging with its signal line. They do not mean the trend is reversing: the bars can shrink and then grow again without any crossover.

MACD divergence, and how it differs from a crossover

A MACD divergence compares two price swings with the MACD values at the same sessions. A bullish divergence is a lower low in price with a higher MACD low; a bearish divergence is a higher high in price with a lower MACD high.

The illustration on this page shows a bullish divergence on hypothetical data. Price closes at 51.00 at low A and lower, at 50.40, at low B, but MACD reads -2.11 at A and -1.23 at B. The second decline was smaller relative to its moving averages, which is what the divergence records. The first signal-line crossover in the illustration comes between the two lows and is followed by the lower low at B, a reminder that crossovers can come early.

Because MACD is in price units, the size of a divergence depends on the stock’s price and volatility. Compare swings on the same chart, and decide in advance how far apart two swings must be before you compare them.

Crossover versus divergence
AspectCrossoverDivergence
What is comparedTwo lines at one sessionTwo swings in price and in MACD
When it is knownAt the session it happensOnly after the second swing is complete
What it describesA change in the relationship between averagesMomentum that does not confirm the price swing
Main weaknessFrequent crosses in sideways marketsCan persist through several swings

Divergence describes momentum. Price can keep trending while MACD diverges, sometimes for a long time.

MACD, PPO and comparing stocks

The percentage price oscillator, or PPO, divides the same EMA gap by the slower EMA and multiplies by 100. Expressing the gap as a percentage of price makes readings comparable across stocks with different prices.

PPO = (EMA(fast) − EMA(slow)) ÷ EMA(slow) × 100

A MACD of 1.50 is a gap of about 7.50% of price for a $20 stock and about 0.50% for a $300 stock. PPO puts both on the same footing. Its sign always matches MACD’s, because the slow EMA of a positive price is positive, so the division is always defined.

CleverScan offers PPOLine(50, 200, 9), the PPO line built from the 50- and 200-session EMAs of the close. It is a much slower, long-term relative of MACD(12, 26, 9), not the same indicator. A positive value means the 50-session EMA is above the 200-session EMA, so the two rules below express the same condition.

securityType = "Stock" and PPOLine(50, 200, 9) > 0
securityType = "Stock" and ema50 > ema200

Limitations of MACD

MACD summarizes moving averages, so it inherits their delay and adds the choice of three periods.

  • It lags. Every component is an average of past closes, and the zero-line crossover is a moving-average crossover.
  • It has no fixed range. There is no built-in overbought or oversold level, and raw values cannot be compared across stocks; PPO addresses the second point.
  • Settings and seeding change the numbers. Different periods, or a different starting value for each EMA, give different early readings.
  • Sideways markets produce repeated crossovers that quickly reverse.
  • Divergence can persist through several swings.
  • It sees closes only. Gaps and intraday ranges affect MACD only through the closes they leave behind.

Sources

  • Gerald Appel, Technical Analysis: Power Tools for Active Investors (FT Press, 2005)

Read our data and methodology notes for calculation context. This guide explains research tools and observations. It does not recommend a trade or investment.

Follow your curiosity

One good question leads to another.

All guides
Make room for better research

Put your curiosity to work.

Build a scan with filters or CleverScan rules. Explore the results. Find your next idea.

Open a stock chart