Indicator · Pine Script v5 · On the chart

OrderBook For Success

by unemployedrabi

Builds a volume-by-price view from the chart's own candles and draws it as horizontal boxes around the current price.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code94
Settings7inputs
LicenceMIT
Last update4 months ago23 Jun 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

94 lines of Pine Script v5 from pinescript-strategies-web/src/orderbook/orderbook.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

orderbook.pine
//@version=5
indicator("OrderBook for success",overlay=true,max_boxes_count=500,max_lines_count=500)
//~~}

// ~~ Inputs {
src   = input.source(close,"Source")
rows  = input.int(10,"Rows",0,20,inline="rows")
mult  = input.float(.5,"Width",.1,2,step=.05,inline="rows")
poc   = input.bool(false,"POC",inline="rows")
tbl   = input.bool(false,"Table",inline="table")
left  = input.int(5,"Left",0,50,5,inline="table")
tbli  = input.bool(false,"Grid",inline="table")
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Variables & Array's {
b = bar_index
var step = 0.0

type Table
    array<box> boxes
    array<line> lines
    array<label> lab

var levels  = array.new<float>()
var volumes = array.new<float>()
var vols    = array.new<float>(rows*2+1)
var tab     = Table.new(array.new<box>(rows*2+2),array.new<line>(rows*2+1),array.new<label>(rows*2+1))
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

// ~~ Code {
//Save first candle size
if barstate.isfirst
    step := (high-low)*mult

//Stores each candle volume in levels
if levels.size()<=0
    levels.push(src+step)
    levels.push(src-step)
    volumes.push(volume)
else
    found = false
    for i=0 to levels.size()-2
        lvl1 = levels.get(i)
        lvl2 = levels.get(i+1)
        if src<lvl1 and src>lvl2
            volumes.set(i,volumes.get(i)+volume)
            found := true
            break
    if not found
        if src>levels.get(0)
            lvl = levels.get(0)
            while src>lvl
                levels.unshift(lvl+step)
                volumes.unshift(0)
                lvl := lvl+step
            levels.unshift(lvl+step)
            volumes.unshift(volume)
        else if src<levels.get(levels.size()-1)
            lvl = levels.get(levels.size()-1)
            while src<lvl
                levels.push(lvl-step)
                volumes.push(0)
                lvl := lvl-step
            levels.push(lvl-step)
            volumes.push(volume)

//Plots the orderbook
if barstate.islast
    for i=0 to levels.size()-2
        if src<levels.get(i) and src>levels.get(i+1)
            for x=0 to (rows*2)
                vols.set(x,volumes.get(math.max(0,i-rows+x)))
            vol = vols.copy()
            vols.sort()
            for x=0 to (rows*2)
                tab.boxes.get(x).delete()
                col = x<rows?color.red:x>rows?color.lime:color.gray
                colgrade = color.from_gradient(vols.indexof(vol.get(x)),0,vols.size(),color.new(col,80),color.new(col,40))
                tab.boxes.set(x,box.new((b+left+rows*2)-vols.indexof(vol.get(x)),levels.get(math.max(0,i-rows+x)),
                 (b+left+rows*2)+vols.indexof(vol.get(x)),levels.get(math.max(1,i-rows+x+1)),
                 colgrade,bgcolor=colgrade,border_style=line.style_dotted,
                 text=str.tostring(vol.get(x),format.volume),text_color=chart.fg_color,
                 extend=poc and vols.indexof(vol.get(x))==rows*2?extend.left:extend.none))
                if tbli
                    tab.lines.get(x).delete()
                    tab.lines.set(x,line.new(b+left,levels.get(i-rows+x),b+left+rows*2+vols.size()-1,levels.get(i-rows+x),
                     color=color.gray))
            if tbl
                tab.boxes.get(rows*2+1).delete()
                tab.boxes.set(rows*2+1,box.new(b+left,box.get_top(tab.boxes.get(0)),
                 b+left+rows*2+vols.size()-1,box.get_bottom(tab.boxes.get(rows*2)),
                 color.gray,border_width=2,bgcolor=color(na)))
            break
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

Overview

Volume is accumulated into price levels sized from the first candle's range, and the boxes are shaded red below and green above the current level, with width scaled by volume. Settings choose the price source, number of rows, width multiplier, an optional point of control line, a table outline and grid lines. It is not real order book data.

Details

Published by

unemployedrabi on GitHub

Draws

On the price chart

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
Sourcesourceclosesrc
Rowsint10rows
Widthfloat.5mult
POCboolfalsepoc
Tableboolfalsetbl
Leftint5left
Gridboolfalsetbli
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

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

MGIC-tracker

by Allen1212
303 stars

The MGIC-tracker is a TradingView indicator that overlays ARK Invest trade records onto stock price charts. It plots buy and sell labels at the exact timestamp of each transaction, showing share volume and ETF weight. Users select a specific ETF type via setti

Indicator v4 Support & resistanceVolume
Updated 2 years ago · None stated GitHub repository of MGIC-tracker
228 stars

Comprehensive Volume Profile is an overlay indicator that calculates and plots volume distribution across specified time ranges such as daily sessions, weekly, monthly, or custom bar lengths. It identifies key structural price levels including the Point of Con

Indicator v6 VolumeSupport & resistance
Updated 3 months ago · None stated GitHub repository of Comprehensive Volume Profile

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 2 months ago · Custom licence GitHub repository of Moon Dev GEX Arrows

More Volume scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers