MT5 Engulfing Indicator Explained: A Complete Guide for MetaTrader 5 Traders

The Engulfing pattern is one of the most popular candlestick formations used by traders around the world. It is simple to understand, appears frequently on the chart, and can provide powerful clues about a possible trend reversal. In this article, I will explain how the MT5 Engulfing Indicator works, how the provided MQL5 code detects bullish and bearish engulfing patterns, and how traders can use this indicator effectively in real market conditions.

This article is suitable for beginners who are learning price action and also for intermediate traders who want to automate candlestick pattern detection in MetaTrader 5.

What Is an Engulfing Pattern?

An engulfing pattern consists of two candles.

Bullish Engulfing

A bullish engulfing pattern appears after a downward movement.

  • The first candle is bearish (red).
  • The second candle is bullish (green).
  • The body of the second candle completely engulfs the body of the first candle.

This pattern suggests that buyers have taken control and the market may reverse upward.

Bearish Engulfing

A bearish engulfing pattern appears after an upward movement.

  • The first candle is bullish (green).
  • The second candle is bearish (red).
  • The body of the second candle completely engulfs the body of the first candle.

This pattern suggests that sellers have become dominant and the market may reverse downward.

Why Use an Indicator Instead of Manual Analysis?

Many traders manually search for engulfing patterns, but this can be time-consuming, especially when monitoring multiple symbols and timeframes.

An indicator provides several advantages:

  • Automatic detection of bullish and bearish engulfing patterns.
  • Visual arrows directly on the chart.
  • Works on all MT5 symbols including Forex, Gold, Indices, and Crypto.
  • Can be used on any timeframe from M1 to MN.
  • Helps reduce the chance of missing a valid setup.

The provided MQL5 code is a lightweight indicator that focuses only on detecting engulfing candles and drawing arrows on the chart.

Overview of the MT5 Engulfing Indicator Code

The indicator is written in MQL5 and uses chart objects instead of indicator buffers.

At the beginning of the code:

#property indicator_chart_window
#property indicator_plots 0
#property indicator_buffers 0

This means:

  • The indicator is drawn in the main chart window.
  • It does not use standard indicator plots.
  • It uses graphical objects (arrows) for signals.

This approach keeps the indicator simple and efficient.

Detecting Candle Color

The first two helper functions determine whether a candle is bullish or bearish.

bool isGreenCandle(double open, double close) {
   return open < close;
}

If the close is higher than the open, the candle is bullish.

bool isRedCandle(double open, double close) {
   return !isGreenCandle(open, close);
}

A bearish candle is simply the opposite condition.

Bullish Engulfing Logic

The core of the bullish detection is:

open[index] <= close[index - 1] &&
close[index] > open[index - 1]

The indicator checks that:

  • The current candle is bullish.
  • The previous candle is bearish.
  • The current open is below or equal to the previous close.
  • The current close is above the previous open.

This ensures that the body of the current candle fully covers the body of the previous candle.

Bearish Engulfing Logic

For bearish setups:

open[index] >= close[index - 1] &&
close[index] < open[index - 1]

The indicator checks that:

  • The current candle is bearish.
  • The previous candle is bullish.
  • The current open is above or equal to the previous close.
  • The current close is below the previous open.

This creates a valid bearish engulfing pattern.

Drawing Buy and Sell Arrows

When a bullish pattern is found, the indicator creates a buy arrow below the candle low. When a bearish pattern is found, it creates a sell arrow above the candle high.

As a result, the chart becomes very easy to read:

  • Buy arrows appear below bullish engulfing candles
  • Sell arrows appear above bearish engulfing candles

How to Install the Indicator in MetaTrader 5

  1. Open MetaEditor in MT5.
  2. Create a new Custom Indicator.
  3. Replace the generated code with the provided code.
  4. Save the file, for example: Engulfing_Indicator.mq5.
  5. Click Compile.
  6. Return to MT5 and attach the indicator to any chart.

After installation, arrows will appear automatically whenever a new engulfing pattern is detected.

Best Timeframes for Engulfing Trading

Although the indicator works on all timeframes, some are generally more reliable.

Timeframe Reliability
M1 - M5 Low
M15 Medium
M30 Medium
H1 High
H4 Very High
D1 Excellent

For swing trading, H4 and D1 are usually the best choices because they filter out much of the market noise.

Trading Strategy Using This Indicator

Buy Setup

  1. Identify a downtrend or pullback.
  2. Wait for a bullish engulfing arrow.
  3. Enter a buy trade after the candle closes.
  4. Place stop loss below the engulfing candle low.
  5. Target the next resistance level or use a risk-reward ratio of 1:2 or 1:3.

Sell Setup

  1. Identify an uptrend or pullback.
  2. Wait for a bearish engulfing arrow.
  3. Enter a sell trade after the candle closes.
  4. Place stop loss above the engulfing candle high.
  5. Target the next support level or use a 1:2 or 1:3 risk-reward ratio.

Example on XAUUSD (Gold)

Suppose Gold is falling on the H1 timeframe.

  • A small bearish candle forms.
  • The next candle opens lower and closes strongly bullish.
  • The indicator prints a buy arrow.

This signal often indicates that institutional buyers are stepping in. If the pattern forms near a support zone, the probability of a successful reversal becomes higher.

How to Improve Signal Quality

Engulfing patterns should not be traded blindly. Combine them with other tools.

1. Support and Resistance

Take bullish signals near support and bearish signals near resistance.

2. Moving Averages

Use a 50 EMA or 200 EMA to determine the main trend.

3. Volume

Higher volume on the engulfing candle increases reliability.

4. Market Structure

Look for higher highs and higher lows for buys, and lower highs and lower lows for sells.

Advantages of This Indicator

  • Simple and lightweight
  • No repainting after candle close
  • Works on any symbol and timeframe
  • Easy visual interpretation
  • Good for price action traders

Limitations

No indicator is perfect.

  • Many false signals in ranging markets
  • Does not consider trend direction
  • Does not use volume confirmation
  • Can generate frequent signals on lower timeframes

Because of these limitations, risk management remains essential.

Object Management and Memory Cleanup

An important part of the code is the cleanup function.

void OnDeinit(const int reason) {
   delete_objects();
}

When the indicator is removed from the chart, all arrows created by the indicator are deleted automatically. This prevents clutter and keeps the chart clean.

Can This Indicator Be Improved?

Yes. Some useful upgrades include:

  • Alert notifications
  • Push notifications to mobile
  • Email alerts
  • Minimum candle size filter
  • Trend filter using EMA
  • Multi-timeframe confirmation
  • Statistics panel (win rate, total signals, etc.)

These features can make the indicator more suitable for professional trading.

Risk Management Tips

Even a strong engulfing pattern can fail.

Always:

  • Risk 1-2% per trade.
  • Use a stop loss.
  • Avoid trading during major news events.
  • Wait for the candle to close completely.
  • Do not overtrade every signal.

Full Code of Indicator


//+------------------------------------------------------------------+
//|                                              Engulfing Indicator |
//|                                       Copyright 2024, Hieu Hoang |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_plots 0
#property indicator_buffers 0

string object_names[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isGreenCandle(double open, double close) {
   return open < close;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isRedCandle(double open, double close) {
   return !isGreenCandle(open, close);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isBullishEngulfing(int index,
   const double & open[],
      const double & close[]) {
   if (
      isGreenCandle(open[index], close[index]) &&
      isRedCandle(open[index - 1], close[index - 1]) &&
      open[index] <= close[index - 1] &&
      close[index] > open[index - 1]
   )
      return true;
   return false;
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isBearishEngulfing(int index,
   const double & open[],
      const double & close[]) {
   if (
      isRedCandle(open[index], close[index]) &&
      isGreenCandle(open[index - 1], close[index - 1]) &&
      open[index] >= close[index - 1] &&
      close[index] < open[index - 1]
   )
      return true;
   return false;
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
   //ObjectsDeleteAll(0);
   return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void create_object(string name, ENUM_OBJECT obj_type,
   const datetime time,
      const double price) {
   ObjectCreate(0, name, obj_type, 0, time, price);
   ArrayResize(object_names, ArraySize(object_names) + 1);
   object_names[ArraySize(object_names) - 1] = name;
}
//+------------------------------------------------------------------+
//| 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[]) {
   int i = prev_calculated == 0 ? 1 : prev_calculated - 1;
   for (; i < rates_total; i++) {
      if (isBullishEngulfing(i, open, close))
         create_object("Buy at " + DoubleToString(close[i], (int) SymbolInfoInteger(_Symbol, SYMBOL_DIGITS)), OBJ_ARROW_BUY, time[i], low[i]);
      else
      if (isBearishEngulfing(i, open, close))
         create_object("Sell at " + DoubleToString(close[i], (int) SymbolInfoInteger(_Symbol, SYMBOL_DIGITS)), OBJ_ARROW_SELL, time[i], high[i]);
   }

   return (rates_total);
}

//+------------------------------------------------------------------+
void delete_objects() {
   for (int i = 0; i < ArraySize(object_names); i++) {
      ObjectDelete(0, object_names[i]);
   }
   ArrayResize(object_names, 0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
   delete_objects();
}
//+------------------------------------------------------------------+

Conclusion

The MT5 Engulfing Indicator is a practical tool for traders who want to automate the detection of one of the most effective candlestick reversal patterns. The provided MQL5 code is clean, lightweight, and easy to understand, making it an excellent learning resource for anyone studying price action or MetaTrader 5 programming.

Bullish engulfing patterns can help identify potential buying opportunities, while bearish engulfing patterns can highlight possible selling opportunities. However, the real power of this indicator comes when it is combined with support and resistance, trend analysis, and proper risk management.

If you are a beginner, start by testing the indicator on a demo account and observe how the signals behave on H1 and H4 charts. If you are an experienced trader, consider enhancing the code with alerts, trend filters, and multi-timeframe confirmation.

In trading, no single pattern guarantees success. The engulfing pattern is best viewed as a probability tool, not a certainty. Used with discipline and sound money management, this MT5 indicator can become a valuable addition to your trading toolkit and help you make faster, more objective decisions in the market.