TradingView indicators

Arnaud Legoux Moving Average: formula and limits

ALMA averages a finite price window with Gaussian weights. Its offset places the weight center; sigma controls the width through length / sigma. These settings change which bars matter most, but do not remove the tradeoff between smoothing and response.

Use the calculation below to check an implementation before interpreting a crossover. The five-price example produces an ALMA of 104.2903, with the largest weight on the previous bar.

ALMA formula: keep the index direction explicit

Let i run from 0 for the oldest observation to N − 1 for the newest. Define xᵢ = source[N − 1 − i]. The calculation is:

m = offset × (N − 1); s = N / sigma
wᵢ = exp(−(i − m)² / (2s²))
aᵢ = wᵢ / Σwᵢ; ALMA = Σ(aᵢ × xᵢ)

With floor enabled, replace m with floor(m). The division by the total weight makes the normalized weights sum to one. For a valid window and positive sigma, the result stays between the lowest and highest source values. A constant window returns that constant.

The current bar is i = N − 1, not i = 0. Reversing that mapping weights the opposite end of the window. No future samples enter this formula. TradingView provides an equivalent calculation in its ta.alma reference.

A five-price calculation you can reproduce

Hypothetical inputs, oldest to newest: 100, 102, 101, 105, 107. Set N = 5, offset = 0.75, sigma = 5 and floor = false. Then m = 3 and s = 1. This is an arithmetic demonstration, not market data or a backtest.

Normalized Gaussian weights for a hypothetical five-price ALMA window
iPine historyPriceNormalized weightContribution
0src[4]1000.0047080.4708
1src[3]1020.0573575.8505
2src[2]1010.25705825.9629
3src[1]1050.42381844.5009
4src[0]1070.25705827.5052

Using unrounded weights, the contributions sum to 104.2902699. The SMA of these prices is 103. The latest price gets about 25.71% of the weight; the previous price gets 42.38%. If only the latest input rises by 1, ALMA rises by about 0.2571.

Changing offset to 0.50 gives 102.4935; changing it to 0.85 gives 104.9934. At offset 0.85, enabling floor moves m from 3.4 to 3 and returns 104.2903. These differences isolate parameters on the same window.

At offset 0.75, sigma 2 gives 103.4089 and sigma 10 gives 104.7863. The latter places about 78.68% on the previous bar. A larger sigma concentrates the weights; it does not widen the Gaussian.

Parameters, window boundaries and missing values

Length and source
Length counts chart bars. Select the same source, symbol, timeframe, session and chart type when comparing results. The example uses close and starts at 9 bars.
Offset and sigma
The example starts at 0.85 and 6. It bounds offset to 0 through 1 and sigma to 0.1 through 20 as input guardrails. These are demonstration constraints, not optimal trading ranges. Sigma must remain positive for this formula.
A complete window
ALMA needs the full length of history. Missing source values in the window produce na. Do not replace them with zero to force a line: that changes the data. With length 1 and a valid source, ALMA equals the source.
An advancing window
On the next bar, each retained observation moves one position toward the old end and receives a different weight. The oldest observation leaves. A change in ALMA therefore reflects the entire window shift, not just the newest close.

Pine Script v6: ALMA with a confirmed crossover

Paste this indicator into TradingView's Pine Editor and add it to the chart. The line updates on the open bar. The alert condition requires the selected source to cross above ALMA and the chart bar to close. Create an alert from that condition in TradingView; the code does not place orders.

Pine Script v6
//@version=6
indicator("Arnaud Legoux Moving Average", overlay=true)

windowSize = input.int(9, "Window Size", minval=1, maxval=500)
offset = input.float(0.85, "Gaussian Offset", minval=0, maxval=1, step=0.01)
sigma = input.float(6, "Sigma", minval=0.1, maxval=20, step=0.1)
floorCenter = input.bool(false, "Floor Gaussian Center")
src = input.source(close, "Source")

almaValue = ta.alma(src, windowSize, offset, sigma, floorCenter)
crossedAbove = ta.crossover(src, almaValue)
confirmedCross = barstate.isconfirmed and crossedAbove

plot(almaValue, "ALMA", color=color.blue, linewidth=2)
alertcondition(confirmedCross, "Confirmed cross above ALMA", "Source closed above ALMA")

The Gaussian offset is unrelated to the plot offset setting. Keep horizontal plot displacement at zero when comparing current values. Confirmation controls this alert's timing; it does not freeze the line or validate the profitability of a crossing rule.

What responsiveness and smoothing do not prove

A price above ALMA says where the source sits relative to its weighted history. A rising ALMA says the weighted result increased since the previous bar. Neither observation guarantees that the next bar will continue in that direction.

At the same length, SMA assigns equal weights and EMA retains a recursively decaying history. ALMA assigns a finite Gaussian profile. There is no fixed number of bars by which ALMA always leads either alternative: the path of prices and the settings determine the response.

Moving the center toward recent prices raises their influence, including their noise. Narrow weights can respond strongly when a price shock reaches the center, even if its initial effect at the edge was small. Choosing length, offset and sigma after viewing every reversal adds opportunities to fit historical noise.

  1. Match bar timestamps and all inputs before comparing two implementations.
  2. Check several completed-bar values, including the first valid window and a sharp price change.
  3. Choose alert confirmation explicitly. Test trading entries, exits, costs and parameter stability on a separate period.

Educational calculation and code only. No trading performance is established by this example.

Turn an ALMA specification into reviewable code

Pineify's Pine Script AI Coding Agent can help draft or revise the script. Specify the input source, length, Gaussian offset, sigma, floor choice and confirmation timing. Ask for bar-by-bar values before adding strategy exits or transaction costs.

"Plot ALMA on close with length 9, offset 0.85, sigma 6 and floor false. Add a confirmed-bar crossover alert. Keep it as an indicator so I can compare values before defining a strategy."
Open Pine Script AI Coding Agent

ALMA questions

ALMA is a moving average with normalized Gaussian weights over a finite source window. Length sets the window, offset positions the weight center, and sigma changes its width. The output describes the selected source; it does not predict the next price.

No. In the calculation shown here, the Gaussian width is s = length / sigma. Increasing sigma reduces that width and concentrates weights near the center. The effect on visible smoothness depends on the source and the other settings.

No. Gaussian offset changes weights within the current and previous bars. It is separate from the plot offset that moves a drawing horizontally. With samples indexed oldest to newest, a higher Gaussian offset moves the weight center toward the recent end.

The fifth ta.alma argument defaults to false. Setting it to true floors offset × (length − 1) before calculating the weights. It does not round the final ALMA price. Two implementations with different floor settings can disagree on identical input data.

There is no universal best setting. TradingView lists 9, 0.85 and 6 as the standard length, offset and sigma. Treat them as a starting configuration. Define the source and confirmation rule, then evaluate any strategy with separate test data, exits and transaction costs.

An ALMA based on close can change while the current bar is open. The example line updates during the bar, but its alert condition waits for barstate.isconfirmed. That condition does not prevent historical data revisions or changes to an external input source.

Sources and related calculations

Technical sources checked October 17, 2026. The five-price tables are original calculations using the stated assumptions.

Compare SMA equal weights and EMA recursive weights, or return to TradingView indicators.