IC Markets

ALMA in Forex Scalping: Precision Without the Lag

Optimize MetaTrader 4, MetaTrader 5, cTrader, and TradingView for speed. Discuss Level II Market Depth (DOM), custom hotkeys, and volume indicators.
Post Reply
PTScalper
Site Admin
Posts: 210
Joined: Mon Jul 20, 2026 1:28 pm

ALMA in Forex Scalping: Precision Without the Lag

Post by PTScalper »

Hi traders,
today i would like to share with you little more information about one of special indicator, which is not so well known,
but it can have interesting potencial for you.
Its called ALMA.

In the fast-paced arena of forex scalping, standard moving averages force a frustrating compromise: you either get rapid signals full of false breakouts (EMA) or smooth lines that lag terribly (SMA). The Arnaud Legoux Moving Average (ALMA) engineers a highly effective way out of this trap.

Developed by Arnaud Legoux and Dimitris Kouzis-Loukas, ALMA borrows signal-processing techniques to apply a Gaussian (bell curve) weight distribution to price data. It essentially filters price action from left to right and right to left, virtually eliminating the phase shift (lag) while ironing out the micro-noise that whipsaws short-term traders. For M1 or M5 scalpers, ALMA acts as an exceptionally clean dynamic support and resistance level. Its behavior is governed by three primary parameters:Window: The lookback period (e.g., 9 for rapid scalping). Offset: Dictates responsiveness on a scale of 0 to 1. Pushing it to 0.85 heavily weights the curve toward the most recent prices, allowing the line to tightly hug the trend. Sigma: Controls the Gaussian curve's width. A standard setting of 6 (inspired by the Six Sigma process) keeps the distribution crisp.

When the ALMA line slopes sharply, it confirms pure momentum. When price pulls back to the ALMA during an established micro-trend, it often presents a high-probability entry point. By stripping out market noise without delaying the signal, ALMA gives scalpers one of the clearest reads on immediate price action.

Custom ALMA Indicator for MT4 (MQL4)
Here is a lightweight, optimized MQL4 custom indicator script. You can compile this directly in MetaEditor and drop it into your platform's Indicators folder.

Code: Select all

//+------------------------------------------------------------------+
//|                                                         ALMA.mq4 |
//|                                Arnaud Legoux Moving Average      |
//+------------------------------------------------------------------+
#property copyright "Custom Indicator"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrDodgerBlue
#property indicator_width1 2

input int Window = 9;       // Window size
input double Offset = 0.85; // Gaussian Offset (0 to 1)
input double Sigma = 6.0;   // Curve width

double ALMABuffer[];

int OnInit() {
    SetIndexBuffer(0, ALMABuffer);
    SetIndexStyle(0, DRAW_LINE);
    IndicatorShortName("ALMA(" + IntegerToString(Window) + ")");
    return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {
                
    if (rates_total < Window) return(0);
    
    int limit;
    
    // Determine how many bars to calculate
    if (prev_calculated == 0) {
        limit = rates_total - Window + 1;
    } else {
        limit = rates_total - prev_calculated + 1; // Always recalculate the current active bar
    }
    
    double m = Offset * (Window - 1);
    double s = Window / Sigma;
    
    // Safeguard against division by zero
    if (s == 0) s = 0.000001; 
    
    // Loop through chart bars
    for (int i = 0; i < limit; i++) {
        double wtdSum = 0.0;
        double cumWt = 0.0;
        
        // Apply Gaussian weighting over the Window
        for (int k = 0; k < Window; k++) {
            double wtd = MathExp(-MathPow(k - m, 2) / (2 * s * s));
            
            // Close[] is an MT4 predefined timeseries array (0 is the current bar)
            wtdSum += wtd * Close[i + Window - 1 - k];
            cumWt += wtd;
        }
        
        if (cumWt > 0) {
            ALMABuffer[i] = wtdSum / cumWt;
        }
    }
    
    return(rates_total);
}
//+------------------------------------------------------------------+
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 210
Joined: Mon Jul 20, 2026 1:28 pm

Re: ALMA in Forex Scalping: Precision Without the Lag

Post by PTScalper »

Here are the custom ALMA (Arnaud Legoux Moving Average) indicator implementations for both MetaTrader 5 (MQL5) and cTrader (C#).

Both implementations pre-calculate the Gaussian weight distribution upon initialization to maximize execution speed during live tick processing.

1. MetaTrader 5 Implementation (MQL5)
Save this file as ALMA.mq5 inside your MT5 MQL5/Indicators directory and compile it using MetaEditor 5.

Code: Select all

//+------------------------------------------------------------------+
//|                                                         ALMA.mq5 |
//|                                Arnaud Legoux Moving Average      |
//+------------------------------------------------------------------+
#property copyright "Custom Indicator"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

#property indicator_label1  "ALMA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

// Inputs
input int    InpWindow = 9;       // Window size
input double InpOffset = 0.85;    // Gaussian Offset (0 to 1)
input double InpSigma  = 6.0;     // Curve width

// Indicator Buffers
double ALMABuffer[];

// Dynamic weight cache
double weights[];
double weightSum;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0, ALMABuffer, INDICATOR_DATA);
   PlotIndexSetString(0, PLOT_LABEL, "ALMA(" + IntegerToString(InpWindow) + ")");
   
   // Pre-calculate Gaussian weights for maximum runtime performance
   ArrayResize(weights, InpWindow);
   weightSum = 0.0;
   
   double m = InpOffset * (InpWindow - 1);
   double s = InpWindow / (InpSigma > 0 ? InpSigma : 1.0);
   
   for(int k = 0; k < InpWindow; k++)
     {
      weights[k] = MathExp(-MathPow(k - m, 2.0) / (2.0 * s * s));
      weightSum += weights[k];
     }
     
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(rates_total < InpWindow) return(0);

   int start = prev_calculated - 1;
   if(start < InpWindow - 1) start = InpWindow - 1;

   for(int i = start; i < rates_total; i++)
     {
      double sum = 0.0;
      for(int k = 0; k < InpWindow; k++)
        {
         sum += close[i - (InpWindow - 1 - k)] * weights[k];
        }
      if(weightSum > 0)
         ALMABuffer[i] = sum / weightSum;
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 210
Joined: Mon Jul 20, 2026 1:28 pm

Re: ALMA in Forex Scalping: Precision Without the Lag

Post by PTScalper »

And here i prepared for Ic traders:

cTrader Implementation (C#)
In cTrader, navigate to Automate > Indicators > New, paste the C# code below, and press Ctrl + B to build.

Code: Select all

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ArnaudLegouxMovingAverage : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Window Size", DefaultValue = 9, MinValue = 1)]
        public int Window { get; set; }

        [Parameter("Offset", DefaultValue = 0.85, MinValue = 0, MaxValue = 1)]
        public double Offset { get; set; }

        [Parameter("Sigma", DefaultValue = 6.0, MinValue = 0.1)]
        public double Sigma { get; set; }

        [Output("ALMA", LineColor = "DodgerBlue", PlotType = PlotType.Line, Thickness = 2)]
        public IndicatorDataSeries Result { get; set; }

        private double[] _weights;
        private double _weightSum;

        protected override void Initialize()
        {
            _weights = new double[Window];
            _weightSum = 0;

            double m = Offset * (Window - 1);
            double s = Window / Sigma;

            for (int k = 0; k < Window; k++)
            {
                _weights[k] = Math.Exp(-Math.Pow(k - m, 2) / (2 * s * s));
                _weightSum += _weights[k];
            }
        }

        public override void Calculate(int index)
        {
            if (index < Window - 1)
            {
                Result[index] = double.NaN;
                return;
            }

            double sum = 0;
            for (int k = 0; k < Window; k++)
            {
                int sourceIndex = index - (Window - 1 - k);
                sum += Source[sourceIndex] * _weights[k];
            }

            Result[index] = _weightSum > 0 ? sum / _weightSum : Source[index];
        }
    }
}
Parameter Setup
Window (9): Standard period length for M1/M5 scalping.

Offset (0.85): Places the Gaussian bell peak closer to current price action for maximum responsiveness.

Sigma (6.0): Standard deviation parameter ensuring sharp weight distribution across the lookback period.

I hope, you will like it and please let me know, if it was usefull for you :-)

Take a care and lot of good trades.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Post Reply