Ready to go further
Next: test a rule step by step
The how to backtest guide walks through the steps in order, with the traps that catch rules like these.
What is included
- What it is, in plain words
- The formula or mechanism, with exact arithmetic
- How it hits grid, martingale and DCA bots
- A check you can run before you switch a bot on
Who it is for
- People who run or plan to run a trading bot
- Anyone reading a backtest or a bot sales page
- Readers who want the numbers, not the pitch
- Not advice, and not a signal service
Key facts
- One candle holds four prices for one period: the open, the high, the low and the close. The body runs from open to close. The wicks run from the body to the high and the low.
- A pattern name such as hammer, engulfing or doji is a loose description. A bot needs numbers: for example, a lower wick of at least 2 times the body.
- In the made-up candle above, the body is 0.8, the lower wick is 6.0 and the upper wick is 0.2 (calculated by us on 31 Oct 2026, exact). It passes the hammer rule below.
- Change one price and the answer can flip. Raising the low so the wick shrinks from 6.0 to 1.5 makes the same candle fail. Two people can rule the same chart differently.
- This page defines shapes. It does not say that any shape predicts the next move. That has to be tested, with costs, on data the rule has not seen.
What one candle shows
A chart is cut into periods. A period can be one minute, one hour or one day. For each period the chart records four prices.
- Open: the first price of the period.
- High: the highest price reached in the period.
- Low: the lowest price reached in the period.
- Close: the last price of the period.
The candle draws these as a body and two wicks. The body is the box between the open and the close. It is usually drawn one colour when the close is above the open and another when it is below. The wicks are the thin lines. The upper wick runs from the top of the body to the high. The lower wick runs from the bottom of the body to the low.
Range = high - low
Upper wick = high - the larger of open and close
Lower wick = the smaller of open and close - low
Two things are worth knowing before any pattern. First, a candle hides what happened inside the period. Two candles with the same four prices can have very different paths. Second, the sizes are relative. A body of 1 means little unless you know whether the range is 2 or 20.
For another way to draw the same prices, see Heikin Ashi, which averages the candles to smooth them.
Three patterns as exact rules
Books describe patterns in words. A bot cannot read words, so each name has to become a test that returns yes or no. The rules below are one reasonable version of each. They are not the official version, because there is none. Other books use other cut-offs.
Hammer
The word picture is a small body at the top and a long lower wick, like a hammer standing on its handle. As a rule:
- The body is not zero and is at most one third of the range.
- The lower wick is at least 2 times the body.
- The upper wick is at most 10 percent of the range.
Bullish engulfing
The word picture is a down candle followed by an up candle whose body covers the first body. It takes two candles. As a rule:
- The previous candle closed below its open.
- The current candle closed above its open.
- The current open is at or below the previous close.
- The current close is at or above the previous open.
The bearish engulfing is the mirror image. Some versions drop the "at or", and that changes which candles qualify.
Doji
The word picture is a candle where the open and close are almost the same, so the body is a thin line. As a rule: the range is above zero and the body is at most 10 percent of the range. The 10 percent is a choice.
A made-up example
Every number here is made up to show the arithmetic. None of it is from a real market.
| Candle | O / H / L / C | Body | Range | Upper wick | Lower wick | Rule result |
|---|---|---|---|---|---|---|
| A | 100 / 101 / 94 / 100.8 | 0.8 | 7.0 | 0.2 | 6.0 | Hammer: yes |
| A2 (low raised) | 100 / 101 / 98.5 / 100.8 | 0.8 | 2.5 | 0.2 | 1.5 | Hammer: no |
| Previous | 103 / 103.5 / 99.5 / 100 | 3.0 | 4.0 | 0.5 | 0.5 | Down candle |
| Current | 99.8 / 104.2 / 99.5 / 103.6 | 3.8 | 4.7 | 0.6 | 0.3 | Engulfs: yes |
| D | 50 / 51 / 49 / 50.1 | 0.1 | 2.0 | 0.9 | 1.0 | Doji: yes |
Take candle A. The body is 0.8 and the range is 7.0. One third of the range is 2.33, and the body is below that. Twice the body is 1.6, and the lower wick is 6.0, which is above it. The upper wick is 0.2, and 10 percent of the range is 0.70, so the upper wick is under that too. All three tests pass.
Now raise the low to 98.5, giving candle A2. The lower wick shrinks to 1.5 and twice the body is still 1.6. The test fails. To the eye it still looks hammer-like. To the rule it is nothing.
For the engulfing pair, the previous candle closed at 100, below its open of 103. The current candle opened at 99.8, which is at or below 100, and closed at 103.6, which is at or above 103. All four tests pass. If the current close had been 102.9, it would fail by a tenth of a point.
Candle D has a body of 0.1 and a range of 2.0. The body is 5.0 percent of the range, under the 10 percent line, so it is a doji.
The subjectivity problem
A person looking at a chart sees a hammer and says "that is a hammer". A bot sees numbers and says yes or no. Between those two is a set of choices, and each choice is a setting.
- How long must the wick be? Twice the body, three times, half the range?
- How small must the body be? One third of the range, one quarter, one tenth?
- Does the pattern need a trend before it? If so, how is the trend measured, and over how many candles?
- Which time frame? A 5 minute chart and a daily chart show different events.
- Does the next candle have to confirm it? By how much?
This matters for two reasons. The first is that a result from one set of choices says nothing about another set. A book that reports that a pattern worked is reporting on its own definition. The second is that a bot builder who tries many settings and keeps the best is doing what the overfitting guide describes: fitting the past, not finding something that lasts.
Counts are the other trap. A tight definition might fire only a handful of times in a long history. A made-up example: a rule that fires 6 times in 2,000 candles gives 6 outcomes. Six outcomes can look good or bad by luck alone. A loose definition fires often, but then it is catching shapes that do not look like the name.
How to backtest a pattern honestly
A backtest runs a rule over past prices to see what it would have done. The general method is in how to backtest. For a candle pattern, these steps matter most.
- Write the rule before looking at results. Fix the cut-offs, the entry, the exit and the stop in advance, and write them down.
- Use only what was known at the time. A candle is only complete at its close. A bot that acts on the high or the low of the candle it is still inside is using the future. Enter on the next candle open at the earliest.
- Include costs. Spread, commission and slippage come out of every trade. A pattern that fires often pays them often.
- Count the trades. Report how many times the rule fired. A small count means the result is weak evidence either way.
- Test more than one market and period. Include rising, falling and flat stretches. A rule that only appears to work in one stretch has probably fitted it.
- Keep data back. Settle the rule on one part of the history, then run it once on a part it has never seen. If you then change the rule and re-run, that part is no longer unseen.
- Compare with a plain baseline. Ask what the same exits and costs would give from entries at random times. If the pattern is no different from random entries, the pattern is not adding anything.
- Look at the worst stretch, not only the average. The deepest fall and the longest losing run decide whether a bot can be run at all.
How bots misuse candle patterns
A bot that trades one named shape on its own ignores the setting around it. A hammer inside a long fall can be followed by more falling. An engulfing candle in a thin, quiet market can be a single large print and nothing more. Builders add filters, such as a trend test. Each filter is another setting and another chance to fit the past, so the tests above apply to the whole stack, not to one rule.
Patterns that span several candles, such as the shapes in chart patterns, add more freedom still, because the pieces are not fixed in size.
What it does not tell you
A candle pattern is a description of what price just did. It is not a forecast, and a name does not give it meaning. Nothing here says how often a pattern works, or that it works. That is a question for your own tested data, with your own costs, and a rule that passes a test is still not a promise about the future.
Keep Going
Related Tools and Guides
Keep exploring
FAQ
Frequently Asked Questions
What do the parts of a candlestick mean?
The body runs from the open to the close. The wicks run from the body to the high and the low. Together they show four prices for one period.
How can a bot detect a hammer?
Write it as numbers: a body of at most a third of the range, a lower wick of at least twice the body, and a small upper wick. The cut-offs are choices, not standards.
Why do two people disagree about a pattern?
The names are loose. One person accepts a wick of 1.5 times the body and another wants 3. A bot forces the choice into a number and shows how sensitive the answer is.
How do I backtest candlestick patterns?
Fix the rule first, act only after the candle closes, include costs, count the trades, test several markets and keep unseen data back. Compare with random entries.
Can a few matches prove a pattern works?
No. A small number of matches can look good or bad by chance. A made-up 6 matches in 2,000 candles is too few to say anything.
Are the numbers on this page real?
Example numbers are made up to show how the maths works, and the page says so. A figure only counts as exact when the page says it was calculated on a stated date. Nothing you enter in a calculator leaves your browser.
Can I use this to decide whether to run a bot?
It can show whether a bot's numbers hold together and how much an account can lose. It cannot say what the market will do, and it is not advice. Use it to ask better questions, then read the terms of your own broker or exchange.
Is this financial advice?
No. It is general education about how candles and rules are defined. The numbers are made up and nothing here is a signal.
Know the Risk Before You Run It
Free calculators and guides, added every week. Leave your details and we will email you when new ones go up.
Trading carries a risk of loss