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

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.