Moving AveragesPine Script v6

ta.wma()Weighted Moving Average

Computes the weighted moving average (WMA) over the last length bars, assigning greater weight to more recent observations within the window. It sits between SMA and EMA in responsiveness for many settings.

Syntax

Syntax
ta.wma(source, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthseries intNumber of bars (length).

Returns

Weighted moving average of source for length bars back.

Remarks

na values in the source series are ignored.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.wma")
plot(ta.wma(close, 15))

// same on pine, but much less efficient
pine_wma(x, y) =>
    norm = 0.0
    sum = 0.0
    for i = 0 to y - 1
        weight = (y - i) * y
        norm := norm + weight
        sum := sum + x[i] * weight
    sum / norm
plot(pine_wma(close, 15))

Trading Applications

Give more weight to recent prices for faster trend detection

Reduce lag compared to SMA while maintaining smoothness

Use in custom indicator calculations

Combine with volume-weighted approaches

Frequently Asked Questions

ta.wma() calculates a weighted moving average: within the lookback window, newer bars receive higher linear weights and older bars lower weights, then the weighted sum is normalized.

SMA uses equal weights. WMA uses a fixed linear weight ramp over a finite window. EMA uses infinite recursive smoothing with exponential decay. WMA is often more responsive than SMA but behaves differently from EMA.

Consider WMA when you want explicit finite-window weighting toward recent prices without the full recursive nature of EMA, or when building indicators that specify WMA as part of their definition.

Generate ta.wma() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.wma() and other built-in functions instantly.