In this article
After this article, you can
- Separate body containment from the second candle’s direction.
- Record a custom color filter without attributing it to the library.
Terms at hand: Backtesting · Trading Plan · Balance · Stop loss · Relative Strength Index (RSI)
Harami describes a smaller second real body contained in a larger first one. The name means “pregnant” in Japanese. A bullish version is considered after a decline and a bearish version after an advance. Distinguish body from full High–Low range, define “large” and “small”, and state the chosen colour, edge-equality and context rules. The shape does not prove a reversal or reveal participants’ intentions.
Body containment and color are separate rules
The second candle’s body can occupy the same interval in opposite directions. If your strategy requires opposite colors, record that separately.
Scroll sideways to see the full diagram
Our own data: Arbitrary price units. A and B are alternative second candles after the same first record. The first body is [90; 100], length 10; both variants have body [93; 96], length 3. Their length ratio is 3 / 10 = 30% in both cases.
Our additional rule is: “the second candle has the opposite color to the first.” The first falls. A rises and passes this filter; B falls and fails it. Body containment gives the same answer in both variants.
TA-Lib’s CDLHARAMI code does not require an opposite-colored second body here. It also uses “long” and “short” conditions dependent on settings and history. We have not supplied that history, so we do not calculate the complete function result. The color filter explicitly belongs to our rule; it is not a universal Harami definition or a promise of better results.
| Candle/variant | Open | High | Low | Close |
|---|---|---|---|---|
| First | 100 | 101 | 89 | 90 |
| Second A | 93 | 97 | 92 | 96 |
| Second B | 96 | 97 | 92 | 93 |
What exactly is the harami pattern?
The real body spans Open to Close; the full range spans Low to High. Our exercise requires strict containment: both second-body endpoints lie inside the first body without touching its edges. Second-candle shadows do not enter this particular condition. Thus a harami body can coexist with a second High above the first or Low below it, failing a full-range inside-bar test.
For our own model choose opposite colours: bullish harami has a falling first candle and rising second after a decline; bearish harami reverses those colours after an advance. TradingView describes these opposite-colour variants and allows SMA50, SMA50/SMA200 or no trend detection. TA-Lib’s CDLHARAMI instead does not require the second colour or check trend. Different labels can reflect different definitions rather than bad data.
One name, different detector conditions
Define size numerically before selecting examples. For our own exercise require the first body to be at least 1.5 times the mean body of ten completed preceding candles, and the second to be nonzero and at most half the first. These are arbitrary model settings, not TA-Lib defaults or validated optimal parameters. With a prior mean 40 pips the large-body threshold is 60 pips; a 100-pip first body passes, and a 30-pip second body is below its 50-pip limit. Exclude both pattern candles from that chosen prior mean.
TA-Lib C 0.6.4 uses two different adaptive reference windows. Keep a fictional pair 100/102/88/90 and 93/96/92/96 unchanged: bodies 10 and 3 with strict containment in 90–100. Prepend 12 candles O/H/L=100/106/94 and C=102 or 104. Only preceding closes change.
| Earlier bodies | Second-body reference | Our half-first limit | CDLHARAMI |
|---|---|---|---|
| All 2 | (9×2+10)/10=2.8 | 3≤5: pass | 0 |
| All 4 | (9×4+10)/10=4.6 | 3≤5: pass | 100 |
The first body 10 exceeds both prior means and our 1.5-times threshold. The second is always 30% of the first, yet 3 exceeds 2.8 and is below 4.6. Its TA-Lib reference includes the first pattern candle, not itself. The default function emits 100 for strict containment or 80 at an accepted body edge; neither code is a probability. The existing saved 120-bar Kraken EUR/USD H1 sample, 21–25 September 2026, contains eight nonzero CDLHARAMI codes, including two of magnitude 80. This is classification of one sample, not a profitability test.
What changes in harami cross?
Harami cross uses a second doji with little or no body. “Almost equal” Open and Close requires a stated tolerance or adaptive definition. This geometry does not prove perfect balance between buyers and sellers or disclose their intentions.
A doji-based variant changes the conditions and may change how many candidates are selected. Its name alone establishes no greater reliability. The spinning top and doji candles guide helps compare definitions. Evaluate unchanged rules, execution, costs and exits on comparable data before comparing outcomes.
How does body containment differ from engulfing?
Harami and the bullish and bearish engulfing pattern reverse the direction of body containment: the second is inside the first in harami, whereas the second contains the first in engulfing. Full-range relationships are a separate question. This geometry does not establish an effectiveness ranking.
A pattern is distinct from entry, exit and execution rules. OHLC does not identify which side “took control”; a small second body can have wide shadows. Compare definitions, retained failures and costs rather than treating body order as proof that a market move has already reversed.
What does the harami look like in an example?
These two EUR/USD models are fictional and independent, with a preceding decline assumed for the bullish version and advance for the bearish version. One pip=0.0001. Two candles alone do not document those preceding trends. Both first bodies have 100 pips and second bodies 30 pips, or 30% of the first.
| Model/candle | Open | High | Low | Close |
|---|---|---|---|---|
| Bullish 1 | 1.0900 | 1.0920 | 1.0780 | 1.0800 |
| Bullish 2 | 1.0830 | 1.0940 | 1.0810 | 1.0860 |
| Bearish 1 | 1.0800 | 1.0920 | 1.0780 | 1.0900 |
| Bearish 2 | 1.0870 | 1.0890 | 1.0760 | 1.0840 |
The bullish second body 1.0830–1.0860 is strictly within 1.0800–1.0900, yet High 1.0940 exceeds the first High 1.0920 by 20 pips. It passes our body condition and fails an inside-bar range test. The bearish example similarly has the second Low 20 pips below the first. Size and context conditions still need their own checks; body containment alone is not a complete definition for every detector.
As a separate confirmation rule, require a later completed bullish-model close above both highs, hence above 1.0940. Close 1.0930 fails while 1.0942 passes. The first Open 1.0900 is not its High 1.0920, and neither is the maximum of the pair. This is a chosen observational condition, not an entry instruction or universal harami requirement.
Where do you place the entry, stop-loss and target?
A close-based classification is final only after the second candle closes; earlier its body can change or leave the boundary. Any later confirmation becomes available later still. Record those times separately from the time and quote at a possible order or fill. A later close beyond a level does not justify backdating an entry or infer buyer control.
Harami does not itself specify a stop, target or maximum loss. A chosen exit beyond a particular candle extreme is one strategy input, not a mandatory order derived from its name. Determine position size and reward:risk using actual assumed quote sides, fills and costs. Ordinary stops can execute worse, so a planned level supplies no guaranteed loss ceiling. Compare separately specified entry/exit variants on later data.
How do you confirm a harami and avoid the trap?
The Three Inside Up or Down setup adds further candle conditions. State those conditions explicitly rather than treating any third close in the preferred direction as a universally stronger version. Later confirmation changes the decision time and possible execution; it does not by itself establish fewer false signals.
The RSI indicator can be an additional fixed filter. A price-derived oscillator is not automatically independent evidence from a price candle. Keep size, containment, context and confirmation rules separate, preserving rejected cases rather than selecting favourable historical examples.
What to do tomorrow
- Record the exact body/range, colour, size, trend and edge-equality criteria. Body containment alone does not reproduce every harami detector.
- Choose any later confirmation rule before inspecting outcomes and record when it becomes known. Keep candidate identification separate from execution.
- Specify entry, stop, target and position size as separate inputs, including quote sides and costs. An ordinary stop is not a guaranteed loss ceiling.
- Compare classic and doji variants using the same unchanged data and trade rules, retaining failures. A few journal examples alone do not establish superiority.
- The technical analysis section compares the definitions with engulfing and other patterns. Reversed body containment alone does not prove one strategy stronger.
Check your understanding
One short exercise
About 2 min · you can try again
What changes between variants A and B in this model?
- The second candle’s direction and the custom opposite-color filter result.
- Body placement: B falls outside the first candle.
- The complete TA-Lib result becomes known without history.
Check the answer and explanation
The second candle’s direction and the custom opposite-color filter result.
Open and Close swap places, reversing color. Body interval [93; 96] and its containment remain unchanged.
Frequently asked
What is the harami pattern and where does the name come from?
How does the harami differ from the engulfing pattern?
How do you correctly trade the harami pattern?
Sources & bibliography
-
Candlecharts.com (Steve Nison) Candlestick Trading Courses — Shop · Steve Nison's official shop for educational courses on candlestick patterns. candlecharts.com ↗
-
StockCharts ChartSchool Candlestick Pattern Dictionary · An alphabetical dictionary of candlestick patterns, including harami and harami cross. chartschool.stockcharts.com ↗
-
StockCharts ChartSchool Candlestick Charts — Education Hub · Educational material on candlestick construction and the conventional interpretation of reversal and continuation patterns. chartschool.stockcharts.com ↗
-
TA-Lib CDLHARAMI — pinned C 0.6.4 implementation · Adaptive BodyLong/BodyShort thresholds, strict 100 versus edge 80 classification, no second-colour or trend requirement. Code documentation, not success probabilities. raw.githubusercontent.com ↗
-
TradingView Harami — bullish candlestick pattern · Provider’s opposite-colour bullish variant and selectable SMA50/SMA50-SMA200 or NoDetection trend rules. www.tradingview.com ↗
-
TradingView Harami — bearish candlestick pattern · Provider’s red-second/green-first variant and selectable trend filter, distinguishing its definition from TA-Lib. www.tradingview.com ↗
