⬡ INDICATOR · WITH CODE · 11 MIN READ

Moving averages: SMA, EMA and WMA — which one to use.

The most fundamental indicator of them all — the base of almost every strategy. Let's go through the three variations, when to use each one, the popular periods (9, 21, 50, 200) and the ready-made code.

By the RoboTraderIA team· updated May 2026· beginner level

If you were going to learn a single indicator, it would be the moving average. It smooths out price noise to reveal the trend, works as dynamic support/resistance, and is the building block of other indicators (MACD is made of averages, Bollinger Bands revolve around an average). But there is more than one type, and picking the wrong one costs you late or false signals. Let's clear it up.

01What a moving average is

A moving average calculates the average price over a number of periods and "walks" forward with time — every new candle, it recalculates. The result is a smooth line that filters out small swings and shows the underlying direction. The longer the period, the smoother (and slower) the line.

02SMA, EMA and WMA: the real difference

All three calculate an average, but they distribute the weight differently:

TypeHow it weights pricesCharacteristicBest for
SMAEqual weight for allSmoother, slowerSeeing the underlying trend, filtering noise
EMAMore weight on recent pricesReacts fasterQuick signals, day trading
WMALinearly decreasing weightIntermediate reactionMiddle ground between SMA and EMA

The SMA (Simple Moving Average) treats the price from 20 candles ago with the same weight as the current candle. The EMA (Exponential) gives much more importance to recent prices, so it "hugs" price more closely and reacts faster to changes. The WMA (Weighted) sits in between, with linearly decreasing weights.

price EMA (fast) SMA (slow) price turn
After a turn in price, the EMA (green) follows faster; the SMA (gold) takes longer to turn.

The fundamental trade-off: fast reaction (EMA) = catches trends early, but gives more false signals. Smoothing (SMA) = fewer false signals, but enters late. There is no "best" — there is the right one for your goal. Day trading leans toward the EMA; a view of the underlying trend, the SMA.

03The popular periods (and why they matter)

Some periods are used so widely that they become "self-fulfilling" — so many people watch them that price reacts to them:

  • 9 and 21: short term, popular in day trading. The 9×21 crossover is a classic.
  • 20: the basis of Bollinger Bands and a short-to-medium-term reference.
  • 50: medium-term trend. Widely watched.
  • 200: the queen. Long-term trend. Price above the 200 average = structural uptrend; below = downtrend. Used as a master filter.

"Golden cross" and "death cross": when the 50 average crosses above the 200, it's called a golden cross (a long-term bullish signal); crossing below, a death cross (bearish). They're followed so closely that they make the news — and move the market for exactly that reason.

04The practical uses

  • Trend direction: price above the average = uptrend; below = downtrend. Simple and effective.
  • Dynamic support/resistance: in a trend, price often pulls back to the average and respects it — a re-entry zone.
  • Crossovers: a fast average crossing the slow one generates signals (the basis of the moving average crossover strategy).
  • Filter: only trading in line with the 200 average eliminates a lot of bad trades against the bigger trend.

05Coding the averages

Pine Script (TradingView)
//@version=5
indicator("Médias Móveis", overlay=true)

p = input.int(21, "Período")

sma = ta.sma(close, p)   // simple
ema = ta.ema(close, p)   // exponential
wma = ta.wma(close, p)   // weighted

plot(sma, "SMA", color=color.orange)
plot(ema, "EMA", color=color.lime)
plot(wma, "WMA", color=color.blue)

// trend filter using the 200 moving average
ma200 = ta.sma(close, 200)
tendencia_alta = close > ma200
plot(ma200, "MM200", color=tendencia_alta ? color.green : color.red, linewidth=2)
Python (with pandas)
import pandas as pd

def medias(precos, periodo=21):
    sma = precos.rolling(periodo).mean()
    ema = precos.ewm(span=periodo, adjust=False).mean()
    # WMA: linear weights 1..n
    pesos = pd.Series(range(1, periodo+1))
    wma = precos.rolling(periodo).apply(
        lambda x: (x * pesos).sum() / pesos.sum(), raw=True)
    return sma, ema, wma

sma, ema, wma = medias(df["close"])

# trend filter: only go long above the 200 MA
df["ma200"] = df["close"].rolling(200).mean()
pode_comprar = df["close"].iloc[-1] > df["ma200"].iloc[-1]

Ready to build the strategy?

The moving average crossover is the #1 strategy in our collection — with the full code.

See strategies →

06Common mistakes

The 3 classic mistakes: (1) using an average that's too short and getting chopped up by noise; (2) trading moving average crossovers in a ranging market, where they cross constantly and produce whipsaws; (3) forgetting that a moving average is a lagging indicator — it confirms the trend, it doesn't predict it. An average is never a standalone trigger; it's context and a filter.

07Frequently asked questions

What's the difference between SMA and EMA?

The SMA gives equal weight to every price in the period; the EMA gives more weight to recent prices, so it reacts faster. The EMA is preferred for quick signals and day trading; the SMA for smoothing and seeing the underlying trend.

Which moving average should I use?

EMA for a fast reaction, SMA for smoothing. Periods 9 and 21 for the short term; 50 and 200 for the long-term trend. There is no universal "best" — it depends on your goal and the asset, validated by backtesting.

What is the 200 moving average?

The 200-period moving average is the long-term trend reference. Price above = structural uptrend; below = downtrend. Widely used as a master trend filter in strategies.

What is a golden cross?

When the 50 average crosses above the 200 — a long-term bullish signal. The opposite (crossing below) is the death cross. They're watched so closely that they make the news and influence the market.

Does a moving average predict price?

No. It's a lagging indicator — it's calculated from past prices. It confirms and smooths the trend, works as dynamic support/resistance and as a filter, but it doesn't predict. Anyone expecting a forecast ends up disappointed.

Read next

🎁 Get the free trading bot (with Quotex, Deriv and IQ Option APIs)

Open source bot + ready-made API code. You edit it by chatting with ChatGPT/Claude — no programming. Free, no spam.

👉 Want the ready-made bot? Go to botbinaryoptions.com →