How to calculate moving average in forex

Explore How to calculate moving: mechanics, differences, limitations, and practical checks.

What moving average means in forex

A moving average (MA) is a statistical smoothing method that turns a series of prices into a new series. In forex charting, you usually apply it to a price field such as the close (or sometimes the mid-price) of each candle.

Because an MA uses earlier values to compute today’s value, it generally reflects the recent “trend” level rather than the exact current price. The key inputs are:

  • Price series: the values you average (commonly the closing price per bar).
  • Lookback window (N): how many past bars are included.
  • Method: usually simple moving average (SMA) or exponential moving average (EMA).

How to calculate a simple moving average (SMA)

The SMA with window N at bar t is the arithmetic mean of the last N price values.

Formula:

  • SMA(t) = (Price(t) + Price(t-1) + … + Price(t-N+1)) / N

Step-by-step:

  1. Choose the window length N (for example, 20 bars).
  2. Pick the price field (for example, candle close).
  3. For each new bar, collect the most recent N closes.
  4. Add them and divide by N.
  5. Repeat for each bar after the first N bars.

Important assumptions and limitations:

  • The result depends on N. A longer window smooths more but lags more.
  • The result depends on the timeframe (e.g., 1H vs 4H), because the bar sequence changes.

How to calculate an exponential moving average (EMA)

An EMA also smooths prices, but it weights recent bars more than older ones.

Typical EMA definition:

  1. Compute an initial EMA value (often based on an SMA over the first N bars, depending on the platform’s convention).
  2. Use a recursive update for subsequent bars.

Formula (recursive form):

  • EMA(t) = Price(t) × k + EMA(t-1) × (1 − k)
  • k = 2 / (N + 1)

Step-by-step:

  1. Choose N and compute k = 2/(N+1).
  2. Establish EMA(t-1) using the chosen initialization method.
  3. For each new bar, apply the recursive formula.

Material limitation: Different charting tools may initialize EMA slightly differently (especially for the first available values). That means the EMA series can differ at the start even if the smoothing constant k is the same.

Example checks and practical verification

Because implementations vary (especially around EMA initialization and the exact price input), independent checks help.

SMA check:

  • Take a small window (e.g., N = 3).
  • Write down the last three chosen prices.
  • Compute the average manually and compare it to the plotted SMA at that bar.

EMA check:

  • Use the EMA formula with the same N and confirm the platform’s convention for the initial EMA.
  • Recalculate forward from that initial point to see whether the later values match.

Common pitfalls to confirm:

  • Are you using close or mid or open?
  • Are values based on candles of a certain timeframe?
  • Does your platform label the window as N, or does it interpret it differently?

Relevant limitations and risks of using moving averages

Moving averages are descriptive, not predictive. Key limitations include:

  • Lag: the MA is built from past data, so it can react after price changes.
  • Parameter sensitivity: window length N and method (SMA vs EMA) can change the signal shape.
  • No certainty: an MA can summarize historical direction but cannot guarantee future outcomes.

For verification, always rely on reproducible inputs (the exact price field and timeframe) and, for EMA, note how the first EMA value is initialized in your tool. If the initialization differs, the early EMA points will differ even if the formula is correct.

Trading foreign exchange and CFDs involves substantial risk. Information on FoxiForex is educational and is not personal financial advice. Sponsored placements are labelled clearly.