Hammer Candlestick Pattern

The hammer is a bullish reversal candlestick pattern that forms after a decline. It shows that sellers pushed price sharply lower during the bar, but buyers stepped in and forced price back up before the close. That rejection of lower prices can signal that bearish momentum is weakening.

Like all candlestick patterns, the hammer works best in context. A hammer at support, after a pullback, or following a strong sell-off is far more meaningful than one that appears in the middle of sideways price action.

A quick taxonomy before we begin

These four patterns are closely related, and it helps to separate them clearly from the start:

This matters because traders often group these candles together too loosely.

A hammer and a hanging man have almost the same shape: a small body near the top of the candle's range, a long lower shadow, and little or no upper shadow. What changes their meaning is the context. After a decline, that lower-wick rejection can be bullish. After a rally, the same structure can act as a bearish warning.

An inverted hammer and a shooting star work the same way, but with the wick structure flipped. They have a long upper shadow instead of a long lower shadow. Again, the context determines whether the candle is interpreted as bullish or bearish.

That distinction is important because it stops us from mixing up shape with meaning. The candle structure matters, but where it appears matters more.

How to identify a hammer pattern

A hammer has a very specific structure:

The colour of the candle is less important than the shape. A bullish close can be slightly stronger, but the key message is the rejection of lower prices.

What the hammer tells traders

The hammer shows that sellers were in control at some point during the bar, but could not hold price near the lows.

Buyers absorbed the selling pressure and pushed price back up before the candle closed. That does not guarantee a reversal, but it can be an early sign that the down move is losing strength.

This pattern becomes more useful when it forms:

How traders use the hammer

Most traders do not treat the hammer as an automatic entry signal. Instead, they use it as a reversal candidate and look for confirmation.

A common process is:

Confirmation matters because many hammer-like candles appear in noisy conditions and fail immediately.

Hammer candlestick forming at support after a decline, showing rejection of lower prices
A hammer showing rejection of lower prices after a downward move into support.

Hammer pattern detector in Pine Script

The script below detects all four patterns from the hammer family:

A dropdown lets you choose which pattern to display on the chart.

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// Copyright (c) 2026 - BuildTradingStrategies.com / TradeXecution.com

//@version=6
indicator("Hammer Pattern Detector", overlay=true)

// -----------------------------------------------------------------------------
// User input
// -----------------------------------------------------------------------------
// Let the user choose exactly which candlestick pattern to scan for.
//
// Hammer          = lower-wick rejection candle after a decline
// Hanging Man     = lower-wick rejection candle after a rally
// Inverted Hammer = upper-wick rejection candle after a decline
// Shooting Star   = upper-wick rejection candle after a rally
patternType = input.string(
     defval  = "Hammer",
     title   = "Pattern Type",
     options = ["Hammer", "Hanging Man", "Inverted Hammer", "Shooting Star"]
)

// -----------------------------------------------------------------------------
// Candle measurements
// -----------------------------------------------------------------------------
// Real body size of the candle
bodySize = math.abs(close - open)

// Full candle range from high to low
rangeSize = high - low

// Lower wick / shadow size
lowerWick = math.min(open, close) - low

// Upper wick / shadow size
upperWick = high - math.max(open, close)

// -----------------------------------------------------------------------------
// Common body rule
// -----------------------------------------------------------------------------
// All four patterns usually have a relatively small real body compared to the
// total candle range.
smallBody = rangeSize > 0 and bodySize <= rangeSize * 0.35

// -----------------------------------------------------------------------------
// Lower-wick family
// -----------------------------------------------------------------------------
// These rules define the Hammer / Hanging Man family:
//
// - long lower wick
// - small upper wick
// - body positioned near the top of the candle range
//
// Same shape, different meaning depending on context.
longLowerWick = lowerWick >= bodySize * 2
smallUpperWick = upperWick <= bodySize
bodyNearTop = math.max(open, close) >= low + rangeSize * 0.6

// Base shape for Hammer / Hanging Man
lowerWickPattern = smallBody and longLowerWick and smallUpperWick and bodyNearTop

// -----------------------------------------------------------------------------
// Upper-wick family
// -----------------------------------------------------------------------------
// These rules define the Inverted Hammer / Shooting Star family:
//
// - long upper wick
// - small lower wick
// - body positioned near the bottom of the candle range
//
// Again, same shape, different meaning depending on context.
longUpperWick = upperWick >= bodySize * 2
smallLowerWick = lowerWick <= bodySize
bodyNearBottom = math.min(open, close) <= low + rangeSize * 0.4

// Base shape for Inverted Hammer / Shooting Star
upperWickPattern = smallBody and longUpperWick and smallLowerWick and bodyNearBottom

// -----------------------------------------------------------------------------
// Simple context filters
// -----------------------------------------------------------------------------
// We keep the same simple context logic used previously:
//
// afterDecline = price was moving down into the candle
// afterRally   = price was moving up into the candle
//
// This keeps the script easy to understand and lets the user test the concepts
// visually on a chart.
afterDecline = close[1] < close[2]
afterRally = close[1] > close[2]

// Only confirm the pattern once the bar has fully closed
confirmedBar = barstate.isconfirmed

// -----------------------------------------------------------------------------
// Final pattern conditions
// -----------------------------------------------------------------------------
// Hammer:
// Lower-wick rejection pattern after a decline
hammer = lowerWickPattern and afterDecline and confirmedBar

// Hanging Man:
// Same lower-wick shape, but after a rally
hangingMan = lowerWickPattern and afterRally and confirmedBar

// Inverted Hammer:
// Upper-wick rejection pattern after a decline
invertedHammer = upperWickPattern and afterDecline and confirmedBar

// Shooting Star:
// Same upper-wick shape, but after a rally
shootingStar = upperWickPattern and afterRally and confirmedBar

// -----------------------------------------------------------------------------
// Dropdown selection filters
// -----------------------------------------------------------------------------
// Only plot the pattern selected by the user in the combo box.
showHammer = patternType == "Hammer"
showHangingMan = patternType == "Hanging Man"
showInvertedHammer = patternType == "Inverted Hammer"
showShootingStar = patternType == "Shooting Star"

// -----------------------------------------------------------------------------
// Plot: Hammer
// -----------------------------------------------------------------------------
// Plot below the bar because this is a bullish reversal candidate.
plotshape(
     hammer and showHammer,
     title     = "Hammer",
     style     = shape.triangleup,
     location  = location.belowbar,
     text      = "H",
     size      = size.small
)

// -----------------------------------------------------------------------------
// Plot: Hanging Man
// -----------------------------------------------------------------------------
// Plot above the bar because this is a bearish warning / reversal candidate.
plotshape(
     hangingMan and showHangingMan,
     title     = "Hanging Man",
     style     = shape.triangledown,
     location  = location.abovebar,
     text      = "HM",
     size      = size.small
)

// -----------------------------------------------------------------------------
// Plot: Inverted Hammer
// -----------------------------------------------------------------------------
// Plot below the bar because this is generally treated as a bullish reversal
// candidate after a decline.
plotshape(
     invertedHammer and showInvertedHammer,
     title     = "Inverted Hammer",
     style     = shape.triangleup,
     location  = location.belowbar,
     text      = "IH",
     size      = size.small
)

// -----------------------------------------------------------------------------
// Plot: Shooting Star
// -----------------------------------------------------------------------------
// Plot above the bar because this is generally treated as a bearish reversal
// candidate after a rally.
plotshape(
     shootingStar and showShootingStar,
     title     = "Shooting Star",
     style     = shape.triangledown,
     location  = location.abovebar,
     text      = "SS",
     size      = size.small
)

This version is deliberately simple. It focuses on candle structure first, then applies a minimal context filter to separate the bullish hammer from the bearish hanging man.

Hammer / Hanging Man detector plotted on chart showing bullish and bearish signals
The same lower-wick candle structure can be bullish after a decline or bearish after a rally.

Why a strict version is often better

A basic detector can find the correct candle shape but still produce poor-quality signals.

That usually happens because the pattern appears in the wrong place, after too little directional movement, or in a market that is simply chopping sideways.

A stricter version helps by tightening the structure rules and being more selective about the pattern. In practice, that usually means:

That will normally reduce the number of signals, but it can improve the average quality.

Hammer Pattern Detector v2 in Pine Script

This version adds a strictness selector so traders can control how selective the detector is.

It also covers all four patterns: Hammer, Hanging Man, Inverted Hammer, and Shooting Star.

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// Copyright (c) 2026 - BuildTradingStrategies.com / TradeXecution.com

//@version=6
indicator("Hammer Pattern Detector", overlay=true)

// ============================================================================
// USER INPUTS
// ============================================================================

// Select which candle pattern to scan for.
patternType = input.string(
     defval  = "Hammer",
     title   = "Pattern Type",
     options = ["Hammer", "Hanging Man", "Inverted Hammer", "Shooting Star"]
)

// Select how selective the detector should be.
//
// Standard     = more signals, looser structure rules
// Strict       = fewer signals, tighter candle structure and clearer context
// Extra Strict = very selective, strongest structure rules and strongest context
strictness = input.string(
     defval  = "Standard",
     title   = "Strictness",
     options = ["Standard", "Strict", "Extra Strict"]
)

// ============================================================================
// CANDLE MEASUREMENTS
// ============================================================================

// Real body size
bodySize = math.abs(close - open)

// Full candle range
rangeSize = high - low

// Lower wick / shadow size
lowerWick = math.min(open, close) - low

// Upper wick / shadow size
upperWick = high - math.max(open, close)

// ============================================================================
// STRICTNESS SETTINGS
// ============================================================================
//
// We vary five things based on the chosen strictness:
//
// 1) How small the body must be relative to the full range
// 2) How long the dominant wick must be
// 3) How small the opposite wick must be
// 4) How near the body must sit to the top or bottom of the candle
// 5) How clear the directional move must be into the pattern
//
// Standard:
// - body <= 35% of range
// - dominant wick >= 2.0x body
// - opposite wick <= 1.0x body
// - body near top/bottom using 60% / 40%
// - 1-step context
//
// Strict:
// - body <= 30% of range
// - dominant wick >= 2.5x body
// - opposite wick <= 0.5x body
// - body near top/bottom using 65% / 35%
// - 2-step context
//
// Extra Strict:
// - body <= 25% of range
// - dominant wick >= 3.0x body
// - opposite wick <= 0.35x body
// - body near top/bottom using 70% / 30%
// - 3-step context
smallBodyThreshold =
     strictness == "Standard" ? 0.35 :
     strictness == "Strict" ? 0.30 : 0.25

dominantWickMultiplier =
     strictness == "Standard" ? 2.0 :
     strictness == "Strict" ? 2.5 : 3.0

oppositeWickMultiplier =
     strictness == "Standard" ? 1.0 :
     strictness == "Strict" ? 0.50 : 0.35

topThreshold =
     strictness == "Standard" ? 0.60 :
     strictness == "Strict" ? 0.65 : 0.70

bottomThreshold =
     strictness == "Standard" ? 0.40 :
     strictness == "Strict" ? 0.35 : 0.30

contextSteps =
     strictness == "Standard" ? 1 :
     strictness == "Strict" ? 2 : 3

// ============================================================================
// BODY RULE
// ============================================================================

// Require a relatively small real body compared to the full candle range.
smallBody = rangeSize > 0 and bodySize <= rangeSize * smallBodyThreshold

// ============================================================================
// LOWER-WICK FAMILY: HAMMER / HANGING MAN
// ============================================================================
//
// These patterns share the same broad geometry:
//
// - long lower wick
// - small upper wick
// - body near the top of the candle range
//
// Their interpretation changes based on context.
longLowerWick = lowerWick >= bodySize * dominantWickMultiplier
smallUpperWick = upperWick <= bodySize * oppositeWickMultiplier
bodyNearTop = math.max(open, close) >= low + rangeSize * topThreshold

lowerWickPattern = smallBody and longLowerWick and smallUpperWick and bodyNearTop

// ============================================================================
// UPPER-WICK FAMILY: INVERTED HAMMER / SHOOTING STAR
// ============================================================================
//
// These patterns share the opposite wick structure:
//
// - long upper wick
// - small lower wick
// - body near the bottom of the candle range
//
// Again, context determines whether the signal is bullish or bearish.
longUpperWick = upperWick >= bodySize * dominantWickMultiplier
smallLowerWick = lowerWick <= bodySize * oppositeWickMultiplier
bodyNearBottom = math.min(open, close) <= low + rangeSize * bottomThreshold

upperWickPattern = smallBody and longUpperWick and smallLowerWick and bodyNearBottom

// ============================================================================
// CONTEXT FILTERS
// ============================================================================
//
// These filters define whether price was moving down or up into the candle.
//
// Standard     = 1-step decline/rally
// Strict       = 2-step decline/rally
// Extra Strict = 3-step decline/rally
afterDecline =
     contextSteps == 1 ? close[1] < close[2] :
     contextSteps == 2 ? close[1] < close[2] and close[2] < close[3] :
                         close[1] < close[2] and close[2] < close[3] and close[3] < close[4]

afterRally =
     contextSteps == 1 ? close[1] > close[2] :
     contextSteps == 2 ? close[1] > close[2] and close[2] > close[3] :
                         close[1] > close[2] and close[2] > close[3] and close[3] > close[4]

// Only trigger after the bar has fully closed
confirmedBar = barstate.isconfirmed

// ============================================================================
// FINAL PATTERN CONDITIONS
// ============================================================================
//
// Hammer:
// Lower-wick pattern after a decline
hammer = lowerWickPattern and afterDecline and confirmedBar

// Hanging Man:
// Same lower-wick pattern after a rally
hangingMan = lowerWickPattern and afterRally and confirmedBar

// Inverted Hammer:
// Upper-wick pattern after a decline
invertedHammer = upperWickPattern and afterDecline and confirmedBar

// Shooting Star:
// Same upper-wick pattern after a rally
shootingStar = upperWickPattern and afterRally and confirmedBar

// ============================================================================
// PATTERN SELECTION
// ============================================================================

// Only plot the pattern selected by the user.
showHammer = patternType == "Hammer"
showHangingMan = patternType == "Hanging Man"
showInvertedHammer = patternType == "Inverted Hammer"
showShootingStar = patternType == "Shooting Star"

// ============================================================================
// PLOTTING
// ============================================================================

// Hammer
plotshape(
     hammer and showHammer,
     title     = "Hammer",
     style     = shape.triangleup,
     location  = location.belowbar,
     text      = strictness == "Standard" ? "H" : strictness == "Strict" ? "H-S" : "H-X",
     size      = size.small
)

// Hanging Man
plotshape(
     hangingMan and showHangingMan,
     title     = "Hanging Man",
     style     = shape.triangledown,
     location  = location.abovebar,
     text      = strictness == "Standard" ? "HM" : strictness == "Strict" ? "HM-S" : "HM-X",
     size      = size.small
)

// Inverted Hammer
plotshape(
     invertedHammer and showInvertedHammer,
     title     = "Inverted Hammer",
     style     = shape.triangleup,
     location  = location.belowbar,
     text      = strictness == "Standard" ? "IH" : strictness == "Strict" ? "IH-S" : "IH-X",
     size      = size.small
)

// Shooting Star
plotshape(
     shootingStar and showShootingStar,
     title     = "Shooting Star",
     style     = shape.triangledown,
     location  = location.abovebar,
     text      = strictness == "Standard" ? "SS" : strictness == "Strict" ? "SS-S" : "SS-X",
     size      = size.small
)

// ============================================================================
// ALERTS
// ============================================================================

// Optional alert hooks for automation or manual testing
alertcondition(hammer and showHammer, title="Hammer Detected", message="Hammer detected.")
alertcondition(hangingMan and showHangingMan, title="Hanging Man Detected", message="Hanging Man detected.")
alertcondition(invertedHammer and showInvertedHammer, title="Inverted Hammer Detected", message="Inverted Hammer detected.")
alertcondition(shootingStar and showShootingStar, title="Shooting Star Detected", message="Shooting Star detected.")

This stricter version is usually more practical for educational examples and cleaner screenshots because it avoids flagging as many borderline candles.

Strict hammer / hanging man detector with fewer, cleaner signals on chart
A stricter detector typically produces fewer signals, but the pattern quality is often cleaner.

Inverted hammer

The inverted hammer belongs to a different but related family.

It forms after a decline and has:

Like the hammer, it is generally interpreted as bullish when it appears after a decline.

The important distinction is that the inverted hammer is not the bearish opposite of the hammer. Its bearish counterpart is the shooting star, which has the same upper-wick structure but forms after a rally.

Hanging man

The hanging man has almost the same shape as a hammer. The difference is context.

A hammer forms after a decline and is treated as potentially bullish. A hanging man forms after an uptrend and is treated as a bearish warning sign.

That is why it makes sense for the bearish option in the detector to show a hanging man rather than an inverted hammer. The detector is built around the lower-wick rejection family, not the upper-wick family.

How traders use the hanging man

The hanging man is usually not traded on shape alone.

A common approach is:

As with the hammer, the pattern is far more useful when it appears in the right location.

Hanging man candlestick forming after an uptrend, warning that buying pressure may be weakening
A hanging man uses the same broad shape as a hammer, but the interpretation changes because it appears after a rally.

Strengths and limitations

The hammer is popular because it is simple, practical, and easy to recognise.

Its main strengths are:

Its limitations are just as important:

That is why the hammer is usually best used as a supporting signal inside a broader framework rather than as a standalone strategy.

Final thought: The hammer is best understood as evidence of rejection, not proof of reversal. When it forms after a decline and in the right location, it can be a useful sign that sellers are losing control. When the same candle shape forms after a rally, it becomes a hanging man and carries a very different message. Used properly, these patterns can be valuable parts of a wider price action approach.