Indicator · Pine Script v4 · On the chart

Real-Time Volume Analyzer Template

by LysergikProductions· code credited to Lysergik

A real-time volume indicator template that tracks intrabar tick execution to classify volume into bullish and bearish tallies.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code171
Settings5inputs
LicenceAGPL-3.0
Last update4 years ago5 Oct 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

171 lines of Pine Script v4 from Tick-Based_OrderVolumeTally_template.pine, published under AGPL-3.0. Keep the author's credit and licence lines when you reuse it.

Tick-Based_OrderVolumeTally_template.pine
//@version=4
// LICENSE: AGPLv3 (https://www.gnu.org/licenses/agpl-3.0.en.html)
// Copyright (C) 2021  Lysergik Productions (https://github.com/LysergikProductions)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.

// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

// set overlay == `false` if you want to plot data in its own pane
study(title="Real-Time Volume Analyzer Template", shorttitle="Real-Time Volume Analyzer", format=format.volume, precision=2, scale=scale.right, overlay=true)

i_posColor = input(color.rgb(38, 166, 154), title="Positive Color")
i_negColor = input(color.rgb(240, 83, 80), title="Negative Color")

var bool showPercent = input(true, title='Show Percentages')

var buCol = color.black
var beCol = color.black

varip int ticks = 0
varip lastPrice = close
varip lastVol = volume
varip float volChange = 0.0

varip bool isLate = false // This will be true when the script recognizes it has not seen data for the current candle's first tick
varip string lastDir = 'null' // This is used to store the previous tick's affect on the current candle; up or down

varip float diff = 0.0 // This will equal `bullOrder - bearOrder`
varip float bullOrder = 0.0
varip float bearOrder = 0.0
varip float bullPercent = 0.0
varip float bearPercent = 0.0

if barstate.isnew and volume != 0
    isLate := true
    buCol := color.black
    beCol := color.black

if barstate.isrealtime and lastPrice != close and lastVol != volume
    ticks += 1
    if not isLate
        volChange := abs(volume-lastVol)
    
    if close < lastPrice
        lastDir := 'down'
        bearOrder += volChange
        bearPercent := bearOrder / volume * 100
        buCol := color.black
        beCol := i_negColor
        
    else if close > lastPrice
        lastDir := 'up'
        bullOrder += volChange
        bullPercent := bullOrder / volume * 100
        buCol := i_posColor
        beCol := color.black
    
    lastPrice := close
    lastVol := volume
    isLate := false

// there was a tick but price did not change, so add half of volChange to each tally, unless last direction was known, then add it to that tally
else if barstate.isrealtime and lastPrice == close and lastVol != volume
    ticks += 1
    if not isLate
        volChange := abs(volume-lastVol)
        if lastDir == 'up'
            bullOrder += volChange
            buCol := i_posColor
            beCol := color.black
        else if lastDir == 'down'
            bearOrder += volChange
            buCol := color.black
            beCol := i_negColor
        else if lastDir != 'up' and lastDir != 'down'
            bullOrder += volChange/2
            bearOrder += volChange/2
            buCol := color.black
            beCol := color.black

    lastPrice := close
    lastVol := volume
    isLate := false

// reset values when a new candle is detected
if barstate.isnew
    ticks := 0
    lastVol := 0
    bullOrder := 0
    bearOrder := 0
    bullPercent := 0
    bearPercent := 0

diff := bullOrder-bearOrder
var table perfTable = table.new(position.bottom_right, 1, 4, border_width = 3)

text_size = input("AUTO", "Text Size:", options=["AUTO", "TINY","SMALL", "NORMAL", "LARGE", "HUGE"])
table_size = input(6, "Table Width:")

text = size.auto
if text_size == "TINY"
    text := size.tiny
else if text_size == "SMALL"
    text := size.small
else if text_size == "NORMAL"
    text := size.normal
else if text_size == "LARGE"
    text := size.large
else if text_size == "HUGE"
    text := size.huge

x = "k"
vol1 = volume
bu1 = bullOrder
be1 = bearOrder

if lastVol < 1000
    x := ""
if lastVol >= 1000
    vol1 := volume / 1000
    bu1 := bullOrder / 1000
    be1 := bearOrder / 1000
if lastVol >= 1000000
    x := "M"
    vol1 := volume / 1000000
    bu1 := bullOrder / 1000000
    be1 := bearOrder / 10000000
if lastVol >= 1000000000
    x := "B"
    vol1 := volume / 1000000000
    bu1 := bullOrder / 1000000000
    be1 := bearOrder / 1000000000

a = array.new_float(0)
for i = 1 to 20
    array.push(a, vol1[i])

m1c = security(syminfo.tickerid, '1', close)
m1o = security(syminfo.tickerid, '1', open)

f_fillCell(_table, _column, _row, _value, _timeframe) =>
    _c_color = m1c > m1o ? i_posColor : i_negColor
    _transp = 85
    _cellText = tostring(_value, "#.##") + x
    
    if showPercent == true
        _cellText := tostring(_value, "#.##") + x + ' (' + tostring(_value/vol1*100, "0.0") + '%)'
    
    table.cell(_table, _column, _row, _cellText, text_color = color.white, width = table_size)
    
    table.cell_set_text_size(perfTable, 0, 0, text)
    table.cell_set_text_size(perfTable, 0, 1, text)    
    table.cell_set_text_size(perfTable, 0, 2, text)
    
    table.cell_set_bgcolor(perfTable, 0, 0, close > open ? color.new(i_posColor, _transp) : color.new(i_negColor, _transp))
    table.cell_set_bgcolor(perfTable, 0, 1, color.new(buCol, _transp))    
    table.cell_set_bgcolor(perfTable, 0, 2, color.new(beCol, _transp))

if barstate.islast
    f_fillCell(perfTable, 0, 0, vol1 , "vol1")
    f_fillCell(perfTable, 0, 1, bu1, "bu1")
    f_fillCell(perfTable, 0, 2, be1, "be1")

Overview

Utilizing intrabar variables, it calculates volume changes on live price updates and tracks buyer versus seller volume percentages per candle. Users can adjust positive and negative color settings and toggle percentage displays. Because calculations depend on real-time tick updates, intrabar tick distribution data is not saved or reproducible on historical bars.

Details

Published by

LysergikProductions on GitHub

Code credit

Lysergik, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Volume, Screeners & dashboards

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
Positive Colorcolorcolor.rgb(38, 166, 154)i_posColor
Negative Colorcolorcolor.rgb(240, 83, 80)i_negColor
Show PercentagesbooltrueshowPercent
Text Size:stringAUTOtext_size
Table Width:int6table_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

This overlay indicator screens a pasted list of up to forty symbols and draws a table on the price chart. It classifies bullish or bearish setups from the percent change between the current candle and the candle 250 bars back, then shows RSI with a simple movi

Indicator v5 Oscillators & momentumVolume
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

Daily Volume

by benso87
24 stars

Daily Volume is an overlay indicator that displays current daily volume statistics inside an on-chart table in the top-right corner. It fetches higher-timeframe daily data to report real-time current daily volume, yesterday's total volume, and a simple moving

Indicator v5 VolumeScreeners & dashboards
Updated 4 years ago · MPL-2.0 GitHub repository of Daily Volume

Equity Intraday Analyst

by chris-c-thomas
14 stars

Equity Intraday Analyst is a comprehensive intraday overlay indicator for US equities and ETFs. It evaluates multi-EMA ribbons, session-anchored VWAP bands, OBV trends, momentum oscillators, TTM Squeeze, and optional market breadth indicators like NYSE TICK an

Indicator v6 TrendVolume
Updated 6 months ago · MIT GitHub repository of Equity Intraday Analyst

This daily-timeframe indicator provides futures market context by evaluating open interest and term structure without altering chart price scales. It requests front-month and next-month futures contracts to measure spread relationships like contango or backwar

Indicator v6 VolumeScreeners & dashboards
Updated yesterday · MIT GitHub repository of Futures Context Module [WavesUnchained]

Nexural QWAP

by JasonTeixeira
9 stars

Nexural QWAP calculates a volume-weighted average price combined with a cumulative volume delta order flow engine directly on the main price chart. It analyzes market structure by detecting volume absorption, liquidity sweeps, price-CVD divergence, stacked imb

Indicator v6 SMC / ICT / price actionVolume
Updated 12 days ago · Custom licence GitHub repository of Nexural QWAP

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