TrendPine Script v6

Arnaud Legoux Moving Average Pine Script — Complete TradingView Guide

The Arnaud Legoux Moving Average (ALMA) is a low-lag moving average built into Pine Script v6 via ta.alma(source, length, offset, sigma). Unlike the EMA or SMA, the ALMA applies a Gaussian (bell-curve) distribution to weight recent bars — the offset parameter controls where the peak weight falls, and sigma controls the width of the bell curve — delivering significantly less lag than a simple average while filtering out short-term noise. The default settings are length 9, offset 0.85, sigma 6, which produce a clean overlay line on the price chart. ALMA works on all asset classes — stocks, crypto, forex, and futures — and is particularly valued in volatile markets where EMA crossovers generate too many false signals. This guide covers the complete Pine Script v6 implementation using ta.alma(), all configurable parameters with recommended ranges, three concrete ALMA trading strategies, and a five-step guide to generating ALMA scripts instantly with Pineify.

What Is the Arnaud Legoux Moving Average?

The Arnaud Legoux Moving Average is a trend-following overlay indicator that calculates a Gaussian-weighted average of price, used to identify trend direction with lower lag and fewer false crossovers than the Simple Moving Average. Unlike the SMA or EMA, which apply uniform or exponentially decaying weights, ALMA uses a configurable Gaussian bell curve that concentrates weight on a user-defined region of the lookback window — enabling independent control over both responsiveness and smoothness.

ALMA was developed by Arnaud Legoux and Dimitri Yotov and published in 2009. Legoux, a quantitative analyst, designed the algorithm to address the core trade-off in moving average design: standard averages force you to choose between speed (short periods, high noise) or smoothness (long periods, high lag). ALMA resolves this by applying a Gaussian distribution — the statistical bell curve — as the weighting function. The resulting line tracks price trends faster than a same-period SMA while producing a smoother output than a same-period EMA.

Core formula: ALMA = Σ(w(i) × price(i)) ÷ Σw(i), where the weight for each bar is w(i) = exp(−(i − m)² / (2 × s²)). The variable m = offset × (length − 1) sets the peak of the bell curve — an offset of 0.85 peaks the weight distribution 85% of the way through the window, toward recent bars. The variable s = length / sigma controls the width of the bell: a sigma of 6 produces a narrow, focused distribution; a smaller sigma spreads the weights more evenly. In Pine Script v6, the entire calculation is handled by ta.alma(close, 9, 0.85, 6).

ALMA applies to all liquid asset classes: stocks, crypto, forex, and futures. It is most effective in trending markets and performs well in volatile crypto markets where EMA crossovers produce excess noise. Best timeframes are 15-minute to Daily charts. On 1-minute and 5-minute charts, ALMA's Gaussian smoothing reduces noise compared to EMA, but very short periods (length below 5) can still produce erratic behavior. On weekly and monthly charts, increase length to 20–50 to capture meaningful trend signals.

Best Markets

Stocks · Crypto · Forex · Futures

Best Timeframes

15m, 1H, 4H, Daily

Overlay

Yes — plots directly on price chart

ALMA Pine Script Code Example

The code below plots a 9-period ALMA as a blue line overlaid on the price chart using Pine Script v6. To add it to TradingView, open the Pine Script editor with Alt+P, paste the code, and click Add to chart. Adjust the 9 (length), 0.85 (offset), and 6 (sigma) in ta.alma(close, 9, 0.85, 6) to match your trading style.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="Arnaud Legoux Moving Average", overlay=true, max_labels_count=500)

// ALMA — uses a Gaussian distribution to weight bars, reducing lag while filtering noise
// Parameters: source, length (window), offset (0–1, controls lag vs. smoothness), sigma (bell curve width)
p_ind_1 = ta.alma(close, 9, 0.85, 6) // ALMA with default period 9, offset 0.85, sigma 6

// Plot the ALMA line on the price chart
plot(p_ind_1, title="ALMA", color=color.rgb(41, 98, 255, 0), linewidth=1)

Chart Preview

Arnaud Legoux Moving Average indicator Pine Script code example in TradingView

ALMA Parameters

ParameterDefault ValueDescriptionRecommended Range
sourcecloseThe price series to apply the ALMA calculation to. Commonly close, but can be hl2, hlc3, or any numeric series.Any numeric series
length9Number of bars in the lookback window. Controls overall smoothing — larger values produce a slower, smoother line; smaller values react faster to recent price changes.5–50 depending on timeframe
offset0.85Controls where the peak of the Gaussian bell curve falls within the window. Values closer to 1 shift the weight peak toward recent bars (less lag); values closer to 0 shift weight toward older bars (more smoothness).0.5–0.95
sigma6Controls the width of the Gaussian bell curve. Higher sigma narrows the distribution, concentrating weight on fewer bars near the peak. Lower sigma spreads the distribution, producing smoother but slower output.3–10

Tuning Guide by Trading Style

  • Scalping (1m–5m charts): length 5, offset 0.85, sigma 6 — ultra-fast response for micro-trend detection
  • Day trading (15m–1H charts): length 9, offset 0.85, sigma 6 — the default setting, balanced speed and smoothness
  • Swing trading (4H–Daily charts): length 21, offset 0.85, sigma 6 — captures multi-day trend shifts without excessive noise
  • Position trading (Daily–Weekly charts): length 34–50, offset 0.85, sigma 6 — smooth macro trend filter with low false-signal rate

ALMA Trading Strategies

The ALMA is most effective as a low-lag trend filter and crossover signal generator in trending markets. Below are three concrete strategies with specific entry and exit conditions.

Strategy 1 — ALMA Fast/Slow Crossover (Trend Following)

Market environment: trending markets · Best timeframe: 1H, 4H

Pairing a fast ALMA (length 9) with a slow ALMA (length 21) generates trend-following crossover signals with less lag than a SMA 9/21 pair. When the fast ALMA crosses above the slow ALMA, it signals a bullish trend shift. Use ta.crossover(ta.alma(close,9,0.85,6), ta.alma(close,21,0.85,6)) to detect the signal.

  1. Calculate fast ALMA: alma9 = ta.alma(close, 9, 0.85, 6)
  2. Calculate slow ALMA: alma21 = ta.alma(close, 21, 0.85, 6)
  3. Long entry: ta.crossover(alma9, alma21) — fast ALMA crosses above slow ALMA
  4. Confirm ADX > 20 (trend strength filter — avoid signals in ranging, choppy conditions)
  5. Exit: ta.crossunder(alma9, alma21) — fast ALMA crosses below slow ALMA

Strategy 2 — ALMA Pullback Entry (Trend Continuation)

Market environment: established uptrends · Best timeframe: 4H, Daily

In an established uptrend, price often pulls back to the ALMA 9 before continuing higher. This strategy uses the ALMA as a dynamic support level, entering on bounces after confirmed pullbacks. Pair with the RSI to confirm momentum is still bullish before entry.

  1. Calculate ALMA: alma = ta.alma(close, 9, 0.85, 6)
  2. Calculate RSI momentum filter: rsi14 = ta.rsi(close, 14)
  3. Condition 1 (trend): close > alma on the prior 5 bars — confirming an established uptrend
  4. Condition 2 (pullback): low touches or dips below alma, then close reclaims alma on the same or next bar
  5. Condition 3 (momentum): rsi14 > 45 — momentum still bullish; exit if rsi14 < 40 or close breaks below alma for 2+ consecutive bars

Strategy 3 — ALMA + Bollinger Bands Breakout Filter

Market environment: volatile trending markets · Best timeframe: 1H, 4H

Combining ALMA direction with Bollinger Bands breakouts filters high-probability trend entries. When price breaks above the upper Bollinger Band AND the ALMA is rising, it signals a strong trending breakout with momentum confirmation. This setup reduces false breakouts common in choppy markets.

  1. Calculate ALMA direction: alma = ta.alma(close, 9, 0.85, 6), alma rising = alma > alma[1]
  2. Calculate Bollinger Bands: [bb_mid, bb_upper, bb_lower] = ta.bb(close, 20, 2)
  3. Long entry: close crosses above bb_upper AND alma is rising — confirming trend direction
  4. Avoid: signals where close immediately reverts back below bb_upper on the next bar (false breakout filter — wait one bar to confirm)
  5. Exit: close crosses below alma OR price returns to bb_mid (mean reversion signal)

Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.

How to Generate the ALMA Indicator in Pineify

  1. 1

    Open Pineify

    Go to pineify.app and sign in — a free account is sufficient to generate ALMA indicators with ta.alma() in Pine Script v6.

  2. 2

    Click "New Indicator"

    Select "Indicator" as the script type from the creation menu on the dashboard to start a new Pine Script project.

  3. 3

    Describe the ALMA you want

    Type a prompt such as: "Plot a 9-period Arnaud Legoux Moving Average as a blue overlay using ta.alma(close, 9, 0.85, 6)." Pineify's AI Coding Agent generates the complete Pine Script v6 code in seconds.

  4. 4

    Copy to TradingView

    Click "Copy to TradingView" to copy the generated code, then open the TradingView Pine Script editor (Alt+P), paste the code, and click "Add to chart" to see the ALMA plotted immediately.

  5. 5

    Adjust the length, offset, and sigma

    In the TradingView indicator settings panel, change the ALMA length (e.g., from 9 to 21), offset (e.g., 0.85 to 0.9), or sigma to match your timeframe and trading style — no code editing required.

Frequently Asked Questions

Build Your ALMA Indicator in Seconds

Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script indicators — including ALMA crossover strategies and Bollinger Band combinations — instantly for free.

Try Pineify Free