Arnaud Legoux Moving Average (ALMA)
Summary
Arnaud Legoux Moving Average: the last N inputs weighted by a Gaussian whose peak sits a fraction offset of the way from the oldest to the newest bar. Moving the offset toward 1 puts the peak on recent bars and cuts the lag; moving it toward 0 puts the peak on old bars and lags most. Smoothing is greatest with the peak mid-window, near 0.5. Sigma sets the width: the Gaussian's standard deviation is N / sigma bars, so a larger sigma concentrates the weight around the peak and smooths less.
The weights are non-negative and sum to one, so the line stays within the range of its window, up to rounding. At the default shape and a period of 5 or more, it lags about half as much as an SMA of the same period and passes about twice its noise.
Formula
N = optInTimePeriod, m = floor( offset * (N-1) ), s = N / sigma
g[j] = exp( -(j-m)^2 / (2 s^2) ), j = 0 .. N-1, j = 0 the oldest bar of the window
ALMA[t] = sum_j ( g[j] / sum_k g[k] ) * x[t-N+1+j]
The first output is at bar N-1.
Notes
- The peak is floored to a whole bar, as in the authors' code. At periods below about 5 this puts it on an older bar: at period 2 the line is almost entirely the previous bar.
TA_MAType_ALMAruns this function at the default sigma and offset, so the line inMAand every function taking an MAType has the lag and noise stated above.- The published paper's summary formula uses a different parameterisation; this is the form of the authors' own implementation.
Inputs
inReal— Data on which to compute the average
Outputs
outReal— Arnaud Legoux Moving Average line
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 9 | 1–100000 | Number of bars in the window |
optInSigma | real | 6 | ≥ 0.01 | Divides the period to give the Gaussian's width in bars |
optInOffset | real | 0.85 | 0–1 | Position of the peak weight, 0 at the oldest bar and 1 at the newest |
Properties
Numerical Stability: Start-Independent
| ✅ Overlap Input i |
| ☐ Independent Y-Axis |
| ☐ Candlestick |
| ☐ Can Output NaN or ±Inf |
| ✅ Identity at Period 1 i |
Implementation
TA-Lib Definition: alma.c · alma.yaml
| Native | File |
|---|---|
| C | ta_ALMA.c |
| Rust | alma.rs |
| Java | Core_ALMA.java |
| C# | Core_ALMA.cs |
TA-Lib is also available for Python, R and more using a wrapper.
See Also
References
- Arnaud Legoux and Dimitris Kouzis-Loukas, "ALMA; In search for the perfect Moving Average", November 2009. The authors' NinjaTrader implementation (2010) fixes the operational form above.