Technical Indicators · Illustrated reference
Moving averages
Weights, initialization, shock response and the meaning of lag.
Animated explanation · synthetic observations
Moving averages: price changes first
In the final range, repeated crossings have little durable follow-through. Faster response also means more whipsaw. The optional sideways view isolates this failure condition.
Original synthetic observations. Captions explain purpose, price relationships and failure; calculations use the displayed inputs. The complete reference is shown when motion is unavailable. Playback is optional.
Read the complete animated explanation
Complete cycle
- Established decline: The established decline keeps EMA5 below EMA20. Both summarize earlier closes. The shorter average gives the latest close more weight and responds sooner.
- Acceleration and bullish crossover: Price turns upward and accelerates. EMA5 reacts first and crosses above EMA20 only after price has already changed. The growing separation describes strengthening movement; it does not cause it.
- A sustained advance: The advance continues with the short average above the long average. Both lag price. A crossover is a description of this synthetic trend, not a guarantee that the next observation will rise.
- Deterioration and bearish crossover: Upward increments shrink, then price falls. EMA5 turns sooner; EMA20 retains more older prices. Their bearish crossover follows the deterioration rather than predicting its exact start.
- Decline accelerates: The decline accelerates after the crossover in this example. The averages follow the same computed closes. A different future path could reverse immediately; the crossing itself causes no selling.
- Sideways whipsaw: In the final range, repeated crossings have little durable follow-through. Faster response also means more whipsaw. The optional sideways view isolates this failure condition.
Sideways whipsaw
- Established decline: The same EMA5/20 calculation follows a bounded sideways price sequence. Repeated crossing markers have no sustained trend behind them. Shorter memory reacts sooner but cannot distinguish every meaningful turn from a temporary fluctuation.
- Acceleration and bullish crossover: The same EMA5/20 calculation follows a bounded sideways price sequence. Repeated crossing markers have no sustained trend behind them. Shorter memory reacts sooner but cannot distinguish every meaningful turn from a temporary fluctuation.
- A sustained advance: The same EMA5/20 calculation follows a bounded sideways price sequence. Repeated crossing markers have no sustained trend behind them. Shorter memory reacts sooner but cannot distinguish every meaningful turn from a temporary fluctuation.
- Deterioration and bearish crossover: The same EMA5/20 calculation follows a bounded sideways price sequence. Repeated crossing markers have no sustained trend behind them. Shorter memory reacts sooner but cannot distinguish every meaningful turn from a temporary fluctuation.
- Decline accelerates: The same EMA5/20 calculation follows a bounded sideways price sequence. Repeated crossing markers have no sustained trend behind them. Shorter memory reacts sooner but cannot distinguish every meaningful turn from a temporary fluctuation.
- Sideways whipsaw: The same EMA5/20 calculation follows a bounded sideways price sequence. Repeated crossing markers have no sustained trend behind them. Shorter memory reacts sooner but cannot distinguish every meaningful turn from a temporary fluctuation.
In this reference
- A moving average is a weighting rule
- SMA: equal weights inside a finite window
- EMA: recursive weights with a decaying tail
- Initialization is part of the calculation
- Response atlas: shock, step, trend and alternating prices
- Lag depends on the signal being measured
- Crossovers describe relative positions
- Understanding moving average calculation differences
A moving average is a weighting rule
A moving average summarizes a sequence of observations by assigning weights to them. It can make a broad direction easier to inspect, but it cannot reveal future prices. The smoothing comes from how observations are combined; the resulting delay is a consequence of that combination, not a defect that can be removed without changing the rule.
Specify the input field, interval, period, initialization and missing-value policy. An average of daily closes differs from an average of intraday closes or typical prices. A period of 20 means 20 supplied observations, not automatically 20 calendar days. Corporate-action adjustments can change those observations.
The two principal constructions here are the simple moving average (SMA) and exponential moving average (EMA). The mathematics is independently derived below, and all visual examples are original synthetic series.
SMA: equal weights inside a finite window
SMAₙ(t) = (Pₜ + Pₜ₋₁ + … + Pₜ₋ₙ₊₁)/n Rolling update: SMAₙ(t) − SMAₙ(t−1) = (Pₜ − Pₜ₋ₙ)/n
For closes 100, 102 and 104, SMA3 is 102. When 106 arrives, 100 leaves, so the new mean is (102+104+106)/3=104. The update depends on the arriving observation and the departing observation. It does not depend only on whether the newest price rose from the immediately preceding close.
An SMA can rise on a down day if the new close is still above the older observation leaving its window. For example, 100, 110, 108 gives SMA3=106. When 107 arrives, the average becomes 108.33 despite the latest decline from 108 to 107. The update equation explains the apparent contradiction.
The animated comparison follows a one-bar price shock. The SMA carries the shock at a fixed weight until the observation leaves the window. The EMA reduces its remaining contribution gradually. The difference is a weighting mechanism, not a claim that one forecast is superior.
EMA: recursive weights with a decaying tail
α = 2/(n+1) EMAₜ = αPₜ + (1−α)EMAₜ₋₁ Equivalent update: EMAₜ − EMAₜ₋₁ = α(Pₜ − EMAₜ₋₁)
With n=3, α=0.5. If the previous EMA is 102 and the next close is 106, the new EMA is 104. With another close at 106, it becomes 105. The new observation receives weight α; the entire previous state receives weight 1−α.
Expanding the recursion k times gives a weighted sum of the latest k inputs plus the remaining seed contribution (1−α)kEMAₜ₋ₖ. The individual recent weights are α, α(1−α), α(1−α)² and so on. They decline geometrically, but do not abruptly become zero after n bars.
The conventional EMA period is a parameterization of α, not a literal window containing only n observations. Wilder smoothing commonly uses α=1/n, which is a different convention. An EMA with period 2n−1 has the same α as Wilder smoothing with period n, but different seeds can still produce different outputs.
Initialization is part of the calculation
A first-value seed sets the first EMA to the first valid observation and begins the recursion immediately. An SMA seed waits for n valid observations, sets the initial EMA to their arithmetic mean, then recurses. These definitions do not yield identical early values on a general series.
For 100, 102, 104 and n=3, a first-value seed produces 100, 101, 102.5. An SMA seed first becomes available at the third observation with value 102. After the next close 106, their values are 104.25 and 104 respectively.
Seed-error propagation, with identical subsequent inputs: Δₖ = (1−α)ᵏ Δ₀ For α=0.5, the discrepancy halves at each update.
Warm-up therefore reduces a seed difference under fixed inputs, but no single bar count guarantees the same displayed precision for every series and tolerance. Report the tolerance and the available history. Do not create pre-initialization values by drawing a line across missing outputs.
Response atlas: shock, step, trend and alternating prices
One-bar shock
Permanent step
Steady trend
Alternating
A one-bar shock leaves an abrupt exit in the finite SMA window and a fading contribution in the EMA. A permanent step makes both averages approach the new level by different paths. A steady trend creates persistent separation from current price. Alternating observations can produce frequent price/average crossings without a sustained directional move.
For an established constant price followed by an isolated shock of size A, the immediate SMA effect is A/n and the immediate EMA effect is αA. The EMA initially responds more under the conventional α=2/(n+1) for n>1, but the later responses can cross. “EMA is always faster” is too imprecise to describe the whole impulse response.
Lag depends on the signal being measured
For a sufficiently long linear ramp with increment b per bar, an SMA’s difference from the current value is b(n−1)/2. The steady-state conventional EMA has the same ramp lag because (1−α)/α=(n−1)/2. The two filters can therefore have equal steady ramp lag while responding differently to a sudden jump.
Lag in a turning market is not a fixed number of bars that can always be shifted away. Moving an average backward on a chart can make it look better aligned with historical prices, but the shifted value may use future inputs relative to the displayed timestamp. A causal calculation must retain the time at which the output was actually available.
Crossovers describe relative positions
A price crossing above an average means that the two series exchanged order under a specified equality and completion rule. A short average crossing a long average describes another relationship. Neither event by itself establishes a profitable strategy or an independent confirmation of trend.
In a range, repeated crossings can generate costs and reversals. In a sustained trend, a slow rule can retain a position through a large counter-move. Any tradeoff needs a defined objective, execution convention and test sample. More averages drawn on the same prices do not automatically provide more independent information.
Understanding moving average calculation differences
A recursive EMA uses a smoothing factor of α = 2/(period + 1). One calculation convention starts from the first valid observation and carries the previous average through missing observations. Other conventions may use different starting values or missing-data rules.
The educational simulations in this guide require valid numerical inputs. When comparing moving averages across charts or platforms, align the price history, adjustment method, input field, initialization and missing-data treatment.
Continue with MACD’s two averages and signal line, Wilder’s gain/loss smoothing, and context and classification uncertainty.