Pine Script: Dark Cloud Cover Candlestick Pattern

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

Posted: Expertise: Intermediate/Advanced

Why the Dark Cloud Cover Pattern Matters in Pine Script

The Dark Cloud Cover candlestick pattern is a two-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 despite initial buying pressure, sellers stepped in decisively, pushing prices significantly lower to "cover" deep into the body of the previous bullish candle. This makes Dark Cloud Cover patterns invaluable for:

Understanding the Dark Cloud Cover Candlestick Pattern

A Dark Cloud Cover pattern consists of two specific candles:

  1. First Candle (Bullish): A long bullish (green) candle, indicating strong buying pressure and a continuation of the uptrend.
  2. Second Candle (Bearish): A long bearish (red) candle that opens above the high of the first bullish candle (a significant gap up) and then closes below the midpoint of the first bullish candle's body, but *above* its low.

The pattern demonstrates an initial bullish momentum followed by a strong bearish rejection of higher prices, "covering" the previous bullish sentiment.

Dark Cloud Cover Pattern

Midpoint of previous candle

A long green candle, followed by a red candle that gaps up, but then falls to close below the midpoint of the green candle's body.

Key Characteristics:

Basic Dark Cloud Cover Pattern Detection in Pine Script

Here's how to create a basic indicator to detect Dark Cloud Cover patterns in Pine Script v5:

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

// Candle 1 (previous bar) - Long Bullish
isC1Bullish = close[1] > open[1]
// The length of the first candle's body should be significant (e.g., > 0.5 ATR)
isC1Long = (close[1] - open[1]) > ta.atr(14)[1] * 0.5

// Candle 2 (current bar) - Long Bearish with Specific Open/Close conditions
isC2Bearish = close < open
// The length of the second candle's body should also be significant
isC2Long = (open - close) > ta.atr(14) * 0.5

// Condition 1: Second candle opens above the high of the first candle
opensAbovePrevHigh = open > high[1]

// Condition 2: Second candle closes below the midpoint of the first candle's body
midpointPrevBody = close[1] - ((close[1] - open[1]) / 2) // Calculate midpoint of previous bullish body
closesBelowMidpoint = close < midpointPrevBody

// Condition 3: Second candle closes above the low of the first candle
closesAbovePrevLow = close > low[1]

// Combine all criteria for Dark Cloud Cover
isDarkCloudCover = isC1Bullish and isC1Long and isC2Bearish and isC2Long and opensAbovePrevHigh and closesBelowMidpoint and closesAbovePrevLow

// Plot signal on the chart
plotshape(isDarkCloudCover, title="Dark Cloud Cover", location=location.abovebar, color=color.new(color.maroon, 0), style=shape.triangledown, size=size.normal)

// Alert condition (optional)
alertcondition(isDarkCloudCover, title="Dark Cloud Cover Detected", message="Dark Cloud Cover Candlestick Pattern Detected!")

Advanced Dark Cloud Cover Strategies

Combining Dark Cloud Cover patterns with other indicators and market context provides stronger, more reliable signals for potential bearish reversals.

1. Dark Cloud Cover with Uptrend Confirmation (Using Moving Average)

//@version=5
strategy("Dark Cloud Cover 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

// Dark Cloud Cover Pattern Detection (from basic example)
isC1Bullish = close[1] > open[1]
isC1Long = (close[1] - open[1]) > ta.atr(14)[1] * 0.5

isC2Bearish = close < open
isC2Long = (open - close) > ta.atr(14) * 0.5

opensAbovePrevHigh = open > high[1]
midpointPrevBody = close[1] - ((close[1] - open[1]) / 2)
closesBelowMidpoint = close < midpointPrevBody
closesAbovePrevLow = close > low[1]

isDarkCloudCover = isC1Bullish and isC1Long and isC2Bearish and isC2Long and opensAbovePrevHigh and closesBelowMidpoint and closesAbovePrevLow

// 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 = isDarkCloudCover and isUptrend

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

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

2. Dark Cloud Cover with Volume Confirmation

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

// Dark Cloud Cover Pattern Detection (from basic example)
isC1Bullish = close[1] > open[1]
isC1Long = (close[1] - open[1]) > ta.atr(14)[1] * 0.5

isC2Bearish = close < open
isC2Long = (open - close) > ta.atr(14) * 0.5

opensAbovePrevHigh = open > high[1]
midpointPrevBody = close[1] - ((close[1] - open[1]) / 2)
closesBelowMidpoint = close < midpointPrevBody
closesAbovePrevLow = close > low[1]

isDarkCloudCover = isC1Bullish and isC1Long and isC2Bearish and isC2Long and opensAbovePrevHigh and closesBelowMidpoint and closesAbovePrevLow

// Volume Confirmation:
// Volume on the second 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
confirmedDarkCloudCover = isDarkCloudCover and isVolumeConfirmed

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

plotshape(confirmedDarkCloudCover, title="Dark Cloud Cover (Vol Confirmed)", location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, size=size.small, text="DCC 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. Dark Cloud Cover with RSI Confirmation

//@version=5
indicator("Dark Cloud Cover 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)

// Dark Cloud Cover Pattern Detection
isC1Bullish = close[1] > open[1]
isC1Long = (close[1] - open[1]) > ta.atr(14)[1] * 0.5

isC2Bearish = close < open
isC2Long = (open - close) > ta.atr(14) * 0.5

opensAbovePrevHigh = open > high[1]
midpointPrevBody = close[1] - ((close[1] - open[1]) / 2)
closesBelowMidpoint = close < midpointPrevBody
closesAbovePrevLow = close > low[1]

isDarkCloudCover = isC1Bullish and isC1Long and isC2Bearish and isC2Long and opensAbovePrevHigh and closesBelowMidpoint and closesAbovePrevLow

// 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
signalDarkCloudCover = isDarkCloudCover and rsiConfirmation

// Plot signals
plotshape(signalDarkCloudCover, title="Dark Cloud Cover (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.new(color.blue, 0), linewidth=2, display=display.pane)
hline(overbought, "Overbought", color.new(color.red, 0))
    

Optimizing Dark Cloud Cover Pattern Performance

To maximize the effectiveness of Dark Cloud Cover patterns in your Pine Script strategies:

Common Dark Cloud Cover Pattern Pitfalls to Avoid

Warning: Not every two-candle sequence that superficially resembles a Dark Cloud Cover is a valid pattern. Strict adherence to criteria and contextual analysis are essential.

Conclusion

The Dark Cloud Cover candlestick pattern is a robust and visually clear signal for bearish reversals. By understanding its precise two-candle formation, its contextual importance within an uptrend, and integrating it with other technical confirmations, you can leverage it effectively in your trading. Implementing Dark Cloud Cover 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.