Home / Foundations
Foundations
Simple vs exponential moving average.
All three common moving averages smooth price and trail it. They differ in how much weight each past bar gets, which changes how quickly they react.
What every moving average does
A moving average replaces a noisy series of prices with a smoother one. Each point on the line is some average of the most recent N bars. Because it contains older prices, the line always trails the market. That trailing is called lag, and it is the price you pay for smoothness. Every difference between the SMA, EMA and WMA comes down to one question: how much weight does each past bar get?
The simple moving average (SMA)
The SMA gives every bar in the window equal weight. Add up the last N closes and divide by N.
SMA(N) = (P[0] + P[1] + ... + P[N-1]) / N
For example, five closes of 10, 11, 12, 13 and 14 give a 5-period SMA of 60 / 5 = 12. When the next bar arrives, the oldest close drops out of the window completely and the newest one comes in. That abrupt exit can make the SMA step visibly when a large old bar leaves the window.
The exponential moving average (EMA)
The EMA never drops a bar entirely. It keeps a running value and nudges it toward each new price by a fixed fraction, called the smoothing factor.
alpha = 2 / (N + 1)
EMA[t] = alpha * Price[t] + (1 - alpha) * EMA[t-1]
For N = 9, alpha is 2/10 = 0.2. If the previous EMA is 100 and the new close is 105, the new EMA is 0.2 × 105 + 0.8 × 100 = 101. Older prices fade out gradually rather than falling off an edge, so recent bars carry more influence. Charting platforms typically start the series by seeding the first value with an SMA or the first price, which is why an EMA's earliest values can differ slightly between platforms.
The weighted moving average (WMA)
A linearly weighted average multiplies the newest bar by N, the one before by N-1, and so on down to 1, then divides by the sum of the weights, N(N+1)/2.
WMA(3) of 10, 11, 12 = (12*3 + 11*2 + 10*1) / 6 = 68 / 6 = 11.33
How they lag
It is tempting to say the EMA simply has less lag. The truth is more careful. In a steady trend, an N-bar SMA and an N-bar EMA built with alpha = 2/(N+1) trail price by about the same amount, roughly (N-1)/2 bars, while the WMA trails by about (N-1)/3 bars. Where they really differ is how they respond to a sudden move. After a jump, the EMA closes more of the gap in the first few bars, because the newest price is weighted heavily. The SMA closes the gap more slowly at first, then fully at bar N, when the old prices finally leave the window.
| Type | Weighting | Reaction to a sudden move | Notes |
|---|---|---|---|
| SMA | Equal across N bars | Gradual, then complete at bar N | Simple to compute; steps when an old bar leaves |
| EMA | Decaying, never zero | Faster at first, never fully complete | Needs a seed value; very common on trading platforms |
| WMA | Linear, N down to 1 | Fast; lowest steady-trend lag of the three | Less common; can look jumpy |
What this means for crossovers
A crossover compares two averages, so each average's character shows up in the signal. Faster-reacting averages tend to cross sooner, which can mean earlier entries and also more false starts. Smoother averages cross later and less often. That trade-off exists whichever type you pick; choosing an EMA over an SMA shifts it a little but does not remove it. You can see this directly in the playground on the home page: toggle between SMA and EMA on the same synthetic series and watch the crossings move.
For how EMA pairs are used in practice, read the EMA crossover guide. For the long-term version using the 50 and 200-day averages, see golden cross and death cross. Tools that help you plot the averages in NinjaTrader are covered on the NinjaTrader page, and indicators.ninja collects indicator ideas.
Note. All charts here use synthetic data created for illustration. They are not market data and not a test of any approach.
Frequently asked questions
Is an EMA better than an SMA?
Neither is better in general. An EMA reacts faster to recent moves, which is useful when you want earlier signals and costly when price chops. An SMA is easier to calculate by hand and to reason about. Which one suits you depends on the market, timeframe and rules, and the only honest way to compare them is to test both on the same data.
What does 2/(N+1) mean in the EMA formula?
It is the smoothing factor, usually written alpha. For a 9-period EMA it is 2/10 = 0.2, so each new bar contributes 20 percent and the previous EMA contributes 80 percent. Longer periods give a smaller alpha and a smoother line.
Do an SMA and an EMA of the same length cross at the same time?
Generally not. Because the weights differ, the two lines sit at slightly different levels and turn at different moments, so crossovers built from SMAs and from EMAs of the same lengths will not line up exactly.
What is a weighted moving average used for?
A WMA gives the newest bar the largest linear weight and the oldest the smallest. It is less common than the SMA and EMA but appears in some indicators, and it trails a steady trend by less than the other two at the same length.
Keep reading
Golden cross and death cross
The 50/200-day crossover: what the names mean, what they do not, and where it falls short.
Day tradingEMA crossover
Common pairs such as 9/21 and 12/26, sensible filters, and why ranges chew crossovers up.
Honest answerBest settings
Why no universal best pair exists and how to test the ones you care about properly.