MT4 Closed-Bar Liquidity Sweep and Relative Tick Volume: Advanced MQL4 Indicator

Advanced Trading Tutorial · MT4 · MQL4

Research question. Can a wick through an established local extreme be separated from an ordinary range expansion without relying on the still-forming candle? This study combines a prior-range sweep, an ATR-normalized excursion, a close back inside the range, and relative broker tick volume. It produces two historical arrow buffers, not automated trades.

Why a wick alone is insufficient

A long wick may represent a liquidity probe, a volatile news candle, or simply thin trading. The indicator therefore demands four independent properties. The bar must exceed the prior ten completed bars' extreme; the excess must be large enough relative to recent volatility but not excessively large; the close must recover the crossed boundary; and tick activity must exceed its own recent baseline. This is a candidate rejection pattern, not proof of institutional orders or actual stop executions.

MT4 Closed-Bar Liquidity Sweep and Relative Tick Volume: Advanced MQL4 Indicator
Figure 1. Illustrative rejection geometry; the prices are schematic, not historical market data.

Exact signal contract

For bar i, the reference low is the minimum low across bars i+1 through i+10. The reference high is the corresponding maximum high. The ATR is the standard MT4 ATR(14) evaluated on bar i. Relative tick volume is the bar's tick volume divided by the average of the preceding 20 bars. Bullish sweep depth = (prior low − current low)/ATR; bearish depth = (current high − prior high)/ATR. Close position = (close − low)/(high − low).

A bullish arrow requires sweep depth from 0.10 to 0.90 ATR, close above the prior low, relative tick volume at least 1.30, and close position at least 0.65. Bearish conditions mirror this using the prior high and a close position at most 0.35. Zero-range bars, zero ATR and zero average tick volume are rejected. The current unfinished bar is always empty.

Worked hypothetical example

Suppose the prior ten-bar low is 1.0840, the candidate bar low is 1.0834, ATR(14) is 0.0015, the close is 1.0848, and the bar high is 1.0850. The normalized sweep depth is (1.0840 − 1.0834)/0.0015 = 0.40 ATR. The close position is (1.0848 − 1.0834)/(1.0850 − 1.0834) = 0.875. If tick volume is 195 and the previous 20-bar mean is 130, relative volume is 1.50. All four bullish filters pass. If the close had been 1.0838, the recovery test would fail despite the wick.

Setting Default Practical effect
SweepLookback 10 Longer windows identify less frequent reference extremes
VolumeLookback 20 Smooths the relative tick-volume baseline
ATRPeriod 14 Normalizes sweep depth to volatility
MinimumSweepATR / MaximumSweepATR 0.10 / 0.90 Rejects microscopic and unusually deep excursions
MinimumRelativeVolume 1.30 Requires 30% above baseline tick activity
MinimumClosePosition 0.65 Requires the bullish close in the upper 35% of the bar
ArrowOffsetATR 0.20 Separates the arrow from the candle visually

Complete MT4 indicator source

Create ClosedBarSweepVolume.mq4 under MQL4/Indicators. The indicator uses native MT4 event handlers, two arrow buffers and the built-in iATR function. Source code has not been compiled in MetaEditor in this publication workflow; compile and review it locally before trading.

//+------------------------------------------------------------------+
//| ClosedBarSweepVolume.mq4 - closed-bar rejection study |
//| Educational indicator; tick volume is broker dependent. |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrSeaGreen
#property indicator_color2 clrIndianRed
#property indicator_width1 2
#property indicator_width2 2

input int SweepLookback = 10;
input int VolumeLookback = 20;
input int ATRPeriod = 14;
input double MinimumSweepATR = 0.10;
input double MaximumSweepATR = 0.90;
input double MinimumRelativeVolume = 1.30;
input double MinimumClosePosition = 0.65;
input double ArrowOffsetATR = 0.20;

double BullBuffer[];
double BearBuffer[];

int OnInit()
{
   if(SweepLookback < 2 || VolumeLookback < 2 || ATRPeriod < 2 ||
      MinimumSweepATR < 0 || MaximumSweepATR <= MinimumSweepATR ||
      MinimumRelativeVolume <= 0 || MinimumClosePosition <= 0 ||
      MinimumClosePosition >= 1 || ArrowOffsetATR < 0)
      return(INIT_PARAMETERS_INCORRECT);

   SetIndexBuffer(0, BullBuffer);
   SetIndexBuffer(1, BearBuffer);
   ArraySetAsSeries(BullBuffer, true);
   ArraySetAsSeries(BearBuffer, true);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(0, 233);
   SetIndexArrow(1, 234);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexLabel(0, "Bullish Sweep");
   SetIndexLabel(1, "Bearish Sweep");
   IndicatorShortName("Closed-Bar Sweep + Relative Tick Volume");
   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[])
{
   ArraySetAsSeries(open, true);
   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   ArraySetAsSeries(close, true);
   ArraySetAsSeries(tick_volume, true);

   int required = MathMax(MathMax(SweepLookback, VolumeLookback),
                          ATRPeriod + 1);
   if(rates_total < required + 2)
      return(0);

   // Bar zero is still forming: never issue a live-bar signal.
   BullBuffer[0] = EMPTY_VALUE;
   BearBuffer[0] = EMPTY_VALUE;

   int oldest = rates_total - required - 1;
   int limit = (prev_calculated == 0) ? oldest : MathMin(2, oldest);

   for(int i = limit; i >= 1; i--)
   {
      BullBuffer[i] = EMPTY_VALUE;
      BearBuffer[i] = EMPTY_VALUE;

      double atr = iATR(NULL, 0, ATRPeriod, i);
      double range = high[i] - low[i];
      if(atr <= 0 || range <= 0)
         continue;

      double priorLow = low[i+1];
      double priorHigh = high[i+1];
      for(int j = 2; j <= SweepLookback; j++)
      {
         priorLow = MathMin(priorLow, low[i+j]);
         priorHigh = MathMax(priorHigh, high[i+j]);
      }

      double avgVolume = 0.0;
      for(int k = 1; k <= VolumeLookback; k++)
         avgVolume += (double)tick_volume[i+k];
      avgVolume /= VolumeLookback;
      if(avgVolume <= 0)
         continue;

      double relativeVolume = (double)tick_volume[i] / avgVolume;
      if(relativeVolume < MinimumRelativeVolume)
         continue;

      double bullishDepth = (priorLow - low[i]) / atr;
      double bearishDepth = (high[i] - priorHigh) / atr;
      double closePosition = (close[i] - low[i]) / range;

      bool bull = bullishDepth >= MinimumSweepATR &&
                  bullishDepth <= MaximumSweepATR &&
                  close[i] > priorLow &&
                  closePosition >= MinimumClosePosition;

      bool bear = bearishDepth >= MinimumSweepATR &&
                  bearishDepth <= MaximumSweepATR &&
                  close[i] < priorHigh &&
                  closePosition <= 1.0 - MinimumClosePosition;

      if(bull)
         BullBuffer[i] = low[i] - ArrowOffsetATR * atr;
      if(bear)
         BearBuffer[i] = high[i] + ArrowOffsetATR * atr;
   }
   return(rates_total);
}

Implementation details that matter

Series orientation: explicit ArraySetAsSeries calls ensure index 0 means the current candle and larger indices mean older candles. The indicator only evaluates bars 1 and older. Incremental updates: on first calculation it walks historical bars; on later calls it refreshes only the latest two completed bars, limiting unnecessary work. Buffer semantics: EMPTY_VALUE suppresses absent arrows. The indicator deliberately does not place orders or infer executions from arrows.

Historical versus live behavior: a signal for bar 1 is available only after that candle has closed and a subsequent tick triggers recalculation. Bar 0 is never populated. Historical arrows can still change if a broker revises historical OHLC or tick-volume data, and different broker feeds may disagree. This is not a guarantee against all forms of historical revision.

Installation and verification

  1. Open MetaEditor, create a new custom indicator file, replace its contents with the complete code, then compile and inspect any diagnostics.
  2. Attach it to a liquid instrument and verify the green and red arrows against prior ten-bar extremes.
  3. Use the Data Window to inspect arrow buffers; compare the latest completed bar with the still-forming bar.
  4. Calculate the worked example by hand and test a flat candle, zero-volume feed, and low-liquidity session.
  5. Compare different brokers, timeframes and spreads; do not treat a visually attractive sample as a backtest.

Parameter sensitivity and failure modes

Lowering MinimumRelativeVolume raises candidate count but may admit weak probes. Increasing MinimumClosePosition produces stricter rejection bars but fewer observations. A narrow maximum ATR sweep can exclude genuine volatile reversals; a very wide maximum may include disorderly news moves. The filters are correlated with market regime, so tuning all of them on the same short history invites overfitting.

Tick volume is a broker-specific count of price updates, not centralized exchange volume. MT4 iATR uses the selected chart's symbol and timeframe. This indicator does not measure spread, slippage, depth of market, execution feasibility or economic-news exposure. For systematic use, define an independent entry trigger, protective stop, exit logic and out-of-sample test before considering live orders.

Possible extensions

A next iteration could add a higher-timeframe trend regime, time-of-day filters, optional alerts, an explicit non-repainting closed-bar scan interface, and a strategy tester EA that separates signal generation from execution. If you would like to extend this free idea for your own trading workflow, explore our Custom Trading Software Development Services.

Risk notice: These rules are educational, not investment advice. A detected rejection does not establish profitability, and the source requires platform-side compilation and testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.