Skip to content

Technical indicators

Weighted Moving Average (WMA)

A moving average where each bar in the window has its own weight.

A weighted mean of the last periods closes. The newest close has weight n, the one before n − 1, and so on down to 1 for the oldest, divided by their total, n × (n + 1) / 2.

Because the newest bar has the largest weight, it follows the price more closely than a simple average. Read it as a faster moving average.

WMA = (n × close₁ + (n − 1) × close₂ + … + 1 × closeₙ) / (n × (n + 1) / 2)

where close₁ is the bar that just closed and closeₙ the oldest in the window.

Call: wma(periods)

Setting Chart default
periods: Periods 20

What you get: a number.

Warm-up: with wma(20), it asks for 20 bars of history and a run-up of 1, and its first value came on bar 21 of the example data.

Weighted Moving Average (WMA) drawn by its own code on example prices

The prices are made up, hourly, and the same on every page, so the chart shows how the indicator behaves, not how a market behaved.

function onIntervalClose() {
log("WMA(20)", wma(20), "SMA(20)", sma(20));
}