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:
- Identifying potential strong bullish trend reversals, especially after a downtrend.
- Confirming the strength and continuation of an existing uptrend.
- Generating high-conviction entry signals for long positions.
Understanding the Three White Soldiers Candlestick Pattern
A Three White Soldiers pattern consists of three specific, consecutive bullish candles:
- First Candle (Bullish): A long bullish (green) candle, ideally closing near its high, indicating initial buying strength.
- 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.
- 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.
- Three Consecutive Bullish Candles: All three must be green.
- Long Bodies: Each candle should have a significant body, showing strong buying pressure.
- Higher Closes: Each candle's close must be higher than the previous candle's close.
- Open within Previous Body: The open of the second candle should be within the real body of the first; the open of the third should be within the real body of the second.
- Small/No Lower Shadows: Ideally, little to no lower shadow on each candle, indicating buying pressure throughout the period.
- Context: Most significant when appearing after a clear downtrend or during a pullback in an uptrend.
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:
- Context is King: This pattern is most powerful when it appears after a clear downtrend (signaling a reversal) or during a minor pullback within an established uptrend (signaling continuation). Avoid it in choppy or ranging markets.
- Volume Confirmation: Look for increasing or consistently high volume accompanying the three bullish candles. Strong volume adds conviction to the buying pressure.
- Candle Sizes: While all three should be "long," watch for diminishing candle sizes, which could indicate weakening momentum. Ideally, they maintain or increase in size slightly.
- Small Shadows: Minimal lower shadows indicate that buyers held control throughout the session, with little rejection of higher prices.
- Support Levels: When the pattern forms at a significant support level (e.g., a previous low, moving average, Fibonacci retracement), its reliability as a reversal signal increases.
- Timeframe: Signals on higher timeframes (e.g., daily, weekly) generally carry more weight and are more reliable for sustained moves than those on lower timeframes.
Common Three White Soldiers Pattern Pitfalls to Avoid
- Ignoring Body Size: If the bodies are too small, they don't indicate strong buying pressure. Ensure they are substantial relative to the average candle size.
- Overlapping Bodies: If the second or third candle's open is below the previous candle's close (i.e., a gap up), it's a stronger signal, but the pattern allows for opens *within* the previous body. However, if the open is below the previous candle's low, it's not a Three White Soldiers.
- Large Lower Shadows: Significant lower shadows on any of the three candles can indicate underlying selling pressure, weakening the bullish signal.
- Lack of Higher Closes: If any of the candles fail to close higher than the previous one, the bullish momentum is broken, and it's not a valid pattern.
- Trading Against the Trend: Using this pattern as a reversal signal when the broader trend is strongly bearish can lead to false signals. Always confirm the context.
- Over-reliance: Relying solely on this pattern without confirmation from other indicators or broader market analysis can lead to whipsaws or missed opportunities.
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