Inside & Outside Bar Highlighter
An inside bar occurs when a candle's high and low both fall within the previous bar's range, signaling a contraction in volatility and consolidation. An outside bar occurs when a candle breaks beyond both the previous bar's high and low, indicating volatility expansion. Traders use these patterns to identify potential breakouts, reversals, or continuation setups. This indicator automatically highlights both formations, removing the need to scan manually.
//@version=6
indicator("Inside & Outside Bar Highlighter", overlay=true)
// Inputs for toggle and styling
showInsideBar = input(true, "Show Inside Bars")
showOutsideBar = input(true, "Show Outside Bars")
insideBarColor = input(color.new(color.blue, 85), "Inside Bar Color")
outsideBarColor = input(color.new(color.orange, 85), "Outside Bar Color")
// Current and previous bar extremes
currentHigh = high
currentLow = low
prevHigh = high[1]
prevLow = low[1]
// Inside bar: current high lower than previous high, current low higher than previous low
isInsideBar = currentHigh < prevHigh and currentLow > prevLow
// Outside bar: current high higher than previous high, current low lower than previous low
isOutsideBar = currentHigh > prevHigh and currentLow < prevLow
// Highlight bars using background color
if showInsideBar and isInsideBar
barcolor(insideBarColor)
if showOutsideBar and isOutsideBar
barcolor(outsideBarColor)
How the code works
The indicator stores the previous bar's high and low using the history operator [1](#ref-1), then compares them to the current bar's extremes. An inside bar condition is met when both high < high[1](#ref-1) and low > low[1](#ref-1) are true, which means the entire current candle fits within the vertical range of the prior one. An outside bar requires the opposite: high > high[1](#ref-1) and low < low[1](#ref-1), meaning the current bar extends beyond the prior bar in both directions. The barcolor() function applies a semi-transparent background to matching bars, making them visually distinct without obscuring price data. Both conditions are optional via input toggles, allowing traders to focus on one pattern type if preferred. Colors are configurable and default to blue for inside bars and orange for outside bars.
Reading it on a chart
Inside bars appear as candles fully contained within their predecessor's range. They often cluster during quiet markets, sideways consolidation phases, or before major institutional moves. Traders watch for inside bars at support and resistance levels, as breakouts from these tight ranges can generate significant moves. Some scalpers interpret multiple inside bars as a spring-loading effect: the tighter the range, the larger the expected breakout.
Outside bars are visually obvious: they span a wider range than the prior bar, signaling increased participation or volatility. A single outside bar can mark the start of a trend, the reversal of one, or simply a retest of support/resistance. Context matters: an outside bar at the top of a trend may warn of rejection; one at the bottom may signal accumulation. Combining both patterns helps traders map quiet zones (inside bars) and active zones (outside bars) across the timeframe, building a sense of market rhythm.
Limitations
Inside and outside bars are purely mechanical identifiers of volatility contraction and expansion, not predictive tools. They do not indicate direction, probability of breakout success, or profitability. A cluster of inside bars does not guarantee a large move; it only identifies a period of range compression. Markets can contract for weeks, then continue sideways. An outside bar does not confirm a reversal or continuation; it merely records that volatility expanded that day. Countless outside bars occur during consolidation without producing any tradeable move.
The indicator repaints: past bars retain their color only if their relationship to the previous bar does not change retroactively, which is guaranteed with standard OHLC data. However, on first load or when switching timeframes, the most recent bars may highlight or unhighlight as new data arrives and the prior bar closes.
This tool is best used as a filter or scanner within a broader trading plan, not as a standalone signal. Many traders combine inside/outside bars with support/resistance levels, trend structure, or volume analysis. Without context, the indicator can generate false positives and lead to overtrading. The absence of inside or outside bars carries no signal: markets have many ways to move, and flat range-bound bars or dojis exist outside this classification.
Key definitions
Inside bar: A candle whose high is lower than the previous bar's high and whose low is higher than the previous bar's low, indicating a contraction in trading range.
Outside bar: A candle whose high exceeds the previous bar's high and whose low is lower than the previous bar's low, indicating an expansion in trading range.
Volatility: The magnitude of price movement; expanding volatility is often associated with increased trader participation or conviction.
Consolidation: A period of sideways or range-bound price action, characterized by contracting volatility and small average candle size.
Breakout: A move beyond a prior support or resistance level, often preceded by a period of tight range consolidation.
References
- CME Group, "Globex Market Data and Specifications", https://www.cmegroup.com/markets/data.html (accessed 2026)
- TradingView, "Pine Script Language Reference, version 6", https://www.tradingview.com/pine-script-reference/ (accessed 2026)
- Investopedia, "Inside Bar Definition", https://www.investopedia.com/ (accessed 2026)
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-08-30. Educational research on historical data, not financial advice.
Keep reading
Anchored VWAP
Free open-source Pine Script indicator: anchored VWAP from a selectable bar. Full code and a plain-English walkthrough.
Swing Structure & Break of Structure Marker
Free open-source Pine Script indicator: swing high/low structure marker (BOS and CHoCH labels). Full code and a plain-English walkthrough.
Relative Volume vs N-Day Average
Free open-source Pine Script indicator: relative volume vs N-day average. Full code and a plain-English walkthrough.