Why usFeaturesTemplatesBlogGlossary

Exponential Moving Average (EMA)

A moving average that weights recent bars more heavily than older ones, so it tracks price turns faster than a simple average of the same length.

An exponential moving average solves one complaint about the simple average: a close from 50 sessions ago counts as much as this morning’s. The EMA fixes that by decaying the weight of each older bar geometrically. In the expression language it is @EMA(close, 20).

How it is computed

EMA_t = alpha * P_t + (1 - alpha) * EMA_(t-1)

where alpha = 2 / (N + 1)

For N = 20 the smoothing constant is 2 / 21, about 0.095. Each new close contributes roughly 9.5% of the new value and the previous EMA carries the remaining 90.5%. Nothing ever leaves the window entirely, it just fades. The result is a rupee price, so it compares to price the same way an SMA does:

close > @EMA(close, 50)

A short-over-long comparison on HDFCBANK reads:

@EMA(close, 12) > @EMA(close, 26)

Typical windows

ExpressionWeight on newest barCommonly read as
@EMA(close, 12)15.4%fast line, feeds MACD
@EMA(close, 20)9.5%short-term trend
@EMA(close, 26)7.4%slow line, feeds MACD
@EMA(close, 50)3.9%intermediate trend

The 12 and 26 pairing comes from Gerald Appel’s MACD work in the 1970s, when the trading week had six sessions. Those numbers survived the change in market structure by inertia rather than by evidence.

How to read the output

An EMA turns sooner than an SMA of the same length, which is often described as an advantage. It is a trade-off. Faster response means the line reacts to single-day noise that the simple average would have absorbed, so you get earlier signals and more false ones. Which side of that trade suits a strategy is an empirical question for a backtest, not something the formula settles.

Risks and caveats

The EMA still lags. Weighting the recent bars more heavily shortens the delay, it does not remove it, because the value is still built entirely from prices that have already printed.

In a range-bound market the faster response makes whipsaw worse, not better. On a stock chopping sideways, a 20-period EMA will cross price more often than a 20-period SMA will, and every extra crossing is another round of costs.

Because the recursion never fully forgets old data, the EMA value at any date depends slightly on where your price history starts. On a short backtest window the first several dozen bars carry a warm-up artefact. Give the series enough history before the strategy’s start date that the initialisation has decayed away.

Back to Glossary