Indicator · Pine Script v4 · On the chart

Poor Man's Volume Profile

by akhilman

This indicator calculates an approximate volume profile directly on the price chart for a specified block of historical bars.

View on GitHub

Repaints Archived by its author

GitHub stars27on the repository
Pine versionv4older, still runs
Lines of code103
Settings5inputs
LicenceMPL-2.0
Last update2 years ago11 Jan 2024

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

103 lines of Pine Script v4 from profile.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

profile.pine
//@version=4
study("Poor man's volume profile", "PMVolProf", overlay=true, max_bars_back={{max_bars_back}})

block_size = input({{block_size}}, "Bars in profile block", minval=10, maxval={{max_bars_back}})
visual_row_width = input({{visual_row_width}}, "Visual row width", minval=10)
show_peaks = input(true, "Show peaks")
use_custom_volume_source = input(false, "Use custom volume source")
volume_source_symbol = input("", "Custom volume source symbol", input.symbol)

BOUNDS_COLOR = color.{{profile_color}}
PROFILE_COLOR = color.new(color.{{profile_color}}, 50)
PEAK_COLOR = color.new(color.{{peak_color}}, 50)

custom_volume = use_custom_volume_source ? security(volume_source_symbol, timeframe.period, volume, lookahead=barmerge.lookahead_on) : volume

////
// Calculate profile
///

block_high = highest(high, block_size)
block_low = lowest(low, block_size)
float highest_row_value = 0

{% for n in range(n_rows) -%}
float row{{n}}_price = na
int row{{n}}_width = 0
float row{{n}}_value = 0.0
row{{n}}_is_peak = false
{% endfor %}

if barstate.islast

    block_height = block_high - block_low
    row_height =  block_height / {{n_rows}}

    {% for n in range(n_rows) -%}
    row{{n}}_low = block_low + row_height * {{n}}
    row{{n}}_high = block_low + row_height * {{n+1}}
    {% endfor %}

    for i = 0 to block_size + 1
        n_rows_affected = 0
        {% for n in range(n_rows) -%}
        bar_row{{n}}_value = 0.0
        if low[i] < row{{n}}_high and high[i] > row{{n}}_low
            bar_row{{n}}_value := nz(custom_volume[i])
            n_rows_affected := n_rows_affected + 1
        {% endfor %}
        {% for n in range(n_rows) -%}
        row{{n}}_value := row{{n}}_value + (n_rows_affected != 0 ? bar_row{{n}}_value / n_rows_affected : 0)
        {% endfor %}

    {% for n in range(n_rows) -%}
    highest_row_value := max(highest_row_value, row{{n}}_value)
    {% endfor %}

    {% for n in range(n_rows) -%}
    row{{n}}_price := (row{{n}}_low + row{{n}}_high ) / 2
    row{{n}}_width := floor(visual_row_width * row{{n}}_value / highest_row_value)
    {% endfor %}

    {% for n in range(n_rows) -%}
    if {% for m in range([n-peak_size, 0]|max, [n+peak_size+1, n_rows]|min) | reject("eq", n) -%}
        {%- if not loop.first %} and {% endif -%}
        row{{n}}_value >= row{{m}}_value
        {%- endfor %}
        row{{n}}_is_peak := true
    {% endfor %}

////
// Draw profile
///

var int first_bar_time = time
if barstate.isfirst
    first_bar_time := time

var line block_high_line = line.new(bar_index, high, bar_index, high, color=BOUNDS_COLOR)
var line block_low_line = line.new(bar_index, low, bar_index, low, color=BOUNDS_COLOR)
{% for n in range(n_rows) -%}
var label row{{n}}_label = label.new(time_close, close, "", xloc=xloc.bar_time, yloc=yloc.price, color=PROFILE_COLOR, style=label.style_label_left, size=size.auto)
{% endfor %}

if barstate.islast
    line.set_xloc(block_high_line, max(time[block_size], first_bar_time), time_close, xloc.bar_time)
    line.set_y1(block_high_line, block_high)
    line.set_y2(block_high_line, block_high)

    line.set_xloc(block_low_line, max(time[block_size], first_bar_time), time_close, xloc.bar_time)
    line.set_y1(block_low_line, block_low)
    line.set_y2(block_low_line, block_low)

    {% for n in range(n_rows) -%}
    row{{n}}_text = ""
    for i = 0 to row{{n}}_width + 1
        row{{n}}_text := row{{n}}_text + "#"
    row{{n}}_color = show_peaks and row{{n}}_is_peak ? PEAK_COLOR : PROFILE_COLOR
    label.set_x(row{{n}}_label, time_close)
    label.set_y(row{{n}}_label, row{{n}}_price)
    label.set_color(row{{n}}_label, row{{n}}_color)
    label.set_textcolor(row{{n}}_label, row{{n}}_color)
    label.set_text(row{{n}}_label, row{{n}}_text)
    {% endfor %}

Overview

Poor Man's Volume Profile divides the high-low price range of the block into discrete rows, distributes bar volume across overlapping rows, and visually plots the profile using text labels. It can optional highlight volume peaks and fetch volume from a custom symbol source. The calculation renders exclusively on the live bar and updates dynamically, and fetching external symbol volume utilizes lookahead.

Details

Published by

akhilman on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Volume, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Bars in profile blockinput{{block_size}}block_size
Visual row widthinput{{visual_row_width}}visual_row_width
Show peaksbooltrueshow_peaks
Use custom volume sourceboolfalseuse_custom_volume_source
Custom volume source symbolsymbolvolume_source_symbol
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
218 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 8 weeks ago · Custom licence GitHub repository of Moon Dev GEX Arrows

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