Skip to content
Open RaamTrade

ALMA — Arnaud Legoux Moving Average

A Gaussian-weighted average whose weight peak you place yourself. Push offset toward 1 and the weight sits on the newest bars (low lag, more noise); pull it toward 0.5 and it centres (smooth, laggy). sigma controls how tight the bell is.

Signature

ALMA(period, offset, sigma, on=<source>)
Argument Type Required Notes
period int Param or literal Yes Window. Default 9, bounds 1–400.
offset float Param or literal Yes Where the Gaussian peaks, 0 (oldest) to 1 (newest). Default 0.85, bounds 0.0–1.0.
sigma float Param or literal Yes Window sharpness; larger is tighter. Default 6.0, bounds 0.1–50.0.
on= symbol, OHLCV field, or indicator No Source. Defaults to the trade symbol’s close.

Formula

$$ m = \text{offset},(n-1), \quad s = n/\sigma, \quad w_i = e^{-(i-m)^2 / (2s^2)} $$ $$ \text{ALMA} = \frac{\sum_i w_i C_i}{\sum_i w_i} $$

Warmup

period bars; the raw close until the window fills.

Reading the value

alma.value
alma.crossed_above(slow)

Example

class AlmaTrend(Strategy):
"""Low-lag trend filter with the weight pushed toward recency."""
period = Param(21, min=1, max=400)
trade = Symbol()
sizing = FixedCapital()
def execute(self):
alma = ALMA(self.period, 0.85, 6.0, on=self.trade)
if self.trade.close > alma.value and self.trade.is_flat:
self.buy(self.trade, reason="Above ALMA")
if self.trade.close < alma.value and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Below ALMA")

Notes

  • Arnaud Legoux and Dimitrios Kouzis-Loukas (2009).
  • Proven by an assert-via-trade run on SPY daily (matched a strategy-side Gaussian-weight reference to 1e-3 on every bar; zero alarm trades).
  • Three parameters is a lot for one average — sweep offset and leave sigma at 6 unless you have a reason.
  • A different recipe from pandas_ta’s alma(9, 6.0, 0.85), not a different scale: measured on a 300-bar tape ours stays about 0.5 % away and never converges to it, because the construction (window offset, seed, weight normalisation) is its own.