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.
Chart
Chart metadata i
Outputs
outReal:line
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 |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ✅ Identity at Period 1 i |
| ✅ Uses Transcendental i |
| ☐ Input Must Be Positive |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_ALMA( 0, n - 1, series, 9, 6.0, 0.85, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d; last out = %f\n", outNBElement, outBegIdx, out[outNBElement - 1] );use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.alma(0, series.len() - 1, &series, 9, 6.0, 0.85, &mut out)?;
println!("{} values from bar {}; last out = {}", range.count, range.beg_idx, out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.alma(0, series.length - 1, series, 9, 6.0, 0.85, out);
System.out.println(r.count() + " values from bar " + r.begIdx() + "; last out = " + out[r.count() - 1]);using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Alma(0, series.Length - 1, series, 9, 6.0, 0.85, outReal);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}; last outReal = {outReal[r.Count - 1]}");import { alma } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = alma(series, {
timePeriod: 9,
sigma: 6,
offset: 0.85,
});
console.log(values.length + ' values from bar ' + begIdx + '; last values = ' + values[values.length - 1]);Implementation
Added in 0.8.3 (ta-lib-python 0.8.3).
TA-Lib Definition: alma.c · alma.yaml
| Native | File |
|---|---|
| C | ta_ALMA.c |
| Rust | alma.rs |
| Java | Core_ALMA.java |
| C# | Core_ALMA.cs |
| TypeScript | alma.ts |
Python: talib.ALMA (ta-lib-python 0.8.3 or later), see ta-lib-python.
TA-Lib is also available for 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.