Indicator · Pine Script v6 · On the chart

NQ Stats - Initial Balance

by TamaraKGreen· code credited to notprofessorgreen

NQ Stats - Initial Balance calculates and displays the Initial Balance range, including the session high, low, and midpoint, for a customizable intraday time window.

View on GitHub

GitHub stars46on the repository
Pine versionv6current
Lines of code131
Settings9inputs
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

131 lines of Pine Script v6 from NQ Stats Initial Balance.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

NQ Stats Initial Balance.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=6
indicator("NQ Stats - Initial Balance", shorttitle="IB", overlay=true, max_bars_back=5000)

// Options
ib_session = input.session("0830-0930", title="Calculation period for the initial balance", group="Calculation period")
fill_ib_areas = input.bool(true, "Colour IB areas", group="Information")
only_current_zone = input.bool(true, "Only display the current IB calculation area", group="Information")
fill_ib_color = input.color(color.rgb(33, 149, 243, 80), "IB area background color", group="Drawings")
border_color = input.color(color.gray, "Box outline color", group="Drawings")
midpoint_color = input.color(color.gray, "Midpoint line color", group="Drawings")
line_style = input.string("Dotted", "Line style for outline and midpoint", options=["Solid", "Dashed", "Dotted"], group="Drawings")
table_position = input.string("Top Right", "Stats Table Position", options=["Bottom Center", "Bottom Left", "Bottom Right", "Middle Center", "Middle Left", "Middle Right", "Top Center", "Top Left", "Top Right"], group="Stats Table")
table_size = input.string("Tiny", "Stats Table Text Size", options=["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group="Stats Table")

// Variables
var box ib_area = na
var line ib_midpoint = na
var table stats_table = na
var offset = 0
var float ib_high = na
var float ib_low = na
var float ib_mid_price = na
var bool ib_formed = false

// Function to check if in session
inSession(sess) =>
    na(time(timeframe.period, sess)) == false

// Function to get high, low, and midpoint
get_levels(n) =>
    h = high[1]
    l = low[1]
    for i = 1 to n
        if low[i] < l
            l := low[i]
        if high[i] > h
            h := high[i]
    [h, l, (h + l) / 2]

// Function to convert string style to line style
get_line_style(s) =>
    s == "Solid" ? line.style_solid : s == "Dashed" ? line.style_dashed : line.style_dotted

// Function to convert table position string to position constant
get_table_position(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

// Function to convert table size string to size constant
get_table_text_size(size) =>
    result = switch size
        "Auto" => size.auto
        "Tiny" => size.tiny
        "Small" => size.small
        "Normal" => size.normal
        "Large" => size.large
        "Huge" => size.huge

ins = inSession(ib_session)

// Increment offset during session
if ins
    offset += 1

// Draw IB box, midpoint line, and stats table when session ends
if ins[1] and not ins
    [h, l, m] = get_levels(offset)
    ib_high := h
    ib_low := l
    ib_mid_price := m
    ib_formed := true

    if fill_ib_areas
        if only_current_zone
            box.delete(ib_area)
            line.delete(ib_midpoint)
        ib_area := box.new(
             left=bar_index[offset], 
             top=h, 
             right=bar_index, 
             bottom=l, 
             bgcolor=fill_ib_color, 
             border_color=border_color, 
             border_style=get_line_style(line_style), 
             border_width=1
         )
        ib_midpoint := line.new(
             x1=bar_index[offset], 
             y1=m, 
             x2=bar_index, 
             y2=m, 
             color=midpoint_color, 
             style=get_line_style(line_style), 
             width=1
         )

    // Create stats table
    if only_current_zone
        table.delete(stats_table)
    stats_table := table.new(
         position=get_table_position(table_position),
         columns=2,
         rows=2,
         bgcolor=color.white,
         border_color=color.black,
         border_width=1,
         frame_color=color.black,
         frame_width=1
     )
    ts = get_table_text_size(table_size)
    // Determine breakout probability based on close position
    breakout_text = close > m ? "High Break: 81%" : "Low Break: 74%"
    // Top row: black background, white text
    table.cell(stats_table, 0, 0, "IB Breakout", bgcolor=color.black, text_color=color.white, text_size=ts, text_font_family=font.family_monospace)
    table.cell(stats_table, 1, 0, "Probability", bgcolor=color.black, text_color=color.white, text_size=ts, text_font_family=font.family_monospace)
    // Second row: white background, black text
    table.cell(stats_table, 0, 1, close > m ? "Closed above midpoint" : "Closed below midpoint", bgcolor=color.white, text_color=color.black, text_size=ts, text_font_family=font.family_monospace)
    table.cell(stats_table, 1, 1, close > m ? "Probability of IB high breakout: 81%" : "Probability of IB low breakout: 74%", bgcolor=color.white, text_color=color.black, text_size=ts, text_font_family=font.family_monospace)

    offset := 0

Overview

Once the defined calculation period ends, the indicator overlays a shaded box and a midpoint line directly on the price chart, along with a statistical table. Inputs allow traders to adjust the session timeframe, customize visual colors and line styles, select whether to display historical ranges or only the active zone, and modify table formatting.

Details

Published by

TamaraKGreen on GitHub

Code credit

notprofessorgreen, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Sessions & time, Support & resistance

Markets

Indices

Timeframes

M15-H1

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
Calculation period for the initial balancesession0830-0930ib_session
Colour IB areasbooltruefill_ib_areas
Only display the current IB calculation areabooltrueonly_current_zone
IB area background colorcolorcolor.rgb(33, 149, 243, 80)fill_ib_color
Box outline colorcolorcolor.grayborder_color
Midpoint line colorcolorcolor.graymidpoint_color
Line style for outline and midpointstringDottedline_style
Stats Table PositionstringTop Righttable_position
Stats Table Text SizestringTinytable_size
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

575 stars

This indicator builds Market Profile Time Price Opportunity (TPO) structures across defined session timeframes directly on the main price chart. It visualizes the Point of Control (POC) and Value Area boundaries using dynamic box drawings. An integrated multi-

Indicator v5 Support & resistanceScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of Market Profile with Screener
257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of Auto Trade Futures ES
219 stars

This indicator plots reference levels for previous daily high and low prices directly on the price chart. It requests daily timeframe data using the security function and plots the offset values as continuous lines, displaying resistance in red and support in

Indicator v4 Support & resistanceSessions & time
Updated 5 years ago · None stated GitHub repository of 昨日高低點標示

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago · None stated GitHub repository of Golden Bullet Strategy

Moon Dev GEX Arrows

by moondevonyt
92 stars

This overlay indicator plots option strike walls and an optional session VWAP on the price chart for SPY or ES. It spaces major strikes by the selected instrument, draws a set number of strikes on each side, and marks wall-trap and sweep events after a cooldow

Indicator v5 Support & resistanceSessions & time
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev GEX Arrows

Key Levels

by cryptorife
75 stars

This indicator plots reference levels and session markers directly on the price chart. It calculates and draws lines for the daily open, weekly open, monthly open, previous day OHLC, and previous week extremes, along with a selectable day-of-week range and ini

Indicator v4 Support & resistanceSessions & time Repaints
Updated 3 years ago · GPL-3.0 GitHub repository of Key Levels

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