Free lesson · Charts & patterns
Engulfing, inside bars and multi-candle sequences
Open interactive lessonPractice calculationsExplore labs
Start with the idea
Multiple candles add order and relationship to geometry. Translate “engulfing” or “inside” into interval comparisons so there is only one definition in the dataset.
Symbols, units & horizon
- Oₜ,Cₜ,Hₜ,Lₜ: current bar open, close, high and low
- t−1: immediately preceding bar
- [a,b]: interval including endpoints a and b
- <,>: strict inequality
- ≤,≥: inclusive inequality
- Bullish/bearish: rising/falling body in the geometric rule, not a forecast guarantee
When and why to use this
Use sequence rules to study expansion after compression, continuation or reversal conditional on trend and liquidity. Choose a next executable entry after the final required bar.
Bullish body engulfing uses a falling first body and a rising second body whose open-to-close interval covers the first body. Bearish body engulfing reverses the directions. Some authors require strict inequalities and others permit equal endpoints; the lab uses inclusive coverage. Body engulfing does not necessarily engulf the previous high and low.
Compare the two body intervals
- A falling first candle spans [Cₜ₋₁,Oₜ₋₁]. A rising second candle spans [Oₜ,Cₜ].
- For the second interval to contain the first, its lower endpoint must be no higher and its upper endpoint no lower: Oₜ≤Cₜ₋₁ and Cₜ≥Oₜ₋₁. Add the two direction tests.
First O=103,C=100; second O=99,C=104 passes. A second high of 104 still fails to cover a prior high of 105, showing body and full-range engulfing differ.
An inside bar keeps its entire high–low interval within the preceding bar; an outside bar covers the preceding interval. A harami concerns body containment, usually after a larger opposing body. These are distinct events. Using one name for all of them silently changes a backtest’s sample.
Compare the two full trading ranges
- An inside range [Lₜ,Hₜ] lies within [Lₜ₋₁,Hₜ₋₁] when its low is at least the prior low and its high at most the prior high.
- Reverse those inequalities to define an outside range. Equality is included here; identical ranges can satisfy both and should be handled explicitly.
Previous range [98,105], current [99,104] is inside; current [97,106] is outside.
A morning-star narrative combines a large declining body, a small middle body and an advancing third body that recovers into the first. An evening star mirrors it. Classical versions often include gaps; continuous markets and intraday bars may rarely satisfy those gaps. Three white soldiers or three black crows describe successive directional bodies, but body size, open placement, wick limits and prior context still need explicit rules.
A two-bar pattern cannot be known before the second bar closes; a three-bar pattern waits for the third. Any next-open strategy must enter after that recognition time. If a trade is entered during the bar, the current high, low and close are provisional and the rule is a different strategy.
Python implementation
Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.
def two_bar_patterns(previous, current):
"""Each bar is a dict with o,h,l,c; endpoints count as contained."""
p,c=previous,current
for b in (p,c):
if not b['l']<=min(b['o'],b['c'])<=max(b['o'],b['c'])<=b['h']:
raise ValueError("Invalid OHLC")
return {
"bullish_body_engulfing":p['c']<p['o'] and c['c']>c['o'] and c['o']<=p['c'] and c['c']>=p['o'],
"bearish_body_engulfing":p['c']>p['o'] and c['c']<c['o'] and c['o']>=p['c'] and c['c']<=p['o'],
"inside":c['h']<=p['h'] and c['l']>=p['l'],
"outside":c['h']>=p['h'] and c['l']<=p['l']
}
print(two_bar_patterns(dict(o=103,h=105,l=98,c=100),dict(o=99,h=104,l=98,c=104)))Continue learning
Candles, Structures & Pattern Research — all lessons- First principles: what a candle actually records
- Doji, hammer, shooting star and long-body bars
- Engulfing, inside bars and multi-candle sequences
- Trends, ranges, breakouts and chart structures
- Indicators as arithmetic: ATR, moving averages, RSI and bands
- Known strategy families: from chart idea to complete rules
- Pattern recognition: rules, features, shapelets and image models
- Quantitative recognition I: build a causal candle feature table
- Quantitative recognition II: shapelets and constrained dynamic time warping
- Quantitative recognition III: causal encoders and contrastive learning
- Quantitative recognition IV: GAF images, CNNs, transformers and visual-model audits
- Quantitative recognition V: calibrate, abstain and test the complete strategy
- Research review: what the evidence does and does not establish
Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations