Weighted Moving Average (WMA)
A moving average where each bar in the window has its own weight.
What it measures
Section titled “What it measures”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.
How traders read it
Section titled “How traders read it”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.
Formula
Section titled “Formula”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.
Settings and output
Section titled “Settings and output”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.
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.
In an algorithm
Section titled “In an algorithm”function onIntervalClose() { log("WMA(20)", wma(20), "SMA(20)", sma(20));}