Direct answer
A worked example of MACD shows how the indicator’s lines are calculated from a small set of prices using specific assumptions (EMA periods, smoothing, and starting values). MACD is built from two exponential moving averages (EMAs) of the same price series, then compared to a signal line (another EMA) and visualized with a histogram (difference between MACD and signal). The key point in any worked example is that every choice—periods and how you start the EMAs—must be stated so the numbers can be independently reproduced.
Mechanism and definition
MACD stands for Moving Average Convergence Divergence. In the common version:
- Fast EMA: an EMA of the price using a shorter lookback period.
- Slow EMA: an EMA of the price using a longer lookback period.
- MACD line: MACD = (fast EMA) − (slow EMA).
- Signal line: an EMA of the MACD line using a signal period.
- Histogram: histogram = MACD line − signal line.
EMA smoothing rule (assumption for calculation): For an EMA with period N, the smoothing factor is α = 2 / (N + 1). A standard update step is:
- EMAₜ = α·Priceₜ + (1 − α)·EMAₜ₋₁
Important definition choice: different platforms may initialize EMAs differently (for example, starting with the first price, with an average of the first N values, or after enough bars). In a worked example, you must pick one initialization method and stick to it.
Worked numerical example (with stated assumptions)
Assume you use closing prices with the following fixed settings:
- Fast EMA period N₁ = 3 → α₁ = 2/(3+1) = 0.5
- Slow EMA period N₂ = 5 → α₂ = 2/(5+1) = 2/6 = 0.333333…
- Signal EMA period Nₛ = 3 → αₛ = 0.5
- Initialization assumption: at the first bar (t=1), set fast EMA₁ = Price₁ and slow EMA₁ = Price₁, and set signal EMA₁ = MACD₁.
- Prices:
- Price₁ = 100
- Price₂ = 102
- Price₃ = 101
- Price₄ = 103
- Price₅ = 104
Step 1: compute fast and slow EMAs
t=1
- fast EMA₁ = 100
- slow EMA₁ = 100
t=2
- fast EMA₂ = 0.5·102 + 0.5·100 = 101
- slow EMA₂ = 0.333333·102 + 0.666667·100 = 34.0 + 66.6667 = 100.6667
t=3
- fast EMA₃ = 0.5·101 + 0.5·101 = 101
- slow EMA₃ = 0.333333·101 + 0.666667·100.6667 = 33.6667 + 67.1111 = 100.7778
t=4
- fast EMA₄ = 0.5·103 + 0.5·101 = 102
- slow EMA₄ = 0.333333·103 + 0.666667·100.7778 = 34.3333 + 67.1852 = 101.5185
t=5
- fast EMA₅ = 0.5·104 + 0.5·102 = 103
- slow EMA₅ = 0.333333·104 + 0.666667·101.5185 = 34.6667 + 67.6790 = 102.3457
Step 2: compute MACD line
t=1: MACD₁ = 100 − 100 = 0 t=2: MACD₂ = 101 − 100.6667 = 0.3333 t=3: MACD₃ = 101 − 100.7778 = 0.2222 t=4: MACD₄ = 102 − 101.5185 = 0.4815 t=5: MACD₅ = 103 − 102.3457 = 0.6543
Step 3: compute signal line (EMA of MACD)
Using signal EMA update with αₛ = 0.5 and initialization signal EMA₁ = MACD₁:
- signal EMA₁ = 0
- t=2: signal EMA₂ = 0.5·0.3333 + 0.5·0 = 0.1667
- t=3: signal EMA₃ = 0.5·0.2222 + 0.5·0.1667 = 0.1111 + 0.0833 = 0.1944
- t=4: signal EMA₄ = 0.5·0.4815 + 0.5·0.1944 = 0.2408 + 0.0972 = 0.3380
- t=5: signal EMA₅ = 0.5·0.6543 + 0.5·0.3380 = 0.3272 + 0.1690 = 0.4962
Step 4: compute histogram
histogramₜ = MACDₜ − signal EMAₜ:
- t=2: 0.3333 − 0.1667 = 0.1666
- t=3: 0.2222 − 0.1944 = 0.0278
- t=4: 0.4815 − 0.3380 = 0.1435
- t=5: 0.6543 − 0.4962 = 0.1581
Verification: if you recompute EMAs using the same α values and the same initialization rule, you should arrive at the same MACD, signal, and histogram numbers up to rounding.
Limitations and risks (material failure modes)
- Parameter dependence: MACD values change when fast/slow/signal periods change. A worked example is valid only under its stated periods. 2) Initialization differences: EMA start rules differ across software. Early MACD values can differ even when later values converge.