Noon Barbari
S'inscrire
Tous les articles
conceptPublié ·Lecture de 9 min

Moving averages, explained from scratch (SMA, EMA, WMA)

The single most overused — and most misunderstood — indicator in trading. Here's what moving averages actually do, what the flavours mean, and how to use them without fooling yourself.

Sur cette page

A moving average is the most common indicator on Earth, and also the most over-trusted. Open any chart, slap a 50- and 200-period line on it, and you have what looks like a system. You don't. You have a smoothing function. What you do with that smoothing function is where the real work is — and where most retail traders skip the work and go straight to the trade.

What a moving average actually is

Strip away the chart drawing and a moving average is one number: the average of the last N closes. That's it. At every new bar, the window slides forward — the oldest close drops out, the newest joins, the number is recomputed. The line you see on the chart is just that running number plotted bar by bar.

Why average at all? Price is noisy. A 5-second candle on BTC includes a hundred algo trades, a few panicked humans, and zero information about the medium-term direction. Averaging suppresses the noise so the underlying drift becomes visible. The cost: every average lags reality — the longer the window, the more it lags.

The three flavours

Three weighted variants of the same idea show up everywhere. Each is a different answer to the same trade-off: how much do you care about the recent close versus the older ones?

SMA, EMA and WMA over the same 5-bar window
# All three use closes [c1, c2, c3, c4, c5] where c5 is most recent.

# Simple MA  — every close weighted equally
SMA = (c1 + c2 + c3 + c4 + c5) / 5

# Exponential MA — newer closes weighted more
alpha = 2 / (5 + 1)              # ≈ 0.333
EMA[t] = alpha * c5 + (1 - alpha) * EMA[t-1]

# Weighted MA — linear weights, newest gets N, oldest gets 1
WMA = (1*c1 + 2*c2 + 3*c3 + 4*c4 + 5*c5) / (1+2+3+4+5)

The practical consequence: SMA is the smoothest and slowest. EMA reacts faster but is noisier. WMA sits between them. There's no universally best choice — there's a choice that fits what your strategy is trying to do, and a choice that doesn't. We covered EMA vs SMA in detail in a separate post; see the link at the bottom.

Picking a period

The number after the MA — the 20 in EMA(20), the 50 in SMA(50) — is the lookback window. Short periods (5, 10, 14) react in a few bars. Long periods (50, 100, 200) react in dozens. The 50/200 pair on a daily chart is a famous default because it roughly tracks the 2-month and 9-month trends; the 9/21 pair on a 4h chart approximates 1.5-day and 3.5-day trends.

How to choose? Match the period to your strategy's holding time. A scalp that lasts 30 minutes on a 5-minute chart will not benefit from a 200-period MA — that's a 16-hour signal. A swing strategy that holds for two weeks won't get a useful signal out of a 10-bar MA — that's 40 hours of noise on a 4h chart.

What MAs actually tell you

Three legitimate uses, in increasing order of difficulty.

  • Trend filter. Price above a long-period MA → uptrend bias; below → downtrend bias. Use it as a gate that lets entry rules fire only on the trend side.
  • Dynamic support and resistance. A widely watched MA (50- or 200-period) sometimes acts as a self-fulfilling level because thousands of traders place orders near it. The effect is real but smaller than retail folklore claims — about 1–2% edge on touch reactions in liquid markets.
  • Crossover signals. Fast MA crossing slow MA is the original systematic trade. It survives because it captures real trend changes — but it whipsaws painfully in chop.

When MAs lie

Two failure modes will kill an MA-based strategy if you don't plan for them. First, range-bound markets. When price oscillates around an MA without a real trend, every minor swing produces a crossover, then an opposite crossover three bars later. You'll get chopped to pieces on a strategy that looked beautiful in backtest because the backtest period happened to be trending.

Second, regime changes. The volatility profile of BTC in 2021 (parabolic retail mania) is not the volatility profile of BTC in 2025. An MA period that worked perfectly in one regime will be too fast or too slow in the next. The only honest defence is walk-forward optimisation — refit the period periodically and don't expect any single number to hold forever.

A rule-set snippet

rules.yaml — ADX-gated EMA crossover with regime filter
strategy:
  name: trend_follow_ma
  indicators:
    - { id: fast,  kind: EMA, period: 20 }
    - { id: slow,  kind: EMA, period: 50 }
    - { id: regime, kind: SMA, period: 200 }
    - { id: trend, kind: ADX, period: 14 }
  rules:
    entry:
      type: AND
      children:
        - { type: cross_above, left: fast, right: slow }
        - { type: gt, left: bar.close, right: regime }   # only when above 200-SMA
        - { type: gt, left: trend, right: 22 }            # only in a trending regime
    exit:
      type: cross_below
      left: fast
      right: slow
  risk:
    size_pct: 1.0
    stop_loss_atr: 2.5

The 200-SMA gate prevents counter-trend trades in big bear moves. The ADX gate keeps you out of range markets where MA crossovers are noise. Both gates cost you trades you'd have taken — and almost all of those trades were going to lose money.

Next steps

Read the EMA vs SMA head-to-head for the numbers behind picking one variant over another, then look at the trend post to understand the market structure your MA is supposed to be measuring. The platform's indicators reference ships SMA, EMA and WMA with identical kwargs, so swapping one for the other in a YAML rule set is a single-line change.

Essaie-le sur tes propres données

Chaque concept ci-dessus est implémenté dans la plateforme. Backtest, walk-forward, paper trading, puis passage en live — même jeu de règles à chaque étape.

Lectures associées