Understanding Moving Averages

SMA, EMA, and WMA explained — how they work, when to use them, and common crossover strategies.

What is a Moving Average?

A moving average (MA) calculates the average price over a specified number of past candles, creating a smooth line that filters out short-term noise and reveals the underlying trend. As each new candle forms, the oldest candle drops out of the calculation and the newest one enters — hence "moving" average.

Moving averages are the most widely used indicators in trading. They form the foundation of countless strategies and are a building block for other indicators like MACD and Bollinger Bands.

Types of Moving Averages

Simple Moving Average (SMA) — Calculates the arithmetic mean of the last N closing prices. Every price in the window has equal weight.

SMA = (Price[1] + Price[2] + ... + Price[N]) / N

Advantages: Smooth, stable, easy to understand. Disadvantages: Reacts slowly to price changes because old prices have the same weight as recent ones.

Exponential Moving Average (EMA) — Gives more weight to recent prices using an exponential smoothing factor. This makes it react faster to price changes than SMA.

EMA = Price * k + EMA_previous * (1 - k)
where k = 2 / (N + 1)

Advantages: Faster response to new price data. Disadvantages: More prone to false signals in choppy markets.

Weighted Moving Average (WMA) — Assigns linearly decreasing weights to older prices. The most recent price gets weight N, the previous gets N-1, and so on.

WMA falls between SMA (slowest) and EMA (fastest) in responsiveness.

Choosing the Right Period

The period (N) determines how many candles are averaged:

  • Short-term (5-20): Captures quick moves, many signals, more false signals. Used for scalping and day trading.
  • Medium-term (20-50): Balances responsiveness and reliability. The 20 EMA and 50 SMA are among the most popular settings.
  • Long-term (100-200): Shows the major trend. The 200 SMA is watched by institutional traders worldwide as the definitive trend marker.
💡
The 200 SMA Rule

A widely followed rule: if price is above the 200 SMA, the market is in an uptrend — look for buying opportunities. If below, it is in a downtrend — look for selling opportunities. This single rule eliminates many bad trades.

Moving Average Crossover Strategies

When a shorter MA crosses above a longer MA, it signals that momentum is shifting upward. When it crosses below, momentum is shifting downward.

Golden Cross — The 50-period MA crosses above the 200-period MA. This is considered a strong bullish signal and is watched by traders and institutions globally.

Death Cross — The 50-period MA crosses below the 200-period MA. A bearish signal suggesting a potential extended downtrend.

Shorter crossover pairs like 9/21 EMA generate more frequent signals suitable for day trading, while 50/200 SMA crossovers are for position trading and investment timing.

Using Moving Averages as Support and Resistance

In trending markets, moving averages often act as dynamic support (in uptrends) or resistance (in downtrends). Price frequently bounces off the 20 EMA or 50 SMA during pullbacks, providing entry opportunities in the direction of the trend.

The stronger the trend, the more reliably the MA acts as support/resistance. When price breaks through a major MA (like the 200 SMA), it often signals a trend change.

Limitations

  • Lagging indicator — MAs are based on past data, so they always lag behind current price action. They confirm trends rather than predict them.
  • Poor in ranging markets — When price moves sideways, MAs generate constant false crossover signals (whipsaws). Always confirm the market is trending before relying on MA signals.
  • No perfect period — There is no universally "best" period. The optimal setting depends on the instrument, timeframe, and market conditions.

MQL5 Implementation Preview

In MQL5, you can access moving averages programmatically using the iMA() function:

int maHandle = iMA(_Symbol, PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE);
double maBuffer[];
CopyBuffer(maHandle, 0, 0, 3, maBuffer);

This creates a 200 SMA handle and copies the latest 3 values into a buffer array. We will cover this in detail in the MQL5 Programming tutorials.