Pine Script: Morning Star Candlestick Pattern

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

Posted: Expertise: Intermediate/Advanced

Why the Morning Star Pattern Matters in Pine Script

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

Understanding the Morning Star Candlestick Pattern

A Morning Star pattern consists of three specific candles:

  1. First Candle (Bearish): A long bearish (red) candle, indicating strong selling pressure and a continuation of the downtrend.
  2. Second Candle (Star/Doji): A small-bodied candle (a doji or a spinning top, can be bullish or bearish) that gaps down from the first candle's close. This candle represents indecision in the market.
  3. Third Candle (Bullish): A long bullish (green) candle that gaps up from the second candle and closes well into (ideally above the midpoint) of the first bearish candle's body. This signifies that buyers have taken control.

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

Morning Star Pattern

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

Key Characteristics:

Basic Morning Star Pattern Detection in Pine Script

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

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

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

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

// Candle 3 (current bar) - Long Bullish and Gaps Up, closing into C1 body
isC3Bullish = close > open
isC3Long = (close - open) > ta.atr(10) * 0.5 // Body is significant
isC3GapsUp = open > high[1] // Gaps up from previous candle's high
isC3ClosesIntoC1 = close > (open[2] + close[2]) / 2 // Closes above midpoint of C1 body

// Combine all criteria for Morning Star
isMorningStar = isC1Bearish and isC1Long and isC2Star and isC3Bullish and isC3Long and isC3GapsUp and isC3ClosesIntoC1

// Plot signal on the chart
plotshape(isMorningStar, title="Morning Star", location=location.belowbar, color=color.new(color.fuchsia, 0), style=shape.triangleup, size=size.normal)

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

Advanced Morning Star Strategies

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

1. Morning Star with Downtrend Confirmation (Using Moving Average)

//@version=5
strategy("Morning 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 downtrend detection

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

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

isC3Bullish = close > open
isC3Long = (close - open) > ta.atr(10) * 0.5
isC3GapsUp = open > high[1]
isC3ClosesIntoC1 = close > (open[2] + close[2]) / 2

isMorningStar = isC1Bearish and isC1Long and isC2Star and isC3Bullish and isC3Long and isC3GapsUp and isC3ClosesIntoC1

// Trend Confirmation: Price should be below the MA (downtrend)
// AND the MA itself should be sloping downwards (optional, but stronger)
isDowntrend = close < ma and ma < ma[1]

// Strategy Logic with Trend Confirmation
longSignal = isMorningStar and isDowntrend

if (longSignal)
    strategy.entry("Long", strategy.long)
    
// Plot MA
plot(ma, "Trend MA", color.blue)

// Plot confirmed signals
plotshape(longSignal, title="Confirmed Morning Star", location=location.belowbar, color=color.new(color.navy, 0), style=shape.arrowup, size=size.normal)

2. Morning Star with Volume Confirmation

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

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

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

isC3Bullish = close > open
isC3Long = (close - open) > ta.atr(10) * 0.5
isC3GapsUp = open > high[1]
isC3ClosesIntoC1 = close > (open[2] + close[2]) / 2

isMorningStar = isC1Bearish and isC1Long and isC2Star and isC3Bullish and isC3Long and isC3GapsUp and isC3ClosesIntoC1

// Volume Confirmation:
// Volume on the third bullish 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
confirmedMorningStar = isMorningStar and isVolumeConfirmed

// Plot confirmed signals
barcolor(confirmedMorningStar ? color.new(color.aqua, 60) : na)

plotshape(confirmedMorningStar, title="Morning Star (Vol Confirmed)", location=location.belowbar, color=color.new(color.green, 0), style=shape.labelup, size=size.small, text="MS 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. Morning Star with RSI Confirmation

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

// RSI Inputs
rsiLength = input(14, "RSI Length")
oversold = input(30, "RSI Oversold Level")

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

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

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

isC3Bullish = close > open
isC3Long = (close - open) > ta.atr(10) * 0.5
isC3GapsUp = open > high[1]
isC3ClosesIntoC1 = close > (open[2] + close[2]) / 2

isMorningStar = isC1Bearish and isC1Long and isC2Star and isC3Bullish and isC3Long and isC3GapsUp and isC3ClosesIntoC1

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

// Combined signal
signalMorningStar = isMorningStar and rsiConfirmation

// Plot signals
plotshape(signalMorningStar, title="Morning Star (RSI Confirmed)", location=location.belowbar, color=color.new(color.lime, 0), style=shape.arrowup, size=size.normal)

// Plot RSI in a separate pane
plot(rsiValue, "RSI", color.blue, linewidth=2, display=display.pane)
hline(oversold, "Oversold", color.green)

Optimizing Morning Star Pattern Performance

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

Common Morning Star Pattern Pitfalls to Avoid

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

Conclusion

The Morning Star candlestick pattern is a well-regarded and visually clear signal for bullish reversals. By understanding its precise three-candle formation, its contextual importance within a downtrend, and integrating it with other technical confirmations, you can leverage it effectively in your trading. Implementing Morning 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.