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:
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.
| i | Pine history | Price | Normalized weight | Contribution |
|---|---|---|---|---|
| 0 | src[4] | 100 | 0.004708 | 0.4708 |
| 1 | src[3] | 102 | 0.057357 | 5.8505 |
| 2 | src[2] | 101 | 0.257058 | 25.9629 |
| 3 | src[1] | 105 | 0.423818 | 44.5009 |
| 4 | src[0] | 107 | 0.257058 | 27.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.
//@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.
- Match bar timestamps and all inputs before comparing two implementations.
- Check several completed-bar values, including the first valid window and a sharp price change.
- 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
Sources and related calculations
Technical sources checked October 17, 2026. The five-price tables are original calculations using the stated assumptions.
- TradingView ALMA overview and defaults
- Pine Script v6 ta.alma reference and calculation example
- TradingView bar states and confirmation timing
Compare SMA equal weights and EMA recursive weights, or return to TradingView indicators.