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

Detecting Morning Star Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Morning Star Candlestick Pattern

The Morning Star candlestick pattern is a bullish reversal pattern typically observed at the end of a downtrend in financial markets. This pattern is considered a strong signal for a reversal in market sentiment from bearish to bullish. It consists of three candles and is interpreted as a sign of a potential turnaround in a declining market.

Morning Star Candlestick Pattern

Components of the Morning Star Pattern

  1. First Candle: This is a large bearish candle, indicating strong selling pressure. It’s part of the existing downtrend.
  2. Second Candle: This candle opens lower than the first candle’s close, reflecting the continuation of the bearish sentiment. However, it’s a smaller candle, which can be either bearish or bullish and indicates indecision in the market. The key is that it gaps down from the first candle and does not overlap much with it. This candle is sometimes a Doji candle with a small body, signifying a state of equilibrium between buyers and sellers.
  3. Third Candle: The final candle is a large bullish candle that opens higher than the second candle and closes near the middle of the first candle. This indicates a strong buying pressure overcoming the previous selling pressure, signaling a potential reversal.

Importance in Technical Analysis

The importance of the Morning Star candlestick pattern in technical analysis lies in its ability to signal a potential reversal in a bearish trend, offering traders and investors an opportunity to anticipate a shift in market sentiment. Here’s why it holds significance:

Early Warning of Trend Reversal

  1. Indication of Momentum Shift: The Morning Star pattern is considered a reliable indicator of a change in market momentum from bearish to bullish. This shift is crucial for traders looking to capitalize on the early stages of a trend reversal.
  2. Psychological Insight: Candlestick patterns like the Morning Star offer insight into market psychology. The first candle signifies bearish sentiment, the second shows indecision, and the third indicates a growing bullish sentiment, marking a shift in trader psychology.

Decision-Making Tool

  1. Entry and Exit Points: For traders who follow trend reversals, the Morning Star pattern can serve as a signal for entry into long positions or exiting short positions.
  2. Risk Management: By identifying potential reversals, the Morning Star can aid in risk management, allowing traders to set stop-loss orders or adjust their investment strategy accordingly.

Example From Trading View

Example From Trading View

Defining the Morning Star Candlestick Pattern Criteria 

  1. First Candle (Bearish):
    • Nature: A long bearish (red or black) candle.
    • Indication: Reflects the continuation of the prevailing downtrend.
  2. Second Candle (Indecisive):
    • Nature: A small candle, which can be bullish or bearish, or even a Doji (where the opening and closing prices are almost equal).
    • Gap Down: This candle typically opens lower than the close of the first candle, emphasizing market indecision.
    • Position: It should not overlap significantly with the body of the first candle.
  3. Third Candle (Bullish):
    • Nature: A long bullish (green or white) candle.
    • Opening: It opens at or below the second candle’s close.
    • Closing: It should close at least halfway into the body of the first candle, indicating a strong reversal in sentiment.

Code For Detecting Morning Star

//@version=5
indicator("Morning Star Pattern", overlay=true) // Use 'indicator' instead of 'study' for v5

// Candle definitions remain the same
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

// Bullish calculations
candle1_BodySize = candle1_Open - candle1_Close
candle2_BodySize = candle2_Close - candle2_Open
candle2_WickLength = candle2_High - candle2_Close
candle3_BodySize = candle3_Close - candle3_Open

// Logic for Morning Star pattern
Morningstar = (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))

// Plotting the indicator
plotshape(Morningstar, style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)

Output

Output

Overview of the script 

1. Script Initialization

//@version=5
indicator("Morning Star Pattern", overlay=true)
  • //@version=5: Specifies that the script is written in version 5 of the Pine Script language, which is the latest version.
  • indicator(...): This function initializes the script as an indicator. “Morning Star Pattern” is the name given to the indicator. The overlay=true parameter indicates that this indicator will be overlaid on the price chart.

2. 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
  • This section defines the open, close, low, and high prices of the three candles involved in the Morning Star pattern.
  • open[2], close[2], etc., refer to the price two candles ago (candle1), open[1], close[1], etc., refer to the previous candle (candle2), and open, close refer to the current candle (candle3).

3. Bullish Calculations

candle1_BodySize = candle1_Open - candle1_Close
candle2_BodySize = candle2_Close - candle2_Open
candle2_WickLength = candle2_High - candle2_Close
candle3_BodySize = candle3_Close - candle3_Open
  • These lines calculate the sizes of the bodies of the candles. The body size is the absolute difference between the open and close prices of a candle.
  • candle2_WickLength calculates the length of the upper wick of the second candle, which is the difference between its high and close prices.

4. Logic for Morning Star Pattern

Morningstar = (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))
  • This is the core logic that defines the Morning Star pattern.
  • It checks if the first candle is bearish (candle1_Close < candle1_Open), the second candle is a small body candle, and the third candle is bullish and closes into the body of the first candle.

5. Plotting the Indicator

plotshape(Morningstar, style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)
  • plotshape(...): This function plots a shape on the chart whenever the Morning Star pattern criteria are met.
  • The shape is a triangle (shape.triangleup), plotted below the bar (location.belowbar). It’s colored green (color.green) and is small in size (size.small).

Frequently Asked Questions

What does this Pine Script do?

This Pine Script is designed to identify and indicate the Morning Star candlestick pattern on financial charts. The Morning Star pattern is a bullish reversal indicator that appears at the end of a downtrend, signaling a potential shift to an uptrend.

Which version of Pine Script is this code written for?

The code is written for Pine Script Version 5, the latest version of TradingView’s scripting language for creating custom trading strategies, indicators, and alerts.

Can this script be used on any time frame?

Yes, the script can be applied to any time frame, such as 1-hour, daily, or weekly charts. However, the significance of the pattern may vary across different time frames, with higher time frames generally providing more reliable signals.

How does the script identify the Morning Star pattern?

The script identifies the pattern based on the characteristics of three consecutive candles. It checks for a large bearish candle, followed by a small-bodied candle that gaps down, and then a large bullish candle that closes within the body of the first candle.

What is the significance of the overlay=true parameter in the script?

The overlay=true parameter means that the indicator (the Morning Star pattern, in this case) will be drawn directly on the main price chart, overlaying the price data, rather than on a separate panel below the chart.

Conclusion

The Pine Script provided for identifying the Morning Star candlestick pattern is a valuable tool for traders and analysts looking for potential bullish reversals in a bearish market trend. Its versatility across different time frames and compatibility with the latest version of Pine Script (version 5) makes it an adaptable and useful indicator for a wide range of trading strategies. However, it’s crucial to remember that while the script effectively identifies the Morning Star pattern, it does not encompass all aspects of a comprehensive trading strategy. The reliability of the pattern can be enhanced when combined with other technical indicators, volume analysis, and an understanding of the overall market context.

Leave a Comment