WMA

Calculates the Weighted Moving Average indicator.

Accepts the following parameters:

Parameter NameTypeDefault ValueNotes
applyToSeries<Number>--
periodNumber--

Returns: Series<Number>

WMA is a built-in function - you can use it directly. Below is an example implementation:

1 function WMA(applyTo, period):
2 sum = 0
3 for i from 0 to (period - 1)
4 sum = sum + applyTo[i] * (period - i)
5 sum / (period * (period + 1) / 2)