Pine Script: Three White Soldiers Candlestick Pattern

Unlock powerful bullish trend reversal and continuation signals with this comprehensive guide to detecting and strategizing with Three White Soldiers patterns in TradingView's Pine Script.

Subscribe now @ $99/month

Why the Three White Soldiers Pattern Matters in Pine Script

The Three White Soldiers candlestick pattern is a strong three-candle bullish reversal or continuation pattern. It indicates a clear shift in market sentiment from selling to strong buying pressure. This pattern is characterized by three consecutive long bullish (green) candles that open within the body of the previous candle and close higher than the previous candle's close, ideally with small or no lower shadows. This demonstrates consistent bullish strength and makes Three White Soldiers patterns invaluable for:

Understanding the Three White Soldiers Candlestick Pattern

A Three White Soldiers pattern consists of three specific, consecutive bullish candles:

  1. First Candle (Bullish): A long bullish (green) candle, ideally closing near its high, indicating initial buying strength.
  2. Second Candle (Bullish): A long bullish (green) candle that opens within the body of the first candle and closes higher than the first candle's close, ideally with little to no lower shadow.
  3. Third Candle (Bullish): Another long bullish (green) candle that opens within the body of the second candle and closes higher than the second candle's close, also ideally with little to no lower shadow.

This sequence demonstrates a sustained and powerful surge in buying activity, overcoming previous selling pressure.

Three White Soldiers Pattern

Three consecutive long green candles, each opening within the previous body and closing higher, with small lower shadows.

Key Characteristics:

Basic Three White Soldiers Pattern Detection in Pine Script

Here's how to create a basic indicator to detect Three White Soldiers patterns in Pine Script v5:

//@version=5
indicator("Three White Soldiers Detector", overlay=true)

// User input for minimum body size (as a percentage of ATR)
minBodySize = input.float(0.4, title="Min Body Size (ATR multiple)", minval=0.1, maxval=2.0)
// User input for maximum lower shadow size (as a percentage of body)
maxLowerShadowRatio = input.float(0.2, title="Max Lower Shadow Ratio (of Body)", minval=0.01, maxval=0.5)

// Helper function to check if a candle is a strong bullish candle with small lower shadow
isStrongBullish(idx) =>
    body = close[idx] - open[idx]
    lowerShadow = math.min(open[idx], close[idx]) - low[idx]
    
    body > ta.atr(14)[idx] * minBodySize and // Body is significant
    close[idx] > open[idx] and // It's a bullish candle
    lowerShadow < body * maxLowerShadowRatio // Small lower shadow

// Check individual candle properties
isC1StrongBullish = isStrongBullish(2)
isC2StrongBullish = isStrongBullish(1)
isC3StrongBullish = isStrongBullish(0) // Current bar

// Check opening conditions
isC2OpensInC1Body = open[1] > open[2] and open[1] < close[2]
isC3OpensInC2Body = open[0] > open[1] and open[0] < close[1] // open[0] is current `open`

// Check higher closes
isC2ClosesHigherThanC1 = close[1] > close[2]
isC3ClosesHigherThanC2 = close[0] > close[1] // close[0] is current `close`

// Combine all criteria for Three White Soldiers
isThreeWhiteSoldiers = isC1StrongBullish and isC2StrongBullish and isC3StrongBullish and \
                       isC2OpensInC1Body and isC3OpensInC2Body and \
                       isC2ClosesHigherThanC1 and isC3ClosesHigherThanC2

// Plot signal on the chart
plotshape(isThreeWhiteSoldiers, title="Three White Soldiers", location=location.belowbar, color=color.new(color.lime, 0), style=shape.triangleup, size=size.normal)

// Alert condition (optional)
alertcondition(isThreeWhiteSoldiers, title="Three White Soldiers Detected", message="Three White Soldiers Pattern Detected!")

Advanced Three White Soldiers Strategies

Combining Three White Soldiers patterns with other indicators and market context provides stronger, more reliable signals for potential bullish moves.

1. Three White Soldiers with Downtrend Reversal Confirmation (Using Moving Average)

//@version=5
strategy("Three White Soldiers (Trend Reversal)", overlay=true)

// Input for Moving Average length (for trend detection)
maLength = input(50, "MA Length (for trend)")
ma = ta.ema(close, maLength) 

// Three White Soldiers Pattern Detection (from basic example - simplified for brevity)
isC1StrongBullish = close[2] > open[2] and (close[2] - open[2]) > ta.atr(14)[2] * 0.4 
isC2StrongBullish = close[1] > open[1] and (close[1] - open[1]) > ta.atr(14)[1] * 0.4
isC3StrongBullish = close > open and (close - open) > ta.atr(14) * 0.4

isC2OpensInC1Body = open[1] > open[2] and open[1] < close[2]
isC3OpensInC2Body = open > open[1] and open < close[1]

isC2ClosesHigherThanC1 = close[1] > close[2]
isC3ClosesHigherThanC2 = close > close[1]

// Additional check for small lower shadows for robustness
isSmallLowerShadowC1 = (math.min(open[2], close[2]) - low[2]) < (math.abs(open[2] - close[2]) * 0.2)
isSmallLowerShadowC2 = (math.min(open[1], close[1]) - low[1]) < (math.abs(open[1] - close[1]) * 0.2)
isSmallLowerShadowC3 = (math.min(open, close) - low) < (math.abs(open - close) * 0.2)

isThreeWhiteSoldiers = isC1StrongBullish and isC2StrongBullish and isC3StrongBullish and \
                       isC2OpensInC1Body and isC3OpensInC2Body and \
                       isC2ClosesHigherThanC1 and isC3ClosesHigherThanC2 and \
                       isSmallLowerShadowC1 and isSmallLowerShadowC2 and isSmallLowerShadowC3

// Trend Confirmation: Pattern appears after a clear downtrend (price below MA)
isDowntrend = close[3] < ma[3] and close[2] < ma[2] and close[1] < ma[1] // Check prior bars for downtrend context

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

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

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

2. Three White Soldiers with Volume Confirmation

//@version=5
indicator("Three White Soldiers with Volume Confirmation", overlay=true)

// Three White Soldiers Pattern Detection (from basic example - simplified)
isC1StrongBullish = close[2] > open[2] and (close[2] - open[2]) > ta.atr(14)[2] * 0.4 
isC2StrongBullish = close[1] > open[1] and (close[1] - open[1]) > ta.atr(14)[1] * 0.4
isC3StrongBullish = close > open and (close - open) > ta.atr(14) * 0.4

isC2OpensInC1Body = open[1] > open[2] and open[1] < close[2]
isC3OpensInC2Body = open > open[1] and open < close[1]

isC2ClosesHigherThanC1 = close[1] > close[2]
isC3ClosesHigherThanC2 = close > close[1]

isThreeWhiteSoldiers = isC1StrongBullish and isC2StrongBullish and isC3StrongBullish and \
                       isC2OpensInC1Body and isC3OpensInC2Body and \
                       isC2ClosesHigherThanC1 and isC3ClosesHigherThanC2

// Volume Confirmation:
// Each bullish candle should have equal or increasing volume,
// and the third candle's volume should be significantly higher than average volume.
avgVolume = ta.sma(volume, 20) // 20-period Simple Moving Average of Volume
isVolumeConsistent = volume[2] <= volume[1] and volume[1] <= volume // Volume equal or increasing
isVolumeConfirmed = volume > avgVolume * 1.2 // Current volume is 1.2x average

// Combined signal
confirmedThreeWhiteSoldiers = isThreeWhiteSoldiers and isVolumeConsistent and isVolumeConfirmed

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

plotshape(confirmedThreeWhiteSoldiers, title="3 White Soldiers (Vol Confirmed)", location=location.belowbar, color=color.new(color.green, 0), style=shape.labelup, size=size.small, text="3WS 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. Three White Soldiers with RSI Confirmation

//@version=5
indicator("Three White Soldiers 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)

// Three White Soldiers Pattern Detection (simplified)
isC1StrongBullish = close[2] > open[2] and (close[2] - open[2]) > ta.atr(14)[2] * 0.4 
isC2StrongBullish = close[1] > open[1] and (close[1] - open[1]) > ta.atr(14)[1] * 0.4
isC3StrongBullish = close > open and (close - open) > ta.atr(14) * 0.4

isC2OpensInC1Body = open[1] > open[2] and open[1] < close[2]
isC3OpensInC2Body = open > open[1] and open < close[1]

isC2ClosesHigherThanC1 = close[1] > close[2]
isC3ClosesHigherThanC2 = close > close[1]

isThreeWhiteSoldiers = isC1StrongBullish and isC2StrongBullish and isC3StrongBullish and \
                       isC2OpensInC1Body and isC3OpensInC2Body and \
                       isC2ClosesHigherThanC1 and isC3ClosesHigherThanC2

// RSI Confirmation: RSI rising from oversold territory or showing bullish divergence
rsiConfirmation = rsiValue > rsiValue[1] and rsiValue[1] > rsiValue[2] and rsiValue[2] <= oversold // RSI rising from oversold
// Or simpler: rsiValue >= oversold and rsiValue > rsiValue[1]

// Combined signal
signalThreeWhiteSoldiers = isThreeWhiteSoldiers and rsiConfirmation

// Plot signals
plotshape(signalThreeWhiteSoldiers, title="3 White Soldiers (RSI Confirmed)", location=location.belowbar, color=color.new(color.blue, 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 Three White Soldiers Pattern Performance

To maximize the effectiveness of Three White Soldiers patterns in your Pine Script strategies:

Common Three White Soldiers Pattern Pitfalls to Avoid

Warning: Not every sequence of three green candles constitutes a valid "Three White Soldiers" pattern. Strict adherence to criteria and contextual analysis are essential.

Conclusion

The Three White Soldiers candlestick pattern is a powerful and visually clear signal for robust bullish price action. By understanding its precise three-candle formation, its contextual importance (especially after a downtrend), and integrating it with other technical confirmations like volume and momentum oscillators, you can leverage it effectively in your trading. Implementing Three White Soldiers 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.

Enhance Your Trading

Get a high-performance Pine Script analysis tool for actionable market insights, designed for traders on the move.

This strategy runs in live mode on TradingView, helping you identify potential opportunities.

Subscribe now @ $99/month