Pine Script: Evening Star Candlestick Pattern

Unlock powerful bearish reversal signals with this comprehensive guide to detecting and strategizing with Evening Star patterns in TradingView's Pine Script.

Subscribe now @ $99/month

Why the Evening Star Pattern Matters in Pine Script

The Evening Star candlestick pattern is a powerful three-candle bearish reversal pattern that typically forms after an uptrend. It signals a potential top and a strong shift in momentum from buyers to sellers. This pattern indicates that buyers were dominant initially, but their power waned, leading to indecision, and then sellers took control, pushing prices significantly lower. This makes Evening Star patterns invaluable for:

Understanding the Evening Star Candlestick Pattern

An Evening Star pattern consists of three specific candles:

  1. First Candle (Bullish): A long bullish (green) candle, indicating strong buying pressure and a continuation of the uptrend.
  2. Second Candle (Star/Doji): A small-bodied candle (a doji or a spinning top, can be bullish or bearish) that gaps up from the first candle's close. This candle represents indecision in the market, often appearing at the peak of the rally.
  3. Third Candle (Bearish): A long bearish (red) candle that gaps down from the second candle and closes well into (ideally below the midpoint) of the first bullish candle's body. This signifies that sellers have taken control and reversed the prior upward momentum.

The overall structure indicates a progression from buying dominance to indecision, followed by a strong bearish takeover.

Evening Star Pattern

A long green candle, followed by a small star candle (often with a gap up), then a large red candle that pushes back into the first candle's body.

Key Characteristics:

Basic Evening Star Pattern Detection in Pine Script

Here's how to create a basic indicator to detect Evening Star patterns in Pine Script v5:

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

// Candle 1 (previous-previous bar) - Long Bullish
isC1Bullish = close[2] > open[2]
isC1Long = (close[2] - open[2]) > ta.atr(10)[2] * 0.5 // Body is significant, e.g., > 0.5 ATR

// Candle 2 (previous bar) - Small Body (Star) and Gaps Up
isC2SmallBody = math.abs(close[1] - open[1]) <= (high[1] - low[1]) * 0.3 // Small body, e.g., <= 30% of range
isC2GapsUp = open[1] > close[2] // Gap up from previous candle's close
isC2Star = isC2SmallBody and isC2GapsUp

// Candle 3 (current bar) - Long Bearish and Gaps Down, closing into C1 body
isC3Bearish = close < open
isC3Long = (open - close) > ta.atr(10) * 0.5 // Body is significant
isC3GapsDown = open < low[1] // Gaps down from previous candle's low
isC3ClosesIntoC1 = close < (open[2] + close[2]) / 2 // Closes below midpoint of C1 body

// Combine all criteria for Evening Star
isEveningStar = isC1Bullish and isC1Long and isC2Star and isC3Bearish and isC3Long and isC3GapsDown and isC3ClosesIntoC1

// Plot signal on the chart
plotshape(isEveningStar, title="Evening Star", location=location.abovebar, color=color.new(color.maroon, 0), style=shape.triangledown, size=size.normal)

// Alert condition (optional)
alertcondition(isEveningStar, title="Evening Star Detected", message="Evening Star Candlestick Pattern Detected!")

Advanced Evening Star Strategies

Combining Evening Star patterns with other indicators and market context provides stronger, more reliable signals for potential bearish reversals.

1. Evening Star with Uptrend Confirmation (Using Moving Average)

//@version=5
strategy("Evening Star with Trend Confirmation", overlay=true)

// Input for Moving Average length
maLength = input(50, "MA Length (for trend)")
ma = ta.ema(close, maLength) // Using EMA for uptrend detection

// Evening Star Pattern Detection (from basic example)
isC1Bullish = close[2] > open[2]
isC1Long = (close[2] - open[2]) > ta.atr(10)[2] * 0.5

isC2SmallBody = math.abs(close[1] - open[1]) <= (high[1] - low[1]) * 0.3
isC2GapsUp = open[1] > close[2]
isC2Star = isC2SmallBody and isC2GapsUp

isC3Bearish = close < open
isC3Long = (open - close) > ta.atr(10) * 0.5
isC3GapsDown = open < low[1]
isC3ClosesIntoC1 = close < (open[2] + close[2]) / 2

isEveningStar = isC1Bullish and isC1Long and isC2Star and isC3Bearish and isC3Long and isC3GapsDown and isC3ClosesIntoC1

// Trend Confirmation: Price should be above the MA (uptrend)
// AND the MA itself should be sloping upwards (optional, but stronger)
isUptrend = close > ma and ma > ma[1]

// Strategy Logic with Trend Confirmation
shortSignal = isEveningStar and isUptrend

if (shortSignal)
    strategy.entry("Short", strategy.short)
    
// Plot MA
plot(ma, "Trend MA", color.blue)

// Plot confirmed signals
plotshape(shortSignal, title="Confirmed Evening Star", location=location.abovebar, color=color.new(color.fuchsia, 0), style=shape.arrowdown, size=size.normal)

2. Evening Star with Volume Confirmation

//@version=5
indicator("Evening Star with Volume Confirmation", overlay=true)

// Evening Star Pattern Detection (from basic example)
isC1Bullish = close[2] > open[2]
isC1Long = (close[2] - open[2]) > ta.atr(10)[2] * 0.5

isC2SmallBody = math.abs(close[1] - open[1]) <= (high[1] - low[1]) * 0.3
isC2GapsUp = open[1] > close[2]
isC2Star = isC2SmallBody and isC2GapsUp

isC3Bearish = close < open
isC3Long = (open - close) > ta.atr(10) * 0.5
isC3GapsDown = open < low[1]
isC3ClosesIntoC1 = close < (open[2] + close[2]) / 2

isEveningStar = isC1Bullish and isC1Long and isC2Star and isC3Bearish and isC3Long and isC3GapsDown and isC3ClosesIntoC1

// Volume Confirmation:
// Volume on the third bearish candle should be higher than average volume
avgVolume = ta.sma(volume, 20) // 20-period Simple Moving Average of Volume
isVolumeConfirmed = volume > avgVolume * 1.5 // Volume is 1.5x average

// Combined signal
confirmedEveningStar = isEveningStar and isVolumeConfirmed

// Plot confirmed signals
barcolor(confirmedEveningStar ? color.new(color.purple, 60) : na)

plotshape(confirmedEveningStar, title="Evening Star (Vol Confirmed)", location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, size=size.small, text="ES Vol")

// Optional: Plot volume for visual check
plot(volume, title="Volume", color=color.gray, style=plot.style_columns)
plot(avgVolume, title="Avg Volume", color=color.orange, style=plot.style_line)

3. Evening Star with RSI Confirmation

//@version=5
indicator("Evening Star with RSI Confirmation", overlay=true)

// RSI Inputs
rsiLength = input(14, "RSI Length")
overbought = input(70, "RSI Overbought Level")

// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)

// Evening Star Pattern Detection
isC1Bullish = close[2] > open[2]
isC1Long = (close[2] - open[2]) > ta.atr(10)[2] * 0.5

isC2SmallBody = math.abs(close[1] - open[1]) <= (high[1] - low[1]) * 0.3
isC2GapsUp = open[1] > close[2]
isC2Star = isC2SmallBody and isC2GapsUp

isC3Bearish = close < open
isC3Long = (open - close) > ta.atr(10) * 0.5
isC3GapsDown = open < low[1]
isC3ClosesIntoC1 = close < (open[2] + close[2]) / 2

isEveningStar = isC1Bullish and isC1Long and isC2Star and isC3Bearish and isC3Long and isC3GapsDown and isC3ClosesIntoC1

// RSI Confirmation: RSI should be in overbought territory or falling from it
rsiConfirmation = rsiValue >= overbought or (rsiValue[1] >= overbought and rsiValue < rsiValue[1])

// Combined signal
signalEveningStar = isEveningStar and rsiConfirmation

// Plot signals
plotshape(signalEveningStar, title="Evening Star (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)

Optimizing Evening Star Pattern Performance

To maximize the effectiveness of Evening Star patterns in your Pine Script strategies:

Common Evening Star Pattern Pitfalls to Avoid

Warning: Not every three-candle sequence that superficially resembles an Evening Star is a valid pattern. Strict adherence to criteria and contextual analysis are essential.

Conclusion

The Evening Star candlestick pattern is a well-regarded and visually clear signal for bearish reversals. By understanding its precise three-candle formation, its contextual importance within an uptrend, and integrating it with other technical confirmations, you can leverage it effectively in your trading. Implementing Evening Star detection in Pine Script allows you to automate signal generation, combine it with complementary indicators for higher probability trades, and enhance your price action analysis to make more informed trading decisions on TradingView.

Enhance Your Trading

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.

Subscribe now @ $99/month