OPEN-SOURCE SCRIPT

Arnaud Legoux Gaussian Flow | AlphaNatt

378
Arnaud Legoux Gaussian Flow | AlphaNatt

A sophisticated trend-following and mean-reversion indicator that combines the power of the Arnaud Legoux Moving Average (ALMA) with advanced Gaussian distribution analysis to identify high-probability trading opportunities.

🎯 What Makes This Indicator Unique?

This indicator goes beyond traditional moving averages by incorporating Gaussian mathematics at multiple levels:

  • ALMA uses Gaussian distribution for superior price smoothing with minimal lag
  • Dynamic envelopes based on Gaussian probability zones
  • Multi-layer gradient visualization showing probability density
  • Adaptive envelope modes that respond to market conditions


📊 Core Components

1. Arnaud Legoux Moving Average (ALMA)
The ALMA is a highly responsive moving average that uses Gaussian distribution to weight price data. Unlike simple moving averages, ALMA can be fine-tuned to balance responsiveness and smoothness through three key parameters:

  • ALMA Period: Controls the lookback window (default: 21)
  • Gaussian Offset: Shifts the Gaussian curve to adjust lag vs. responsiveness (default: 0.85)
  • Gaussian Sigma: Controls the width of the Gaussian distribution (default: 6.0)


2. Gaussian Envelope System
The indicator features three envelope calculation modes:

  • Fixed Mode: Uses ATR-based fixed width for consistent envelope sizing
  • Adaptive Mode: Dynamically adjusts based on price acceleration and volatility
  • Hybrid Mode: Combines ATR and standard deviation for balanced adaptation


The envelopes represent statistical probability zones. Price moving beyond these zones suggests potential mean reversion opportunities.

3. Momentum-Adjusted Envelopes
The envelope width automatically expands during strong trends and contracts during consolidation, providing context-aware support and resistance levels.

⚡ Key Features

Multi-Layer Gradient Visualization
The indicator displays 10 gradient layers between the ALMA and envelope boundaries, creating a visual "heat map" of probability density. This helps traders quickly assess:
  • Distance from the mean
  • Potential support/resistance strength
  • Overbought/oversold conditions in context


Dynamic Color Coding
  • Cyan gradient: Price below ALMA (bullish zone)
  • Magenta gradient: Price above ALMA (bearish zone)
  • The ALMA line itself changes color based on price position


Trend Regime Detection
The indicator automatically identifies market regimes:
  • Strong Uptrend: Trend strength > 0.5% with price above ALMA
  • Strong Downtrend: Trend strength < -0.5% with price below ALMA
  • Weak trends and ranging conditions


📈 Trading Strategies

Mean Reversion Strategy
Look for price entering the extreme Gaussian zones (beyond 95% of envelope width) when trend strength is moderate. These represent statistical extremes where mean reversion is probable.


Signals:
  • Long: Price in lower Gaussian zone with trend strength > -0.5%
  • Short: Price in upper Gaussian zone with trend strength < 0.5%


Trend Continuation Strategy
Enter when price crosses the ALMA during confirmed strong trend conditions, riding momentum while using the envelope as a trailing stop reference.


Signals:
  • Long: Price crosses above ALMA during strong uptrend
  • Short: Price crosses below ALMA during strong downtrend


🎨 Visualization Guide

The gradient layers create a "probability cloud" around the ALMA:
  • Darker shades (near ALMA): High probability zone - price tends to stay here
  • Lighter shades (near envelope edges): Lower probability - potential reversal zones
  • Price at envelope extremes: Statistical outliers - strongest mean reversion setups


⚙️ Customization Options

ALMA Parameters
  • Adjust period for different timeframes (lower for day trading, higher for swing trading)
  • Modify offset to tune responsiveness vs. smoothness
  • Change sigma to control distribution width


Envelope Configuration
  • Choose envelope mode based on market characteristics
  • Adjust multiplier to match instrument volatility
  • Modify gradient depth for visual preference (5-15 layers)


Signal Enhancement
  • Momentum Length: Lookback for trend strength calculation
  • Signal Smoothing: Additional EMA smoothing to reduce noise


🔔 Built-in Alerts

The indicator includes six pre-configured alert conditions:
  1. ALMA Trend Long - Price crosses above ALMA in strong uptrend
  2. ALMA Trend Short - Price crosses below ALMA in strong downtrend
  3. Mean Reversion Long - Price enters lower Gaussian zone
  4. Mean Reversion Short - Price enters upper Gaussian zone
  5. Strong Uptrend Detected - Momentum confirms strong bullish regime
  6. Strong Downtrend Detected - Momentum confirms strong bearish regime


💡 Best Practices

  • Use on clean, liquid markets with consistent volatility
  • Combine with volume analysis for confirmation
  • Adjust envelope multiplier based on backtesting for your specific instrument
  • Higher timeframes (4H+) generally provide more reliable signals
  • Use adaptive mode for trending markets, hybrid for mixed conditions


⚠️ Important Notes

  • This indicator works best in markets with normal price distribution
  • Extreme news events can invalidate Gaussian assumptions temporarily
  • Always use proper risk management - no indicator is perfect
  • Backtest parameters on your specific instrument and timeframe


🔬 Technical Background

The Arnaud Legoux Moving Average was developed to solve the classic dilemma of moving averages: the trade-off between lag and noise. By applying Gaussian distribution weighting, ALMA achieves superior smoothing while maintaining responsiveness to price changes.

The envelope system extends this concept by creating probability zones based on volatility and momentum, effectively mapping where price is "likely" vs "unlikely" to be found based on statistical principles.

Created by AlphaNatt - For educational purposes. Always practice proper risk management. Not financial advice. Always DYOR.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.