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

ta.swma() applies a fixed symmetric weight scheme over four bars of the source. It is a built-in smoother with predetermined weights rather than a configurable-length simple average.

The SWMA definition in TradingView uses a specific 4-point symmetric kernel. The shape is fixed by design, so only the source series is passed in.

Unlike SMA/EMA/WMA with arbitrary length, SWMA has a built-in short symmetric window. Any na in the required history propagates to na, which differs from some averages that ignore na.

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.