Hammer
Install and import#
npm install fintech-algorithmsimport { hammer } from "fintech-algorithms/price-action-and-candlesticks/single-candle-patterns/hammer";Signature#
hammer(inputs)Evaluates one candle against explicit hammer geometry, scale, and downtrend context conventions.
Parameters#
| Name | Type | Notes |
|---|---|---|
inputs | { current: { open: number; high: number; low: number; close: number }; prior_bodies: number[]; prior_ranges: number[]; trend_context: string; tick_size: number } | Record containing current, prior body/range history, trend_context, and tick_size. |
Returns#
{ topic_id, pattern, matched, state, direction, trend_context, required_context, body, upper_shadow, lower_shadow, range, body_scale, range_scale, history_count, geometry_score, checks, failed_checks }
One pattern record. state is warmup, wrong-context, matched, or not-matched; this is not a positional series.
Warm-up#
The first 5 prior observations positions are state: warmup. The detector returns one readiness record before five prior body/range observations are available; it does not emit a positional null prefix.
Errors#
- When OHLC, history, context, or tick-size input violates the data contract — throws
Complexity: time ,
space .
Worked example#
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input#
{
"current": {
"open": 102,
"high": 103.2,
"low": 100,
"close": 103
},
"prior_bodies": [2, 2.2, 1.8, 2.1, 1.9, 2],
"prior_ranges": [5, 5, 5, 5, 5, 5],
"trend_context": "downtrend",
"tick_size": 0.1
}Call#
hammer(inputs)Returns#
object with 17 fields: topic_id, pattern, matched, state, direction, trend_context, required_context, body, …
{
"topic_id": "D06-F02-A06",
"pattern": "Hammer",
"matched": true,
"state": "matched",
"direction": "bullish",
"trend_context": "downtrend",
"required_context": "downtrend",
"body": 1,
"upper_shadow": 0.20000000000000284,
"lower_shadow": 2,
"range": 3.200000000000003,
"body_scale": 2,
"range_scale": 5,
"history_count": 10
}Showing 14 of 17 fields.
Other exports#
This module also exports
calculate, shadowToBodyRatio, gapClassification, trendContextFilter, doji, dragonflyDoji, gravestoneDoji, marubozu, spinningTop, hangingMan, invertedHammer, shootingStar, bullishEngulfing, bearishEngulfing, bullishHarami, bearishHarami, piercingLine, darkCloudCover, tweezerTop, tweezerBottom. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams#
Calculation flow#
Hammer calculation flow
flowchart LR
S1["Validate the candle tick context and aligned prior sca"]
S2["Calculate body upper shadow lower shadow and prior med"]
S3["Evaluate the Hammer Boolean checks in formula order"]
S4["Apply required context when applicable and return ever"]
S1 --> S2
S2 --> S3
S3 --> S4
S4 --> D{"the material geometry threshold at exact equality"}
D --> O["matched + diagnostics"]
O --> A["Audit: A matched output has no failed Boolean checks"]
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Japanese Candlestick Charting Techniques, Second Edition — Steve Nison
- CMT Program Guide 2026 — CMT Association
- Candlestick Settings — TA-Lib project
- Hammer recognizer — TA-Lib project
- Evidence boundary