MT5 Engulfing Candle Quality Filter: Closed-Bar Signals with Body Strength and Relative Tick Volume

MT5 Engulfing Candle Quality Filter: Closed-Bar Signals with Body Strength and Relative Tick Volume

Beginner Trading Tutorial | MetaTrader 5 | MQL5 custom indicator

A bullish or bearish engulfing candle is easy to spot after the fact. But a large-looking real body does not necessarily represent a strong candle, and quote activity can be thin even when the visual pattern appears dramatic. This lesson builds a transparent MT5 chart indicator that combines real-body engulfing, a body-to-range quality threshold, and an optional relative tick-volume check. Its arrows appear only on completed candles, never on the bar still forming.

The goal is not to label every reversal correctly or create an automated trading strategy. It is to turn an often-vague candlestick description into three measurable tests that a beginner can calculate, verify, and eventually research systematically. This is an original teaching example, not a claim of trading performance.

The pattern: engulf the body, not necessarily the shadows

For a bullish candidate, the preceding candle must be bearish (close below open); the signal candle must be bullish (close above open). Its opening price must be at or below the prior close, and its closing price at or above the prior open. Together, those tests mean the green real body covers the entire previous red real body. For a bearish candidate, reverse the directions: a bearish candle opens at or above the preceding bullish close and closes at or below the preceding bullish open.

Equal boundary values count as engulfing here, although the candle colors require strict open-versus-close inequalities. The wicks do not need to engulf one another. That distinction matters: demanding both highs and lows to engulf would be a different, more restrictive pattern definition. A candlestick pattern alone also tells us nothing about the next bar unless subsequent outcomes are tested.

Two hypothetical MT5 candles with the green real body engulfing the red one and 78.9 percent signal-candle body-to-range calculation
Figure 1. Illustrative OHLC example. The second candle opens at 1.1021 and closes at 1.1051, encompassing the preceding candle body from 1.1024 to 1.1048. With high 1.1056 and low 1.1018, the body occupies 78.9% of the full range.

Add a quality condition: body as a share of total range

Our first filter measures the strength of the candle body independently from the engulfing shape. The formula is Body % = 100 × |Close − Open| ÷ (High − Low). If the high and low are identical, the bar is ignored so the indicator does not divide by zero. The default minimum is 55%. A candle with long opposing wicks may technically engulf the previous body but fail this quality gate.

In Figure 1, the signal candle opens at 1.1021 and closes at 1.1051. Its real body is 0.0030. The full range is 1.1056 − 1.1018 = 0.0038, yielding 0.0030 ÷ 0.0038 × 100 ≈ 78.9%; it passes. Now imagine the same engulfing relationship but with high 1.1085 and low 1.1015. The body remains 0.0030, yet the total range grows to 0.0070; body percentage falls to 42.9%, below the default threshold. Those longer shadows may imply greater rejection or intrabar disagreement, depending on context.

Confirm activity without confusing tick volume and contracts

Our second optional filter asks whether the signal candle received more quote updates than recent completed bars. Relative tick volume = tick volume of signal bar ÷ average tick volume of the preceding 20 bars. The signal candle is deliberately excluded from the baseline. The default threshold, 1.15, requires activity at least 15% above that recent average.

For example, suppose the signal candle records 1,320 ticks, compared with a 20-bar average of 1,100. Relative tick volume is 1.20, exceeding 1.15. If a candle has convincing body strength but relative volume of 0.94, the optional volume gate rejects it. On many spot-FX MT5 symbols this field counts broker-feed quote changes, not centrally reported exchange share volume. It is an activity proxy, not proof of buyer aggression or institutional positioning.

Technical decision flow for engulfing pattern, at least 55 percent real-body ratio and at least 1.15 relative tick volume with pass and reject examples

Figure 2. The completed candle must pass all enabled gates. Candidate A qualifies with 78.9% body and 1.20 relative tick volume; B fails body quality; C fails relative volume. All numbers are hypothetical.

Practical parameter guide

Input Default Purpose
MinimumBodyPercent 55.0 Reject long-wick, weak-body candles.
AverageVolumeBars 20 Mean tick volume from earlier bars, excluding the signal.
MinimumRelativeTickVolume 1.15 Required signal-bar participation versus baseline.
ApplyTickVolumeFilter true Turn off to study the pattern and body rule alone.
HistoryBarsToScan 500 Limit calculation work to a manageable historical sample.

Increasing body strength from 55% to 70% makes the filter more selective, but could also eliminate relevant candles after volatile sessions. Raising relative-volume requirements can exclude quiet consolidations, while lowering them can admit ordinary activity. Neither choice is universally superior; compare results by market and timeframe. The lookback length changes the comparison baseline: a shorter average adapts faster but is more unstable.

Complete MQL5 indicator source (ready to copy)

Save the following as PS_EngulfingQuality.mq5 in MQL5/Indicators. This is an MT5 indicator, not an MT4 script: it binds two INDICATOR_DATA buffers using SetIndexBuffer(), configures DRAW_ARROW plots, and handles the full indicator OnCalculate() event. The script does not call iCustom() or CopyBuffer() because it calculates from the price and tick-volume arrays provided directly to its own calculation event.

// PS_EngulfingQuality.mq5 - closed-candle educational indicator
// Two arrow plots: bullish and bearish real-body engulfing
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrSeaGreen
#property indicator_width1 2
#property indicator_label1 "Bullish engulfing"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrTomato
#property indicator_width2 2
#property indicator_label2 "Bearish engulfing"

input double MinimumBodyPercent = 55.0;
input int    AverageVolumeBars = 20;
input double MinimumRelativeTickVolume = 1.15;
input bool ApplyTickVolumeFilter = true;
input int    HistoryBarsToScan = 500;

double UpArrow[];
double DownArrow[];

int OnInit()
{
if(MinimumBodyPercent <= 0.0 || MinimumBodyPercent > 100.0 ||
     AverageVolumeBars < 2 || MinimumRelativeTickVolume <= 0.0 ||
     HistoryBarsToScan < 1)
     return INIT_PARAMETERS_INCORRECT;

if(!SetIndexBuffer(0, UpArrow, INDICATOR_DATA) ||
     !SetIndexBuffer(1, DownArrow, INDICATOR_DATA))
     return INIT_FAILED;

// Set time-series indexing AFTER SetIndexBuffer.
ArraySetAsSeries(UpArrow, true);
ArraySetAsSeries(DownArrow, true);
PlotIndexSetInteger(0, PLOT_ARROW, 233);
PlotIndexSetInteger(1, PLOT_ARROW, 234);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
IndicatorSetString(INDICATOR_SHORTNAME,
                     "PS Engulfing Quality (closed bars)");
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 < AverageVolumeBars + 2)
     return 0;

ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);

if(prev_calculated == 0)
{
     ArrayInitialize(UpArrow, EMPTY_VALUE);
     ArrayInitialize(DownArrow, EMPTY_VALUE);
}

// Index zero is the CURRENT unfinished candle: no provisional arrow.
UpArrow[0] = EMPTY_VALUE;
DownArrow[0] = EMPTY_VALUE;

int last = MathMin(HistoryBarsToScan,
                     rates_total - AverageVolumeBars - 1);
for(int i = last; i >= 1; --i)
{
     UpArrow[i] = EMPTY_VALUE;
     DownArrow[i] = EMPTY_VALUE;

     double range = high[i] - low[i];
     if(range <= 0.0)
         continue;

     double bodyPercent = 100.0 * MathAbs(close[i] - open[i]) / range;
     if(bodyPercent < MinimumBodyPercent)
         continue;

     // Real-body engulfing, not necessarily entire wick engulfing.
     bool bullish = close[i + 1] < open[i + 1] &&
                     close[i] > open[i] &&
                     open[i] <= close[i + 1] &&
                     close[i] >= open[i + 1];
     bool bearish = close[i + 1] > open[i + 1] &&
                     close[i] < open[i] &&
                     open[i] >= close[i + 1] &&
                     close[i] <= open[i + 1];
     if(!bullish && !bearish)
         continue;

     if(ApplyTickVolumeFilter)
     {
         double volumeSum = 0.0;
         for(int j = 1; j <= AverageVolumeBars; ++j)
            volumeSum += (double)tick_volume[i + j];
         double baseline = volumeSum / AverageVolumeBars;
         if(baseline <= 0.0)
            continue;
         double relativeVolume = (double)tick_volume[i] / baseline;
         if(relativeVolume < MinimumRelativeTickVolume)
            continue;
     }

     double offset = MathMax(10.0 * _Point, range * 0.15);
     if(bullish)
         UpArrow[i] = low[i] - offset;
     else
         DownArrow[i] = high[i] + offset;
}
return rates_total;
}

How the code prevents premature arrows

In MQL5 timeseries indexing, bar [0] is still forming; the most recent fully closed bar is [1], and its predecessor is [2]. The program explicitly sets the source arrays to timeseries order, binds drawing buffers, and then sets those buffers to timeseries indexing after SetIndexBuffer(). That last ordering is intentional: binding a buffer can alter how its array is indexed.

Both arrow buffers set element zero to EMPTY_VALUE on every calculation. The loop begins at index 1, so it never prints a provisional arrow on the candle that has not closed. All historical candidate bars need at least 20 previous bars for the reference volume, and the scan is capped at 500 bars by default. This makes computation predictable; bars older than the configured scan window are intentionally not classified.

There are separate green and red buffers, and the arrow position is offset from the candle extreme. These buffers are chart-display outputs. They are not trades, notifications, stops, or risk controls. Confirmed-bar processing limits ordinary intrabar changes; corrected market history or broker data revisions may still alter old calculations.

Installation, verification, and a simple experiment

  1. Open MetaTrader 5 → File → Open Data Folder → MQL5 → Indicators.
  2. Create PS_EngulfingQuality.mq5, paste the complete source in MetaEditor, then compile. Confirm the result in your terminal; this code has not been compiled or backtested in your environment.
  3. In the MT5 Navigator, refresh Indicators and attach the study to a chart. First test a liquid instrument on H1 or H4 with default settings.
  4. Check a bullish engulfing candidate in the Data Window: the preceding candle must be red, the signal candle green, and the latter real body must cover the prior real body.
  5. Calculate the signal candle body percentage and, where enabled, its tick volume relative to the preceding 20 completed bars. Confirm the arrow matches the math.
  6. Toggle ApplyTickVolumeFilter and compare the number and characteristics of arrows. Check the forming bar to verify that no arrow appears at index zero.

Failure modes and sensible extensions

Engulfing patterns may cluster around illiquid market openings, spreads, scheduled news, and sharp countertrend bounces. A large candle can still be exhausted rather than beginning a reversal. Tick-volume distributions differ across brokers and symbol types. A 55% body on one asset and a 1.15 volume ratio on another may not indicate comparable risk. The study also ignores wider trend context, support and resistance, volatility-adjusted stops, transaction costs, and actual order execution.

To evaluate whether the idea is useful, record at least 30 to 50 candidates across several regimes. Include both passed and rejected cases; log spread, news regime, next-bar excursion, and the price distance required for entry. Avoid optimizing thresholds solely against a tiny sample. Potential future versions could require proximity to a support zone, detect the broader trend through an indicator handle and CopyBuffer(), add alerts, or expose the arrow buffers to an Expert Advisor. Each extension should be validated separately.

If you are interested in customizing this free indicator or adapting the idea into alerts, scanners, or an EA, you can explore Custom Trading Software Development Services for tailored changes.

Educational software only. No claim of compilation, backtest profit, or future performance is made. Confirm the code and indicator semantics on your broker feed; trading always involves risk.

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.