Indicator · Pine Script v6 · On the chart

Inside Bar Chain Detector

by major

Inside Bar Chain Detector identifies sequences of inside bars fully contained within the prior bar's high-low range on price charts.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv6current
Lines of code76
Settings4inputs
LicenceApache-2.0
Last update3 months ago29 Jul 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

76 lines of Pine Script v6 from inside_days/inside_days.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

inside_days.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MajorThorn

//@version=6
indicator('Inside Bar Chain Detector', shorttitle='Inside Chain 🔗', overlay=true, max_labels_count=500)

// ============================================================================
// 📊 USER INPUTS
// ============================================================================

// Visual Settings
showLabels = input.bool(false, 'Show Chain Info Labels', tooltip='Display labels showing chain length and range contraction percentage')
markerColor = input.color(color.yellow, 'Marker Color', tooltip='Color of the marker displayed below inside bars')
labelColor = input.color(color.new(color.white, 0), 'Label Text Color', tooltip='Color of the text in chain info labels')
labelBgColor = input.color(color.new(color.blue, 20), 'Label Background', tooltip='Background color for chain info labels')

// ============================================================================
// 📈 INSIDE BAR CHAIN DETECTION LOGIC
// ============================================================================

// An inside bar fits completely within the previous bar's range
// High must be lower than previous high AND low must be higher than previous low
isInsideBar = high < high[1] and low > low[1]

// Track anchor bar (the bar that starts the chain) using state variables
var float anchorHigh = na  // High of the anchor bar
var float anchorLow = na   // Low of the anchor bar
var int chainLength = 0     // Number of bars in current chain (including anchor)

// When we find an inside bar, check if we're continuing a chain or starting a new one
if isInsideBar
    if chainLength == 0
        // First inside bar in a new chain - the anchor is the previous bar
        anchorHigh := high[1]
        anchorLow := low[1]
        chainLength := 2  // Anchor + this inside bar
    else
        // Continuing existing chain
        chainLength := chainLength + 1
else
    // Chain broken - reset
    anchorHigh := na
    anchorLow := na
    chainLength := 0

// Calculate range contraction relative to anchor bar
currentRange = high - low
anchorRange = anchorHigh - anchorLow
rangeContraction = not na(anchorRange) and anchorRange > 0 ? (currentRange / anchorRange) * 100 : na

// ============================================================================
// 🎨 VISUAL OUTPUT
// ============================================================================

// Mark every inside bar with a yellow diamond below the bar
plotshape(
     series=isInsideBar,
     location=location.belowbar,
     style=shape.diamond,
     size=size.auto,
     color=markerColor,
     title='Inside Bar Marker'
     )

// Show optional labels with chain length and range contraction
if showLabels and isInsideBar and not na(rangeContraction)
    labelText = str.format('Chain: {0}\nCompression: {1}%', chainLength, str.tostring(rangeContraction, '#.#'))
    label.new(
         bar_index,
         low,
         text=labelText,
         style=label.style_label_up,
         color=labelBgColor,
         textcolor=labelColor,
         size=size.small
         )

Overview

Inside Bar Chain Detector marks each inside bar with a diamond below the bar and optionally shows labels with chain length and range contraction percentage relative to the anchor bar. The indicator tracks consecutive inside bars forming chains and resets the chain when broken. Main settings control label visibility and colors for markers and text. It plots directly on the price chart with no separate pane. This is a detection tool only and provides no trading signals, entries, exits, stop losses or take profits.

Details

Published by

major on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Show Chain Info LabelsboolfalseshowLabels
Marker Colorcolorcolor.yellowmarkerColor
Label Text Colorcolorcolor.new(color.white, 0)labelColor
Label Backgroundcolorcolor.new(color.blue, 20)labelBgColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - VWAP

Candlestick Patterns

by harryguiacorn
219 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers