Concept 19 / 52·Patterns·Reversal candles
‹ Golden Cross & Death CrossHeikin-Ashi ›

Hammer & Shooting Star in Pine Script

pin bar · hammer candle · shooting star candle · hanging man · inverted hammer · rejection candle

Single candles with a small body and one long wick: a hammer's lower wick shows a rejected low after a decline, a shooting star's upper wick a rejected high after an advance.

Reads best on: Liquid markets on 1-hour to daily charts, where a bar's range reflects a real auction. Thin instruments and 1-minute charts produce wicks from single prints.
On this page: the Pine v6 script, checked, drawn on real NVDA bars. Backtest it free, costs charged, every trade on the chart.
01

Definition

A hammer is a single candle with a small body near the top of its range and a lower wick at least twice the body's height; a shooting star is the mirror, a small body near the bottom and a long upper wick. They belong to the reversal candle family. Traders call both shapes pin bars, short for Pinocchio bars, because the long wick is the lie the market told before the close. The hammer is read after a decline and the shooting star after an advance; the same shapes in the opposite context are called the hanging man and the inverted hammer.

The wick is the information. During the bar, price travelled a long way in one direction and was then pushed all the way back before the close. The traders who followed the move are trapped by the end of the bar. A hammer after a decline records sellers driving to a new low, buyers absorbing every offer, and the close returning near the open. The body being small says neither side won the session; the wick being long says one side lost the extreme. That is a rejection, and the reversal case rests on the trapped side having to exit.

The shapes are Japanese candlestick patterns, brought to Western charts by Nison in the early 1990s. The standard proportions are a lower wick at least twice the body, an upper wick no larger than the body and a body that is a small share of the full range. The implementation uses exactly those rules, with the body share capped at 0.35 of the range by default and the candle colour ignored, so a hammer can close up or down. Context is not tested by the script: a hammer is shape only, and the reader supplies the decline it should reverse.

On the chart, expect the pattern to look clearest on liquid markets where a bar's range is a real auction, and to be noisy on thin instruments where one print can draw a wick. Expect hammers to cluster at levels: the previous day's low, a swing low, the lower band of a channel. Expect the best examples to have a long wick relative to recent ranges, not merely relative to their own body. And expect the confirmation to come from the next bar, since the reversal case is only proven once price moves away from the wick.

02

Reading the chart

Measure the candle's three parts, then check the context, because the proportions define the shape and the preceding move gives it a meaning.

  1. Split the candle into its body, upper wick and lower wick. The body is the distance between open and close; the wicks are the range above and below the body.
  2. For a hammer, check that the lower wick is at least twice the body and the upper wick is no larger than the body. For a shooting star, apply the same test the other way up.
  3. Check the body's share of the whole range. A body under about a third of the range keeps the shape honest; a large body with a modest wick is a normal candle, not a pin bar.
  4. Look left for the move it should reverse. A hammer needs a decline into it and a shooting star needs an advance; the same shapes inside a range are just wicks.
  5. Check the location. A hammer at a level that has held before, or at a prior day's low, carries far more weight than one in the middle of nowhere.
  6. Wait for the next bar. A close above the hammer's high, or below the shooting star's low, confirms that price is leaving the wick behind; a close back into the wick weakens the case.
03

The maths

The test measures the three parts of one candle and compares them with each other and with the full range.

bodyt=∣Ct−Ot∣\mathrm{body}_t = \lvert C_t - O_t \rvert
ranget=Ht−Lt\mathrm{range}_t = H_t - L_t
lowert=min⁡(Ot, Ct)−Lt\mathrm{lower}_t = \min(O_t,\, C_t) - L_t
uppert=Ht−max⁡(Ot, Ct)\mathrm{upper}_t = H_t - \max(O_t,\, C_t)
hammert={1lowert≥2 bodyt∧uppert≤bodyt∧bodytranget≤r0otherwise\mathrm{hammer}_t = \begin{cases} 1 & \mathrm{lower}_t \ge 2\, \mathrm{body}_t \land \mathrm{upper}_t \le \mathrm{body}_t \land \frac{\mathrm{body}_t}{\mathrm{range}_t} \le r \\ 0 & \text{otherwise} \end{cases}
start={1uppert≥2 bodyt∧lowert≤bodyt∧bodytranget≤r0otherwise\mathrm{star}_t = \begin{cases} 1 & \mathrm{upper}_t \ge 2\, \mathrm{body}_t \land \mathrm{lower}_t \le \mathrm{body}_t \land \frac{\mathrm{body}_t}{\mathrm{range}_t} \le r \\ 0 & \text{otherwise} \end{cases}
Ot,Ht,Lt,CtO_t, H_t, L_t, C_topen, high, low and close of bar t
bodyt\mathrm{body}_tthe body of bar t
ranget\mathrm{range}_tthe full range of bar t, which must be greater than 0
lowert,uppert\mathrm{lower}_t, \mathrm{upper}_tthe lower and upper wicks of bar t
rrthe maximum body as a share of the range, 0.35 by default
hammert,start\mathrm{hammer}_t, \mathrm{star}_tthe hammer and shooting star flags on bar t
ttthe current bar

Colour is not part of the test. A hammer that closes slightly down still qualifies, since the rejection is in the wick; some traders require an up close for a hammer and a down close for a star, which is a stricter variant.

A doji with one wick passes. With a body of 0, the long wick is automatically twice the body, so a dragonfly doji counts as a hammer and a gravestone doji as a shooting star.

The body cap is a share of the range, not an absolute size. On a wide-range bar a body of 0.35 of the range is a large candle, so some traders lower the cap to 0.25 for strictness.

The implementation marks Long on a hammer and Short on a shooting star at the bar close, with no test for a preceding decline or advance; the context is the reader's job.

04

Inputs that matter

InputTypicalWhat changing it does
Max body for a pin bar (share of range)0.35Lower values demand a smaller body and a longer wick, so fewer and cleaner pin bars are marked; higher values admit candles that look more like ordinary bars.
Hammers and shooting starsonSwitches the pin-bar marks on. Turn the engulfing and inside-bar switches off to study the wick patterns alone.
EngulfingonThe two-bar reversal in the same script. Off keeps hammer and shooting star marks from being mixed with body-based signals.
Inside-bar breakoutsonThe continuation pattern in the same script, usually off when reading reversals.
05

In practice

  • As a reversal entry at support: a hammer on the previous day's low or a swing low, with the stop under the wick, is the standard trade; the wick's low is the level the market has already rejected once.
  • As a trend pullback entry: in an uptrend, a hammer that ends a pullback to a moving average or a higher low puts the entry with the trend and the stop at a defined rejection.
  • As an exhaustion tell: a shooting star after several wide-range up bars, especially on high volume, shows the first failed push and is where exit rules scale out or tighten stops.
  • As a false-breakout tell: a shooting star that pokes above a range high and closes back inside is the trapped-long pattern, and the setup is the return to the range's other side.
  • As a scan condition: the implementation marks each pin bar at the close and can alert. The alert names the direction, not the shape, so switch the other patterns off when the alert must mean a pin bar.
  • As a higher-timeframe context: a daily hammer at a weekly level is a stronger statement than any intraday one, and it frames the intraday entries that follow.
06

Where it goes wrong

  • Trading the shape without the move. A hammer in the middle of a range has rejected nothing; require a decline into it and a level under it.
  • Reading a pin bar on a thin instrument. One large print can draw a long wick on a low-volume chart; prefer liquid markets or higher timeframes.
  • Putting the stop inside the wick. The wick is the rejection, so a stop placed within it sits in the zone the market already probed; the entry is wrong only beyond the wick's end.
  • Ignoring the next bar. A hammer followed by a close back into its wick has failed as a reversal, and the trapped side is no longer trapped.
07

Compared with

Engulfing Candle. An engulfing is two bars whose bodies show the previous move reversed at the close; a hammer is one bar whose wick shows an extreme rejected within the bar. The engulfing's evidence is the close, the hammer's is the wick.

Inside Bar. An inside bar has a narrow range inside the previous bar and says nothing about direction until it breaks. A hammer has a wide range with a long wick and makes a directional claim at its close.

Divergence. Divergence is an oscillator disagreeing with price over two swings, a slow warning. A hammer is a single-bar price event, a fast trigger. Divergence into a level followed by a hammer at that level is a common combination.

Support & Resistance. Support is where price has reversed before; a hammer is how a reversal at that level looks on one bar. The level gives the hammer its meaning, and a hammer gives the level a fresh test with a defined invalidation point.

08

Build it in Quant

Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.

Open Hammer & Shooting Star on the workbench chart
Drawn on real data; then audit, backtest and refine in conversation.
Open in Quant →
09

Questions

  • What is the difference between a hammer and a pin bar?

    None in shape. Pin bar is the price-action name for any candle with a small body and one long wick; hammer and shooting star are the candlestick names for the bullish and bearish versions read after a decline or an advance. The implementation calls them hammers and shooting stars and responds to the pin-bar keyword as well.

  • Does a hammer have to close green?

    Not in the implementation, and not in most definitions. The rejection is in the wick; a close slightly below the open with a long lower wick still shows that the low met demand. Some traders prefer an up close for extra strength, and a hammer that closes at its high is the strongest version.

  • What is a hanging man?

    A hammer shape after an advance instead of a decline. The same small body and long lower wick read differently at the top of a move: the long wick shows that sellers were able to push price a long way down within the bar, even if buyers recovered it. The inverted hammer is the mirror, a shooting star shape after a decline.

  • How long should the wick be?

    At least twice the body, with the opposite wick no larger than the body, and the body no more than about a third of the range. Those are the implementation's rules with the default cap of 0.35. Beyond the ratios, compare the wick with recent bars: a wick that is long relative to the last ten ranges means more than one that only looks long against a tiny body.

  • Where do the stop and the entry go?

    Entry on a close beyond the body side of the wick, or on the next bar's break of the hammer's high, and the stop beyond the end of the wick. The wick's extreme is the price the market rejected, so a return through it says the rejection has failed. Stops inside the wick sit in the noise the bar already produced.

  • Why does the script mark hammers in the middle of a trend?

    Because it tests shape only. It marks any candle that meets the wick and body ratios, on confirmed bars, and does not check for a preceding decline or advance. That is deliberate: the context rules differ between traders, so the script detects and the reader filters. Add a trend filter or read the marks only at levels.