VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / Indicators and signals

Hammer candlestick: hammer vs hanging man and how to test them

A hammer is a small-bodied candle with a long lower shadow. After a decline it is read as bullish. After a rise the same shape is the bearish hanging man. To test it, write exact shape and trend rules, wait for confirmation and enter on the next bar.

By · Published · updated · Editorial policy

Contents
  1. What is a hammer candlestick?
  2. What shape rules make a candle a hammer?
  3. When is a hammer bearish? Hammer versus hanging man
  4. Why wait for a confirmation candle, and when do you enter?
  5. How do you test a hammer rule on futures?
  6. What can a hammer backtest show, and what can it not?
  7. How does AlphaPrime fit into a hammer test?
  8. Frequently asked questions
  9. References

What is a hammer candlestick?

A hammer candlestick is a candle with a small body near the top of its range and a lower shadow at least twice the body. After a decline it is read as bullish. After a rise the same shape is called a hanging man, or "bearish hammer". To test it, write exact shape rules and enter on the next bar.

The body is the thick part of the candle, between the open and the close. A shadow (also called a wick) is the thin line above or below the body that shows how far price traveled before it came back. The range is the full distance from the high to the low of the bar. A hammer is read from a single candle, while most technical indicators are calculated from many bars.

The usual story behind the hammer is simple. Sellers push price far down during the bar. Buyers then push it back up, and the bar closes near its high. The long lower shadow is the record of that failed push down. Whether that story leads to a tradable edge is a separate question, and only a test can answer it.

Anatomy of a hammer candle: the high, close, open and low are labelled, with a small body at the top of the range, a short upper shadow, a lower shadow about three times the body, and a bracket showing the full range Small body, long lower shadow Where each part of the candle sits Range Close Open Low High Small body Lower shadow 3× the body Lower shadow at least 2× the body. So: write each shape rule as a number.
Anatomy of a hammer: a small body at the top of the range and a long lower shadow.

What shape rules make a candle a hammer?

A candle counts as a hammer only when it passes a set of measurable rules, and you choose the thresholds. Chart books describe the shape in words. A backtest needs numbers. The table below lists the rules most traders use and a common starting value for each.

RuleWhat it measuresCommon starting value
Long lower shadowLower shadow compared with the bodyAt least 2 times the body
Small upper shadowUpper shadow compared with the rangeAt most 10% of the range
Body near the topWhere the body sits within the rangeBody inside the top third of the range
Minimum sizeRange compared with recent barsRange at least as large as the recent average range

The first rule is the heart of the pattern. Written as one line: lower shadow ≥ k × body. Here "lower shadow" is the lower of the open and the close, minus the low. "Body" is the distance between the open and the close. "k" is the ratio you choose, often 2.

Hypothetical example

A bar opens at 98, rises to a high of 100, falls to a low of 90 and closes at 99. The range is 10 points. The body is 1 point (98 to 99). The lower shadow is 8 points (98 down to 90). The upper shadow is 1 point (99 to 100). The lower shadow is 8 times the body, the upper shadow is 10% of the range, and the body sits in the top fifth of the range. This bar passes the three shape rules; the minimum size rule needs the recent bars to check.

Two details need a decision before you test. First, the minimum size rule. Without it, tiny bars in a quiet market qualify, and those bars say little about buyers or sellers. Many traders compare the range with the average true range (ATR), which is the average bar size over recent bars. Second, a bar with no body at all, where the open equals the close. The ratio rule then always passes, so decide in advance whether such a bar counts.

The color of the body, up or down, matters little in most definitions. You can test it as a separate filter: require a close above the open and see whether that changes the result.

When is a hammer bearish? Hammer versus hanging man

The shape is the same, and only the trend before the candle decides whether it is a bullish hammer or a bearish hanging man. A hammer appears after a decline and is read as a possible bottom. A hanging man is the same candle after a rise and is read as a possible top. "Bearish hammer" usually refers to the hanging man.

Think of a long lower shadow as a question, not an answer. After a fall, it suggests sellers are tiring. After a rise, it shows that sellers were able to push price down hard inside one bar, which can be an early sign of weakness in an uptrend.

NameShapeTrend beforeUsual reading
HammerSmall body at the top, long lower shadowDownBullish
Hanging manSmall body at the top, long lower shadowUpBearish
Inverted hammerSmall body at the bottom, long upper shadowDownBullish
Shooting starSmall body at the bottom, long upper shadowUpBearish

For a test, "the trend before" must also be a rule. A simple version for a hammer: the close is below its 20-bar moving average, and the close is lower than it was 5 bars ago. For a hanging man, reverse both conditions. Any common type of moving average works for this filter; choose one type before the test and keep it fixed. The lengths 20 and 5 are only starting values. Test a few lengths, not just one.

The same candle gets two names: after five falling candles it is a hammer and read as bullish, after five rising candles it is a hanging man and read as bearish Same candle, two names Only the trend before it differs Hammer Bullish Hanging man Bearish The trend decides the name. So: make the trend a test rule.
The same candle gets two names: after a decline it is a hammer, after a rise it is a hanging man.

Why wait for a confirmation candle, and when do you enter?

A confirmation candle reduces false signals, but it also delays the entry, so test with and without it. A confirmation candle is the bar after the pattern that moves in the expected direction. For a hammer, that is usually a close above the hammer's high. For a hanging man, it is a close below the hanging man's low.

The entry must use only information that existed at that moment. Look-ahead bias is the error of letting a backtest act on prices it could not have known yet. With candlestick patterns it often creeps in like this: the test waits for the confirmation bar to close, and then fills at that same bar's open. In real trading that is impossible. The safe order of steps for a bullish hammer is:

  1. Bar 1 closes. Check the shape rules and the trend rule using data up to this close.
  2. Bar 2 closes. Check the confirmation: did bar 2 close above the high of bar 1?
  3. Bar 3 opens. Enter at the open of bar 3. Place the stop one tick below the low of bar 1.

For a hanging man, mirror every step: confirmation is a close below bar 1's low, the entry is a short sale at the open of bar 3, and the stop goes one tick above bar 1's high.

Entry methodWhen the trade startsTrade-off
No confirmationOpen of bar 2Earliest entry and best price, most false signals
Stop orderDuring bar 2, if price rises one tick above bar 1's highConfirms and enters at once; may pay slippage on the stop fill
Close confirmationOpen of bar 3Fewest false signals, latest entry and often a worse price
Close confirmation without look-ahead: bar 1 is a hammer checked at its close, bar 2 closes above bar 1's high as confirmation, the trade enters at the open of bar 3, and the stop sits as a dashed line below bar 1's low Enter at the next open Close confirmation without look-ahead Stop Signal at close Confirm at close Entry next open Decide at a close, fill later. So: enter at the next bar's open.
Close confirmation without look-ahead: the signal and the confirmation are both known at a bar close, and the trade starts at the next open.

How do you test a hammer rule on futures?

A fair test defines everything in advance, includes costs, and compares the pattern with a simple baseline. Do these steps in this order:

  1. Fix the bar type and the session. A candle's shape depends on the hours the bar covers. Many futures, such as TAIEX futures, trade in a day session and a separate after-hours session. A hammer on a day-session chart may not exist on a full-session chart. The guide to night sessions in futures backtests explains the choice. Exchanges can change session times, so check the exchange's contract page or the futures market hours tool for current hours.
  2. Use continuous data that handles contract rolls. A price jump at a roll can create a fake long shadow or a fake trend.
  3. Write the shape, trend and confirmation rules as numbers, using the tables above.
  4. Define the exit before you look at results. For example: the stop below the hammer's low, and an exit after a fixed number of bars or at a fixed multiple of the initial risk.
  5. Include commission and slippage on every trade. Candlestick rules often trade near the open of a bar, where fills can be worse. The article on trading costs in backtests shows how to compare the average trade with the round-trip cost.
  6. Build a baseline. A baseline is a simple rule that keeps everything except the pattern. For the hammer: buy at the next open after any bar that closes below its 20-bar moving average, with the same stop and exit. If the hammer does not beat this, the candle shape adds nothing to "buy after weakness".
  7. Test nearby settings. Try shadow ratios of 2, 2.5 and 3, and two or three trend lengths. A real effect should look similar across nearby settings, not appear in one combination only.
  8. Keep the most recent years aside. Choose the settings on the older data, then run them once on the held-back period without changes.

The broader article on testing bullish and bearish candlestick patterns applies the same steps to other patterns.

What can a hammer backtest show, and what can it not?

A backtest shows how a precisely defined hammer rule behaved on your data and costs; it does not prove that the pattern will work in the future. The useful questions are narrow. Did the rule beat its baseline after costs? Did it hold up in the held-back years? Did nearby settings behave similarly?

Hypothetical example

You test bullish hammers on one index future over ten years and find 140 signals. The average trade after costs is +3 ticks. The baseline that buys after any close below the 20-bar moving average, with the same stop and exit, averages +2.5 ticks. The hammer adds half a tick per trade. With only 140 trades and a wide spread of individual results, a difference that small can easily come from chance. Most of the result comes from buying after weakness, not from the candle shape.

The number of variants you tried matters as much as the result. Each new shadow ratio, trend length or exit is another draw. Try enough of them and one will look good by luck. Data snooping is the error of testing many variants on the same data until one looks good by luck; this error has been studied directly for technical trading rules (Sullivan, Timmermann and White, 1999; White, 2000). The more variants you test, the higher the bar a result has to clear (Bailey, Borwein, López de Prado and Zhu, 2014). Keep a written count of every variant you ran. The strategy databank in AlphaPrime (Valynox) keeps the results of every hammer variant in one list you can search and sort, so the count of draws is a number you read off rather than recall.

Hammers are also rare signals. On daily bars, a strict definition with a trend filter may produce only a handful of trades per year on one market. Testing several markets with the same rules gives more trades without adding new parameters.

How does AlphaPrime fit into a hammer test?

AlphaPrime handles the parts that are slow to do by hand. Its strategy generation turns a research idea into testable trading rules, with parameter ranges, entry and exit conditions and search constraints. That fits part of the "test nearby settings" step: a trend length from 10 to 30 becomes a range instead of a single guess, while AlphaPrime's built-in Hammer condition has no shadow-ratio setting. AlphaPrime's backtesting evaluates every candidate with the same settings, including fees and slippage, next-bar execution and trading sessions, so each variant faces the same costs and the same entry timing as the baseline.

What this means if you use AlphaPrime: define the hammer, the trend filter, the confirmation and the baseline as rules with parameter ranges, and let every variant run with costs and next-bar entry from the first run. Then compare the variants with the baseline and with each other, not with your expectations.

Frequently asked questions

Is a hammer candlestick bullish or bearish?

A hammer is read as bullish, because it appears after a decline and shows that buyers pushed price back up from the low. The same shape after a rise is called a hanging man and is read as bearish. The shape alone does not decide; the trend before it does.

What is the difference between a hammer and a hanging man?

Both candles have a small body near the top of the range and a long lower shadow. A hammer follows a downtrend, and a hanging man follows an uptrend. In a backtest, the difference is a trend rule, such as the close being below or above a moving average.

Does the color of a hammer candle matter?

Most definitions accept a hammer with either an up or a down body. Some traders prefer a close above the open for a hammer and a close below the open for a hanging man. You can test color as an extra filter and keep it only if it improves the result across nearby settings.

What is an inverted hammer?

An inverted hammer has a small body near the bottom of the range and a long upper shadow, and it appears after a decline. It is read as a possible bullish turn. The same shape after a rise is called a shooting star and is read as bearish.

How many hammer signals do I need for a meaningful backtest?

There is no fixed number, but a few dozen trades is a bare minimum, and more is better. With few trades, one or two large winners can decide the whole result. Testing the same rules on several markets and comparing them with a baseline makes a small sample easier to judge.

References

  • Sullivan, R., Timmermann, A., & White, H. (1999). Data-Snooping, Technical Trading Rule Performance, and the Bootstrap. The Journal of Finance, 54(5), 1647–1691.
  • White, H. (2000). A Reality Check for Data Snooping. Econometrica, 68(5), 1097–1126.
  • Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.