Moving averages: SMA and EMA

How simple and exponential moving averages are calculated, and the trade-off between smoothness and lag.

All courses · Lesson 1 of 6 · Intermediate · 5 min

A moving average replaces a noisy series of closes with a smoother line. You will learn how the simple and exponential versions are calculated, why every moving average lags price, and which graph-editor nodes produce them.

Indicators are derived from price

An indicator is a formula applied to candle data such as the open, high, low, close or volume. It contains no information that was not already in those candles: it only rearranges them so that a feature, such as direction or momentum, is easier to see.

This has two consequences. First, an indicator cannot know what price will do next. Second, two indicators built from the same closes often say nearly the same thing in different clothes, which matters when you combine them later in this course.

The simple moving average

The simple moving average (SMA) of N periods is the plain average of the last N closes. Each new candle adds the newest close and drops the oldest one, so the line moves along with price. All N closes carry the same weight.

SMA(N) = (C1 + C2 + ... + CN) / N
C1 to CN are the last N closes, CN being the newest.

Worked example

A 3-period SMA on five closes

  1. Take five closes in order: 100, 102, 101, 104, 106.
  2. A 3-period SMA needs three closes, so the first value appears on the third candle: (100 + 102 + 101) / 3 = 303 / 3 = 101.00.
  3. On the fourth candle the window drops 100 and adds 104: (102 + 101 + 104) / 3 = 307 / 3 = 102.33 (rounded to two decimals).
  4. On the fifth candle the window drops 102 and adds 106: (101 + 104 + 106) / 3 = 311 / 3 = 103.67.

The SMA values are 101.00, 102.33 and 103.67, while the last close is 106: the average trails price.

The exponential moving average

The exponential moving average (EMA) keeps a running value and moves it a fixed fraction of the way towards each new close. That fraction is the smoothing factor α (alpha), and the common choice is α = 2 / (N + 1). Recent closes therefore weigh more than old ones, and old closes fade but never drop out abruptly.

α = 2 / (N + 1)
EMA now = α × Close + (1 − α) × EMA previous
The same update can be written as EMA previous + α × (Close − EMA previous).

Worked example

One EMA step with N = 10

  1. The smoothing factor is α = 2 / (10 + 1) = 2 / 11 = 0.1818.
  2. Suppose the previous EMA is 100.00 and the new close is 105.00.
  3. The gap between close and EMA is 105 − 100 = 5.
  4. The EMA moves a fraction α of that gap: 0.1818 × 5 = 0.909, so EMA now = 100 + 0.909 = 100.91 (rounded).

A 5-point jump in the close moves the 10-period EMA by only about 0.91 points.

An EMA needs a starting value. Charting packages differ in how they seed it, for example with the first close or with an SMA of the first N closes, so the first values of an EMA may differ between platforms even though later values converge.

Lag and the smoothness trade-off

Every moving average lags: it reacts after price has already moved. A longer period smooths more noise but reacts later, and a shorter period reacts sooner but follows every wiggle. An EMA reacts a little faster than an SMA of the same N, but it is not free of lag. There is no setting that is both smooth and fast.

A common use is to plot a fast and a slow average together. When the fast line moves from below the slow line to above it, the recent average has risen faster than the longer-term average, which some traders read as a change towards an uptrend. Whether that is useful is something to test, not assume.

A price line with a fast and a slow moving average, and a marker where the fast average crosses above the slow one.

In the graph editor

The SMA and EMA nodes each have one input socket, Data, and one output socket named after the node (SMA or EMA). Each has a Period (N) field. Connect Data.Close to Data for the usual closing-price average, and use two nodes with different periods, for example 20 and 50, for a fast and a slow line.

Key takeaways

  • An indicator is a formula over existing candle data and adds no new information about the future.
  • An SMA is the plain average of the last N closes, while an EMA moves a fraction α = 2 / (N + 1) towards each new close.
  • Every moving average lags price, and a longer period gives a smoother line that reacts later.
  • In QuantRaider the SMA and EMA nodes take Data as input and have a Period (N) setting.

Sign in to save your progress and quiz results.