What the moving average calculator does
A moving average smooths a price series by averaging its last N closes, so the direction of the market is easier to read than raw price. Paste closing prices from a spreadsheet, a broker export or a data download, and the calculator computes the three common types at once: the simple (SMA), exponential (EMA) and weighted (WMA) moving averages. It shows the latest value of each, how far the last close sits from the average you pick, that average's change on the last bar, and the last 20 values in a table.
The calculations match TradingView's ta.sma, ta.ema and ta.wma, so you can use the calculator to check an indicator, a spreadsheet or code you wrote.
How to use it
- Paste closing prices separated by commas, spaces or new lines. Dates and column headers are skipped. Use a dot as the decimal mark ("1.1650"); a list without any dot, such as "1,1650 1,1660", reads the comma as the decimal mark instead.
- Tell the calculator the order of the list: oldest first (most exports) or newest first (many broker statements).
- Set the length, the number of closes each average covers. 20, 50 and 200 are the most common.
- Pick the headline average. All three are always computed; the headline one drives the "price versus" rows.
The formulas
SMA = (C1 + C2 + … + CN) ÷ N
EMA = α × close + (1 − α) × previous EMA, α = 2 ÷ (N + 1)
first EMA = SMA of the first N closes
WMA = (N × latest close + (N − 1) × the one before + … + 1 × oldest)
÷ (N × (N + 1) ÷ 2)
The SMA gives every close in the window the same weight. The WMA gives the latest close N times the weight of the oldest one. The EMA weighs all past closes, with weights that shrink by a factor of (1 − α) per bar, so it reacts quickly but never completely forgets the past.
Worked example
The sample loaded in the calculator is 30 daily closes, a classic textbook series, with a length of 10:
- The first SMA, after 10 closes, is 22.22; the last one is 23.13.
- The EMA starts from that same 22.22 and then uses α = 2 ÷ 11 ≈ 0.1818. It ends at 22.92, down 0.17 on the last bar.
- The last WMA is 22.87.
- The last close, 22.17, is about 3.2% below the EMA and 4.1% below the SMA.
After the drop at the end of the list, the averages that favour recent closes sit closest to price: WMA first, then EMA, with the SMA furthest behind. That ordering is how the three averages usually line up after a sharp move.
Which average to use
- SMA: the simplest and the one behind the widely watched 50- and 200-day levels. It reacts slowest, and an old close leaving the window moves it as much as a new one entering.
- EMA: reacts faster for the same length, which is why crossovers such as 9/21 and the MACD (12/26) use it. See the EMA crossover strategy in Pine Script.
- WMA: faster still for the same length, and the building block of the Hull moving average.
No type is better in general. A faster average gives earlier signals and more false ones; a slower one gives fewer, later signals. Choose with a backtest, not by eye.
Why your chart may show a slightly different EMA
The EMA depends on where it started. A chart's EMA has been running since the first bar of the chart's history, while this calculator starts it from the SMA of the first N closes you paste. The influence of the starting point fades by (1 − α) per bar: for a 20-period EMA, after 60 bars it carries less than 0.3% of its original weight. Paste at least three to four times the length and the values match to the decimals that matter. The SMA and WMA have no memory beyond N closes, so they match as soon as the same N closes are used.
Two other usual causes: the chart's last bar is still open, so its close (and every average) keeps moving until the bar ends; and different data feeds close their daily bars at different times, especially in forex.
Common mistakes
- Reversed order. A list pasted newest first but read as oldest first gives the averages of a mirrored market. Check the order switch.
- Mixing timeframes. Averages of daily closes and averages of hourly closes are different indicators, even with the same length.
- Too little data for the EMA. Paste at least three times the length; the calculator warns you below that.
- Treating a cross as a signal on its own. Price crossing an average happens often in a range. Test any rule built on it, and size every trade from its stop with the position size calculator.