Indicator · Pine Script v6 · On the chart

Hammer & Inverted Hammer Patterns

by ognenmitev

Labels four single-candle reversal patterns on the price chart: bullish hammer, inverted hammer, hanging man and shooting star.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code131
Settings7inputs
LicenceCustom licencefile: MPL-2.0
Last update11 months ago3 Dec 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

131 lines of Pine Script v6 from Alerts/hammer_patterns.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

hammer_patterns.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ognenmitev - Modified for Hammer Patterns Only

//@version=6
indicator("Hammer & Inverted Hammer Patterns", overlay=true, max_labels_count=100)

// INPUTS
showBullishHammer = input.bool(true, "Show Bullish Hammer", group="Hammer Patterns")
showInvertedHammer = input.bool(true, "Show Inverted Hammer", group="Hammer Patterns")
showBearishHammer = input.bool(true, "Show Bearish Hammer (Hanging Man)", group="Hammer Patterns")
showShootingStar = input.bool(true, "Show Shooting Star (Inverted Bearish)", group="Hammer Patterns")
sensitivity = input.string("Normal", "Sensitivity", options=["Strict", "Normal", "Relaxed"], group="Settings")
wickMultiplier = input.float(2.0, "Wick to Body Ratio", minval=1.5, maxval=4.0, step=0.5, group="Settings")
useTimeframeFilter = input.bool(true, "Only Show on 2-Minute Chart", group="Settings")

// TIMEFRAME CHECK
is2MinChart = timeframe.period == "2"
showPatterns = not useTimeframeFilter or is2MinChart

// SENSITIVITY MULTIPLIERS
strictMult = sensitivity == "Strict" ? 0.8 : sensitivity == "Normal" ? 1.0 : 1.2

// CANDLE MEASUREMENTS
bodySize = math.abs(close - open)
upperWick = high - math.max(close, open)
lowerWick = math.min(close, open) - low
fullRange = high - low
avgBody = ta.sma(bodySize, 14)
avgRange = ta.atr(14)

isBullish = close > open
isBearish = close < open
smallBody = bodySize < avgBody * 0.5 * strictMult

// Dynamic wick checks
longUpperWick = upperWick > bodySize * wickMultiplier
longLowerWick = lowerWick > bodySize * wickMultiplier

// =============================================================================
// HAMMER PATTERN DETECTION
// =============================================================================

// BULLISH HAMMER (bullish reversal)
// Small body at top, long lower wick, appears after downtrend
// Body should be in upper part of the candle
isBullishHammer = longLowerWick and 
                  upperWick < bodySize * strictMult and 
                  close > (high - fullRange * 0.3) and 
                  close[1] < open[1] and
                  lowerWick > fullRange * 0.6

// INVERTED HAMMER (bullish reversal)
// Small body at bottom, long upper wick, appears after downtrend
// Body should be in lower part of the candle
isInvertedHammer = longUpperWick and 
                   lowerWick < bodySize * strictMult and 
                   close < (low + fullRange * 0.3) and
                   close[1] < open[1] and
                   upperWick > fullRange * 0.6

// HANGING MAN / BEARISH HAMMER (bearish reversal)
// Same as hammer but appears after uptrend
// Small body at top, long lower wick
isHangingMan = longLowerWick and 
               upperWick < bodySize * strictMult and 
               close < (high - fullRange * 0.7) and 
               close[1] > open[1] and
               lowerWick > fullRange * 0.6

// SHOOTING STAR / INVERTED BEARISH HAMMER (bearish reversal)
// Same as inverted hammer but appears after uptrend
// Small body at bottom, long upper wick
isShootingStar = longUpperWick and 
                 lowerWick < bodySize * strictMult and 
                 close[1] > open[1] and
                 upperWick > fullRange * 0.6

// =============================================================================
// PLOT SIGNALS
// =============================================================================

// BULLISH PATTERNS (Green/Lime colors)
plotshape(showPatterns and showBullishHammer and isBullishHammer, 
          title="Bullish Hammer", 
          style=shape.labelup, 
          location=location.belowbar, 
          color=color.new(color.lime, 0), 
          text="HAMMER ↑", 
          size=size.normal)

plotshape(showPatterns and showInvertedHammer and isInvertedHammer, 
          title="Inverted Hammer", 
          style=shape.labelup, 
          location=location.belowbar, 
          color=color.new(color.green, 0), 
          text="INV HAMMER ↑", 
          size=size.normal)

// BEARISH PATTERNS (Red/Orange colors)
plotshape(showPatterns and showBearishHammer and isHangingMan, 
          title="Hanging Man", 
          style=shape.labeldown, 
          location=location.abovebar, 
          color=color.new(color.orange, 0), 
          text="HAMMER ↓", 
          size=size.normal)

plotshape(showPatterns and showShootingStar and isShootingStar, 
          title="Shooting Star", 
          style=shape.labeldown, 
          location=location.abovebar, 
          color=color.new(color.red, 0), 
          text="INV HAMMER ↓", 
          size=size.normal)

// BACKGROUND COLORING (subtle)
bgcolor(showPatterns and (isBullishHammer or isInvertedHammer) ? color.new(color.lime, 95) : na, title="Bullish Hammer Background")
bgcolor(showPatterns and (isHangingMan or isShootingStar) ? color.new(color.red, 95) : na, title="Bearish Hammer Background")

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

alertcondition(isBullishHammer, "Bullish Hammer", "Bullish Hammer detected - Potential reversal UP")
alertcondition(isInvertedHammer, "Inverted Hammer", "Inverted Hammer detected - Potential reversal UP")
alertcondition(isHangingMan, "Hanging Man", "Hanging Man detected - Potential reversal DOWN")
alertcondition(isShootingStar, "Shooting Star", "Shooting Star detected - Potential reversal DOWN")

// Combined alerts
alertcondition(isBullishHammer or isInvertedHammer, "Any Bullish Hammer", "Bullish Hammer Pattern - Consider LONG")
alertcondition(isHangingMan or isShootingStar, "Any Bearish Hammer", "Bearish Hammer Pattern - Consider SHORT")

Overview

Detection compares wick length to body size, using a wick-to-body ratio setting and a Strict, Normal or Relaxed sensitivity multiplier, and checks the colour of the previous candle for context. Each pattern can be switched off. By default it only shows patterns on the 2-minute chart, and that filter can be disabled.

Details

Published by

ognenmitev on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Candlestick patterns

Markets

Any symbol

Timeframes

M1-M5

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show Bullish HammerbooltrueshowBullishHammer
Show Inverted HammerbooltrueshowInvertedHammer
Show Bearish Hammer (Hanging Man)booltrueshowBearishHammer
Show Shooting Star (Inverted Bearish)booltrueshowShootingStar
SensitivitystringNormalsensitivity
Wick to Body Ratiofloat2.0wickMultiplier
Only Show on 2-Minute ChartbooltrueuseTimeframeFilter
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Heikin-Ashi Chart Identifier is an indicator that checks if the current chart uses Heikin-Ashi candles. It tracks matched candles where open equals the average of previous open and close, and verifies no gaps between bars. When conditions match, it display

Indicator v4 Candlestick patterns
Updated 11 days ago · GPL-3.0 GitHub repository of Heikin-Ashi Chart Identifier
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

[RS]MTF Candle Sticks

by ricardosantos79
261 stars

This indicator overlays up to five higher-timeframe candlestick groups on the price chart. For each enabled timeframe it requests open, high, low, and close and can show up to five candles, offset by a spacing setting. The main inputs set the candle count, the

Indicator v4 Candlestick patternsSupport & resistance Repaints
Updated 4 years ago · None stated GitHub repository of [RS]MTF Candle Sticks
257 stars

This indicator detects a large set of classic candlestick patterns and plots colored labels on the price chart. Trend context uses a 50-period simple moving average, or the 50 and 200 averages stacked together, and can be switched off. Users filter bullish, be

Indicator v4 Candlestick patternsTrend
Updated 6 weeks ago · None stated GitHub repository of Snag - All Candlestick Patterns

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers