Returns the weighted moving average, giving the newest bar a weight of length and each older bar one less, down to 1.
ta.wma multiplies the newest value in the window by length, the one before by length - 1, and so on to 1 for the oldest, then divides by length * (length + 1) / 2. The weights fall in a straight line.
The first value appears on bar number length, and any na inside the window makes the result na.
Syntax
ta.wma(source: series int/float, length: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series of values to average. |
| length | series int | required | Number of bars in the window and the weight of the newest bar. A whole number of 1 or more. |
Returns
series float: the linearly weighted average of the last length values, or na while the window is not full.
Remarks
ta.wmafollows price more closely thanta.smaof the same length and stays smoother than a shortta.ema.ta.hmaandta.swmaare built on this weighting.
Example
//@version=6
indicator("WMA", overlay = true)
len = input.int(21, "Length", minval = 1)
plot(ta.wma(close, len), "WMA", color = color.fuchsia, linewidth = 2)
plot(ta.sma(close, len), "SMA", color = color.gray)See also
Runs on Sidechair