Unlock powerful reversal signals with this comprehensive guide to detecting and strategizing with Engulfing patterns in TradingView's Pine Script.
The Engulfing candlestick pattern is one of the most powerful and widely recognized reversal signals in technical analysis. It consists of two candles, where the second candle's body completely "engulfs" the first candle's body. These patterns often indicate a strong shift in market sentiment, making them invaluable for:
An engulfing pattern provides a strong visual clue about who's in control—buyers or sellers. The larger the engulfing candle relative to the previous one, and the larger its body, the stronger the signal. Importantly, the colors of the two candles must be opposite.
The engulfing candle's body (the solid part between open and close) must completely overlap the previous candle's body. Wicks (shadows) are not considered for the engulfing criteria, although wider engulfing wicks can add to conviction.
//@version=5
indicator("Engulfing Pattern Detector", overlay=true)
// Get candle properties for current and previous bar
prevOpen = open[1]
prevClose = close[1]
prevHigh = high[1]
prevLow = low[1]
// Check if previous candle was bullish (green) or bearish (red)
isPrevBullish = prevClose > prevOpen
isPrevBearish = prevClose < prevOpen
// Define Bullish Engulfing criteria
isBullishEngulfing = isPrevBearish and (close > open) and (close > prevHigh) and (open < prevLow)
// Define Bearish Engulfing criteria
isBearishEngulfing = isPrevBullish and (close < open) and (open > prevHigh) and (close < prevLow)
// Plot signals on the chart
plotshape(isBullishEngulfing, title="Bullish Engulfing", location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(isBearishEngulfing, title="Bearish Engulfing", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small)
// Alert conditions (optional)
alertcondition(isBullishEngulfing, title="Bullish Engulfing Alert", message="Bullish Engulfing Pattern Detected!")
alertcondition(isBearishEngulfing, title="Bearish Engulfing Alert", message="Bearish Engulfing Pattern Detected!")
//@version=5
strategy("Engulfing with Trend Confirmation", overlay=true)
// Input for Moving Average length
maLength = input(20, "MA Length")
ma = ta.ema(close, maLength)
// Engulfing Pattern Detection
isPrevBullish = close[1] > open[1]
isPrevBearish = close[1] < open[1]
isBullishEngulfing = isPrevBearish and (close > open) and (close > high[1]) and (open < low[1])
isBearishEngulfing = isPrevBullish and (close < open) and (open > high[1]) and (close < low[1])
// Trend Confirmation
isDowntrend = close < ma
isUptrend = close > ma
// Strategy Logic with Trend Confirmation
longSignal = isBullishEngulfing and isDowntrend
shortSignal = isBearishEngulfing and isUptrend
if (longSignal)
strategy.entry("Long", strategy.long)
if (shortSignal)
strategy.entry("Short", strategy.short)
// Plot MA
plot(ma, "Trend MA", color.blue)
// Plot confirmed signals
plotshape(longSignal, title="Confirmed Bullish Engulfing", location=location.belowbar, color=color.new(color.navy, 0), style=shape.arrowup, size=size.normal)
plotshape(shortSignal, title="Confirmed Bearish Engulfing", location=location.abovebar, color=color.new(color.fuchsia, 0), style=shape.arrowdown, size=size.normal)
//@version=5
indicator("Engulfing with Volume Confirmation", overlay=true)
// Engulfing Pattern Detection
isPrevBullish = close[1] > open[1]
isPrevBearish = close[1] < open[1]
isBullishEngulfing = isPrevBearish and (close > open) and (close > high[1]) and (open < low[1])
isBearishEngulfing = isPrevBullish and (close < open) and (open > high[1]) and (close < low[1])
// Volume Confirmation
isVolumeConfirmed = volume > volume[1]
// Combined signals
confirmedBullish = isBullishEngulfing and isVolumeConfirmed
confirmedBearish = isBearishEngulfing and isVolumeConfirmed
// Plot confirmed signals
barcolor(confirmedBullish ? color.new(color.teal, 60) : na)
barcolor(confirmedBearish ? color.new(color.maroon, 60) : na)
plotshape(confirmedBullish, title="Bullish Engulfing (Vol Confirmed)", location=location.belowbar, color=color.new(color.green, 0), style=shape.labelup, size=size.small, text="Bull Vol")
plotshape(confirmedBearish, title="Bearish Engulfing (Vol Confirmed)", location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, size=size.small, text="Bear Vol")
// Optional: Plot volume for visual check
plot(volume, title="Volume", color=color.gray, style=plot.style_columns)
//@version=5
indicator("Engulfing with RSI Confirmation", overlay=true)
// RSI Inputs
rsiLength = input(14, "RSI Length")
overbought = input(70, "RSI Overbought Level")
oversold = input(30, "RSI Oversold Level")
// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)
// Engulfing Pattern Detection
isPrevBullish = close[1] > open[1]
isPrevBearish = close[1] < open[1]
isBullishEngulfing = isPrevBearish and (close > open) and (close > high[1]) and (open < low[1])
isBearishEngulfing = isPrevBullish and (close < open) and (open > high[1]) and (close < low[1])
// RSI Confirmation
rsiBullishConfirm = rsiValue < oversold
rsiBearishConfirm = rsiValue > overbought
// Combined signals
signalBullish = isBullishEngulfing and rsiBullishConfirm
signalBearish = isBearishEngulfing and rsiBearishConfirm
// Plot signals
plotshape(signalBullish, title="Bullish Engulfing (RSI Confirmed)", location=location.belowbar, color=color.new(color.aqua, 0), style=shape.arrowup, size=size.normal)
plotshape(signalBearish, title="Bearish Engulfing (RSI Confirmed)", location=location.abovebar, color=color.new(color.orange, 0), style=shape.arrowdown, size=size.normal)
// Plot RSI in a separate pane
plot(rsiValue, "RSI", color.blue, linewidth=2, display=display.pane)
hline(overbought, "Overbought", color.red)
hline(oversold, "Oversold", color.green)
To maximize the effectiveness of Engulfing patterns in your Pine Script strategies:
Not all engulfing patterns are strong reversal signals. Avoid trading them in choppy or ranging markets without additional confirmation, as they can lead to false signals.
The Engulfing candlestick pattern is a foundational element of price action analysis and a powerful tool in a trader's arsenal. When properly understood and combined with other technical indicators and market context, it can provide high-probability signals for trend reversals. By implementing these patterns in Pine Script, you can automate their detection, integrate them into sophisticated trading strategies, and enhance your ability to read the market's pulse, ultimately improving your trading decisions.
Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Get Pine Script Strategy