# Weighted Moving Average Formula: How to Calculate WMA

URL: https://emaindicator.com/blog/weighted-moving-average-formula/
Published: 2026-05-10T09:00:00+05:30
Modified: 2026-05-06T06:00:00+05:30
Category: Formulas
Type: Spoke (hub: moving-averages-complete-guide)

The **Weighted Moving Average (WMA)** uses a linear weight schedule — the most recent bar gets the highest weight, the oldest bar in the window gets weight 1, and every bar in between gets a weight equal to its position from oldest to newest. This guide walks through the formula, the closed-form denominator, a worked example on NIFTY 50, and implementations in Excel and Python.

## The formula

For a closing-price series `P` and a window of `N` bars, the Weighted Moving Average at time `t` is:

```
            N × P_t + (N−1) × P_t-1 + (N−2) × P_t-2 + ... + 1 × P_t-(N−1)
WMA_t = ───────────────────────────────────────────────────────────────────
            N + (N−1) + (N−2) + ... + 1
```

The numerator is a weighted sum: each price multiplied by its weight, where weights run from N (newest) down to 1 (oldest). The denominator is the sum of weights.

The denominator has a clean closed form: `N × (N+1) / 2`, the sum of the first N positive integers.

| Window N | Denominator |
|---|---|
| 5 | 15 |
| 10 | 55 |
| 20 | 210 |
| 50 | 1,275 |
| 100 | 5,050 |

This means the most recent bar in a 10-period WMA contributes `10/55 ≈ 18.2%` of the total. The oldest bar contributes `1/55 ≈ 1.8%`. By contrast, in a 10-period SMA, every bar contributes exactly `10%`.

## A worked example — 5-period WMA on NIFTY 50

Suppose the last 5 NIFTY 50 daily closes are:

| Position from oldest | Day | Close | Weight |
|---|---|---|---|
| 1 (oldest) | t−4 | 24,000 | 1 |
| 2 | t−3 | 24,100 | 2 |
| 3 | t−2 | 24,250 | 3 |
| 4 | t−1 | 24,200 | 4 |
| 5 (newest) | t | 24,400 | 5 |

**Numerator:** `(5 × 24,400) + (4 × 24,200) + (3 × 24,250) + (2 × 24,100) + (1 × 24,000)`
= `122,000 + 96,800 + 72,750 + 48,200 + 24,000`
= `363,750`.

**Denominator:** `5 + 4 + 3 + 2 + 1 = 15`.

**WMA** = `363,750 / 15 = 24,250`.

Compare to the 5-period SMA over the same five closes: `(24,000 + 24,100 + 24,250 + 24,200 + 24,400) / 5 = 24,190`. The WMA, at 24,250, is closer to the most recent close (24,400) because the weighting pulls it toward recent strength — exactly what WMA is designed to do.

## Implementing WMA in Excel

For a 10-period WMA with closes in column A starting at A2, the formula in B11 is:

```
=SUMPRODUCT(A2:A11, ROW(A2:A11) − ROW(A2) + 1) / 55
```

How it works:

- `ROW(A2:A11) − ROW(A2) + 1` produces the array `{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}`.
- `SUMPRODUCT(A2:A11, {1, 2, ..., 10})` multiplies each close by its weight and sums.
- Dividing by 55 (the closed-form denominator for N=10) gives the WMA.

Drag the formula down. Excel automatically slides both the close range and the row-position calculation, keeping the weights `1..10` for every step.

For a 20-period WMA, change `A2:A11` to `A2:A21` and the divisor `55` to `210`.

## Implementing WMA in Python / pandas

In pandas, `rolling().apply()` does the work. For a 10-period WMA:

```python
import numpy as np
import pandas as pd

closes = pd.Series([24000, 24100, 24250, 24200, 24400, 24500, 24550, 24600, 24700, 24800, 24850, 24900])
n = 10
weights = np.arange(1, n + 1)  # [1, 2, 3, ..., 10]
denominator = weights.sum()    # 55

def wma_func(window):
    return (window * weights).sum() / denominator

wma = closes.rolling(n).apply(wma_func, raw=True)
print(wma.tolist())
```

For larger datasets the `raw=True` flag makes pandas pass numpy arrays into the function, which is much faster than passing pandas Series.

## Implementing WMA in Pine Script (TradingView)

```pine
//@version=5
indicator("Custom WMA", overlay=true)
length = input.int(20, title="Length")
wma_val = ta.wma(close, length)
plot(wma_val, color=color.purple, linewidth=2)
```

TradingView's built-in `ta.wma` uses the linear-weight formula above. There is also `ta.vwma` (volume-weighted) and `ta.alma` (Arnaud Legoux) for alternative weighting schemes.

## Common WMA periods on Indian indices

The conventions overlap with EMA and SMA:

- **9-WMA / 21-WMA** on 5-min and 15-min charts — intraday signals
- **20-WMA / 50-WMA** on 1-hour charts — swing-trade bias
- **50-WMA / 200-WMA** on daily charts — long-term trend filter

A practical observation: on NIFTY 50 daily, the 9/21 WMA crossover historically flips 1–2 trading days *earlier* than the 9/21 EMA crossover at trend changes — but with comparable false-signal rate. WMA is essentially a slightly faster EMA with a cleaner mathematical formulation.

## How weights change with N

A useful intuition for picking the right WMA period: see how much "voice" the most recent bar has.

| N | Weight of newest bar | Weight of oldest bar |
|---|---|---|
| 5 | 33.3% | 6.7% |
| 10 | 18.2% | 1.8% |
| 20 | 9.5% | 0.5% |
| 50 | 3.9% | 0.08% |
| 200 | 1.0% | 0.005% |

For a fast WMA (5, 9, 14), the most recent bar dominates — single-bar volatility moves the WMA noticeably. For a slow WMA (50, 100, 200), recent bars are small contributions; the line is dominated by the bulk of the lookback.

This is why short WMAs are good for **early signals** (they "see" the latest bar clearly) and long WMAs are good for **trend filters** (they smooth out single-bar noise).

## WMA vs EMA — when each wins

WMA and EMA are similar in spirit — both weight recent bars more heavily than older ones. They differ in **how** the weights decay:

- **WMA**: linear decay from N at newest to 1 at oldest. Sharp cut-off at the lookback edge: bars older than N drop out completely.
- **EMA**: exponential decay. Bars older than N never fully drop out — they fade gradually. Slightly smoother in long-running data.

In practice, the two indicators move very close together. WMA tends to react fractionally faster on the latest bar; EMA tends to be slightly smoother across multi-week ranges. For most traders, the choice is more about implementation preference than measurable edge.

For a side-by-side EMA vs SMA comparison on NIFTY 50 — including average lag at trend turns and 5-year forward-return profile — see our [EMA vs SMA page](/ema-vs-sma/).

## Putting it together

The WMA formula is straightforward arithmetic — multiply each close by its position-weight, sum, divide by the closed-form denominator `N(N+1)/2`. The output is a moving average that responds to recent price changes faster than SMA but with a simpler, more transparent weighting scheme than EMA.

For Indian-index trend definition, WMA at 50 on daily is a sensible alternative to 50-EMA. For intraday work, 9/21 WMA crossovers fire slightly earlier than EMA equivalents at trend changes. As always, no moving average is a complete trading system — pair WMA with the regime classifier and multi-timeframe alignment tools on emaindicator.com before risking capital.

## Frequently asked questions

**What is the formula for the Weighted Moving Average?**

WMA = (N × P_t + (N−1) × P_t-1 + (N−2) × P_t-2 + ... + 1 × P_t-(N−1)) / (N + (N−1) + (N−2) + ... + 1). The denominator simplifies to N × (N+1) / 2 — the sum of the first N integers.

**What is the difference between WMA and SMA?**

SMA gives every bar in the lookback equal weight — 1/N each. WMA gives linearly increasing weights — the most recent bar gets weight N/Σ, the next-most-recent gets (N−1)/Σ, and so on down to 1/Σ for the oldest bar. WMA is more responsive to recent prices than SMA but uses simpler linear weighting than EMA.

**How do I calculate WMA in Excel?**

For a 10-period WMA with closes in column A starting at A2, drop this formula into B11: =SUMPRODUCT(A2:A11, ROW(A2:A11) − ROW(A2) + 1) / 55. The constant 55 is N × (N+1)/2 = 10 × 11/2. For other periods, replace 10 with N and 55 with N(N+1)/2.

**What is the denominator of the WMA formula?**

The denominator is the sum of weights — N + (N−1) + (N−2) + ... + 1 — which equals N × (N+1) / 2. For N = 10 the denominator is 55. For N = 20 the denominator is 210. For N = 50 it is 1275.

**Why use WMA instead of SMA or EMA?**

WMA reacts faster than SMA because recent bars weigh more, but uses simple linear weights instead of exponential decay. It is faster than SMA at trend changes and easier to compute in spreadsheets than EMA's recursion. Many traders also find linear weights more intuitive than the exponential schedule.
