Why the Hanging Man Pattern Matters in Pine Script
The Hanging Man candlestick pattern is a single-candle bearish reversal pattern that typically forms after an uptrend. It signals a potential top and a shift in momentum from buyers to sellers. The Hanging Man's unique shape indicates that despite initial buying pressure during the trading period, sellers stepped in strongly to push prices back down, often near the opening price. This shows that the market struggles to maintain higher prices, making Hanging Man patterns invaluable for:
- Identifying potential bearish trend reversals.
- Signaling a rejection of higher prices (resistance).
- Generating entry signals in short strategies.
Understanding the Hanging Man Candlestick Pattern
A Hanging Man candle has a small real body (the difference between open and close) and a long lower shadow (wick) that is typically at least twice the length of the real body. It has little or no upper shadow. The color of the body (bullish or bearish) is less important than its shape and location after an uptrend. It looks identical to a Hammer, but its significance is entirely dependent on its position within an uptrend.
Hanging Man (Bullish Body)
Open below close. Even with a green body, the long lower wick shows selling pressure.
Hanging Man (Bearish Body)
Open above close. A red body reinforces the bearish sentiment.
- Small Real Body: The distance between the open and close is small.
- Long Lower Shadow: The lower wick is at least twice the length of the real body.
- Little or No Upper Shadow: Ideally, there should be no upper wick, or it should be very short.
- Context is Critical: Most significant when appearing at the top of a clear uptrend.
Basic Hanging Man Pattern Detection in Pine Script
Here's how to create a basic indicator to detect Hanging Man patterns in Pine Script v5:
//@version=5
indicator("Hanging Man Pattern Detector", overlay=true)
// Calculate candle body and wick lengths
realBody = math.abs(close - open)
upperShadow = high - math.max(open, close)
lowerShadow = math.min(open, close) - low // Corrected calculation for lower shadow length
// Define Hanging Man criteria
// 1. Small real body (body is at most 30% of total candle range)
isSmallBody = realBody <= (high - low) * 0.3
// 2. Long lower shadow (at least 2x the body size)
isLongLowerShadow = lowerShadow >= realBody * 2
// 3. Little to no upper shadow (upper shadow is at most 50% of body, or less than 10% of total range)
isSmallUpperShadow = upperShadow <= realBody * 0.5
// Alternative for upper shadow: upperShadow < (high - low) * 0.1
// Combine criteria for Hanging Man
isHangingMan = isSmallBody and isLongLowerShadow and isSmallUpperShadow
// Plot signal on the chart (above the bar for bearish reversal)
plotshape(isHangingMan, title="Hanging Man", location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, size=size.small)
// Alert condition (optional)
alertcondition(isHangingMan, title="Hanging Man Detected", message="Hanging Man Candlestick Pattern Detected!")
Advanced Hanging Man Strategies
While basic detection is useful, combining Hanging Man patterns with other indicators and market context provides stronger, more reliable signals for potential reversals.
1. Hanging Man with Uptrend Confirmation (Using Moving Average)
//@version=5
strategy("Hanging Man 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
// Hanging Man Pattern Detection (from basic example)
realBody = math.abs(close - open)
upperShadow = high - math.max(open, close)
lowerShadow = math.min(open, close) - low
isSmallBody = realBody <= (high - low) * 0.3
isLongLowerShadow = lowerShadow >= realBody * 2
isSmallUpperShadow = upperShadow <= realBody * 0.5
isHangingMan = isSmallBody and isLongLowerShadow and isSmallUpperShadow
// 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 = isHangingMan and isUptrend
if (shortSignal)
strategy.entry("Short", strategy.short)
// Plot MA
plot(ma, "Trend MA", color.blue)
// Plot confirmed signals
plotshape(shortSignal, title="Confirmed Hanging Man", location=location.abovebar, color=color.new(color.maroon, 0), style=shape.arrowdown, size=size.normal)
2. Hanging Man with Volume Confirmation
//@version=5
indicator("Hanging Man with Volume Confirmation", overlay=true)
// Hanging Man Pattern Detection (from basic example)
realBody = math.abs(close - open)
upperShadow = high - math.max(open, close)
lowerShadow = math.min(open, close) - low
isSmallBody = realBody <= (high - low) * 0.3
isLongLowerShadow = lowerShadow >= realBody * 2
isSmallUpperShadow = upperShadow <= realBody * 0.5
isHangingMan = isSmallBody and isLongLowerShadow and isSmallUpperShadow
// Volume Confirmation:
// Hanging Man candle's volume should be significantly 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
confirmedHangingMan = isHangingMan and isVolumeConfirmed
// Plot confirmed signals
barcolor(confirmedHangingMan ? color.new(color.purple, 60) : na)
plotshape(confirmedHangingMan, title="Hanging Man (Vol Confirmed)", location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, size=size.small, text="Bear 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. Hanging Man with RSI Confirmation
//@version=5
indicator("Hanging Man 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)
// Hanging Man Pattern Detection
realBody = math.abs(close - open)
upperShadow = high - math.max(open, close)
lowerShadow = math.min(open, close) - low
isSmallBody = realBody <= (high - low) * 0.3
isLongLowerShadow = lowerShadow >= realBody * 2
isSmallUpperShadow = upperShadow <= realBody * 0.5
isHangingMan = isSmallBody and isLongLowerShadow and isSmallUpperShadow
// 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
signalHangingMan = isHangingMan and rsiConfirmation
// Plot signals
plotshape(signalHangingMan, title="Hanging Man (RSI Confirmed)", location=location.abovebar, color=color.new(color.teal, 0), style=shape.arrowdown, size=size.normal)
// Plot RSI in a separate pane
plot(rsiValue, "RSI", color.blue, linewidth=2, display=display.pane)
hline(overbought, "Overbought", color.red)
Optimizing Hanging Man Pattern Performance
To maximize the effectiveness of Hanging Man patterns in your Pine Script strategies:
- Confirm Uptrend: The Hanging Man is a bearish reversal pattern, so it's most reliable when it appears after a clear uptrend. Trading a Hanging Man in a downtrend or sideways market is usually less effective.
- Volume Confirmation: A Hanging Man candle formed with higher than average volume indicates stronger conviction from sellers and increases the reliability of the signal.
- Resistance Levels: Hanging Man patterns that form at significant resistance levels (e.g., previous highs, moving averages, Fibonacci levels) are more powerful.
- Subsequent Candle Confirmation: A strong bearish candle after the Hanging Man further confirms the reversal. Some traders wait for this confirmation before entering a short position.
- Timeframe: While visible on all timeframes, Hanging Man signals on higher timeframes (e.g., daily, weekly) generally carry more weight and are more reliable than those on lower timeframes.
Common Hanging Man Pattern Pitfalls to Avoid
- Ignoring Trend Context: A Hanging Man pattern is a *bearish reversal* signal. If it appears in a downtrend, it is NOT a Hanging Man and is actually a Hammer, indicating potential bullishness.
- Insufficient Lower Shadow: A lower shadow that is not at least twice the real body's length might not indicate strong enough rejection of higher prices.
- Large Real Body: If the real body is too large, it suggests less indecision and less of a "top-out" scenario.
- Lack of Confirmation: Relying solely on the Hanging Man pattern without other indicators (volume, resistance, follow-through candles) can lead to false signals.
- Trading in Choppy Markets: In ranging or sideways markets, Hanging Man patterns are less reliable as there's no clear trend to reverse.
Conclusion
The Hanging Man candlestick pattern is a strong and visually intuitive signal for bearish reversals. By understanding its precise characteristics and, more importantly, its contextual significance within an uptrend, you can leverage it effectively in your trading. Implementing Hanging Man detection in Pine Script allows you to automate signal generation, combine it with other technical indicators for higher probability trades, and refine your price action analysis to make more informed trading decisions on TradingView.