Skip to content
Calculators

Moving averagesFree calculator

Moving Average Formula: SMA, EMA and WMA, Step by Step

SMA, WMA and EMA formulas with one set of closes worked through

SMA, WMA, EMASeven closesCalculatorChecked 6 Dec 2026

Moving average formula results on a chart: SMA, WMA and EMA of 10 closes after a breakout

The moving average formula you need depends on the type: a simple moving average adds up the latest n closes and divides by n, a weighted one multiplies each close by a rank before dividing, and an exponential one nudges yesterday's value toward today's close. Below, all three run on the same seven closes so you can see where they agree and where they split. The calculator above repeats the work on any prices you paste.

Quick read

  • SMA

    (C1 + C2 + ... + Cn) / n
  • WMA

    (n×Cnewest + ... + 1×Coldest) / (n(n+1)/2)
  • EMA

    (C − EMAprev) × 2/(n+1) + EMAprev
  • WMA divisor

    15 for 5 bars, 55 for 10, 210 for 20
  • EMA seed

    Mean of the first n prices
  • Shared limit

    Every version uses past closes only, so all of them lag

The moving average formula for each type

SMA = (C1 + C2 + ... + Cn) / n
WMA = (n × C_newest + (n − 1) × C_next + ... + 1 × C_oldest) / (n(n + 1) / 2)
EMA = (C_today − EMA_yesterday) × k + EMA_yesterday, with k = 2 / (n + 1)

C is a closing price and n is the length. The SMA gives each close the same vote. The WMA gives the newest close n votes and the oldest one vote. The EMA has no window at all: it carries yesterday's value forward and moves it part of the way toward today's close.

On the cover chart, all three use 10 closes on the same example series that broke out of a range. On the final bar price closed at 25.20, the WMA reads 25.06, the SMA 24.86 and the EMA 24.79. The WMA sits nearest to price here. The EMA is not ahead of the SMA at every single bar; which line leads depends on the path price took.

How to calculate moving average values with the calculator

Paste closes in time order, oldest first, separated by commas or line breaks. Pick a length and read the table. To test it, enter these seven closes with length 5: 22.10, 22.35, 22.20, 22.60, 22.85, 23.10, 22.95.

  1. Bars 1 to 4 stay empty because a 5 bar average needs five closes.
  2. Bar 5 shows 22.42, bar 6 shows 22.62 and bar 7 shows 22.74.
  3. The working panel for bar 7 lists the sum 22.20 + 22.60 + 22.85 + 23.10 + 22.95 = 113.70 and the division 113.70 / 5 = 22.74.

Switch the mode to WMA or EMA and the same closes give the numbers in the next table.

Seven closes through all three formulas

Length 5 on the same closes
BarCloseSMAWMAEMA
122.10not yetnot yetnot yet
222.35not yetnot yetnot yet
322.20not yetnot yetnot yet
422.60not yetnot yetnot yet
522.8522.4222.536722.4200
623.1022.6222.763322.6467
722.9522.7422.873322.7478

On bar 5 the SMA and EMA match at 22.42 because the EMA is seeded with that very simple average. From then on the EMA pulls ahead of the SMA, and the WMA, which ranks the newest closes highest, stays furthest ahead in this rising sample.

Simple moving average formula, worked

For bar 5: 22.10 + 22.35 + 22.20 + 22.60 + 22.85 = 112.10, and 112.10 / 5 = 22.42. For bar 6 you do not have to add everything again. Take the old sum, remove the close that left the window and add the one that joined: 112.10 − 22.10 + 23.10 = 113.10, so the SMA is 22.62. That running total trick is how calculators and spreadsheets stay fast on long series. The simple moving average guide shows what happens when a single odd close enters and leaves that window.

Weighted moving average formula, worked

For bar 7 the window holds 22.20, 22.60, 22.85, 23.10 and 22.95, oldest to newest. Give them weights from 1 up to 5:

22.20×1 + 22.60×2 + 22.85×3 + 23.10×4 + 22.95×5 = 22.20 + 45.20 + 68.55 + 92.40 + 114.75 = 343.10
343.10 / 15 = 22.8733

The divisor is the sum of the weights, n(n + 1) / 2. That is 15 for 5 bars, 55 for 10, 105 for 14 and 210 for 20. Forget it and divide by n instead, and your WMA lands three times too high for a 5 bar window. More on this line in the weighted moving average guide.

Exponential moving average formula, worked

With n = 5, k = 2 / 6 = 0.3333. The EMA starts on bar 5 at the SMA value, 22.42.

Bar 6: (23.10 − 22.42) × 0.3333 + 22.42 = 0.2267 + 22.42 = 22.6467
Bar 7: (22.95 − 22.6467) × 0.3333 + 22.6467 = 0.1011 + 22.6467 = 22.7478

A second way to write the same rule is EMA = close × k + EMA_yesterday × (1 − k). Both give identical numbers. The exponential moving average page explains the multiplier and why apps disagree slightly on the first values.

Bars comparing the weight of the newest and the 5th newest close in a 5 bar SMA, WMA and EMA formula
In a 5 bar window the WMA and the EMA both give the newest close one third of the weight.

Formula mistakes that give the wrong line

MistakeWhat you seeFix
Closes pasted newest firstThe line runs backward and WMA weights land on the oldest barSort oldest to newest
WMA divided by nValues far above priceDivide by n(n + 1) / 2
EMA with k = 1 / nA much slower lineUse 2 / (n + 1), or call it a smoothed average
EMA started from the first closeEarly values differ from your chartSeed with the SMA of the first n closes
Rounding each step to 2 placesSmall drift that grows over many barsKeep 4 or more decimals until the end
Check one bar by hand before trusting a whole column. If bar n matches, the rest usually does too.

What no formula can tell you

Every version here is built from closes that have already happened, so each one trails a turn in price. A faster formula trails less but also flips more often when the market moves sideways. Getting the arithmetic right does not make a signal right. A cross of two correctly calculated lines can still be followed by a move the other way, which is why the moving average hub treats these lines as context rather than triggers.

Trading on margin can cost more than the money you put in, and most people who trade leveraged currency pairs and CFDs end up losing. Practice on a demo account or on past data first; this page is general education, not financial advice. The Investor.gov note on technical analysis is a fair, short primer.

Questions traders ask

How to calculate moving average by hand?

Pick a length n, add the last n closes and divide by n. Then shift the window by one bar and repeat with the new set. Writing the running sum in a column saves a lot of adding.

What is the simple moving average formula?

SMA = (C1 + C2 + ... + Cn) / n, where C are the last n closes. Every close in the window has the same weight. The first value appears once n closes exist.

What is the exponential moving average formula?

EMA today = (close − EMA yesterday) × k + EMA yesterday, with k = 2 / (n + 1). Most apps start the EMA from the mean of the first n prices. For a 5 bar EMA, k is one third.

What is the weighted moving average formula?

Give the newest close a weight of n, the one before it n − 1, and so on until the oldest gets 1. Add the products and divide by n(n + 1) / 2, the sum of the weights. For 5 bars the divisor is 15.

Why is the EMA multiplier 2 divided by n plus 1?

With that multiplier the average age of the closes inside the EMA equals the average age inside an SMA of the same length, which is (n − 1) / 2 bars. It lets an n period EMA and an n period SMA be compared fairly.

Which moving average formula is best?

None is best everywhere. The SMA is steadier, the WMA and EMA react sooner, and all of them lag. Pick the one whose behavior suits your timeframe, then test it on past charts.