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
ta.wma(source, length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
| length | series int | Number of bars (length). |
Returns
Weighted moving average of source for length bars back.
Remarks
na values in the source series are ignored.
Code Examples
//@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.
Related Pine Script Functions
ta.sma() - Simple Moving Average
Learn how to use ta.sma() in Pine Script. Syntax, parameters, code examples, and trading applications for the Simple Moving Average function.
ta.ema() - Exponential Moving Average
Learn how to use ta.ema() in Pine Script. Syntax, parameters, code examples, and trading applications for the Exponential Moving Average function.
ta.vwma() - Volume Weighted Moving Average
Learn how to use ta.vwma() in Pine Script. Syntax, parameters, code examples for the Volume Weighted Moving Average.
ta.swma() - Symmetrically Weighted Moving Average
Learn how to use ta.swma() in Pine Script. Syntax, code examples for the fixed 4-bar Symmetrically Weighted Moving Average.
ta.alma() - Arnaud Legoux Moving Average
Learn how to use ta.alma() in Pine Script. Syntax, parameters including offset and sigma, code examples for ALMA.