Home » Candlestick Patterns » Detecting Bearish Engulfing Candlestick Pattern in Pine Script

Detecting Bearish Engulfing Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Bearish Engulfing Candlestick Pattern

The Bearish Engulfing Candlestick Pattern is a significant indicator in technical analysis, used by traders to identify potential reversals in the market. Here’s an overview of this pattern:

Bearish Engulfing
  • Composition: This pattern consists of two candlesticks. The first is a smaller green (or white) candlestick, representing a price increase, and the second is a larger red (or black) candlestick, representing a price decrease. The second candlestick must engulf the body of the first, but it does not necessarily need to engulf the shadows.
  • Occurrence in Trends: The Bearish Engulfing Pattern typically appears at the end of an uptrend or during a price rally. It signals that the bullish momentum is waning and that bears are gaining control.
  • Psychology Behind the Pattern: The pattern reflects a shift in market sentiment. Initially, bulls push the price higher, but by the close of the second day, bears have overtaken and driven the price down, negating the gains of the previous day. This sudden shift can indicate a growing bearish sentiment.

Importance in Technical Analysis

The Bearish Engulfing Candlestick Pattern holds significant importance in technical analysis for several reasons:

  1. Early Warning Sign of Trend Reversal: The pattern is considered a reliable early indicator of a potential shift from a bullish trend to a bearish trend. By recognizing this pattern, traders can make timely decisions to either exit long positions or enter short positions.
  2. Market Sentiment Indicator: The Bearish Engulfing pattern is a clear representation of a change in market sentiment. The larger bearish candle engulfing the smaller bullish candle indicates a strong shift from buying (bullish) pressure to selling (bearish) pressure.
  3. Versatility Across Time Frames: This pattern is applicable across various time frames, from short-term intraday charts to long-term monthly charts. This versatility makes it a useful tool for different types of traders, including day traders, swing traders, and long-term investors.
  4. Risk Management Tool: By indicating potential bearish reversals, the Bearish Engulfing pattern can serve as a risk management tool, alerting traders to tighten stop-loss orders or to protect profits in an existing bullish position.

Example From Trading View

Example From Trading View

Defining the Bearish Engulfing Candlestick Pattern Criteria 

The Bearish Engulfing Candlestick Pattern is defined by specific criteria that must be met to validate its presence in a chart. These criteria include:

  1. Prevailing Uptrend:The pattern must occur in the context of an existing uptrend. This uptrend indicates that bullish sentiment has been driving the market before the appearance of the Bearish Engulfing pattern.
  2. First Candlestick: The first candlestick of the pattern is a smaller green (or white) candlestick, indicating a day of gains. This candlestick represents the continuation of the prevailing uptrend.
  3. Second Candlestick: The second candlestick is a larger red (or black) candlestick that ‘engulfs’ the body of the first candlestick. This means that the second candlestick opens at a higher price than the first candlestick’s close (though not necessarily above its high) and closes at a lower price than the first candlestick’s open. This engulfing action is a key characteristic of the pattern.

Code For Detecting Bearish Engulfing

// @version=5
indicator("Basic Engulfing Candles", overlay=true)
// Define the Bearish Engulfing Pattern
bear_ec = close[1] > open[1] and open >= close[1] and close <= open[1]
// Plotting the pattern on the chart
plotshape(bear_ec, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish EC")

Output

Output

Overview of the script 

1. Script Declaration

indicator("Basic Engulfing Candles", overlay=true)
  • This line defines a new indicator named “Basic Engulfing Candles”. The overlay=true parameter means that this indicator will be plotted directly on the price chart, overlaying the price data.

2. Defining the Bearish Engulfing Pattern

bear_ec = close[1] > open[1] and open >= close[1] and close <= open[1]: This line defines the criteria for a Bearish Engulfing pattern.
close[1] > open[1]
  • Checks if the previous candlestick (one period back) is bullish, meaning its closing price (close[1]) is higher than its opening price (open[1]).
  • open >= close[1]: Checks if the opening price of the current candlestick (open) is equal to or higher than the closing price of the previous candlestick. This is part of the engulfing criteria.
  • close <= open[1]: Ensures that the closing price of the current candlestick (close) is lower than or equal to the opening price of the previous candlestick. This confirms that the current candlestick engulfs the previous one, completing the bearish engulfing pattern criteria.

3. Plotting the Pattern on the Chart

plotshape(bear_ec, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish EC")
  • This function plots a shape on the chart whenever the Bearish Engulfing pattern is identified.
  • bear_ec: The condition to plot the shape. The shape is plotted only when bear_ec is true, i.e., when a Bearish Engulfing pattern is detected.
  • style=shape.triangledown: Defines the shape to be plotted as a downward-pointing triangle.
  • location=location.abovebar: The location of the shape will be above the bar/candlestick.
  • color=color.red: The color of the shape will be red.
  • title=”Bearish EC”: Sets the title of the plotted shape as “Bearish EC” (EC stands for Engulfing Candle).

Frequently Asked Questions

What is the purpose of the overlay=true parameter in the indicator declaration?

The overlay=true parameter specifies that the indicator (in this case, the Bearish Engulfing pattern identification) should be displayed directly on top of the price chart, allowing the patterns to be easily seen in the context of the price action.

How does the code determine a Bearish Engulfing pattern?

The code identifies a Bearish Engulfing pattern by comparing the open and close prices of two consecutive candlesticks. The criteria are: the first candlestick must be bullish (close higher than open), and the second candlestick must be bearish (open at or above the previous close and close at or below the previous open), fully engulfing the body of the first candlestick.

What does plotshape function do in the script?

The plotshape function is used to visually mark the occurrence of a Bearish Engulfing pattern on the chart. It plots a downward-pointing triangle (or another chosen shape) above the candlestick where the pattern occurs, providing a clear visual cue for traders.

Can the appearance of the plotted shape be customized?

Yes, the appearance of the shape plotted by plotshape can be customized. Parameters like style, location, color, and title can be adjusted to change the shape, its position on the chart, its color, and the title that appears in the legend.

Is this script sufficient for making trading decisions?

While this script is useful for identifying Bearish Engulfing patterns, which are significant reversal indicators, it should not be the sole basis for trading decisions. Traders are advised to use it in conjunction with other technical analysis tools and consider the broader market context for more informed and risk-managed trading decisions.

Conclusion

In conclusion, detecting the Bearish Engulfing Candlestick Pattern using Pine Script on the TradingView platform offers traders an efficient and automated way to identify potential market reversals. The script’s ability to overlay this pattern directly onto price charts enhances its utility as a visual tool, aiding in prompt and informed decision-making.

Leave a Comment