The Simple Moving Average (SMA) is the simplest possible moving-average calculation: take the last N closing prices, add them up, divide by N. That single arithmetic mean is the SMA. Despite its simplicity — or because of it — SMA remains one of the most-quoted technical indicators in finance, especially when the 50-day SMA crosses the 200-day SMA to produce the textbook Golden Cross or Death Cross.
This guide walks through the formula, computes a worked example on NIFTY 50 daily data, shows how to implement SMA in Excel, Python (pandas), and Pine Script, and explains where SMA fits among the family of moving averages — alongside EMA, WMA, and HMA.
For a closing-price series P and a window of N bars, the Simple Moving Average at time t is:
SMA_t = (P_t + P_t-1 + P_t-2 + ... + P_t-(N-1)) / N
Every bar in the lookback window contributes exactly 1/N of the SMA. The most recent bar P_t weighs the same as the bar N-1 periods ago. This equal-weighting is what distinguishes SMA from EMA (which weighs recent bars more) and WMA (which uses linear weights).
There is no recursion, no smoothing factor, no seed. SMA is fully defined by the most recent N closes — older bars have zero influence, newer bars have all of it.
A worked example — 5-period SMA on NIFTY 50
Suppose the last 5 NIFTY 50 daily closes are:
The 5-period SMA at time t:
SMA = (24,000 + 24,100 + 24,250 + 24,200 + 24,400) / 5
= 120,950 / 5
= 24,190
The next day, when a new close P_t+1 arrives, the SMA window slides forward by one bar — P_t-4 drops out of the calculation entirely, the new close enters, and the new SMA is recomputed. This is the essence of the “moving” part of SMA.
Implementing SMA in Excel
With closes in column A starting at A2, the 10-period SMA in column B can be computed with the AVERAGE function:
B11: =AVERAGE(A2:A11)
B12: =AVERAGE(A3:A12)
B13: =AVERAGE(A4:A13)
...
Excel handles the window-sliding automatically when you drag the formula down. Cells before B11 remain empty because there are not enough closes to compute the average — that is correct behaviour.
For a 50-period SMA on daily NIFTY data, you would need at least 50 daily closes before the first SMA value is meaningful. For a 200-SMA, at least 200 daily closes (about 10 trading months).
Implementing SMA in Python / pandas
In pandas, rolling(N).mean() is the entire implementation:
import pandas as pd
closes = pd.Series([24000, 24100, 24250, 24200, 24400, 24500, 24550, 24600, 24700, 24800])
sma = closes.rolling(window=5, min_periods=5).mean()
print(sma.tolist())
The min_periods=5 argument means the SMA is NaN until there are at least 5 closes in the window. This matches how charting platforms display SMA — the line starts at bar N, not bar 1.
Implementing SMA in Pine Script (TradingView)
//@version=5
indicator("Custom SMA", overlay=true)
length = input.int(50, title="Length")
sma_val = ta.sma(close, length)
plot(sma_val, color=color.blue, linewidth=2)
TradingView’s built-in ta.sma is exactly the formula above. The 50-period SMA is one of the most-watched indicators in financial-news commentary because of its role in the Golden Cross / Death Cross.
Common SMA periods on Indian indices
The conventions for SMA on NIFTY 50 and BANK NIFTY:
- 20-SMA on daily — short-term swing direction
- 50-SMA on daily — primary intermediate trend
- 100-SMA on daily — slower trend filter
- 200-SMA on daily — long-term primary trend; canonical for Golden / Death Cross
- 9-SMA / 20-SMA on intraday charts — used less often than EMA at fast lookbacks because SMA’s equal-weighting makes it slower to react
The 50/200 daily SMA crossover is the most-quoted moving-average signal in finance worldwide. When the 50 crosses above the 200, financial-news desks call it a Golden Cross — historically associated with the start of a long-term uptrend. When the 50 crosses below the 200, it is the Death Cross — a long-term bearish signal.
For live tracking of the 50/200 SMA on NIFTY 50 and BANK NIFTY, with the latest cross date and a 5-year forward-return backtest, see our Golden Cross / Death Cross page.
SMA vs EMA — when to choose each
Both are weighted averages of past closes. The difference is how the weights are distributed:
For pure smoothness on long lookbacks (50, 200), SMA wins. For reactive trend-following on shorter lookbacks (9, 21), EMA wins. For the middle ground, WMA or HMA may be a better fit.
For the side-by-side numbers on NIFTY 50 daily — average lag, cross counts, forward returns — see our EMA vs SMA page, which publishes the comparison from 5 years of OHLCV.
Strengths and weaknesses
Strengths of SMA:
- Simplicity. Easy to compute, easy to explain, no seed value or smoothing factor to tune.
- Smoothness. On long lookbacks, SMA is the smoothest of the four core moving averages.
- Wide recognition. Every charting platform, every news outlet, every textbook uses SMA in the canonical Golden / Death Cross definition.
Weaknesses of SMA:
- Lag. SMA is the slowest moving-average to react to a real trend change. A 200-SMA can lag a turn by two months.
- Equal weighting of stale data. A bar from 50 days ago has the same impact on a 50-SMA as the most recent bar. In a fast-moving market this can feel out of touch.
- Edge effect. The day a far-back bar drops out of the window can produce a small jump in the SMA, even though no real new information arrived. This artefact is sometimes called “drop-off lag.”
Putting it together
SMA is the bedrock moving average — the one every other moving average is compared against. For long-term trend definition, SMA at 50, 100, or 200 is standard. For shorter, more reactive lookbacks, EMA, WMA, or HMA usually beat SMA on signal latency.
For most Indian-index traders, the right approach is to use SMA for the macro trend filter (e.g., 50-SMA or 200-SMA on daily) and EMA for entry triggers on intraday charts. The two complement each other: SMA tells you the bigger picture; EMA tells you when to act.
For the live application — including the current 50-SMA and 200-SMA values on NIFTY and BANK NIFTY, plus the live Golden/Death Cross state — visit our 50/200 SMA Golden Cross / Death Cross page.
Frequently asked questions
- What is the formula for the Simple Moving Average?
- SMA = (P_t + P_t-1 + P_t-2 + ... + P_t-(N-1)) / N. Sum the last N closing prices and divide by N. Every bar in the lookback window contributes equally.
- How do I calculate SMA in Excel?
- Use the AVERAGE function over a rolling N-cell window. For a 10-period SMA with closes in column A starting at A2, the formula in B11 is =AVERAGE(A2:A11), then drag down. Excel automatically slides the window forward as you drag.
- What is the difference between SMA and EMA?
- SMA gives every bar in the lookback equal weight — the n-th most recent bar contributes 1/N just like the most recent bar. EMA gives more weight to recent bars and less to older bars, with weights decaying exponentially. SMA is smoother in chop; EMA reacts faster to trend changes.
- What is the most common SMA period?
- On daily charts, 50 and 200 are the canonical SMA periods — the 50-day SMA crossing the 200-day SMA is the textbook Golden Cross (50 above) or Death Cross (50 below). On intraday charts, 9, 20, and 50 are common; the choice depends on what timeframe you trade.
- Is SMA a lagging indicator?
- Yes. SMA is by definition a lagging indicator — it averages past prices and tells you what the market did, not what it will do. The lag scales with the lookback: a 50-period SMA has roughly 25 bars of effective lag at trend changes, a 200-period SMA has roughly 100 bars. That is the cost of smoothness.
More in Moving Averages: The Complete Guide for NIFTY & BANKNIFTY Traders
Related on emaindicator.com