This guide calculates both on a model Nifty series, measures how far each lags the price, explains the weighted and smoothed variants, the common periods including the 200-day, and how traders use moving averages for trend, support, filters and exits.
Key takeaways
- SMA = the sum of the last N closes ÷ N. A 20-day SMA rises on any day the new close is above the close it replaces, the one from 20 sessions earlier.
- EMA today = close × k + yesterday's EMA × (1 − k), with k = 2 ÷ (N + 1). For a 20-day EMA, k is 0.0952: the latest close carries 9.52% of the weight, against 5% in a 20-day SMA.
- Both a 20-day SMA and a 20-day EMA have an average data age of 9.5 sessions, but the EMA reacts sooner to a change of direction because its weight is concentrated on recent closes.
- Faster averages turn sooner and cross the price more often. On the model series the price crossed its 9-day EMA nine times and its 20-day averages twice.
- Moving averages are read on the index or futures chart. On an option's own chart, time decay pulls the average down whatever the index does.
The model Nifty series
Every number on this page comes from one model series of 72 daily closes, a seeded random walk that is not market data. It is the same series used in the guides to RSI and MACD.
| Phase | Sessions | Close at the start | Close at the end |
|---|---|---|---|
| Dip and slow rise | Days 1 to 25 | 24,800.00 | 24,920.15 |
| Rally to the high | Days 26 to 32 | 24,959.45 | 25,500.00 |
| Fall to the low | Days 33 to 44 | 25,473.00 | 24,158.55 |
| Recovery | Days 45 to 72 | 24,181.20 | 25,867.60 |
The high is 25,500.00 on day 32 and the low 24,158.55 on day 44, a fall of 1,341.45 points or 5.26%. The series ends at 25,867.60.
Simple moving average (SMA)
The example shows the rule behind every SMA: the average changes by the difference between the close that enters and the close that leaves, divided by N. A 20-day SMA rises when today's close is above the close of 20 sessions ago and falls when it is below, whatever happened in between.
That rule explains the SMA's lag after the model low. Nifty bottomed on day 44, but the 20-day SMA kept falling until day 56, because each new close in the recovery was still below the close it replaced, from the rally and the top 20 sessions earlier. On day 57 the close of 24,985.05 finally exceeded the day 37 close of 24,938.05, and the SMA turned up by 2.35 points.
The same rule produces the drop-off effect. A large move 20 sessions ago moves the SMA a second time on the day it leaves the window, even if nothing happens that day.
Exponential moving average (EMA)
An exponential moving average gives the most weight to the latest close and a steadily smaller weight to each older one. No close ever drops out completely, so there is no drop-off effect.
How the weights fall away
| Close | Weight in a 20-day EMA | Weight in a 20-day SMA |
|---|---|---|
| Today | 9.52% | 5% |
| 1 session ago | 8.62% | 5% |
| 2 sessions ago | 7.80% | 5% |
| 3 sessions ago | 7.05% | 5% |
| 4 sessions ago | 6.38% | 5% |
| The last 20 closes together | 86.5% | 100% |
| Older closes | 13.5% | 0% |
The EMA puts almost twice the SMA's weight on the latest close, and the 20 closes an SMA would use carry 86.5% of the EMA's weight. The rest belongs to older closes, with weights that shrink by about a tenth each session.
Where an EMA starts
An EMA needs a starting value. The usual choice is the SMA of the first N closes: on the model series the first 20-day EMA, on day 20, equals the 20-day SMA of 24,710.67. Some platforms start from the first close instead, which gives 24,754.23 on day 20. The two versions converge, and by day 72 they are 0.24 points apart. Starting from later data makes a bigger difference: an EMA built only from day 30 onwards reads 24,751.72 on day 50, 173.58 points above the version built from day 1, and is still 19.20 points away on day 72. Load several times N periods of history before relying on an EMA's exact value.
SMA vs EMA
| SMA | EMA | |
|---|---|---|
| Weighting | Equal for every close in the window | Highest on the latest close, falling for older ones |
| Weight on the latest close, 20 periods | 5% | 9.52% |
| Average age of the data, 20 periods | 9.5 sessions | 9.5 sessions |
| Turns after a change of direction | Later | Sooner |
| Drop-off effect | Yes | No |
| False signals in a sideways market | Fewer | More |
| Common use | Long-term trend, such as the 200-day | Short-term trend and crossovers, such as the 9 and 20 |
The average age of the data is the same for both, (N − 1) ÷ 2 sessions, which is how the EMA's multiplier is chosen. The difference is in the shape of the weights. The EMA leans on the latest closes, so it responds sooner when the direction changes; the SMA spreads its weight evenly and responds when the closes leaving the window are on the other side of the price.
Neither is better in general. The EMA catches turns sooner and crosses the price more often in a sideways market. The SMA is steadier and later.
How much moving averages lag
The model series has one clear top and one clear bottom, so the lag of each average can be counted in sessions.
| Average | Turned down after the high on day 32 | Turned up after the low on day 44 |
|---|---|---|
| 9-day EMA | Day 35, 3 sessions later | Day 50, 6 sessions later |
| 20-day EMA | Day 37, 5 sessions later | Day 51, 7 sessions later |
| 20-day SMA | Day 38, 6 sessions later | Day 57, 13 sessions later |
The SMA's late turn after the low is the drop-off rule at work: the 20 closes before day 57 included the top of the rally, and every recovery close until then was lower than the one it replaced.
The price itself crossed the averages earlier than the averages turned:
| The close crossed | 20-day SMA | 20-day EMA | 9-day EMA |
|---|---|---|---|
| Below, after the high | Day 37 | Day 37 | Day 35 |
| Above, after the low | Day 52 | Day 51 | Day 50 |
| Crossings in all 72 sessions | 2 | 2 | 9 |
The 9-day EMA reacted first, and it also crossed the price seven times between day 10 and day 22, when the index moved sideways between 24,620 and 24,979. Every crossing in that stretch would have been a false signal for a rule that trades them. That is the trade-off in every moving average: a shorter period means earlier signals and more false ones.
Reading the model series with moving averages
| Phase | The close against the 20-day SMA | What the averages said |
|---|---|---|
| Days 20 to 28 | Above it every session, by 82 to 310 points; the 9-day EMA crossed the price on days 20 and 22 | A mild uptrend with small pauses |
| Days 29 to 36 | Above it by up to 545 points, 2.19%, on day 31 | A fast rally, stretched far from its average |
| Days 37 to 51 | Below it every session, by up to 817 points, 3.27%, on day 44 | A downtrend |
| Days 52 to 72 | Above it every session, by 143 to 641 points, ending 2.54% above | A new uptrend |
The 20-day EMA rose on 38 of the 52 sessions from day 21 and fell on 14. The averages anticipated neither turn. What they did well was keep a reader on the right side of each trend once it was under way, and show when the price had stretched far from its average, as on days 31 and 44.
Weighted, smoothed and other averages
| Type | How it weights the closes | Day 72 value, 20 periods |
|---|---|---|
| Simple (SMA) | Equally | 25,227.06 |
| Exponential (EMA) | Falling by a fixed share each session | 25,271.65 |
| Weighted (WMA) | Falling in a straight line: 20, 19, 18 and so on down to 1 | 25,369.13 |
With the close at 25,867.60 after a steady rise, the WMA sits closest to the price, then the EMA, then the SMA. The WMA's newest close carries 20 ÷ 210 = 9.52% of the weight, the same as the EMA's, but its weights reach zero after 20 closes, so its average data age is only 6.33 sessions against 9.5.
Other variants appear in many charting tools:
- Smoothed moving average. Wilder's smoothing, with a weight of 1 ÷ N on the newest close. It is used inside RSI and ATR, and is slower than an EMA of the same length: a 14-period smoothed average reacts like a 27-period EMA.
- Hull moving average. Alan Hull's combination of weighted averages, built to reduce lag while staying smooth.
- Double and triple exponential averages (DEMA, TEMA). Patrick Mulloy's combinations of EMAs that subtract part of the lag.
These change the shape of the weights, not the basic trade-off. Test any of them the same way as an SMA or EMA, with the same costs and the same out-of-sample periods.
Common periods
| Period | Covers on a daily chart | Typical use |
|---|---|---|
| 9 or 10 | About two weeks | Short-term trend and trailing exits |
| 20 or 21 | About a month | Short-term trend and the usual pullback zone |
| 50 | About 2½ months | Medium-term trend |
| 100 | About five months | Medium to long-term trend |
| 200 | About ten months | Long-term trend |
On intraday charts the same periods cover much less time. The NSE session runs from 9:15 am to 3:30 pm, 375 minutes, so a 20-period average covers 100 minutes on a 5-minute chart and 5 hours on a 15-minute chart, most of one session. A 9-period average on a 5-minute chart covers 45 minutes.
Round numbers such as 20, 50 and 200 matter mainly because so many traders use them. A 21-day or a 55-day average behaves almost the same as its rounder neighbour, and a rule that works only on one exact period is more likely to be fitted to past data than to describe the market.
The 200 day moving average
The 200 day moving average is the most watched long-term average. It covers about ten months of NSE sessions, and many investors and traders read Nifty above a rising 200-day average as a long-term uptrend and below a falling one as a long-term downtrend.
Three points apply to it:
- It needs 200 sessions of data. The model series on this page, at 72 sessions, is too short to have one; a real daily chart needs about ten months of history before the first value appears.
- Its slope matters as much as the price's position. A price above a flat 200-day average in a sideways year says less than a price above one that has been rising for months.
- It is slow by design. Its average data age is 99.5 sessions, so it confirms a long trend long after the turn. It is a filter for which side to trade, not a timing tool.
When the 50-day average crosses above the 200-day, traders call it a golden cross, and the opposite a death cross. The rules, worked numbers and backtesting notes for trading crossovers are in the moving average crossover strategy.
How traders use moving averages
Trend direction and slope
The simplest reading uses the slope and the price's position:
- Price above a rising average: uptrend.
- Price below a falling average: downtrend.
- A flat average that the price crosses often: no trend.
The slope can be measured in points a session. On day 72 the 20-day EMA rose 62.73 points, from 25,208.92 to 25,271.65, while the 20-day SMA rose 53.43, from 25,173.63 to 25,227.06. A rule can require the slope to be positive, or above a set number of points, before it allows long trades.
Pullback zones
In a trend, pullbacks often stall near a widely watched average, such as the 20-day or 50-day EMA. Traders treat the average as a zone, not a line, and look for an entry when the price reaches it and turns, with a stop beyond the zone. Prices often pierce an average before turning, so an exact touch rarely makes a good rule.
Filters
Many strategies use an average as a filter for another signal: take long setups only when the price is above the 50-day EMA, or only when the 20-day EMA is above the 50-day. A filter does not create trades; it removes the ones taken against the trend.
Distance from the average
How far the price has moved from its average shows how stretched the move is. On day 72 the model close of 25,867.60 is 640.54 points, or 2.54%, above the 20-day SMA. Mean-reversion rules use that distance, often in units of the average's standard deviation as Bollinger Bands do, to find moves that have gone too far, too fast.
Exits and trailing stops
A moving average can trail an open position: exit a long trade when the close falls below the 20-day EMA, for example. A faster average keeps more of the gain on sharp turns and gets stopped out more often in normal pullbacks. On the model series, a long position exited on the first close below the 9-day EMA after the high would have closed on day 35 at 25,285.10, 214.90 points below the high; one exited on the 20-day EMA would have closed on day 37 at 24,938.05.
Envelopes around a moving average
An envelope draws lines a fixed percentage above and below a moving average. With a 2% envelope around the 20-day SMA, the model closes went outside it on 17 sessions: days 30 to 32 above, days 41 to 48 below, and days 58, 59, 62, 63, 71 and 72 above. With a 3% envelope only days 44 and 45 went outside, at 3.27% and 3.04% below.
Mean-reversion rules use envelopes to find moves that have gone too far from the average; trend rules read a close outside the envelope as strength. The width decides how often either fires, so it has to suit the instrument: a band that suits Nifty is too narrow for a volatile stock. Bollinger Bands replace the fixed percentage with two standard deviations of the closes, so the bands widen when the market is volatile and narrow when it is quiet.
Moving averages on intraday charts
Intraday moving averages follow the same formulas. Two points matter on Indian indices:
- The opening gap. When Nifty opens far from the previous close, the first candle of the day can jump through the averages. A short EMA follows the gap quickly; a 200-period average on a 5-minute chart, which covers almost three sessions, barely moves.
- Continuity across sessions. Most platforms carry the calculation from one session to the next, so the morning's averages still contain the previous afternoon. Some intraday traders prefer VWAP for the day's fair price because it starts fresh at 9:15 am.
Combining timeframes
A common way to combine averages is to take the trend from a slower chart and the entry from a faster one. A trader might trade long only while Nifty's daily close is above a rising 50-day EMA, and use a pullback to the 20-period EMA on a 15-minute chart as the entry, with a stop below the pullback low. The daily average keeps the trades on the side of the main trend; the intraday average keeps the entry close to a level where a stop can be placed. The two timeframes need to be far enough apart to add information: a 5-minute and a 15-minute chart usually say the same thing.
Moving averages on Nifty, Bank Nifty, stocks and options
- Index or futures. Most traders draw moving averages on the Nifty or Bank Nifty index, or on near-month futures. A continuous futures chart jumps at each monthly roll unless the data is adjusted, and the jump passes into every average.
- Options. An option's price falls with time decay, so its own chart drifts down and stays below its averages whatever the index does. Read the averages on the underlying and trade the option on that view.
- Stocks. Corporate actions such as splits and bonus issues change the price without changing value. Use adjusted data, or the averages will show a false collapse on the date of the change.
Moving averages and VWAP
VWAP, the volume-weighted average price, is also an average, but it weights each price by the volume traded at it and resets at the start of every session. A moving average weights by time and runs across sessions. Intraday traders often use VWAP for the day's fair price and a moving average for the trend across days.
Moving averages and other indicators
Several indicators are built from moving averages:
- MACD is the difference between a 12-period and a 26-period EMA, with a 9-period EMA of that difference as its signal line.
- Bollinger Bands are a 20-period SMA with bands two standard deviations above and below.
- RSI uses Wilder's smoothed averages of gains and losses.
- ATR, the average true range, is a smoothed average of each period's range.
Understanding how an SMA and an EMA respond explains a large part of how these indicators behave, including why all of them lag.
The limits of moving averages
- They lag. Every average is built from past closes. The longer the period, the later the signal.
- They whipsaw in ranges. In a sideways market the price crosses its averages again and again, as it crossed the 9-day EMA seven times in 13 sessions on the model series.
- They do not forecast. An average says where the price has been, not where it will go.
- Their exact values depend on the data. The starting point, the data feed and the adjustment of futures and corporate actions all change the numbers.
Common mistakes
- Trading every crossover in a range. Crossovers in a flat market are mostly noise. Use a trend or range filter.
- Optimising the period on past data. A period that fits one year perfectly rarely fits the next. Choose periods that work across a range of nearby values.
- Treating an average as an exact level. Prices often pierce an average before turning. Use a zone and a stop.
- Ignoring the slope. A price above a falling average is not an uptrend.
- Reading averages on an option's chart. Time decay pulls the price below every average.
- Mixing data sources. Compare averages only when they use the same closes and the same history.
Using moving averages in a trading strategy
Moving averages appear in most rule-based strategies, usually in one of four roles:
| Role | Example rule |
|---|---|
| Trend filter | Take long setups only when the close is above a rising 50-day EMA |
| Entry signal | Buy when the 9-day EMA crosses above the 20-day EMA |
| Pullback entry | Buy when the price pulls back to the 20-day EMA in an uptrend and closes higher |
| Exit | Close a long trade on the first close below the 20-day EMA |
The crossover is the best-known entry rule, and also the one most exposed to whipsaws. On the model series the 9-day EMA crossed below the 20-day on day 39 and back above it on day 55: the first came 7 sessions after the high, the second 11 sessions after the low. The technical indicators guide compares moving averages with the other common indicators used in such rules.
Whatever the role, test the rule with the costs of every trade, on years the rule was not built on, and on more than one instrument.
Moving averages in QuantPower
In the option strategy builder, a strategy can require the index to be above or below a moving average before it enters, and moving averages can be used in indicator-based entry and exit conditions. The trade can be an option, a spread or a futures position. Test the rules in backtesting on five years of 1-minute data, then run them on live prices in paper trading before deploying them through your broker.
Start your free trial
Connect your broker, build a strategy and test it on paper before a single live order goes out.
Frequently asked questions
How is a moving average calculated?
A simple moving average adds the last N closes and divides by N. An exponential moving average multiplies today's close by 2 ÷ (N + 1) and adds yesterday's EMA multiplied by the rest. On the model series, the 5-day SMA on day 72 is 25,613.32 and the 20-day EMA 25,271.65.
What is the 200-day moving average of Nifty used for?
It is a long-term trend gauge. Many investors and traders treat Nifty above a rising 200-day average as a long-term uptrend and use it to decide which side to trade, not when to trade.
Which moving average is best for intraday trading?
There is no single best one. The 9 and 20-period EMAs on 5-minute or 15-minute charts are common starting points, and many intraday traders also use VWAP. Shorter averages give earlier signals and more false ones.
Why does the same EMA show different values on two platforms?
The EMA depends on its starting point and on every close since. Platforms start from different dates or seed the first value differently, and their closing prices can differ. The values converge over time but can be far apart on a short history.
What does the slope of a moving average show?
The direction and pace of the trend it measures. A rising average shows that recent closes are higher than older ones; a flat one shows no trend. Many rules require a rising average before a long trade.
How much data does a moving average need?
At least N closes for an SMA, so a 200-day average needs 200 sessions. An EMA needs N closes for its first value and several times N before its exact value stops depending on where the calculation began.
Related guides
- Moving average crossover strategy: crossover rules, model numbers and backtesting notes
- Technical indicators: the common indicators side by side
- RSI indicator: momentum from average gains and losses
- MACD indicator: momentum from two exponential moving averages
- Option strategy builder: moving average conditions on the underlying
Sources
- Murphy, J. J. (1999). Technical Analysis of the Financial Markets. New York Institute of Finance
- Wilder, J. W. (1978). New Concepts in Technical Trading Systems. Trend Research
- Mulloy, P. G. (1994). Smoothing Data with Faster Moving Averages. Technical Analysis of Stocks & Commodities, 12(1)
- NSE: trading hours for the equity and equity derivatives segments
