Moving AveragesPine Script v6

ta.swma()

Symmetrically Weighted Moving Average

Computes the symmetrically weighted moving average (SWMA) using a fixed 4-bar triangular weight pattern (1:2:2:1). There is no length parameter—the window and weights are defined by the function.

Syntax

Syntax
ta.swma(source) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.

Returns

Symmetrically weighted moving average.

Remarks

na values in the source series are included in calculations and will produce an na result.

Code Examples

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

// same on pine, but less efficient
pine_swma(x) =>
    x[3] * 1 / 6 + x[2] * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6
plot(pine_swma(close))

Trading Applications

Apply symmetric weighting for balanced smoothing

Use as a component in more complex indicator calculations

Reduce noise in price data with fixed 4-bar window

Build custom oscillators with symmetric smoothing

Frequently Asked Questions

Generate ta.swma() Code with AI

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