The Exponential Moving Average (EMA) is one of the most-used technical indicators in trading, and its formula is deceptively simple: a single recursive equation that takes today’s close, yesterday’s EMA, and a smoothing factor called alpha. This guide walks through the formula step by step, derives where alpha comes from, computes a worked example on NIFTY 50 daily data, and shows how to implement EMA in Excel, Python, and pandas.
The Exponential Moving Average for a closing-price series P at time t is defined recursively:
α = 2 / (N + 1)
EMA_t = α × P_t + (1 − α) × EMA_t-1
Two values matter:
- N is the period — typically 9, 12, 20, 50, or 200.
- α (alpha) is the smoothing factor, derived from N. For a 10-period EMA, α = 2/11 ≈ 0.1818.
The recursion needs a starting value, EMA_0. The most common conventions are:
- Seed with the first close:
EMA_0 = P_0. Simple but the first few EMA values are biased toward that single starting bar.
- Seed with an N-period SMA:
EMA_N = (P_0 + P_1 + … + P_N−1) / N, then run the recursion from there. This is what TradingView, MetaTrader, and most charting platforms use.
- Use pandas
ewm(adjust=False) with no seed: pandas effectively starts with EMA_0 = P_0. Same as option 1.
After about 3 × N to 4 × N bars, the choice of seed has almost no impact on the current EMA — the exponential decay washes it out.
Where alpha comes from
The choice of α = 2 / (N + 1) is not arbitrary. It is engineered so that the center of mass of the EMA’s weighted-average lookback equals the same lookback you would expect from an N-period simple moving average. In other words, an N-period EMA “feels” like it is averaging over N bars, even though it technically incorporates the entire history with declining weights.
If you unroll the recursion, the implicit weight schedule for an N-period EMA is:
- Today’s bar: weight α
- Yesterday’s bar: weight α(1−α)
- 2 days ago: weight α(1−α)²
- 3 days ago: weight α(1−α)³
- And so on, geometrically declining
The sum of all those weights is exactly 1, which means the EMA is a true weighted average. The choice α = 2/(N+1) makes the effective lookback (the weighted-average bar age) equal to (N−1)/2, the same as an SMA of length N.
A worked example — 10-period EMA on NIFTY 50
Suppose the last 10 NIFTY 50 daily closes are:
For a 10-period EMA, α = 2/11 ≈ 0.1818.
Step 1 — Seed. Use the first close as EMA_0 = 24,100 (the simplest convention). Or use the SMA of all 10 = 24,304 for a more centered seed. Let’s go with the SMA seed: EMA_t-10 = 24,304.
Step 2 — Run the recursion forward. This requires bars after the seed. Suppose the next bar is P = 24,650.
EMA = 0.1818 × 24,650 + (1 − 0.1818) × 24,304
= 4,481 + 19,886
= 24,367
Step 3 — Continue. For each subsequent bar, take 18.18% of today’s close and add 81.82% of yesterday’s EMA. After enough bars, the EMA settles into its long-run behaviour — a smooth line that hugs price during trends and curves through ranges.
Implementing EMA in Excel
In Excel, with closes in column A starting at A2, drop this formula in B2 to seed and B3 onwards to compute:
B2: =A2 (seed — first close)
B3: =(2/11) * A3 + (1 - 2/11) * B2 (10-period EMA recursion)
Drag B3 down to fill the column. The constant 2/11 ≈ 0.1818 is the alpha for a 10-period EMA — change to 2/(N+1) for any other length.
Implementing EMA in Python / pandas
In pandas, ewm does the work:
import pandas as pd
closes = pd.Series([24100, 24200, 24150, 24250, 24300, 24180, 24360, 24420, 24500, 24580])
ema = closes.ewm(span=10, adjust=False).mean()
print(ema.tolist())
The adjust=False flag uses the recursive form above. With adjust=True (the default), pandas uses an alternative finite-window adjustment that produces slightly different values for the first few bars and converges to the same long-run series. For technical-indicator work, adjust=False is standard and matches what trading platforms produce.
Implementing EMA in Pine Script (TradingView)
//@version=5
indicator("Custom EMA", overlay=true)
length = input.int(10, title="Length")
alpha = 2 / (length + 1)
ema_val = ta.ema(close, length)
plot(ema_val, color=color.orange, linewidth=2)
TradingView’s built-in ta.ema uses the same recursion with the SMA-seed convention — virtually identical to pandas ewm(adjust=False) after a few dozen bars.
Common EMA periods on Indian indices
These are the conventions you’ll see on every NIFTY 50 / BANK NIFTY chart:
- 9 / 21 EMA on 5-min and 15-min — intraday momentum
- 20 / 50 EMA on 1-hour — intermediate trend
- 50 / 200 EMA on daily — primary long-term trend (the EMA equivalent of the Golden Cross / Death Cross)
The 9/21 5-min crossover is what intraday momentum traders watch most; the 50/200 daily is what financial-news desks reference in trend reporting.
EMA vs SMA — when to use each
EMA reacts faster than SMA at trend changes because the most recent bar weighs more. It also catches reversals slightly earlier. The trade-off: EMA is slightly noisier in ranges, producing more whipsaws on choppy days.
For a side-by-side comparison on NIFTY 50 — including average lag in trading days, total cross counts over 5 years, and forward-return profile — see our EMA vs SMA comparison page. The data shows that 50/200 EMA on NIFTY daily flips, on average, several trading days before the 50/200 SMA at trend changes.
Putting it together
The EMA formula is small but powerful: a single recursion blends today’s close with yesterday’s average, weighted by a smoothing factor that controls how much memory the line has. Once you understand alpha and the recursion, every “EMA” on every charting platform is just this same calculation under the hood.
For traders, the formula matters because it tells you exactly how reactive an EMA is to a fresh bar — about 18% of a 10-EMA’s value comes from the latest close, about 4% of a 50-EMA’s value, and less than 1% of a 200-EMA’s value. That’s why short-period EMAs are useful for intraday entries and long-period EMAs for trend definition.
For the live application of EMA on Indian indices, see the NIFTY EMA regime and methodology pages — both show the formulas above applied in real time to NIFTY 50 and BANK NIFTY data.
Frequently asked questions
- What is the formula for the Exponential Moving Average?
- EMA_t = alpha × P_t + (1 − alpha) × EMA_t-1, where alpha = 2 / (N + 1) and N is the EMA period. The recursion needs a starting value EMA_0; the convention is to use the simple moving average of the first N closes, or simply the first close, depending on the platform.
- What is alpha in the EMA formula?
- Alpha (α) is the smoothing factor — the fraction of today's price that gets blended into the new EMA. For an N-period EMA, alpha = 2 / (N + 1). For a 10-period EMA, alpha = 2/11 ≈ 0.182, meaning about 18% of the new EMA value comes from today's close and the remaining 82% comes from carrying the previous EMA forward.
- How do I calculate EMA in Excel?
- In Excel, use the recursive formula: EMA_t = alpha × Price_t + (1 − alpha) × EMA_t-1. For a 10-period EMA, alpha = 2/(10+1) = 0.1818. Seed the first EMA cell with the first close (or the average of the first 10 closes), then drag the formula down. The result for any cell is = (2/11) × today's price + (1 − 2/11) × yesterday's EMA.
- Why does EMA give more weight to recent prices?
- Each time the recursion runs, today's price gets weight alpha and the entire history gets weight (1 − alpha) — but that history is itself the previous EMA, which already gave smaller weight to its own recent prices. Unrolled, this produces a geometrically decaying weight schedule where the most recent bar weighs the most and older bars weigh exponentially less.
- Does EMA need a seed value?
- Yes — the recursion starts somewhere. The standard convention is to use the first close as the seed for EMA_0, or to use the simple moving average of the first N closes. After 3-4 × N bars the choice of seed has minimal impact on the current EMA value because of the exponential decay.
More in Moving Averages: The Complete Guide for NIFTY & BANKNIFTY Traders
Related on emaindicator.com