Home » Candlestick Patterns » Detecting Three Black Crows Candlestick Pattern in Pine Script

Detecting Three Black Crows Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Three Black Crows Candlestick Pattern

The “Three Black Crows” candlestick pattern is a significant bearish reversal indicator in technical analysis, providing insights into market sentiment shifts. Here’s an overview of this pattern:

Three Black Crows Candlestick Pattern
  1. Pattern Formation: It consists of three consecutive long-bodied bearish candlesticks. Each candlestick should have a short or nonexistent upper shadow, emphasizing the dominance of selling pressure.
  2. Appearance in Trends: This pattern typically emerges at the end of a bullish trend, signaling that the uptrend is losing strength and a bearish reversal is likely.
  3. Characteristics of Each Candlestick:
    • Open: Each candlestick opens within the body of the previous candle, preferably in the upper half.
    • Close: They close at or near the day’s low, underscoring the sellers’ control.
  4. Market Psychology: The pattern reflects a strong shift in investor sentiment from bullish to bearish. The sustained selling over three sessions indicates that bears are taking control.

Importance in Technical Analysis

The “Three Black Crows” candlestick pattern holds significant importance in technical analysis due to several reasons:

  1. Bearish Reversal Signal: This pattern is a strong indicator of a potential bearish reversal, especially when it occurs after a prolonged uptrend. Its recognition is crucial for traders and investors to anticipate a change in market direction.
  2. Market Sentiment Indicator: The “Three Black Crows” reflect a powerful shift in market sentiment from bullish to bearish. The pattern, characterized by three consecutive long-bodied bearish candles, indicates that sellers are taking control, which is vital information for market participants.
  3. Decision-Making Tool: For traders, the appearance of this pattern can be a signal to close long positions or consider initiating short positions, as it suggests that the current uptrend may be losing momentum.
  4. Volume Confirmation: The reliability of the “Three Black Crows” pattern increases with higher trading volume during its formation. High volume provides additional confirmation of the bearish sentiment.
  5. Risk Management: Recognizing this pattern helps traders in managing their risk, as it can serve as a warning sign of a potential downturn. Traders might set tighter stop-loss orders or adjust their portfolio allocation in response.

Example From Trading View

Example From Trading View

Defining the Three Black Crows Candlestick Pattern Criteria 

The “Three Black Crows” candlestick pattern is defined by a specific set of criteria that technical analysts use to identify this bearish reversal signal. Understanding these criteria is crucial for accurately recognizing the pattern. Here are the key criteria defining the “Three Black Crows” pattern:

  1. Preceding Uptrend: The pattern should emerge after a notable uptrend in the market. Its presence indicates a potential reversal of the bullish sentiment.
  2. Three Long Bearish Candlesticks: The pattern consists of three consecutive long-bodied bearish candlesticks. These candles are typically black or red, indicating that the closing price is significantly lower than the opening price.
  3. Successive Lower Closes: Each of the three candlesticks should close lower than the previous day’s close. This descending sequence of closes demonstrates increasing bearish sentiment.
  4. Opening Prices within Previous Candle’s Body: Each candlestick should open within the body of the previous candle, preferably in the upper half. This overlap suggests that buyers are unable to sustain upward momentum, and bears are gaining control.

Code For Detecting Three Black Crows

//@version=5
indicator("Three Black Crows - Bearish", shorttitle = "Three Black Crows", overlay=true)
C_Len = 14 // ta.ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body

C_BodyHi = math.max(close, open)
C_BodyLo = math.min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = ta.ema(C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high-low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or (math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals

patternLabelPosLow = low - (ta.atr(30) * 0.6)
patternLabelPosHigh = high + (ta.atr(30) * 0.6)

label_color_bearish = input(color.red, "Label Color Bearish")
C_ThreeBlackCrowsBearishNumberOfCandles = 3
C_3BCrw_ShadowPercent = 5.0
C_3BCrw_HaveNotDnShadow = C_Range * C_3BCrw_ShadowPercent / 100 > C_DnShadow
C_ThreeBlackCrowsBearish = false
if C_LongBody and C_LongBody[1] and C_LongBody[2]
    if C_BlackBody and C_BlackBody[1] and C_BlackBody[2]
        C_ThreeBlackCrowsBearish := close < close[1] and close[1] < close[2] and open > close[1] and open < open[1] and open[1] > close[2] and open[1] < open[2] and C_3BCrw_HaveNotDnShadow and C_3BCrw_HaveNotDnShadow[1] and C_3BCrw_HaveNotDnShadow[2]
alertcondition(C_ThreeBlackCrowsBearish, title = "New pattern detected", message = "New Three Black Crows – Bearish pattern detected")
if C_ThreeBlackCrowsBearish
    var ttBearishThreeBlackCrows = "Three Black Crows\nThis is a bearish reversal pattern that consists of three long, red-bodied candles in immediate succession. For each of these candles, each day opens within the body of the day before and closes either at or near its low."
    label.new(bar_index, patternLabelPosHigh, text="Three Black Crows", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishThreeBlackCrows)
bgcolor(ta.highest(C_ThreeBlackCrowsBearish?1:0, C_ThreeBlackCrowsBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_ThreeBlackCrowsBearishNumberOfCandles-1))

Output

Output

Overview of the script 

Indicator Declaration

indicator("Three Black Crows - Bearish", shorttitle = "Three Black Crows", overlay=true)
  • This line declares a new indicator with the name “Three Black Crows – Bearish”.
  • shorttitle is a brief version of the name for display purposes.
  • overlay=true indicates that the indicator will be plotted directly on the price chart.

Parameter Initialization

C_Len = 14 // ta.ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body
  • These lines define various parameters such as the length of the Exponential Moving Average (ta.ema) for the average body size and percentages for the shadow sizes. These parameters are used later in the script to analyze candlestick features.

Candlestick Component Calculations

C_BodyHi = math.max(close, open)
C_BodyLo = math.min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = ta.ema(C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
  • These lines calculate the high and low of each candlestick’s body, the body size, and the upper and lower shadows. These are essential for determining the characteristics of each candlestick.

Candlestick Characteristics

C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high-low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or (math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals
  • This section defines boolean variables to check if a candlestick has significant upper or lower shadows, if it’s a white or black body, and if it’s a Doji candle. These characteristics are crucial in identifying the “Three Black Crows” pattern.

Pattern Recognition Logic

label_color_bearish = input(color.red, "Label Color Bearish")
C_ThreeBlackCrowsBearishNumberOfCandles = 3
C_3BCrw_ShadowPercent = 5.0
C_3BCrw_HaveNotDnShadow = C_Range * C_3BCrw_ShadowPercent / 100 > C_DnShadow
C_ThreeBlackCrowsBearish = false
if C_LongBody and C_LongBody[1] and C_LongBody[2]
    if C_BlackBody and C_BlackBody[1] and C_BlackBody[2]
        C_ThreeBlackCrowsBearish := close < close[1] and close[1] < close[2] and open > close[1] and open < open[1] and open[1] > close[2] and open[1] < open[2] and C_3BCrw_HaveNotDnShadow and C_3BCrw_HaveNotDnShadow[1] and C_3BCrw_HaveNotDnShadow[2]
  • These lines set up label colors and define the core logic for identifying the “Three Black Crows” pattern. The script checks for three consecutive long-bodied, bearish (black) candles, each opening within the previous candle’s body and closing lower than the previous close.

Alerts and Labeling

alertcondition(C_ThreeBlackCrowsBearish, title = "New pattern detected", message = "New Three Black Crows – Bearish pattern detected")
if C_ThreeBlackCrowsBearish
    var ttBearishThreeBlackCrows = "Three Black Crows\nThis is a bearish reversal pattern that consists of three long, red-bodied candles in immediate succession. For each of these candles, each day opens within the body of the day before and closes either at or near its low."
    label.new(bar_index, patternLabelPosHigh, text="Three Black Crows", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishThreeBlackCrows)
bgcolor(ta.highest(C_ThreeBlackCrowsBearish?1:0, C_ThreeBlackCrowsBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_ThreeBlackCrowsBearishNumberOfCandles-1))
  • The script includes an alert condition for when the pattern is detected and code to create a label on the chart at the location of the pattern. It also changes the background color for the bars where the pattern occurs, making it visually prominent.

Frequently Asked Questions

What is the Purpose of the “Three Black Crows – Bearish” Indicator Script?

This script is designed to automatically detect the “Three Black Crows” candlestick pattern on TradingView charts. This pattern is a bearish reversal signal typically occurring at the end of an uptrend.

How Does the Script Identify the “Three Black Crows” Pattern?

The script looks for three consecutive long-bodied bearish (black or red) candlesticks, each closing lower than the previous one and opening within the body of the preceding candlestick. It checks for these criteria using the parameters set in the script.

Can I Customize the Parameters of the Script?

Yes, the script includes customizable parameters like the length for the Exponential Moving Average (EMA) of the candlestick body and shadow percentage, allowing traders to tailor the script to their specific trading strategy or the volatility of the asset being traded.

Does the Script Provide Real-Time Alerts?

Yes, the script features an alertcondition function, which triggers real-time alerts when the “Three Black Crows” pattern is detected. This is useful for traders who wish to be notified immediately of potential bearish reversals without having to constantly monitor the charts.

Is This Script Suitable for All Types of Traders?

The script is versatile and can be a valuable tool for various types of traders, including day traders, swing traders, and long-term investors. However, its effectiveness can vary depending on the asset and the time frame it’s applied to. It’s always recommended to use this script in conjunction with other technical analysis tools and methods for the best results.

Conclusion

This code detects the “Three Black Crows” bearish reversal pattern, making it a valuable asset for technical traders using TradingView. By automating the identification of this key pattern, the script enhances trading efficiency and decision-making. Its customizable parameters allow for flexibility, catering to various trading styles and market conditions. However, while it serves as a powerful tool for spotting potential bearish reversals, traders should use it in conjunction with other technical analysis techniques to confirm signals and manage risk effectively. Overall, this script is a significant addition to the arsenal of technical indicators, particularly for those focusing on candlestick pattern analysis.

Leave a Comment