Indicator · Pine Script v5 · On the chart

Inside bar/outside bar - stats

by TamaraKGreen· code credited to notprofessorgreen

This indicator identifies inside bars and outside bars, classifying each by close direction as bullish or bearish.

View on GitHub

GitHub stars46on the repository
Pine versionv5runs as is
Lines of code108
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update7 weeks ago4 Sep 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

108 lines of Pine Script v5 from Inside and Outside bar stats.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Inside and Outside bar stats.txt
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © notprofessorgreen

//@version=5
indicator("Inside bar/outside bar - stats", shorttitle = 'IB/OB', overlay = true)

get_ib_table_pos(string pos) =>
    result = switch pos
        "Bottom Center" => position.bottom_center
        "Bottom Left" => position.bottom_left
        "Bottom Right" => position.bottom_right
        "Middle Center" => position.middle_center
        "Middle Left" => position.middle_left
        "Middle Right" => position.middle_right
        "Top Center" => position.top_center
        "Top Left" => position.top_left
        "Top Right" => position.top_right
    result


get_ib_size(string size) =>
    result = switch size
        'Tiny' => size.tiny
        'Small' => size.small
        'Normal' => size.normal
        'Large' => size.large
        'Huge' => size.huge
        'Auto' => size.auto
    result

ib_tbl_txt = input.string("small", title="Text Size", options=["tiny", "small", "normal", "large"], group = 'IB stats table - settings')
ib_tbl_pos = get_ib_table_pos(input.string("Bottom Center", "Table Position", options = ['Bottom Center', 'Bottom Left', 'Bottom Right', 'Middle Center', 'Middle Left', 'Middle Right', 'Top Center', 'Top Left', 'Top Right'], group = 'IB stats table - settings'))
text_color = input.color(color.white, title="Text colour", group = 'IB stats table - settings')
bg_color = input.color(color.rgb(50, 50, 50), title="Text colour", group = 'IB stats table - settings')
bd_color = input.color(color.teal, title="Text colour", group = 'IB stats table - settings')


var count_up = 0
var count_dn = 0
var count_up_ob = 0
var count_dn_ob = 0
var ib_up = 0
var ib_dn = 0
var ob_up = 0
var ob_dn = 0

inside_up = false
inside_dn = false
outside_up = false
outside_dn = false

// Inside bar logic
if high <= high[1] and low >= low[1]
    if close > open
        ib_up += 1
        inside_up := true
    else if close < open
        ib_dn += 1
        inside_dn := true

// Outside bar logic
if high > high[1] and low < low[1]
    if close > open
        ob_up += 1
        outside_up := true
    else if close < open
        ob_dn += 1
        outside_dn := true

// Track counts for inside bars being taken
if inside_up[1] and high > high[1]
    count_up += 1
if inside_dn[1] and low < low[1]
    count_dn += 1

// Track counts for outside bars being taken
if outside_up[1] and high > high[1]
    count_up_ob += 1
if outside_dn[1] and low < low[1]
    count_dn_ob += 1

// Table to display statistics
if barstate.islast
    var tbl = table.new(ib_tbl_pos, 10, 10, bg_color, bd_color, 2, bd_color, 1)
    tbl.cell(1,0, "Count", text_color = text_color)
    tbl.cell(2,0, "Taken", text_color = text_color)
    tbl.cell(3,0, "%", text_color = text_color)

    tbl.cell(0,1, "Inside up", text_color = text_color)
    tbl.cell(0,2, "Inside down", text_color = text_color)
    tbl.cell(0,3, "Outside up", text_color = text_color)
    tbl.cell(0,4, "Outside down", text_color = text_color)

    tbl.cell(1,1, str.tostring(ib_up), text_color = text_color)
    tbl.cell(2,1, str.tostring(count_up), text_color = text_color)
    tbl.cell(3,1, str.tostring(math.round(count_up/ib_up * 100,1)), text_color = text_color)

    tbl.cell(1,2, str.tostring(ib_dn), text_color = text_color)
    tbl.cell(2,2, str.tostring(count_dn), text_color = text_color)
    tbl.cell(3,2, str.tostring(math.round(count_dn/ib_dn * 100,1)), text_color = text_color)

    tbl.cell(1,3, str.tostring(ob_up), text_color = text_color)
    tbl.cell(2,3, str.tostring(count_up_ob), text_color = text_color)
    tbl.cell(3,3, str.tostring(math.round(count_up_ob/ob_up * 100,1)), text_color = text_color)

    tbl.cell(1,4, str.tostring(ob_dn), text_color = text_color)
    tbl.cell(2,4, str.tostring(count_dn_ob), text_color = text_color)
    tbl.cell(3,4, str.tostring(math.round(count_dn_ob/ob_dn * 100,1)), text_color = text_color)

Overview

Inside bar/outside bar - stats tracks cumulative occurrences and evaluates how often subsequent price action breaks the high or low of each pattern. A summary table drawn on the price chart displays total pattern counts, breakout counts, and calculated completion percentages. Configuration settings allow adjustments to table positioning, text size, and background or text colors. The script provides statistical data without generating trading signals or plotting bar shapes.

Details

Published by

TamaraKGreen on GitHub

Code credit

notprofessorgreen, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, Screeners & dashboards, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Text Sizestringsmallib_tbl_txt
Table PositionstringBottom CenterTable Position
Text colourcolorcolor.whitetext_color
Text colourcolorcolor.rgb(50, 50, 50)bg_color
Text colourcolorcolor.tealbd_color
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

32 stars

Ghost Channels fits dynamic parallel trend channels over a configurable lookback window using linear regression or pivot swing methods. It layers confirmation signals onto the channel geometry, detecting candlestick pattern reactions at the rails, volume-confi

Indicator v6 TrendBreakout
Updated 2 days ago · MIT GitHub repository of Ghost Channels [mph1nance]

TheStrat Setup Screener

by 345-strategies
5 stars

This indicator screens Rob Smith's TheStrat setups across six configurable timeframes for TradingView's Pine Screener. It classifies bars and exposes inside reversals, 2-2 reversals and continuations, failing 2s, range expansions, and outside bars as numeric p

Indicator v6 Candlestick patternsSupport & resistance Repaints
Updated 2 days ago · MPL-2.0 GitHub repository of TheStrat Setup Screener
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator
219 stars

Candlestick - Inside Bar Pattern is an overlay indicator that identifies inside bar setups across three consecutive candles. It detects when the price range of the preceding bar is completely contained within the range of the bar prior to it. The direction of

Indicator v5 Candlestick patternsBreakout
Updated 1 year ago · None stated GitHub repository of Candlestick - Inside Bar Pattern

Raschke Patterns

by TradersPost
218 stars

This overlay indicator marks Linda Raschke short-term bar setups on the price chart. It flags Turtle Soup and Turtle Soup plus one false breakouts of a prior extreme, 80-20 bars, inside bars, failed inside-bar breakouts, outside up and down bars, NR4 and NR7 c

Indicator v6 Candlestick patternsBreakout Repaints
Updated 3 months ago · None stated GitHub repository of Raschke Patterns

Five-in-one Strategy

by capissimo
114 stars

Five-in-one Strategy combines five analytical tools into a single price chart overlay: the Dual Thrust Trading Algorithm (DTTA), Semafore, HalfTrend, Nick Rypock Trailing Reverse, and Tweezer or Kangaroo Tail candlestick patterns. It generates trade signals us

Indicator v4 TrendBreakout Repaints
Updated 1 year ago · None stated GitHub repository of Five-in-one Strategy

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