Hammer
A small body at the top of the range with a long lower shadow, appearing after a decline: sellers pushed price down and were rejected before the close. Returns +1.
Signature
Hammer(trend_period, body_ratio, shadow_ratio, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
trend_period |
int Param or literal | Yes | Bars back used to establish the prior trend. Default 5, bounds 1–100. |
body_ratio |
float Param or literal | Yes | Largest body, as a fraction of the range. Default 0.33, bounds 0.05–0.9. |
shadow_ratio |
float Param or literal | Yes | Minimum shadow length in body-multiples. Default 2.0, bounds 1.0–10.0. |
on= |
symbol | No | Source symbol. Defaults to the trade symbol. Reads open, high, low, close. |
Formula
Small body near the high, lower shadow at least shadow_ratio × body, upper shadow no larger than the body, and the close below the close trend_period bars ago.
Warmup
trend_period bars, to establish the prior decline.
Reading the value
p.valuep > 0Pattern indicators return a flag, not a level: +1 bullish, -1 bearish, 0 absent. They
are zero on most bars by design, so treat them as event triggers rather than as something to
smooth or cross.
Example
class HammerEntry(Strategy): """Act on the pattern only in the direction of the longer trend.""" trade = Symbol() sizing = FixedCapital()
def execute(self): p = Hammer(5, 0.33, 2.0, on=self.trade) sma = SMA(50, on=self.trade) if p.value > 0 and self.trade.is_flat: self.buy(self.trade, reason="Hammer after a decline") if self.trade.is_long and self.trade.close < sma.value: self.sell(self.trade, self.trade.position, reason="Trend lost")Notes
- The prior-downtrend condition is what separates a hammer from a hanging man — identical
geometry, opposite meaning. Here it is an explicit close-versus-close test over
trend_period.