Concept 23 / 52·Patterns·Continuation candles
‹ Ichimoku CloudKeltner Channels ›

Inside Bar in Pine Script

inside bar breakout · mother bar · harami · inside day · IB

A bar whose whole range sits inside the previous bar's range, so the market paused; the trigger is the first close outside the mother bar, in whichever direction the pause resolves.

Reads best on: Daily and 4-hour charts on any liquid market, where an inside bar is a full session of contraction. Intraday inside bars work on index futures and major FX when read with the trend.
On this page: the Pine v6 script, checked, drawn on real NVDA bars. Backtest it free, costs charged, every trade on the chart.
01

Definition

An inside bar is a candle whose high is below the previous bar's high and whose low is above the previous bar's low, so its entire range fits inside the bar before it. The earlier, larger bar is the mother bar. The pattern belongs to the continuation candle family: on its own it has no direction, and it becomes a signal when price closes outside the mother bar's range. The candlestick name for a body-only version is the harami, and on daily charts an inside bar is often called an inside day.

The pattern works as a compression. The mother bar set a range in which both sides traded; the inside bar shows that the following session could not reach either edge, so activity contracted and orders built up on both sides. The first close beyond the mother bar's high or low shows which side has given way, and the compression that preceded it tends to release as a directional move. In a trend, an inside bar is usually a one-bar pause before continuation, which is why the pattern is filed with continuation shapes even though the break can go either way.

The inside bar has no inventor; it is a range relation any chart shows. The standard rule uses the full range including wicks, and a break is judged on the close outside the mother bar. The stop sits at the mother bar's other extreme, or at the inside bar's own extreme for a tighter version. Traders vary the definition in two ways. Some require the inside bar to be noticeably smaller than the mother bar. Some allow several consecutive inside bars, treating the whole cluster as one compression with the original mother bar as its range.

On the chart, expect inside bars to be frequent on intraday charts and to matter most on daily and 4-hour charts after a strong directional bar. Expect the implementation to draw the mother bar's high and low as amber lines while the range is armed. It marks Long on the first close above the high and Short on the first close below the low, and clears the lines once either happens. Expect a string of inside bars to move the armed range: each new inside bar re-arms to the range of the bar immediately before it.

02

Reading the chart

Identification is a comparison of two ranges, then a wait for the close that leaves them.

  1. Find a bar whose high is lower than the previous high and whose low is higher than the previous low. Both conditions must hold; a bar that shares one extreme with the mother bar is not inside.
  2. Mark the mother bar's high and low. They are the levels the pattern will resolve against, and the implementation draws them as lines while the range is armed.
  3. Judge the mother bar. A wide-range, directional mother bar after a trend leg makes the compression meaningful; a small mother bar inside chop makes the pattern noise.
  4. Wait for a close outside the range. A wick beyond the mother bar that closes back inside is not a break under the close rule, and the range stays armed.
  5. The rule takes the direction of the break, with the stop at the opposite side of the mother bar, or at the inside bar's opposite extreme for a tighter, more fragile version.
  6. Handle clusters. If another inside bar forms before a break, the implementation re-arms to the range of the bar just before it, so check which range is live before reading a mark.
03

The maths

The pattern is a range comparison, followed by a break test against the stored mother-bar levels.

insidet={1Ht<Ht−1∧Lt>Lt−10otherwise\mathrm{inside}_t = \begin{cases} 1 & H_t < H_{t-1} \land L_t > L_{t-1} \\ 0 & \text{otherwise} \end{cases}
MHt={Ht−1insidet=1MHt−1otherwise\mathrm{MH}_t = \begin{cases} H_{t-1} & \mathrm{inside}_t = 1 \\ \mathrm{MH}_{t-1} & \text{otherwise} \end{cases}
MLt={Lt−1insidet=1MLt−1otherwise\mathrm{ML}_t = \begin{cases} L_{t-1} & \mathrm{inside}_t = 1 \\ \mathrm{ML}_{t-1} & \text{otherwise} \end{cases}
breakup,t={1armedt=1∧Ct>MHt0otherwise\mathrm{break}_{\mathrm{up},t} = \begin{cases} 1 & \mathrm{armed}_t = 1 \land C_t > \mathrm{MH}_t \\ 0 & \text{otherwise} \end{cases}
breakdown,t={1armedt=1∧Ct<MLt0otherwise\mathrm{break}_{\mathrm{down},t} = \begin{cases} 1 & \mathrm{armed}_t = 1 \land C_t < \mathrm{ML}_t \\ 0 & \text{otherwise} \end{cases}
risk=MHt−MLt\mathrm{risk} = \mathrm{MH}_t - \mathrm{ML}_t
Ht,Lt,CtH_t, L_t, C_thigh, low and close of bar t
Ht−1,Lt−1H_{t-1}, L_{t-1}high and low of the previous bar, the mother bar
insidet\mathrm{inside}_tthe inside-bar flag on bar t
MHt,MLt\mathrm{MH}_t, \mathrm{ML}_tthe stored mother-bar high and low, set on an inside bar and held until the next one
armedt\mathrm{armed}_t1 while the stored range waits for its break: set by an inside bar, cleared by the first close outside MH_t or ML_t
breakup,t,breakdown,t\mathrm{break}_{up,t}, \mathrm{break}_{down,t}the breakout flags on bar t
risk\mathrm{risk}the stop distance when the stop sits at the mother bar's far side
ttthe current bar

The comparison is strict. An inside bar must be inside on both sides; an equal high or low fails the test, and a bar with the same high but a higher low is not an inside bar.

The break is a close, not a touch, and it is not time-limited. The range stays armed until a bar closes outside it, however many bars that takes, and a single close either way clears it.

Consecutive inside bars re-arm the range. In the implementation, a second inside bar stores the range of the first inside bar, so the live range narrows to the most recent pair rather than staying at the original mother bar.

The inside bar and the break cannot happen on the same bar, because an inside bar's close is by definition within the mother bar's range.

04

Inputs that matter

InputTypicalWhat changing it does
Inside-bar breakoutsonSwitches the inside-bar range lines and break marks on. Turn the engulfing and pin-bar switches off to study inside bars alone.
EngulfingonThe two-bar reversal in the same script. Off keeps break marks from being mixed with reversal signals.
Hammers and shooting starsonThe single-bar reversals in the same script, usually off when reading continuation breaks.
Break ruleclose outside the mother barA touch rule triggers earlier and includes every wick probe; the close rule waits for the bar to finish and misses fewer false breaks.
05

In practice

  • As a trend continuation entry: an inside bar after a strong bar in the trend direction is a pause. The close beyond the mother bar in that direction is the entry, with the stop at the mother bar's other side.
  • As a breakout trigger at a level: an inside bar that forms right under a resistance level compresses the market against the level, and the close above both is a cleaner breakout than a bar that runs through from far below.
  • As a defined-risk setup: the mother bar's range is the risk, so the reward can be set as a multiple of it before entry, which suits fixed-R position sizing.
  • As a daily-chart filter: inside days are rarer and carry more weight than intraday inside bars, and a scan for inside days after a wide-range day finds compressions worth watching the next session.
  • As a fade in ranges: inside a well-defined range, a break out of a mother bar at the range edge often fails, and the return through the mother bar is the counter-trade.
  • As a scan condition: the implementation marks the first close outside the mother bar and can alert on it. The alert names the direction only, so switch the reversal patterns off when the alert must mean an inside-bar break.
06

Where it goes wrong

  • Trading inside bars in chop. A small mother bar in a sideways market makes a compression of nothing; require a directional mother bar or a level.
  • Entering on the wick. A poke through the mother bar that closes back inside is not a break under the close rule, and the trap it creates often runs the other way.
  • Placing the stop inside the mother bar. The mother bar's other side is where the pattern is wrong; a stop between the inside bar and that level is hit by normal rotation.
  • Losing track of clusters. With several inside bars in a row, the live range in the implementation is the most recent pair's, so a mark can appear on a level narrower than the original mother bar.
07

Compared with

Engulfing Candle. An engulfing is the reverse geometry: the second bar extends beyond the first body and signals reversal at its close. An inside bar sits within the first bar and signals nothing until the break, which can be in either direction.

Hammer & Shooting Star. A hammer makes a directional claim on one bar through its wick, and the claim is complete at the close. An inside bar makes no claim; it records compression, and the direction comes only from the later close that leaves the mother bar.

Volatility Squeeze. A squeeze measures compression over many bars with bands and channels; an inside bar is compression over one bar. Both resolve with expansion, and a squeeze that ends with an inside-bar break is a well-defined trigger.

Breakout. A range breakout is measured against a range built over many bars. An inside-bar break is measured against a single mother bar, so it is faster, tighter and more prone to false breaks, which is why it works best in the direction of the larger trend.

08

Build it in Quant

Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.

Open Inside Bar on the workbench chart
Drawn on real data; then audit, backtest and refine in conversation.
Open in Quant →
09

Questions

  • What counts as an inside bar?

    A bar whose high is below the previous bar's high and whose low is above the previous bar's low, wicks included. Both conditions must hold, so a bar that matches one of the mother bar's extremes does not qualify. The body-only version, where only the open and close sit inside the previous body, is the candlestick harami and is a looser pattern.

  • Which way does an inside bar resolve?

    Whichever side closes first outside the mother bar. In a trend, the break usually goes with the trend, which is why the pattern is filed as a continuation shape, but the implementation marks either direction. Many rules keep only the break in the direction of the larger trend and ignore the other side, or fade it in a range.

  • Where does the stop go?

    At the far side of the mother bar: below its low for a long break, above its high for a short. That is where the compression has failed. A tighter version uses the inside bar's own opposite extreme, which reduces risk but is stopped out by normal rotation more often. Size the trade from the chosen stop distance.

  • What happens when several inside bars form in a row?

    The compression continues and usually resolves harder. In the implementation, each new inside bar re-arms the range to the bar just before it, so with a string of inside bars the live range narrows to the most recent pair. Traders who prefer the original mother bar as the range should note the difference before reading a mark.

  • Does the break have to be a close?

    In the implementation, yes: the Long mark is the first close above the mother bar's high and the Short mark the first close below its low, on confirmed bars. A wick through the level that closes back inside leaves the range armed. A touch rule triggers earlier but includes every failed probe, and failed probes are common at mother-bar edges.

  • Are inside bars better on daily charts?

    Usually. An inside day after a wide-range day is a real contraction across a whole session and is rarer than intraday inside bars, which appear constantly on 5-minute charts. On intraday charts the pattern works when the mother bar is a strong directional bar and the break is read with the higher-timeframe trend.