Page 1 of 1

Unlocking the Smart Money Play: Why You Need a Liquidity Sweep Detector for Forex Scalping

Posted: Thu Jul 30, 2026 7:40 pm
by PTScalper
Hey everyone,
If you’re scalping the lower timeframes (like the 5M or 15M), you’ve probably experienced the frustration of getting stopped out
by a sudden spike, only to watch the market immediately reverse in your original direction. This isn’t bad luck—it’s a liquidity
sweep.Smart money (institutions and large market makers) relies on areas with concentrated order blocks, such as prior swing
highs and lows, to fill their massive positions. They intentionally push the price past these key levels to trigger resting stop-loss
and breakout orders. Once the liquidity is absorbed, the market aggressively reverses.

As scalpers, identifying these traps in real-time is one of the most profitable edge-building strategies out there.
However, manually tracking every recent high and low across multiple pairs is exhausting.
This is where a Liquidity Sweep Detector becomes essential.A proper liquidity sweep indicator automates
the process by mapping out recent structure and scanning for a specific candlestick formation: a piercing wick
that breaks a key level, followed by a body close back inside the range.Here is how I trade sweeps:Context is King:
I map my directional bias on the 1H or 4H chart.The Sweep: On the 5M or 15M, I wait for the price to spike above
a recent high (bearish sweep) or below a recent low (bullish sweep).The Confirmation:

The candle must reject the level and close back inside. The longer the wick, the stronger the rejection.Execution:
Enter on the close of the sweep candle or on a break of structure on the 1M chart.To help you get started,
I’ve coded a simple Liquidity Sweep Detector for MT4 (MQL4) below. It scans for a pivot high/low over a customizable
lookback period and plots arrows when price wicks past that level but closes back inside.Test it out on a demo account,
tweak the lookback periods to fit your timeframe, and let me know your thoughts below!

The MT4 Indicator Code (MQL4)Here is the source code for the custom indicator you can include in your post.
It uses the Average True Range (ATR) to cleanly space the arrows away from the candles.C++

Code: Select all

//+------------------------------------------------------------------+
//|                                     LiquiditySweepDetector.mq4 |
//|                                            Liquidity Sweep MT4 |
//+------------------------------------------------------------------+
#property copyright "Open Source"
#property link      ""
#property version   "1.00"
#property strict

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrDeepSkyBlue
#property indicator_color2 clrRed
#property indicator_width1 2
#property indicator_width2 2

//--- input parameters
input int InpLookbackPeriod = 20; // Pivot Lookback Period

//--- indicator buffers
double BullSweepBuffer[];
double BearSweepBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- Bullish Sweep setup (Buy)
   SetIndexBuffer(0, BullSweepBuffer);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 233); // Up Arrow
   SetIndexLabel(0, "Bullish Sweep");
   
   //--- Bearish Sweep setup (Sell)
   SetIndexBuffer(1, BearSweepBuffer);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 234); // Down Arrow
   SetIndexLabel(1, "Bearish Sweep");
   
   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[])
  {
   // Require minimum bars
   if(rates_total < InpLookbackPeriod + 2)
      return(0);

   int limit = rates_total - prev_calculated;
   if(prev_calculated == 0)
      limit = rates_total - InpLookbackPeriod - 2;
      
   for(int i = limit; i >= 1; i--)
     {
      BullSweepBuffer[i] = EMPTY_VALUE;
      BearSweepBuffer[i] = EMPTY_VALUE;
      
      // Look back 'n' bars from the previous candle to find the pivot points
      int highestIndex = iHighest(Symbol(), 0, MODE_HIGH, InpLookbackPeriod, i + 1);
      int lowestIndex = iLowest(Symbol(), 0, MODE_LOW, InpLookbackPeriod, i + 1);
      
      if(highestIndex == -1 || lowestIndex == -1) 
         continue;
         
      double pivotHigh = High[highestIndex];
      double pivotLow = Low[lowestIndex];
      
      // Calculate buffer spacing based on ATR for dynamic arrow placement
      double atr = iATR(Symbol(), 0, 14, i);
      
      // Bearish Sweep: Price pierced above previous pivot high but closed below it
      if(High[i] > pivotHigh && Close[i] < pivotHigh && Open[i] < pivotHigh)
        {
         BearSweepBuffer[i] = High[i] + (atr * 0.5);
        }
        
      // Bullish Sweep: Price pierced below previous pivot low but closed above it
      if(Low[i] < pivotLow && Close[i] > pivotLow && Open[i] > pivotLow)
        {
         BullSweepBuffer[i] = Low[i] - (atr * 0.5);
        }
     }
     
   return(rates_total);
  }
//+------------------------------------------------------------------+

Re: Unlocking the Smart Money Play: Why You Need a Liquidity Sweep Detector for Forex Scalping

Posted: Thu Jul 30, 2026 7:42 pm
by PTScalper
Here i prepared version for MT5 traders:

Code: Select all

//+------------------------------------------------------------------+
//|                                     LiquiditySweepDetector.mq5 |
//|                                            Liquidity Sweep MT5 |
//+------------------------------------------------------------------+
#property copyright "Open Source"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//--- plot Bullish
#property indicator_label1  "Bullish Sweep"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrDeepSkyBlue
#property indicator_width1  2

//--- plot Bearish
#property indicator_label2  "Bearish Sweep"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_width2  2

input int InpLookbackPeriod = 20; // Pivot Lookback Period

double BullSweepBuffer[];
double BearSweepBuffer[];
int atrHandle;
double atrBuffer[];

int OnInit()
  {
   SetIndexBuffer(0, BullSweepBuffer, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_ARROW, 233);
   
   SetIndexBuffer(1, BearSweepBuffer, INDICATOR_DATA);
   PlotIndexSetInteger(1, PLOT_ARROW, 234);
   
   atrHandle = iATR(_Symbol, _Period, 14);
   if(atrHandle == INVALID_HANDLE) return INIT_FAILED;
   
   ArraySetAsSeries(BullSweepBuffer, false);
   ArraySetAsSeries(BearSweepBuffer, false);
   ArraySetAsSeries(atrBuffer, false);
   
   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 < InpLookbackPeriod + 2) return 0;
   
   int limit = prev_calculated == 0 ? InpLookbackPeriod + 1 : prev_calculated - 1;
   
   if(CopyBuffer(atrHandle, 0, 0, rates_total, atrBuffer) <= 0) return 0;
   
   for(int i = limit; i < rates_total; i++)
     {
      BullSweepBuffer[i] = 0.0;
      BearSweepBuffer[i] = 0.0;
      
      double pivotHigh = 0.0;
      double pivotLow = 999999.0;
      
      // Find pivot high/low looking back InpLookbackPeriod bars from i-1
      for(int j = 1; j <= InpLookbackPeriod; j++)
        {
         if(i-j >= 0)
           {
            if(high[i-j] > pivotHigh) pivotHigh = high[i-j];
            if(low[i-j] < pivotLow) pivotLow = low[i-j];
           }
        }
        
      double atr = atrBuffer[i];
      
      // Bearish Sweep: Price pierced above previous pivot high but closed below it
      if(high[i] > pivotHigh && close[i] < pivotHigh && open[i] < pivotHigh)
        {
         BearSweepBuffer[i] = high[i] + (atr * 0.5);
        }
        
      // Bullish Sweep: Price pierced below previous pivot low but closed above it
      if(low[i] < pivotLow && close[i] > pivotLow && open[i] > pivotLow)
        {
         BullSweepBuffer[i] = low[i] - (atr * 0.5);
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Re: Unlocking the Smart Money Play: Why You Need a Liquidity Sweep Detector for Forex Scalping

Posted: Thu Jul 30, 2026 7:42 pm
by PTScalper
And here is version for IC traders:

Code: Select all

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class LiquiditySweepDetector : Indicator
    {
        [Parameter("Lookback Period", DefaultValue = 20)]
        public int LookbackPeriod { get; set; }

        [Output("Bullish Sweep", LineColor = "DeepSkyBlue", PlotType = PlotType.Points, Thickness = 4)]
        public IndicatorDataSeries BullSweep { get; set; }

        [Output("Bearish Sweep", LineColor = "Red", PlotType = PlotType.Points, Thickness = 4)]
        public IndicatorDataSeries BearSweep { get; set; }

        private AverageTrueRange _atr;

        protected override void Initialize()
        {
            _atr = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            if (index < LookbackPeriod + 1)
                return;

            double pivotHigh = double.MinValue;
            double pivotLow = double.MaxValue;

            // Find highest high and lowest low over the lookback period, excluding the current bar
            for (int i = 1; i <= LookbackPeriod; i++)
            {
                if (Bars.HighPrices[index - i] > pivotHigh)
                    pivotHigh = Bars.HighPrices[index - i];
                    
                if (Bars.LowPrices[index - i] < pivotLow)
                    pivotLow = Bars.LowPrices[index - i];
            }

            double atrValue = _atr.Result[index];

            // Bearish Sweep: Pierces above pivot high but closes below
            if (Bars.HighPrices[index] > pivotHigh && Bars.ClosePrices[index] < pivotHigh && Bars.OpenPrices[index] < pivotHigh)
            {
                BearSweep[index] = Bars.HighPrices[index] + (atrValue * 0.5);
            }

            // Bullish Sweep: Pierces below pivot low but closes above
            if (Bars.LowPrices[index] < pivotLow && Bars.ClosePrices[index] > pivotLow && Bars.OpenPrices[index] > pivotLow)
            {
                BullSweep[index] = Bars.LowPrices[index] - (atrValue * 0.5);
            }
        }
    }
}

Let me know, if you like it :-)
Take a care.