Home » Candlestick Patterns » Detecting Dark Cloud Cover Candlestick Pattern in Pine Script

Detecting Dark Cloud Cover Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Dark Cloud Cover Candlestick Pattern

The Dark Cloud Cover is a bearish reversal candlestick pattern commonly used in technical analysis to predict a potential downturn in a bullish market. It appears at the end of an uptrend and signals that the bears are gaining control. Here’s an overview of its characteristics and significance:

Dark Cloud Cover
  1. Formation: This pattern consists of two candlesticks:
    • The first is a long bullish (upward) candle.
    • The second is a bearish (downward) candle that opens at a new high and closes below the midpoint of the body of the first candle.
  2. Market Implication: It indicates a shift in momentum from the bulls to the bears. The higher opening of the second-day shows continued bullish sentiment, but the day closes with significant bearish strength, suggesting a change in market dynamics.

Importance in Technical Analysis

The Dark Cloud Cover candlestick pattern holds significant importance in technical analysis due to several reasons:

  1. Reversal Signal: It serves as a potential early warning sign of a bearish reversal, especially in an uptrend. This helps traders and investors to anticipate a change in market direction, enabling them to make timely decisions, like securing profits from long positions or preparing for short-selling opportunities.
  2. Sentiment Indicator: This pattern reflects a substantial shift in market sentiment from bullish to bearish. The appearance of a Dark Cloud Cover indicates that bearish traders are challenging the prevailing bullish sentiment, which can be a critical insight in gauging market mood.
  3. Risk Management: Identifying bearish reversal patterns like the Dark Cloud Cover aids traders in managing risks. By recognizing potential downturns, they can set stop-loss orders, adjust their portfolio, or hedge their positions to minimize potential losses.
  4. Enhanced with Confirmation: When used in conjunction with other technical analysis tools, such as moving averages, trendlines, or technical indicators (like RSI, MACD), the Dark Cloud Cover can provide a more robust trading strategy. Confirmation from these tools can increase the reliability of the pattern.
  5. Versatility Across Timeframes: It is applicable across various timeframes, from short-term to long-term charts, making it a versatile tool for different trading styles, including day trading, swing trading, and long-term investing.

Example From Trading View

Example From Trading View

Defining the Dark Cloud Cover Candlestick Pattern Criteria 

The Dark Cloud Cover is a bearish reversal candlestick pattern, and its identification is based on specific criteria. Here’s a detailed breakdown of these criteria:

  1. Prior Trend: The pattern must form during an uptrend. It’s essential that the market shows a clear bullish momentum prior to the formation of this pattern. This is because the Dark Cloud Cover is a reversal pattern, indicating a potential shift from bullish to bearish sentiment.
  2. First Candlestick: The first candlestick should be a large bullish (upward) candle. This candle reflects the ongoing bullish sentiment in the market. Its size is important as it represents the strength of the current bullish trend.
  3. Second Candlestick: The second candlestick is bearish (downward). It should open above the high of the first candle, indicating a continuation of the bullish sentiment initially. However, as trading continues, it reverses and closes below the midpoint of the body of the first candle. This shift is crucial as it signifies that bears have taken control and reversed much of the bullish gains.
  4. Closing Price: The second candle’s closing is a critical aspect. It must close well into the body of the first candle, but not below it. Ideally, it should close below the midpoint of the first candle’s body. The deeper the second candle penetrates the first candle’s body, the more significant the reversal signal.

Code For Detecting Dark Cloud Cover

//@version=5
indicator("Dark Cloud Cover", overlay=true)

C_DownTrend = true
C_UpTrend = true
var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = input.string(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"])

if trendRule == trendRule1
	priceAvg = ta.sma(close, 50)
	C_DownTrend := close < priceAvg
	C_UpTrend := close > priceAvg

if trendRule == trendRule2
	sma200 = ta.sma(close, 200)
	sma50 = ta.sma(close, 50)
	C_DownTrend := close < sma50 and sma50 < sma200
	C_UpTrend := close > sma50 and sma50 > sma200
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_DarkCloudCoverBearishNumberOfCandles = 2
C_DarkCloudCoverBearish = false
if (C_UpTrend[1] and C_WhiteBody[1] and C_LongBody[1]) and (C_BlackBody and open >= high[1] and  close < C_BodyMiddle[1] and close > open[1])
	C_DarkCloudCoverBearish := true
alertcondition(C_DarkCloudCoverBearish, title = "New pattern detected", message = "New Dark Cloud Cover – Bearish pattern detected")
if C_DarkCloudCoverBearish
    var ttBearishDarkCloudCover = "Dark Cloud Cover\nDark Cloud Cover is a two-candle bearish reversal candlestick pattern found in an uptrend. The first candle is green and has a larger than average body. The second candle is red and opens above the high of the prior candle, creating a gap, and then closes below the midpoint of the first candle. The pattern shows a possible shift in the momentum from the upside to the downside, indicating that a reversal might happen soon."
    label.new(bar_index, patternLabelPosHigh, text="Dark Cloud Cover", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishDarkCloudCover)
bgcolor(ta.highest(C_DarkCloudCoverBearish?1:0, C_DarkCloudCoverBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_DarkCloudCoverBearishNumberOfCandles-1))

Output

Output

Overview of the script 

1. Script Initialization

//@version=5
indicator("Dark Cloud Cover", overlay=true)
  • Declares the version of Pine Script used (version=5).
  • Sets up an indicator titled “Dark Cloud Cover” that overlays on the main chart.

2. Trend Determination Variables

C_DownTrend = true
C_UpTrend = true
var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = input.string(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"])
  • Defines variables to detect the market trend.
  • trendRule allows users to choose between different trend detection methods: a single 50-period SMA, a combination of 50 and 200-period SMAs, or no trend detection.

3. Trend Detection Logic

if trendRule == trendRule1
    priceAvg = ta.sma(close, 50)
    C_DownTrend := close < priceAvg
    C_UpTrend := close > priceAvg
if trendRule == trendRule2
    sma200 = ta.sma(close, 200)
    sma50 = ta.sma(close, 50)
    C_DownTrend := close < sma50 and sma50 < sma200
    C_UpTrend := close > sma50 and sma50 > sma200
  • Applies the selected trend detection method.
  • For trendRule1, it uses a 50-period SMA to define uptrends and downtrends.
  • For trendRule2, it uses both 50-period and 200-period SMAs for a more complex trend determination.

4. Candlestick Characteristics

C_Len = 14 // ta.ema depth for bodyAvg
C_ShadowPercent = 5.0 // size of shadows
...
C_Doji = C_IsDojiBody and C_ShadowEquals
  • Defines various parameters and calculations to analyze candlestick characteristics, like body length, shadows, and whether a candle is a Doji.
  • These characteristics help in accurately identifying the Dark Cloud Cover pattern.

5. Dark Cloud Cover Pattern Identification

label_color_bearish = input(color.red, "Label Color Bearish")
C_DarkCloudCoverBearishNumberOfCandles = 2
C_DarkCloudCoverBearish = false
if (C_UpTrend[1] and C_WhiteBody[1] and C_LongBody[1]) and (C_BlackBody and open >= high[1] and close < C_BodyMiddle[1] and close > open[1])
    C_DarkCloudCoverBearish := true
  • Sets up conditions to identify the Dark Cloud Cover pattern.
  • Checks if the current trend is upward, followed by a long white (bullish) candle, and then a black (bearish) candle that opens higher than the previous high and closes below the midpoint of the first candle’s body.

6. Pattern Alert and Visualization

alertcondition(C_DarkCloudCoverBearish, title = "New pattern detected", message = "New Dark Cloud Cover – Bearish pattern detected")
if C_DarkCloudCoverBearish
    var ttBearishDarkCloudCover = "Dark Cloud Cover\nDark Cloud Cover is a two-candle bearish reversal candlestick pattern found in an uptrend. ..."
    label.new(bar_index, patternLabelPosHigh, text="Dark Cloud Cover", style=label.style_label_down, color = label_color_bearish, textcolor=color.white, tooltip = ttBearishDarkCloudCover)
bgcolor(ta.highest(C_DarkCloudCoverBearish?1:0, C_DarkCloudCoverBearishNumberOfCandles)!=0 ? color.new(color.red, 90) : na, offset=-(C_DarkCloudCoverBearishNumberOfCandles-1))
  • Creates an alert condition for when the Dark Cloud Cover pattern is identified.
  • Adds a label on the chart and changes the background color for easy visualization of the pattern.

Frequently Asked Questions

What does this Pine Script do?

It identifies the Dark Cloud Cover candlestick pattern on TradingView charts, signaling potential bearish reversals.

How does the script determine market trends?

The script uses either a 50-period SMA or a combination of 50 and 200-period SMAs to ascertain the market trend.

Can I modify the script for my trading needs?

Yes, the script’s parameters, like moving average lengths and candlestick criteria, are adjustable.

What conditions does the script use to identify the Dark Cloud Cover pattern?

It looks for a long bullish candle followed by a bearish candle that opens above the bullish candle’s high and closes below its midpoint in an uptrend.

Does the script provide alerts for pattern detection?

Yes, it generates alerts when the Dark Cloud Cover pattern is identified.

Conclusion

This script automates the detection of the Dark Cloud Cover candlestick pattern, a notable indicator of potential bearish reversals in a prevailing uptrend. By leveraging moving averages for trend analysis and specific criteria for pattern recognition, this script offers a convenient and efficient way to identify key market shifts.

Leave a Comment