Inside Bar and Outside Bar Highlighter
An inside bar occurs when a candle's range (high minus low) is entirely contained within the previous candle's range. An outside bar occurs when a candle's range completely engulfs the previous candle's range. Both patterns signal shifts in price volatility and trader activity. This indicator colors chart backgrounds and places markers to highlight these bars, allowing traders to spot consolidation and expansion zones at a glance without manual scanning.
//@version=6
indicator("Inside Bar & Outside Bar Highlighter", overlay=true)
// Input colors and toggles
insideBarColor = input.color(color.new(color.blue, 85), "Inside Bar Color")
outsideBarColor = input.color(color.new(color.red, 85), "Outside Bar Color")
showMarkers = input(true, "Show Markers")
markerSize = input.string("small", "Marker Size", options=["tiny", "small", "normal", "large", "huge"])
// Identify inside bar: high < previous high AND low > previous low
isInsideBar = high < high[1] and low > low[1]
// Identify outside bar: high > previous high AND low < previous low
isOutsideBar = high > high[1] and low < low[1]
// Highlight background
bgcolor(isInsideBar ? insideBarColor : na, title="Inside Bar Highlight")
bgcolor(isOutsideBar ? outsideBarColor : na, title="Outside Bar Highlight")
// Plot markers for visibility
if showMarkers
plotshape(isInsideBar, style=shape.diamond, location=location.abovebar,
color=color.blue, size=markerSize, title="Inside Bar Marker")
plotshape(isOutsideBar, style=shape.diamond, location=location.abovebar,
color=color.red, size=markerSize, title="Outside Bar Marker")
How the code works
The indicator compares each candle's high and low to the previous bar's high and low using array notation: high[1](#ref-1) and low[1](#ref-1) reference the prior candle's prices.
An inside bar exists when the current high is strictly less than the prior high (high < high[1](#ref-1)) AND the current low is strictly greater than the prior low (low > low[1](#ref-1)). This means the entire range of today's candle sits within yesterday's range.
An outside bar forms when the current high exceeds the prior high (high > high[1](#ref-1)) AND the current low undercuts the prior low (low < low[1](#ref-1)). The current candle's range wholly contains the previous bar's range.
The code applies a semi-transparent background color (85% transparency, allowing the candles beneath to remain visible) to each candle meeting either condition. A small diamond marker appears above the bar for additional confirmation. User inputs allow customization of colors and the option to disable markers if preferred.
No lookahead or future data is used; the comparison only references the immediately previous bar, so no repainting occurs.
Reading it on a chart
Inside bars (highlighted in blue by default) signal price consolidation. The market has contracted: the day's range is smaller than the previous day's, and it sits entirely within that prior range. Traders often view inside bars as a pause or "spring" before a directional move. The consolidation can break upward or downward; the inside bar itself does not predict direction.
Outside bars (highlighted in red by default) signal expansion and increased volatility. The current bar's range exceeds the prior bar in at least one direction (or both). Traders sometimes interpret outside bars as breakout signals or signs of renewed interest. An outside bar that closes near its high, for instance, may attract bullish attention; one closing near its low may draw bearish traders.
In practice, traders may chain these observations: an inside bar following a downtrend can precede an upswing, but only if confirmed by price action afterward. Similarly, an outside bar can be a false breakout if the following bars reverse. The indicator is a pattern-identification tool, not a prediction or trade signal by itself.
Limitations
This indicator has no inherent predictive power. Inside and outside bars are purely mechanical definitions based on range comparison; they do not indicate whether price will rise, fall, or remain flat. A long inside bar can occur before either an explosive move or continued sideways drift.
The indicator is most useful on timeframes where candle structure matters to the trader's strategy (typically 15-minute to daily charts). On very short timeframes (1-minute, 5-minute), inside and outside bars may occur so frequently they become noise. On very long timeframes (weekly, monthly), they occur infrequently and may miss important price action in between bars.
Market context matters. An inside bar in a strong uptrend carries different implications than one in a choppy, range-bound market. The indicator does not account for volume, trend direction, support/resistance levels, or other market structure, it only highlights the candle pattern itself.
False signals are common. An outside bar can reverse sharply on the next candle, or an inside bar can fail to produce any significant move. Traders using this pattern must combine it with other filters (trend confirmation, volume analysis, support/resistance) to improve reliability.
Finally, the indicator operates only on the bar-by-bar close. Intrabar wicks or price rejections that occur during the candle formation are invisible; once the bar closes, the pattern is fixed.
Key definitions
Inside Bar: A candle whose high is lower than the previous candle's high and whose low is higher than the previous candle's low, indicating price consolidation within the prior bar's range.
Outside Bar: A candle whose high is higher than the previous candle's high and whose low is lower than the previous candle's low, indicating price has expanded beyond the prior bar's range in at least one direction.
Volatility: The magnitude of price fluctuation; contracting range (inside bar) implies lower volatility, expanding range (outside bar) implies higher volatility.
Repainting: A technical error where an indicator's value changes retroactively as new data arrives; this indicator does not repaint because it compares only to the prior closed bar.
Lookahead Bias: Using future data in calculations where only historical data should be available; this indicator avoids lookahead by referencing only the previous bar, never future bars.
References
- Investopedia, "Inside Bar," Investopedia. Https://www.investopedia.com/terms/i/inside_bar.asp
- TradingView, Pine Script Documentation v6, TradingView. Https://www.tradingview.com/pine-script-docs/
- CME Group, "Candlestick Charts and Price Action," CME Education. Https://www.cmegroup.com/education.html
Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.
Last reviewed by the PropLedger research pipeline: 2026-10-25. Educational research on historical data, not financial advice.
Keep reading
Swing Structure: BOS and CHoCH Marker
Free open-source Pine Script indicator: swing high/low structure marker (BOS and CHoCH labels). Full code and a plain-English walkthrough.
Spread Tracker: Two Futures Contracts
Free open-source Pine Script indicator: spread tracker between two related futures contracts. Full code and a plain-English walkthrough.
New High / New Low Breadth
Free open-source Pine Script indicator: new high/new low breadth proxy for a symbol basket. Full code and a plain-English walkthrough.