Indicator · Pine Script v4 · On the chart

Equivolume Bars

by g-moe· code credited to goodgains

Equivolume Bars renders candlestick bodies and wicks using Pine Script box objects directly on the main price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv4older, still runs
Lines of code144
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

144 lines of Pine Script v4 from Tradingview/equivolume-bars.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

equivolume-bars.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=4
study("Equivolume Bars", overlay = true, max_boxes_count = 500, scale = scale.right)

// @keywords: equivolume-bars, volume-width, box-candles, volume-ratio, lookback-sum, historical-bars, wick-boxes, body-boxes, margin-lines, bar-width, volume-proportional, live-bar, confirmed-bars, up-down-bars, border-boxes, top-margin, bottom-margin, price-range, volume-lookback, chart-scaling

num_boxes =     input(165, title = "Number of equivolume boxes to display", maxval = 165, tooltip = "Maximum 165")
lb =            input(60, title = "Volume lookback", tooltip = "Number of bars to sum")
full_width =    input(500, title = "Full width in number of bars", tooltip = "Width where current bar's volume = sum of volume lookback\nHigher values result in less rounding with the trade off of using more chart space")
up_col =        input(color.white, title = "Up bar color")
dn_col =        input(color.blue, title = "Down bar color")
hl_col =        input(color.gray, title = "Wick color")
border_col =    input(color.rgb(255, 255, 255, 66), title = "Border color")
top_perc =    input(8, title = "Top margin %")
bottom_perc = input(20, title = "Bottom margin %")



// -----------------------------------------------------------------------------
// Equivolume Calculation
// -----------------------------------------------------------------------------
float   sum_volume =    sum(volume, lb)
float   ratio =         volume / sum_volume[1]
int     width =         max(round(ratio * full_width), 1) // Determines width of equivolume box in bars
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
// Current live bar
// -----------------------------------------------------------------------------
var box current_body =  box.new(left = na, top = na, right = na, bottom = na, border_width = 1, border_color = border_col)
var box current_high =  box.new(left = na, top = na, right = na, bottom = na, border_width = 1, border_color = border_col, bgcolor = hl_col)
var box current_low =   box.new(left = na, top = na, right = na, bottom = na, border_width = 1, border_color = border_col, bgcolor = hl_col)

box.set_lefttop(current_body,       left = bar_index,           top = max(close,open))
box.set_rightbottom(current_body,   right = bar_index + width,  bottom = min(close, open))

box.set_bgcolor(current_body,       color = close >= open ? up_col : dn_col)

box.set_lefttop(current_high,       left = bar_index,           top = high)
box.set_rightbottom(current_high,   right = bar_index + width,  bottom = max(close, open))

box.set_lefttop(current_low,        left = bar_index,           top = min(close, open))
box.set_rightbottom(current_low,    right = bar_index + width,  bottom = low)
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
// Historical bars
// -----------------------------------------------------------------------------

// Historical bar values
var float[] historical_body_tops = array.new_float(num_boxes)
var float[] historical_body_bottoms = array.new_float(num_boxes)
var float[] historical_highs = array.new_float(num_boxes)
var float[] historical_lows = array.new_float(num_boxes)
var bool[]  historical_direction = array.new_bool(num_boxes)
var int[]   historical_widths = array.new_int(num_boxes)

// Historical equivolume boxes
var box[]   historical_bodies = array.new_box(na)
var box[]   historical_high_wicks = array.new_box(na)
var box[]   historical_low_wicks = array.new_box(na)

// Initialize historical box arrays
if barstate.isfirst
    for i = 0 to num_boxes - 1
        array.unshift(historical_bodies,        box.new(left = na, top = na, right = na, bottom = na, border_width = 1, border_color = border_col))
        array.unshift(historical_high_wicks,    box.new(left = na, top = na, right = na, bottom = na, border_width = 1, border_color = border_col, bgcolor = hl_col))
        array.unshift(historical_low_wicks,     box.new(left = na, top = na, right = na, bottom = na, border_width = 1, border_color = border_col, bgcolor = hl_col))
        
// Once the current live bar is on it's last update
if barstate.isconfirmed
    // Add the latest bar's values to historical arrays and remove the oldest
    array.unshift(historical_body_tops, max(open, close)),      array.pop(historical_body_tops)
    array.unshift(historical_body_bottoms, min(open, close)),   array.pop(historical_body_bottoms)
    array.unshift(historical_highs, high),                      array.pop(historical_highs)
    array.unshift(historical_lows, low),                        array.pop(historical_lows)
    array.unshift(historical_direction, close >= open),         array.pop(historical_direction)
    array.unshift(historical_widths, width),                    array.pop(historical_widths)
    
    int offset = 0 // used to track the starting bar_index for subsequent historical bars
    
    for i = 0 to num_boxes - 1
        // Ensure we don't try and draw on a negative bar index
        if offset < bar_index
            // get values for historical bar : i
            high_box =  array.get(historical_high_wicks, i)
            low_box =   array.get(historical_low_wicks, i)
            body_box =  array.get(historical_bodies, i)
            box_width = array.get(historical_widths, i)
        
            left_index =    bar_index - offset - box_width
            right_index =   bar_index - offset
        
            body_top_val =      array.get(historical_body_tops, i)
            body_bottom_val =   array.get(historical_body_bottoms, i)
            high_val =          array.get(historical_highs, i)
            low_val =           array.get(historical_lows, i)
            up_bar =            array.get(historical_direction, i)
            
            //update offset for next historical bar
            offset := offset + box_width + 1        

            // adjust box properties for historical bar
            box.set_lefttop(body_box, left = left_index, top = body_top_val)
            box.set_rightbottom(body_box, right = right_index, bottom = body_bottom_val)
            box.set_bgcolor(body_box, color = up_bar ? up_col : dn_col)
        
            box.set_lefttop(high_box, left = left_index, top = high_val)
            box.set_rightbottom(high_box, right = right_index, bottom = body_top_val)
        
            box.set_lefttop(low_box, left = left_index, top = body_bottom_val)
            box.set_rightbottom(low_box, right = right_index, bottom = low_val)
        else
            break
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
// Setup margin lines
// -----------------------------------------------------------------------------

var line top_margin_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, extend = extend.both, color = color.rgb(0, 0, 0, 100))
var line bottom_margin_line = line.new(x1 = na, y1 = na, x2 = na, y2 = na, extend = extend.both, color = color.rgb(0, 0, 0, 100))

hh = highest(high, num_boxes)
ll = lowest(low, num_boxes)
range = hh - ll
bars_perc = 100 - top_perc - bottom_perc
interval = range / bars_perc
top_margin = hh + interval * top_perc
bottom_margin = ll - interval * bottom_perc

line.set_xy1(top_margin_line, x = bar_index, y = top_margin)
line.set_xy2(top_margin_line, x = bar_index + 1, y = top_margin)
line.set_xy1(bottom_margin_line, x = bar_index, y = bottom_margin)
line.set_xy2(bottom_margin_line, x = bar_index + 1, y = bottom_margin)

Overview

Equivolume Bars adjusts each bar's horizontal width proportionally to its trading volume relative to a historical lookback sum, making high-volume bars appear wider and low-volume bars narrower. Key settings allow customization of the volume lookback length, total scaling width, maximum displayed box count, and color styling for up, down, and wick elements.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Volume

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
Number of equivolume boxes to displayint165num_boxes
Volume lookbackint60lb
Full width in number of barsint500full_width
Up bar colorcolorcolor.whiteup_col
Down bar colorcolorcolor.bluedn_col
Wick colorcolorcolor.grayhl_col
Border colorcolorcolor.rgb(255, 255, 255, 66)border_col
Top margin %int8top_perc
Bottom margin %int20bottom_perc
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

Calculates an Elastic Volume Weighted Moving Average (EVWMA), incorporating trading volume to dynamically adjust moving average responsiveness over a specified lookback length. It plots directly on the price chart as a single moving average line. Optional colo

Indicator v4 Moving averagesVolume
Updated 12 days ago · GPL-3.0 GitHub repository of Elastic Volume Weighted Moving Average

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

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

META-tracker

by Allen1212
303 stars

This indicator overlays historical ARK Invest buy and sell events for META on the price chart. It places green labels below bars for purchases and red labels above bars for sales, with a same-day count of how many selected ARK ETFs traded the stock. The ETF in

Indicator v4 Volume
Updated 2 years ago · None stated GitHub repository of META-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

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