Why the Piercing Line Pattern Matters in Pine Script
The Piercing Line candlestick pattern is a two-candle bullish reversal pattern that typically forms after a downtrend. It signals a potential bottom and a strong shift in momentum from sellers to buyers. This pattern indicates that despite initial selling pressure, buyers stepped in decisively, pushing prices significantly higher to "pierce" deep into the body of the previous bearish candle. This makes Piercing Line patterns invaluable for:
- Identifying potential bullish trend reversals at key support levels.
- Signaling a potential exhaustion of selling pressure.
- Generating entry signals for long positions, often with good risk-reward.
Understanding the Piercing Line Candlestick Pattern
A Piercing Line pattern consists of two specific candles:
- First Candle (Bearish): A long bearish (red) candle, indicating strong selling pressure and a continuation of the downtrend.
- Second Candle (Bullish): A long bullish (green) candle that opens below the low of the first bearish candle (a significant gap down) and then closes above the midpoint of the first bearish candle's body, but *below* its open.
The pattern demonstrates an initial bearish momentum followed by a strong bullish rejection of lower prices, "piercing" the previous bearish sentiment.
Piercing Line Pattern
A long red candle, followed by a green candle that gaps down, but then rallies to close above the midpoint of the red candle's body.
- Candle 1: Long bearish candle.
- Candle 2: Long bullish candle that opens below the low of Candle 1.
- Candle 2's Close: Must close above the midpoint of Candle 1's real body, but below its open.
- Context: Most significant when appearing at the bottom of a clear downtrend.
Basic Piercing Line Pattern Detection in Pine Script
Here's how to create a basic indicator to detect Piercing Line patterns in Pine Script v5:
//@version=5
indicator("Piercing Line Pattern Detector", overlay=true)
// Candle 1 (previous bar) - Long Bearish
isC1Bearish = close[1] < open[1]
// The length of the first candle's body should be significant (e.g., > 0.5 ATR)
isC1Long = (open[1] - close[1]) > ta.atr(14)[1] * 0.5
// Candle 2 (current bar) - Long Bullish with Specific Open/Close conditions
isC2Bullish = close > open
// The length of the second candle's body should also be significant
isC2Long = (close - open) > ta.atr(14) * 0.5
// Condition 1: Second candle opens below the low of the first candle
opensBelowPrevLow = open < low[1]
// Condition 2: Second candle closes above the midpoint of the first candle's body
midpointPrevBody = open[1] - ((open[1] - close[1]) / 2) // Calculate midpoint of previous bearish body
closesAboveMidpoint = close > midpointPrevBody
// Condition 3: Second candle closes below the open of the first candle
closesBelowPrevOpen = close < open[1]
// Combine all criteria for Piercing Line
isPiercingLine = isC1Bearish and isC1Long and isC2Bullish and isC2Long and opensBelowPrevLow and closesAboveMidpoint and closesBelowPrevOpen
// Plot signal on the chart
plotshape(isPiercingLine, title="Piercing Line", location=location.belowbar, color=color.new(color.fuchsia, 0), style=shape.triangleup, size=size.normal)
// Alert condition (optional)
alertcondition(isPiercingLine, title="Piercing Line Detected", message="Piercing Line Candlestick Pattern Detected!")
Advanced Piercing Line Strategies
While basic detection is useful, combining Piercing Line patterns with other indicators and market context provides stronger, more reliable signals for potential bullish reversals.
1. Piercing Line with Downtrend Confirmation (Using Moving Average)
//@version=5
strategy("Piercing Line 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 downtrend detection
// Piercing Line Pattern Detection (from basic example)
isC1Bearish = close[1] < open[1]
isC1Long = (open[1] - close[1]) > ta.atr(14)[1] * 0.5
isC2Bullish = close > open
isC2Long = (close - open) > ta.atr(14) * 0.5
opensBelowPrevLow = open < low[1]
midpointPrevBody = open[1] - ((open[1] - close[1]) / 2)
closesAboveMidpoint = close > midpointPrevBody
closesBelowPrevOpen = close < open[1]
isPiercingLine = isC1Bearish and isC1Long and isC2Bullish and isC2Long and opensBelowPrevLow and closesAboveMidpoint and closesBelowPrevOpen
// Trend Confirmation: Price should be below the MA (downtrend)
// AND the MA itself should be sloping downwards (optional, but stronger)
isDowntrend = close < ma and ma < ma[1]
// Strategy Logic with Trend Confirmation
longSignal = isPiercingLine and isDowntrend
if (longSignal)
strategy.entry("Long", strategy.long)
// Plot MA
plot(ma, "Trend MA", color.blue)
// Plot confirmed signals
plotshape(longSignal, title="Confirmed Piercing Line", location=location.belowbar, color=color.new(color.navy, 0), style=shape.arrowup, size=size.normal)
2. Piercing Line with Volume Confirmation
//@version=5
indicator("Piercing Line with Volume Confirmation", overlay=true)
// Piercing Line Pattern Detection (from basic example)
isC1Bearish = close[1] < open[1]
isC1Long = (open[1] - close[1]) > ta.atr(14)[1] * 0.5
isC2Bullish = close > open
isC2Long = (close - open) > ta.atr(14) * 0.5
opensBelowPrevLow = open < low[1]
midpointPrevBody = open[1] - ((open[1] - close[1]) / 2)
closesAboveMidpoint = close > midpointPrevBody
closesBelowPrevOpen = close < open[1]
isPiercingLine = isC1Bearish and isC1Long and isC2Bullish and isC2Long and opensBelowPrevLow and closesAboveMidpoint and closesBelowPrevOpen
// Volume Confirmation:
// Volume on the second bullish 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
confirmedPiercingLine = isPiercingLine and isVolumeConfirmed
// Plot confirmed signals
barcolor(confirmedPiercingLine ? color.new(color.aqua, 60) : na)
plotshape(confirmedPiercingLine, title="Piercing Line (Vol Confirmed)", location=location.belowbar, color=color.new(color.green, 0), style=shape.labelup, size=size.small, text="PL 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. Piercing Line with RSI Confirmation
//@version=5
indicator("Piercing Line 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)
// Piercing Line Pattern Detection
isC1Bearish = close[1] < open[1]
isC1Long = (open[1] - close[1]) > ta.atr(14)[1] * 0.5
isC2Bullish = close > open
isC2Long = (close - open) > ta.atr(14) * 0.5
opensBelowPrevLow = open < low[1]
midpointPrevBody = open[1] - ((open[1] - close[1]) / 2)
closesAboveMidpoint = close > midpointPrevBody
closesBelowPrevOpen = close < open[1]
isPiercingLine = isC1Bearish and isC1Long and isC2Bullish and isC2Long and opensBelowPrevLow and closesAboveMidpoint and closesBelowPrevOpen
// RSI Confirmation: RSI should be in oversold territory or rising from it
rsiConfirmation = rsiValue <= oversold or (rsiValue[1] <= oversold and rsiValue > rsiValue[1])
// Combined signal
signalPiercingLine = isPiercingLine and rsiConfirmation
// Plot signals
plotshape(signalPiercingLine, title="Piercing Line (RSI Confirmed)", location=location.belowbar, color=color.new(color.lime, 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 Piercing Line Pattern Performance
To maximize the effectiveness of Piercing Line patterns in your Pine Script strategies:
- Confirm Downtrend: The Piercing Line is a bullish reversal pattern, so it's most reliable when it appears after a clear downtrend. Avoid trading it in an uptrend or sideways market.
- Volume Confirmation: Look for higher volume on the second bullish candle compared to the first, as it indicates strong buying interest and adds conviction to the reversal signal.
- Support Levels: Piercing Line patterns that form at significant support levels (e.g., previous lows, strong moving averages, Fibonacci retracement levels) tend to be more powerful and reliable.
- The "Piercing" Depth: The deeper the second candle penetrates the body of the first (ideally well above the 50% mark), the stronger the signal.
- Timeframe: While visible on all timeframes, signals on higher timeframes (e.g., daily, weekly) generally carry more weight and are considered more reliable for sustained reversals.
Common Piercing Line Pattern Pitfalls to Avoid
- Ignoring Trend Context: A Piercing Line is a reversal pattern; if it appears in an uptrend or ranging market, its predictive power is significantly diminished.
- Insufficient Penetration: If the second bullish candle fails to close above the midpoint of the first bearish candle's body, the pattern is weak or invalid.
- Lack of Gap Down: While sometimes less strict in certain markets, a clear gap down at the open of the second candle adds significant strength to the pattern.
- Small Candles: Patterns formed by very small first or second candles might not carry enough conviction. Both should ideally have substantial bodies.
- Over-reliance: Using the Piercing Line pattern in isolation without confirmation from other indicators, support levels, or broader market analysis can lead to false signals.
Conclusion
The Piercing Line candlestick pattern is a robust and visually clear signal for bullish reversals. By understanding its precise two-candle formation, its contextual importance within a downtrend, and integrating it with other technical confirmations, you can leverage it effectively in your trading. Implementing Piercing Line 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