Indicator · Pine Script v4 · On the chart

Fr3d0's Volume Profile Visible Range

by WISEPLAT· code credited to Fr3d0C0rl30n3

This indicator builds a volume profile over a chosen number of recent bars and draws it on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code89
Settings3inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago20 Jun 2023

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

89 lines of Pine Script v4 from VPVR.pine.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

VPVR.pine.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Fr3d0C0rl30n3

//@version=4
study("Fr3d0's Volume Profile Visible Range", "VPVR", overlay=true, max_boxes_count=500)

DEFAULT_COLOR = color.new(color.gray, 0)
BORDER_COLOR = color.new(color.black, 80)
BUY_COLOR = color.new(color.green, 0)
SELL_COLOR = color.new(color.red, 0)
TIME_UNIT = time - time[1]

numOfBars = input(90, 'Number of bars', minval=14, maxval=365)
rangeHigh = highest(high, numOfBars)
rangeLow = lowest(low, numOfBars)
rangeHeight = rangeHigh - rangeLow

numOfHistograms = input(50, 'Number of histograms', minval=10, maxval=200)
widestHistogramWidth = input(50, 'Width of the PoC', minval=20, maxval=100)
histogramHeight = rangeHeight / numOfHistograms

histogramLowList = array.new_float(numOfHistograms, na)
histogramHighList = array.new_float(numOfHistograms, na)
histogramPriceList = array.new_float(numOfHistograms, 0.0)

histogramBuyVolumeList = array.new_float(numOfHistograms, 0.0)
histogramSellVolumeList = array.new_float(numOfHistograms, 0.0)
histogramVolumePercentageList = array.new_float(numOfHistograms, 0.0)

if barstate.islast

    // Define lows and highs of the histograms
    for i = 0 to numOfHistograms - 1
        histogramLow = rangeLow + histogramHeight * i
        histogramHigh = rangeLow + histogramHeight * (i + 1)
        array.set(histogramLowList, i, histogramLow)
        array.set(histogramHighList, i, histogramHigh)
        array.set(histogramPriceList, i, (histogramLow + histogramHigh) / 2)
        
    // Assign bar's volumes to histograms
    for i = 0 to numOfBars - 1
        currentBarHeight = high[i] - low[i]
        currentBuyVolume = iff((high[i] == low[i]), 0, volume[i] * (close[i] - low[i]) / currentBarHeight)
        currentSellVolume = iff((high[i] == low[i]), 0, volume[i] * (high[i] - close[i]) / currentBarHeight)
        
        // Define the percentages of the current volume to give to histograms
        for j = 0 to numOfHistograms - 1
            histogramLow = array.get(histogramLowList, j)
            histogramHigh = array.get(histogramHighList, j)
            target = max(histogramHigh, high[i]) - min(histogramLow, low[i])
                   - (max(histogramHigh, high[i]) - min(histogramHigh, high[i]))
                   - (max(histogramLow, low[i]) - min(histogramLow, low[i]))
            histogramVolumePercentage = target / currentBarHeight
            
            histogramBuyVolume = array.get(histogramBuyVolumeList, j)
            histogramSellVolume = array.get(histogramSellVolumeList, j)
            
            // If there is at least one histogram affected
            // then divide the current volume by the number of histograms affected
            if histogramVolumePercentage > 0
                array.set(histogramBuyVolumeList, j, histogramBuyVolume + currentBuyVolume * histogramVolumePercentage)
                array.set(histogramSellVolumeList, j, histogramSellVolume + currentSellVolume * histogramVolumePercentage)
    
    // Find the histogram with the highest volume
    highestHistogramVolume = 0.0
    for i = 0 to numOfHistograms - 1
        histogramBuyVolume = array.get(histogramBuyVolumeList, i)
        histogramSellVolume = array.get(histogramSellVolumeList, i)
        histogramVolume = histogramBuyVolume + histogramSellVolume
        highestHistogramVolume := max(highestHistogramVolume, histogramVolume)
    
    // Draw top and bottom of the range considered
    line.new(time[numOfBars], rangeHigh, time_close, rangeHigh, xloc=xloc.bar_time, color=DEFAULT_COLOR, width = 2)
    line.new(time[numOfBars], rangeLow, time_close, rangeLow, xloc=xloc.bar_time, color=DEFAULT_COLOR, width = 2)
    
    // Draw histograms and highlight the Point of Control
    for i = 0 to numOfHistograms - 1
        histogramLow = array.get(histogramLowList, i)
        histogramHigh = array.get(histogramHighList, i)
        histogramBuyVolume = array.get(histogramBuyVolumeList, i)
        histogramSellVolume = array.get(histogramSellVolumeList, i)
        histogramVolume = histogramBuyVolume + histogramSellVolume
        histogramWidth = widestHistogramWidth * histogramVolume / highestHistogramVolume
        histogramBuyWidth = floor(histogramWidth * histogramBuyVolume / histogramVolume)
        histogramSellWidth = floor(histogramWidth * histogramSellVolume / histogramVolume)
        
        // Draw buy and send histograms
        box.new(left=bar_index + 1, top=histogramHigh, right=bar_index + 1 + histogramBuyWidth, bottom=histogramLow, bgcolor=BUY_COLOR, border_color=BORDER_COLOR)
        box.new(left=bar_index + 1 + histogramBuyWidth, top=histogramHigh, right=bar_index + 1 + histogramBuyWidth + histogramSellWidth, bottom=histogramLow, bgcolor=SELL_COLOR, border_color=BORDER_COLOR)

Overview

Fr3d0's Volume Profile Visible Range splits each bar's range into price bins, assigns a share of volume to the bins the bar overlaps, and separates that volume into buy and sell using the close position inside the bar. The bin with the largest total volume is treated as the point of control, and its histogram is drawn at a user-set maximum width. Lookback length, bin count, and point-of-control width are the main settings. The profile is calculated only on the last bar.

Details

Published by

WISEPLAT on GitHub

Code credit

Fr3d0C0rl30n3, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Volume, Support & resistance

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 barsint90numOfBars
Number of histogramsint50numOfHistograms
Width of the PoCint50widestHistogramWidth
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