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. Its finite linear weights differ from both equal-weight SMA and recursively smoothed EMA; there is no universal responsiveness ordering.
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
The built-in ignores na source values. The manual loop illustrates linear weights for a complete window and does not reproduce missing-value handling.
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
Study the tradeoff between recent-value weighting and noise
Use in custom indicator calculations
Combine with volume-weighted approaches
Frequently Asked Questions
Generate ta.wma() Code with AI
Draft Pine Script using ta.wma() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
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.