Home » Candlestick Patterns » Detecting Evening Star Candlestick Pattern in Pine Script

Detecting Evening Star Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Evening Star Candlestick Pattern


The Evening Star candlestick pattern is a bearish reversal pattern that typically appears at the top of an uptrend in financial markets. It signals a potential shift from a bullish to a bearish market sentiment. The pattern consists of three distinct candlesticks:

Evening Star Candlestick Pattern
  1. The First Candlestick: This is a large bullish candle, reflecting the ongoing uptrend and strong buying pressure.
  2. The Second Candlestick: This candle is smaller and can be either bullish or bearish. It gaps above the first candlestick, indicating a continuation of the upward momentum but with less conviction. This candle is often a star, having a small real body.
  3. The Third Candlestick: A bearish candle that closes well into the body of the first candle. This candle shows a strong shift towards selling pressure and signals the reversal of the trend.

Importance in Technical Analysis

The Evening Star candlestick pattern holds significant importance in technical analysis for several reasons:

  1. Indication of Reversal: It is considered a reliable indicator of a potential reversal in the market from bullish to bearish. This is particularly valuable for traders and investors looking to anticipate and respond to market trend changes.
  2. Sentiment Shift Recognition: The pattern reflects a shift in market sentiment. The initial bullish candle signifies strong buying pressure, which is then questioned by the smaller star candle. The final bearish candle confirms a shift towards selling pressure, indicating that the bulls are losing control to the bears.
  3. Entry and Exit Signals: Traders use the Evening Star pattern to make informed decisions about market entry and exit points. For instance, it can signal an opportunity to exit long positions or to enter short positions.
  4. Risk Management: Recognizing such patterns can aid in risk management. Traders might set stop-loss orders based on the pattern’s formation, thereby limiting potential losses if the anticipated reversal does not materialize.
  5. Enhanced when Combined with Other Indicators: The effectiveness of the Evening Star pattern increases when combined with other technical analysis tools, such as volume analysis, moving averages, or momentum indicators. For example, higher volume on the third candle of the pattern can provide additional confirmation of the bearish reversal.

Example From Trading View

Example From Trading View

Defining the Evening Star Candlestick Pattern Criteria 

The Evening Star candlestick pattern is defined by specific criteria that distinguish it from other patterns. Here are the key elements that constitute an Evening Star pattern:

  1. Uptrend Precedence: The pattern should form during an uptrend or at least after a significant price increase. This context is crucial as the pattern is a bearish reversal indicator.
  2. First Candlestick: The first candle of the pattern is a large bullish candle. It signifies the continuation of the existing uptrend and reflects strong buying pressure.
  3. Second Candlestick: This is a small-bodied candle, which can be either bullish or bearish. It gaps above the close of the first candlestick, indicating a loss of momentum in the prevailing trend. This candle is typically short, sometimes resembling a star (hence the name “Evening Star”), and it shows indecision in the market.
  4. Third Candlestick: The final candle is a bearish candle that closes well into the body of the first candlestick. Ideally, it should close below the midpoint of the first candlestick’s body, confirming a shift in sentiment from bullish to bearish.

Code For Detecting Evening Star

//@version=5
indicator("Evening Star Pattern",overlay=true)

// Candle definitions
candle1_Open = open[2]
candle1_Close = close[2]
candle2_Open = open[1]
candle2_Close = close[1]
candle2_Low = low[1]
candle2_High = high[1]
candle3_Open = open
candle3_Close = close

// Bearish calculations
candle1_BodySize = candle1_Close - candle1_Open 
candle2_BodySize = candle2_Open - candle2_Close
candle2_WickLength = candle2_Close - candle2_Low
candle3_BodySize = candle3_Open - candle3_Close

// Logic for bearish Evening Star pattern
Eveningstar = (candle1_Close > candle1_Open) and 
              ((candle2_Open >= candle2_Close) and 
               (candle2_BodySize <= (.333333 * candle1_BodySize)) and 
               (candle2_WickLength > candle2_BodySize)) and 
              ((candle3_Open >= candle2_Close) and 
               (candle3_Close < candle3_Open) and 
               (candle2_BodySize <= (.333333 * candle3_BodySize)) and 
               (candle3_Close < candle1_Open))

// Adding a label for the Evening Star pattern
if Eveningstar
    label.new(bar_index, high, text="Evening Star", style=label.style_label_down, color=color.red, textcolor=color.white, yloc=yloc.abovebar)

Output

Output

Overview of the script 

1. Indicator Definition

//@version=5
indicator("Evening Star Pattern", overlay=true)
  • indicator("Evening Star Pattern", overlay=true): This line sets up the indicator with the name “Evening Star Pattern”. The overlay=true the argument specifies that this indicator should be drawn over the price chart.

2. Candle Definitions

// Candle definitions
candle1_Open = open[2]
candle1_Close = close[2]
candle2_Open = open[1]
candle2_Close = close[1]
candle2_Low = low[1]
candle2_High = high[1]
candle3_Open = open
candle3_Close = close
  • The script defines the open and close prices for the three candles involved in the pattern. open[2] and close[2] are used for the first candle, open[1] and close[1] for the second, and open and close for the third (current candle).

3. Bearish Calculations

// Bearish calculations
candle1_BodySize = candle1_Close - candle1_Open 
candle2_BodySize = candle2_Open - candle2_Close
candle2_WickLength = candle2_Close - candle2_Low
candle3_BodySize = candle3_Open - candle3_Close
  • Here, the script calculates the body size of each candle. The body size is the absolute difference between the candle’s open and close prices. For the second candle, it also calculates the length of the lower wick.

4. Pattern Logic:

// Logic for bearish Evening Star pattern
Eveningstar = (candle1_Close > candle1_Open) and 
              ((candle2_Open >= candle2_Close) and 
               (candle2_BodySize <= (.333333 * candle1_BodySize)) and 
               (candle2_WickLength > candle2_BodySize)) and 
              ((candle3_Open >= candle2_Close) and 
               (candle3_Close < candle3_Open) and 
               (candle2_BodySize <= (.333333 * candle3_BodySize)) and 
               (candle3_Close < candle1_Open))

The Eveningstar variable is a boolean that becomes true if the following conditions are met:

  • The first candle is bullish (close > open).
  • The second candle has a small body (indicating indecision), and its body size is less than one-third of the first candle’s body. It also checks if the second candle’s lower wick is longer than its body.
  • The third candle is bearish (open > close), its body size is at least as large as the second candle’s body, and it closes below the open of the first candle.

5. Labeling the Pattern

// Adding a label for the Evening Star pattern
if Eveningstar
    label.new(bar_index, high, text="Evening Star", style=label.style_label_down, color=color.red, textcolor=color.white, yloc=yloc.abovebar)
  • If the Evening Star pattern is identified (if Eveningstar), the script creates a new label on the chart at the position of the pattern. The label is styled with a red color and positioned above the bar.

Frequently Asked Questions

What does the Evening Star pattern indicator in this Pine Script code signify?

It identifies the Evening Star pattern, a bearish reversal indicator in financial markets.

How does the script determine the components of the Evening Star pattern?

The script checks for a sequence of three candles: a large bullish candle, a smaller indecisive candle, and a bearish candle closing into the first candle’s body.

Can this script be used on any time frame?

Yes, it can be applied to any time frame, but effectiveness may vary.

Is this script sufficient on its own for making trading decisions?

No, it should be used with other analysis tools for comprehensive decision-making.

Does the script account for trading volume in identifying the pattern?

No, this version doesn’t include volume analysis, but it can be modified to do so.

Conclusion

This code detects the Evening Star candlestick pattern, a key indicator in technical analysis for signaling potential bearish reversals in financial markets. Crafted for use in various timeframes, it identifies the pattern by analyzing a sequence of three candles: a large bullish candle, followed by a smaller, possibly indecisive candle, and then a bearish candle closing into the body of the first. While adept at pattern recognition, this script is best utilized as part of a broader trading strategy, complemented by other technical tools and fundamental insights. Notably, it does not incorporate volume analysis, which could be a valuable enhancement for confirming the pattern’s strength. In trading, as in all financial endeavors, a balanced approach that includes risk management and market context consideration is essential for success.

Leave a Comment