Moving AveragesPine Script v6

ta.alma()Arnaud Legoux Moving Average

Computes the Arnaud Legoux Moving Average (ALMA), a Gaussian-kernel weighted average over length bars. Parameters offset and sigma let you tune responsiveness versus smoothness; optional floor rounds down the Gaussian center before weighting.

TradingView language reference

Syntax

Syntax
ta.alma(series, length, offset, sigma, floor) → series float

Arguments

ParameterTypeDescription
seriesseries int/floatSeries of values to process.
lengthseries intWindow size for the Gaussian kernel.
offsetsimple int/floatControls tradeoff between smoothness and responsiveness.
sigmasimple int/floatChanges smoothness of the Gaussian weights.
floorsimple boolOptional; default false.

Returns

Arnaud Legoux 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.alma", overlay=true)
plot(ta.alma(close, 9, 0.85, 6))

// same on pine, but much less efficient
pine_alma(series, windowsize, offset, sigma) =>
    m = offset * (windowsize - 1)
    s = windowsize / sigma
    norm = 0.0
    sum = 0.0
    for i = 0 to windowsize - 1
        weight = math.exp(-1 * math.pow(i - m, 2) / (2 * math.pow(s, 2)))
        norm := norm + weight
        sum := sum + series[windowsize - i - 1] * weight
    sum / norm
plot(pine_alma(close, 9, 0.85, 6))

Trading Applications

Use Gaussian weights over a chosen finite window

Fine-tune responsiveness vs smoothness with offset parameter

Compare lag and response on the same data; settings do not ensure fewer false signals

Apply in algorithmic trading systems requiring precise MA tuning

Frequently Asked Questions

ta.alma() implements the Arnaud Legoux MA: a finite window average where weights follow a Gaussian curve. You can shift the peak of that curve (offset) and its width (sigma) to change how the line behaves.

Offset sets the Gaussian center. In the example formula, its width is length / sigma: for a fixed positive length and sigma, increasing sigma narrows the weights around that center. The resulting lag and smoothness depend on both parameters and the input data.

EMA is a single recursive smoother with one length. ALMA uses an explicit Gaussian over a window with two shape parameters, giving finer control over the bias-variance tradeoff for a given horizon.

Generate ta.alma() Code with AI

Draft Pine Script using ta.alma() 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.