Indicator · Pine Script v5 · On the chart

Initial Balance

by MuMuLLC

The Initial Balance indicator highlights high, low, and 50% midpoint levels calculated over a defined session timeframe, such as the opening hour.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code193
Settings19inputs
LicenceMIT
Last update3 years ago28 Dec 2022

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

193 lines of Pine Script v5 from Tradingview/Initial Balance.pinescript, published under MIT. Keep the author's credit and licence lines when you reuse it.

Initial Balance.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MuMuLLC

//@version=5
indicator("Initial Balance", shorttitle="Initial Balance", overlay=true, max_bars_back=5000)

// Options

ib_session = input.session("0930-1030", title="Calculation period for the initial balance", group="Calculation period")

show_extra_levels = input.bool(true, "Show extra levels (IBH x2 & IBL x2)", group="Information")
show_intermediate_levels = input.bool(true, "Show intermediate levels (50%)", group="Information")
show_ib_calculation_area = input.bool(false, "Initial balance calculation period coloration", group="Information")
show_labels = input.bool(true, "Show labels", group="Information")
fill_ib_areas = input.bool(true, "Colour IB areas", group="Information")
only_current_levels = input.bool(true, "Only display the current IB Levels", group="Information")
only_current_zone = input.bool(false, "Only display the current IB calculation area", group="Information")

show_delta_analytics = input.bool(true, "Display IB delta analytics", group="Information")

label_size = input.string("Small", title="Label Size", options=["Auto", "Huge", "Large", "Normal", "Small", "Tiny"], group="Drawings")
lvl_width = input.int(1, "Daily price level width", group="Drawings")
high_col = input.color(color.green, "Initial balance high levels color", group="Drawings")
low_col = input.color(color.red, "Initial balance low levels color", group="Drawings")
middle_col = input.color(#ffa726, "50% initial balance color", group="Drawings")
extend_level = input.string("Right", title="Extend current levels", options=["Right", "Left", "Both", "None"], group="Drawings")

main_levels_style = input.string("Solid" , "Main levels line style", options=["Solid", "Dashed", "Dotted"], group="Drawings")
ext_levels_style = input.string("Dashed" , "Extended levels line style", options=["Solid", "Dashed", "Dotted"], group="Drawings")
int_levels_style = input.string("Dotted" , "Intermediate levels line style", options=["Solid", "Dashed", "Dotted"], group="Drawings")

fill_ib_color= input.color(#b8851faa, "IB area background color", group="Drawings")
ext = extend_level == "Right" ? extend.right : extend_level == "Left" ? extend.left : extend_level == "Both" ? extend.both : extend.none

var delta_history = array.new_float(20)

inSession(sess) => na(time(timeframe.period, sess)) == false

get_line_style(s) =>
    s == "Solid" ? line.style_solid : s == "Dotted" ? line.style_dotted : line.style_dashed

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]

var line ibh = na
var line ibl = na
var line ibm = na
var line ib_plus = na
var line ib_minus = na
var line ib_plus2 = na
var line ib_minus2 = na
var line ibm_plus = na
var line ibm_minus = na

var label labelh = na
var label labell = na
var label labelm = na
var label label_plus = na
var label label_minus = na
var label label_plus2 = na
var label label_minus2 = na
var label labelm_plus = na
var label labelm_minus = na
var box ib_area = na

labelSize = (label_size == "Huge") ? size.huge :
     (label_size == "Large") ? size.large :
     (label_size == "Small") ? size.small :
     (label_size == "Tiny") ? size.tiny :
     (label_size == "Auto") ? size.auto : size.normal

var offset = 0

ins = inSession(ib_session)

bgcolor(show_ib_calculation_area and ins ? #673ab730 : na, title="IB calculation zone")
var float ib_delta = na

if ins
    offset += 1
if ins[1] and not ins
    [h, l, m] = get_levels(offset)
    ib_delta := h - l
    if array.size(delta_history) >= 20
        array.shift(delta_history)
    array.push(delta_history, ib_delta)
    
    line.set_extend(ibh, extend.none)
    line.set_extend(ibl, extend.none)
    if show_intermediate_levels
        line.set_extend(ibm, extend.none)
    if show_extra_levels
        line.set_extend(ib_plus, extend.none)
        line.set_extend(ib_minus, extend.none)
        line.set_extend(ib_plus2, extend.none)
        line.set_extend(ib_minus2, extend.none)
        if show_intermediate_levels
            line.set_extend(ibm_plus, extend.none)
            line.set_extend(ibm_minus, extend.none)
    if show_labels
        if only_current_levels
            label.delete(labelh)
            label.delete(labell)
            label.delete(labelm)
            label.delete(label_plus)
            label.delete(label_minus)
            label.delete(label_plus2)
            label.delete(label_minus2)
            label.delete(labelm_plus)
            label.delete(labelm_minus)
        labelh := label.new(bar_index[offset], h, text="IBH 100%: "+str.tostring(h), style=label.style_none, textcolor=high_col, size=labelSize)
        labell := label.new(bar_index[offset], l, text="IBL 0%: "+str.tostring(l), style=label.style_none, textcolor=low_col, size=labelSize)
        if show_intermediate_levels
            labelm := label.new(bar_index[offset], m, text="IBM 50%: "+str.tostring(m)+"\nIBΔ: "+str.tostring(h - l), style=label.style_none, textcolor=middle_col, size=labelSize)
        if show_extra_levels
            label_plus := label.new(bar_index[offset], h + ib_delta, text="IBH x2 - "+str.tostring(h + ib_delta), style=label.style_none, textcolor=high_col, size=labelSize)
            label_minus := label.new(bar_index[offset], l - ib_delta, text="IBL x2: "+str.tostring(l - ib_delta), style=label.style_none, textcolor=low_col, size=labelSize)
            label_plus2 := label.new(bar_index[offset], h + (ib_delta*2), text="IBH x3 - "+str.tostring(h + (ib_delta*2)), style=label.style_none, textcolor=high_col, size=labelSize)
            label_minus2 := label.new(bar_index[offset], l - (ib_delta*2), text="IBL x3: "+str.tostring(l - (ib_delta*2)), style=label.style_none, textcolor=low_col, size=labelSize)
    if fill_ib_areas
        if only_current_zone
            box.delete(ib_area)
        ib_area := box.new(bar_index[offset], h, bar_index, l, bgcolor=fill_ib_color, border_color=#00000000)//, extend=ext)
    if only_current_levels
        line.delete(ibh)
        line.delete(ibl)
        line.delete(ibm)
        line.delete(ib_plus)
        line.delete(ib_minus)
        line.delete(ib_plus2)
        line.delete(ib_minus2)
        line.delete(ibm_plus)
        line.delete(ibm_minus)
     
    ibh := line.new(bar_index[offset], h, bar_index, h, color=high_col, extend=ext, width=lvl_width, style=get_line_style(main_levels_style))
    ibl := line.new(bar_index[offset], l, bar_index, l, color=low_col, extend=ext, width=lvl_width, style=get_line_style(main_levels_style))
    if show_intermediate_levels
        ibm := line.new(bar_index[offset], m, bar_index, m, color=middle_col, style=get_line_style(int_levels_style), extend=ext, width=lvl_width)
    if show_extra_levels
        ib_plus := line.new(bar_index[offset], h + ib_delta, bar_index, h + ib_delta, color=high_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
        ib_minus := line.new(bar_index[offset], l - ib_delta, bar_index, l - ib_delta, color=low_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
        ib_plus2 := line.new(bar_index[offset], h + (ib_delta*2), bar_index, h + (ib_delta *2), color=high_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)
        ib_minus2 := line.new(bar_index[offset], l - (ib_delta*2), bar_index, l - (ib_delta*2), color=low_col, style=get_line_style(ext_levels_style), extend=ext, width=lvl_width)        
        if show_intermediate_levels
            ibm_plus := line.new(bar_index[offset], h + (ib_delta/2), bar_index, h + (ib_delta/2), color=middle_col, style=get_line_style(int_levels_style), extend=ext, width=lvl_width)
            ibm_minus := line.new(bar_index[offset], l - (ib_delta/2), bar_index, l - (ib_delta/2), color=middle_col, style=get_line_style(int_levels_style), extend=ext, width=lvl_width)
    offset := 0

if (not ins) and (not ins[1])
    line.set_x2(ibh, bar_index)
    line.set_x2(ibl, bar_index)
    if show_intermediate_levels
        line.set_x2(ibm, bar_index)
    if show_extra_levels    
        line.set_x2(ib_plus, bar_index)
        line.set_x2(ib_minus, bar_index)
        line.set_x2(ib_plus2, bar_index)
        line.set_x2(ib_minus2, bar_index)        
        if show_intermediate_levels
            line.set_x2(ibm_plus, bar_index)
            line.set_x2(ibm_minus, bar_index)

var table ib_analytics = table.new(position.bottom_left, 2, 6)

ib_sentiment() =>
    h = array.max(delta_history)
    l = array.min(delta_history)
    a = array.avg(delta_history)
    
    h_comp = ib_delta > h ? ib_delta - h : (ib_delta - h) * -1
    l_comp = ib_delta > l ? ib_delta - l : (ib_delta - l) * -1
    a_comp = ib_delta > a ? ib_delta - a : (ib_delta - a) * -1
    (h_comp < l_comp and h_comp < a_comp) ? "Huge" : (l_comp < h_comp and l_comp < a_comp) ? "Small" : "Medium"
    
if show_delta_analytics
    table.cell(ib_analytics, 0, 0, "IB Delta", bgcolor=color.black, text_color=color.white)
    table.cell(ib_analytics, 0, 1, "20D MAX", bgcolor=color.black, text_color=color.white)
    table.cell(ib_analytics, 1, 1, str.tostring(array.max(delta_history), "#.####"), bgcolor=color.black, text_color=high_col)
    table.cell(ib_analytics, 0, 2, "20D AVG", bgcolor=color.black, text_color=color.white)
    table.cell(ib_analytics, 1, 2, str.tostring(array.avg(delta_history), "#.####"), bgcolor=color.black, text_color=middle_col)
    table.cell(ib_analytics, 0, 3, "20D MIN", bgcolor=color.black, text_color=color.white)
    table.cell(ib_analytics, 1, 3, str.tostring(array.min(delta_history), "#.####"), bgcolor=color.black, text_color=low_col)
    table.cell(ib_analytics, 0, 4, "Today", bgcolor=color.black, text_color=color.white)
    table.cell(ib_analytics, 1, 4, str.tostring(ib_delta), bgcolor=color.black, text_color=color.blue)
    table.cell(ib_analytics, 0, 5, "Status", bgcolor=color.black, text_color=color.white)
    table.cell(ib_analytics, 1, 5, ib_sentiment() , bgcolor=color.black, text_color=color.white)

Overview

Initial Balance draws primary initial balance bounds, optional extended x2 projection levels, intermediate 50% levels, and shaded background zones directly on the price chart. Users can adjust session times, line styles, colors, label sizes, and filter to display only current or historical initial balance levels.

Details

Published by

MuMuLLC on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance, Sessions & time

Markets

Stocks, Indices

Timeframes

M1-M5, 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 balancesession0930-1030ib_session
Show extra levels (IBH x2 & IBL x2)booltrueshow_extra_levels
Show intermediate levels (50%)booltrueshow_intermediate_levels
Initial balance calculation period colorationboolfalseshow_ib_calculation_area
Show labelsbooltrueshow_labels
Colour IB areasbooltruefill_ib_areas
Only display the current IB Levelsbooltrueonly_current_levels
Only display the current IB calculation areaboolfalseonly_current_zone
Display IB delta analyticsbooltrueshow_delta_analytics
Label SizestringSmalllabel_size
Daily price level widthint1lvl_width
Initial balance high levels colorcolorcolor.greenhigh_col
Show all 19 settings
SettingTypeDefaultVariable
Initial balance low levels colorcolorcolor.redlow_col
50% initial balance colorcolor#ffa726middle_col
Extend current levelsstringRightextend_level
Main levels line stylestringSolidmain_levels_style
Extended levels line stylestringDashedext_levels_style
Intermediate levels line stylestringDottedint_levels_style
IB area background colorcolor#b8851faafill_ib_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

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