Indicator · Pine Script v5 · On the chart

Volume Profile Advanced

by Yavuz365

Volume Profile Advanced calculates session-based volume distribution across customizable lookback periods on the main price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code390
Settings14inputs
LicenceMIT
Last update9 months ago19 Jan 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

390 lines of Pine Script v5 from indicators/volume_profile.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

volume_profile.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Yavuz365

//@version=5
indicator("Volume Profile Advanced", overlay=true, max_bars_back=5000, max_boxes_count=500)

// ============================================================================
// INPUTS
// ============================================================================

// Session Settings
session_type = input.string("D", "Session Type", options=["D", "W", "M", "3D", "4H"], group="Session")
lookback_sessions = input.int(5, "Lookback Sessions", minval=1, maxval=50, group="Session")

// Volume Profile Settings
vp_rows = input.int(24, "Profile Rows", minval=10, maxval=100, group="Volume Profile")
value_area_pct = input.float(70, "Value Area %", minval=50, maxval=95, group="Volume Profile")
show_profile = input.bool(true, "Show Profile", group="Volume Profile")
profile_width = input.int(10, "Profile Width", minval=1, maxval=50, group="Volume Profile")

// Display Settings
show_poc = input.bool(true, "Show POC", group="Display")
show_vah_val = input.bool(true, "Show VAH/VAL", group="Display")
show_developing_poc = input.bool(true, "Show Developing POC", group="Display")
extend_lines = input.bool(true, "Extend Lines Right", group="Display")

// Colors
poc_color = input.color(color.new(color.yellow, 0), "POC Color", group="Colors")
vah_val_color = input.color(color.new(color.blue, 50), "VAH/VAL Color", group="Colors")
profile_bull_color = input.color(color.new(color.green, 60), "Profile Bullish", group="Colors")
profile_bear_color = input.color(color.new(color.red, 60), "Profile Bearish", group="Colors")

// ============================================================================
// SESSION DETECTION
// ============================================================================

// Get session timeframe
session_tf = session_type == "3D" ? "3D" : 
             session_type == "4H" ? "240" : 
             session_type

// Detect new session
is_new_session = ta.change(time(session_tf))

var int session_start_bar = 0
var float session_high = na
var float session_low = na
var int session_count = 0

if is_new_session or bar_index == 0
    session_start_bar := bar_index
    session_high := high
    session_low := low
    session_count += 1
else
    session_high := math.max(session_high, high)
    session_low := math.min(session_low, low)

// ============================================================================
// VOLUME PROFILE CALCULATION
// ============================================================================

// Arrays to store volume profile data
var array<float> vp_prices = array.new_float(0)
var array<float> vp_volumes = array.new_float(0)
var array<float> vp_buy_volumes = array.new_float(0)
var array<float> vp_sell_volumes = array.new_float(0)

// Initialize arrays for new session
if is_new_session
    array.clear(vp_prices)
    array.clear(vp_volumes)
    array.clear(vp_buy_volumes)
    array.clear(vp_sell_volumes)
    
    // Initialize rows
    for i = 0 to vp_rows - 1
        array.push(vp_prices, 0.0)
        array.push(vp_volumes, 0.0)
        array.push(vp_buy_volumes, 0.0)
        array.push(vp_sell_volumes, 0.0)

// Build volume profile for current session
if not na(session_high) and not na(session_low) and session_high > session_low
    price_range = session_high - session_low
    row_size = price_range / vp_rows
    
    // Determine which row the current bar belongs to
    for i = 0 to vp_rows - 1
        row_low = session_low + i * row_size
        row_high = session_low + (i + 1) * row_size
        row_mid = (row_low + row_high) / 2
        
        // Check if current price is in this row
        if close >= row_low and close < row_high
            // Update price level
            array.set(vp_prices, i, row_mid)
            
            // Add volume
            current_vol = array.get(vp_volumes, i)
            array.set(vp_volumes, i, current_vol + volume)
            
            // Separate buy and sell volume
            is_buy_volume = close > open
            if is_buy_volume
                current_buy_vol = array.get(vp_buy_volumes, i)
                array.set(vp_buy_volumes, i, current_buy_vol + volume)
            else
                current_sell_vol = array.get(vp_sell_volumes, i)
                array.set(vp_sell_volumes, i, current_sell_vol + volume)
            
            break

// ============================================================================
// CALCULATE POC, VAH, VAL
// ============================================================================

var float poc_price = na
var float vah_price = na
var float val_price = na
var int poc_index = 0

// Find Point of Control (highest volume row)
if array.size(vp_volumes) > 0
    max_volume = 0.0
    max_idx = 0
    
    for i = 0 to array.size(vp_volumes) - 1
        vol = array.get(vp_volumes, i)
        if vol > max_volume
            max_volume := vol
            max_idx := i
    
    poc_index := max_idx
    poc_price := array.get(vp_prices, max_idx)
    
    // Calculate Value Area (70% of volume by default)
    total_volume = 0.0
    for i = 0 to array.size(vp_volumes) - 1
        total_volume += array.get(vp_volumes, i)
    
    target_volume = total_volume * (value_area_pct / 100)
    accumulated_volume = array.get(vp_volumes, max_idx)
    
    upper_idx = max_idx
    lower_idx = max_idx
    
    // Expand value area up and down from POC
    while accumulated_volume < target_volume
        upper_vol = upper_idx < array.size(vp_volumes) - 1 ? array.get(vp_volumes, upper_idx + 1) : 0
        lower_vol = lower_idx > 0 ? array.get(vp_volumes, lower_idx - 1) : 0
        
        if upper_vol == 0 and lower_vol == 0
            break
        
        if upper_vol >= lower_vol and upper_idx < array.size(vp_volumes) - 1
            upper_idx += 1
            accumulated_volume += upper_vol
        else if lower_idx > 0
            lower_idx -= 1
            accumulated_volume += lower_vol
        else if upper_idx < array.size(vp_volumes) - 1
            upper_idx += 1
            accumulated_volume += upper_vol
        else
            break
    
    vah_price := upper_idx < array.size(vp_prices) ? array.get(vp_prices, upper_idx) : na
    val_price := lower_idx < array.size(vp_prices) ? array.get(vp_prices, lower_idx) : na

// ============================================================================
// DRAW VOLUME PROFILE
// ============================================================================

var box[] profile_boxes = array.new_box()

if show_profile and is_new_session and session_count > 1
    // Clear old boxes from previous session
    if array.size(profile_boxes) > vp_rows * lookback_sessions
        for i = 0 to vp_rows - 1
            if array.size(profile_boxes) > 0
                old_box = array.shift(profile_boxes)
                box.delete(old_box)
    
    // Draw new profile
    if array.size(vp_volumes) > 0
        max_volume = 0.0
        for i = 0 to array.size(vp_volumes) - 1
            vol = array.get(vp_volumes, i)
            if vol > max_volume
                max_volume := vol
        
        // Draw each row
        for i = 0 to array.size(vp_volumes) - 1
            vol = array.get(vp_volumes, i)
            if vol > 0
                buy_vol = array.get(vp_buy_volumes, i)
                sell_vol = array.get(vp_sell_volumes, i)
                
                // Calculate box width based on volume
                bar_width = math.floor((vol / max_volume) * profile_width)
                if bar_width < 1
                    bar_width := 1
                
                price_level = array.get(vp_prices, i)
                price_range = session_high - session_low
                row_height = price_range / vp_rows
                
                // Determine color based on buy/sell ratio
                box_color = buy_vol > sell_vol ? profile_bull_color : profile_bear_color
                
                profile_box = box.new(
                     left=session_start_bar,
                     top=price_level + row_height / 2,
                     right=session_start_bar + bar_width,
                     bottom=price_level - row_height / 2,
                     border_color=color.new(box_color, 30),
                     bgcolor=box_color,
                     border_width=1
                 )
                array.push(profile_boxes, profile_box)

// ============================================================================
// DRAW POC, VAH, VAL LINES
// ============================================================================

var line poc_line = na
var line vah_line = na
var line val_line = na
var label poc_label = na
var label vah_label = na
var label val_label = na

if barstate.islast
    // Delete old lines and labels
    line.delete(poc_line)
    line.delete(vah_line)
    line.delete(val_line)
    label.delete(poc_label)
    label.delete(vah_label)
    label.delete(val_label)
    
    // Draw POC line
    if show_poc and not na(poc_price)
        poc_line := line.new(
             x1=session_start_bar,
             y1=poc_price,
             x2=bar_index,
             y2=poc_price,
             color=poc_color,
             width=2,
             style=line.style_solid,
             extend=extend_lines ? extend.right : extend.none
         )
        
        poc_label := label.new(
             x=bar_index,
             y=poc_price,
             text="POC: " + str.tostring(poc_price, format.mintick),
             style=label.style_label_left,
             color=poc_color,
             textcolor=color.white,
             size=size.small
         )
    
    // Draw VAH line
    if show_vah_val and not na(vah_price)
        vah_line := line.new(
             x1=session_start_bar,
             y1=vah_price,
             x2=bar_index,
             y2=vah_price,
             color=vah_val_color,
             width=1,
             style=line.style_dashed,
             extend=extend_lines ? extend.right : extend.none
         )
        
        vah_label := label.new(
             x=bar_index,
             y=vah_price,
             text="VAH: " + str.tostring(vah_price, format.mintick),
             style=label.style_label_left,
             color=vah_val_color,
             textcolor=color.white,
             size=size.tiny
         )
    
    // Draw VAL line
    if show_vah_val and not na(val_price)
        val_line := line.new(
             x1=session_start_bar,
             y1=val_price,
             x2=bar_index,
             y2=val_price,
             color=vah_val_color,
             width=1,
             style=line.style_dashed,
             extend=extend_lines ? extend.right : extend.none
         )
        
        val_label := label.new(
             x=bar_index,
             y=val_price,
             text="VAL: " + str.tostring(val_price, format.mintick),
             style=label.style_label_left,
             color=vah_val_color,
             textcolor=color.white,
             size=size.tiny
         )

// ============================================================================
// PRICE ACTION RELATIVE TO VP LEVELS
// ============================================================================

// Trading signals based on volume profile
price_at_poc = not na(poc_price) and math.abs(close - poc_price) / poc_price * 100 < 0.2
price_above_vah = not na(vah_price) and close > vah_price
price_below_val = not na(val_price) and close < val_price
price_in_value_area = not na(vah_price) and not na(val_price) and close <= vah_price and close >= val_price

// ============================================================================
// VOLUME PROFILE TABLE
// ============================================================================

var table vp_table = na

if barstate.islast
    table.delete(vp_table)
    
    vp_table := table.new(position.middle_right, 2, 6, bgcolor=color.new(color.black, 10), 
                 border_width=2, border_color=color.new(color.gray, 50))
    
    // Header
    table.cell(vp_table, 0, 0, "Volume Profile", bgcolor=color.new(color.blue, 70), 
               text_color=color.white, text_size=size.normal)
    table.merge_cells(vp_table, 0, 0, 1, 0)
    
    // POC
    table.cell(vp_table, 0, 1, "POC:", text_color=color.white)
    table.cell(vp_table, 1, 1, not na(poc_price) ? str.tostring(poc_price, format.mintick) : "-", 
               bgcolor=color.new(poc_color, 70), text_color=color.white)
    
    // VAH
    table.cell(vp_table, 0, 2, "VAH:", text_color=color.white)
    table.cell(vp_table, 1, 2, not na(vah_price) ? str.tostring(vah_price, format.mintick) : "-", 
               bgcolor=color.new(vah_val_color, 70), text_color=color.white)
    
    // VAL
    table.cell(vp_table, 0, 3, "VAL:", text_color=color.white)
    table.cell(vp_table, 1, 3, not na(val_price) ? str.tostring(val_price, format.mintick) : "-", 
               bgcolor=color.new(vah_val_color, 70), text_color=color.white)
    
    // Current Position
    table.cell(vp_table, 0, 4, "Position:", text_color=color.white)
    position_text = price_above_vah ? "Above VA" : price_below_val ? "Below VA" : price_at_poc ? "At POC" : "In VA"
    position_color = price_above_vah ? color.green : price_below_val ? color.red : color.gray
    table.cell(vp_table, 1, 4, position_text, bgcolor=color.new(position_color, 70), text_color=color.white)
    
    // Signal
    table.cell(vp_table, 0, 5, "Signal:", text_color=color.white)
    signal_text = price_below_val ? "Bullish" : price_above_vah ? "Bearish" : price_at_poc ? "Neutral" : "-"
    signal_color = signal_text == "Bullish" ? color.green : signal_text == "Bearish" ? color.red : color.gray
    table.cell(vp_table, 1, 5, signal_text, bgcolor=color.new(signal_color, 70), text_color=color.white)

// ============================================================================
// PLOTTING
// ============================================================================

// Highlight value area
value_area_top = show_vah_val ? vah_price : na
value_area_bottom = show_vah_val ? val_price : na

plot(value_area_top, "VAH", color.new(vah_val_color, 80), linewidth=1, style=plot.style_line)
plot(value_area_bottom, "VAL", color.new(vah_val_color, 80), linewidth=1, style=plot.style_line)

// Fill value area
fill_color = price_in_value_area ? color.new(color.gray, 95) : na
fill(plot(value_area_top, display=display.none), plot(value_area_bottom, display=display.none), fill_color)

// Plot POC
plot(show_poc and show_developing_poc ? poc_price : na, "Developing POC", poc_color, linewidth=2, style=plot.style_circles)

// ============================================================================
// ALERTS
// ============================================================================

alertcondition(price_at_poc, "Price at POC", "Price reached POC on {{ticker}}")
alertcondition(price_above_vah and price_above_vah[1] == false, "Price Above VAH", "Price moved above VAH on {{ticker}}")
alertcondition(price_below_val and price_below_val[1] == false, "Price Below VAL", "Price moved below VAL on {{ticker}}")

Overview

Volume Profile Advanced determines key market profile metrics, including the Point of Control (POC), Value Area High (VAH), Value Area Low (VAL), and a developing POC trajectory. Visual histogram bars illustrate buy and sell volume splits across configurable price rows. Traders can adjust session timeframes, lookback counts, value area percentages, and line extensions to analyze dynamic support, resistance, and high-volume price zones.

Details

Published by

Yavuz365 on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volume, Support & resistance, Sessions & time

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
Session TypestringDsession_type
Lookback Sessionsint5lookback_sessions
Profile Rowsint24vp_rows
Value Area %float70value_area_pct
Show Profilebooltrueshow_profile
Profile Widthint10profile_width
Show POCbooltrueshow_poc
Show VAH/VALbooltrueshow_vah_val
Show Developing POCbooltrueshow_developing_poc
Extend Lines Rightbooltrueextend_lines
POC Colorcolorcolor.new(color.yellow, 0)poc_color
VAH/VAL Colorcolorcolor.new(color.blue, 50)vah_val_color
Show all 14 settings
SettingTypeDefaultVariable
Profile Bullishcolorcolor.new(color.green, 60)profile_bull_color
Profile Bearishcolorcolor.new(color.red, 60)profile_bear_color
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

VP

by dearvn
257 stars

This indicator calculates and plots a session-based volume profile directly on the price chart. It maps volume distribution across price levels, highlighting key structural reference points including the Point of Control, Value Area High, and Value Area Low. C

Indicator v5 VolumeSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of VP

Midnight VWAP

by TradersPost
218 stars

The Midnight VWAP indicator calculates and overlays two distinct Volume Weighted Average Price (VWAP) lines on the price chart based on customizable session timeframes. It tracks an overnight or pre-market session alongside regular trading hours, resetting cal

Indicator v6 Moving averagesSessions & time
Updated 3 months ago · None stated GitHub repository of Midnight VWAP

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

This overlay indicator draws a volume profile for a chosen trading session directly on the price chart. It plots the point of control, value area high and low, an optional value area box, a live zone, and a session box with labels. Users select Tokyo, London,

Indicator v5 Sessions & timeVolume
Updated 7 weeks ago · None stated GitHub repository of Sessions & VP with prev session VP & daily/weekly opens

LoD Intraday Entry

by ChartsLector
41 stars

This overlay indicator marks the current day's low and a suggested entry zone a fraction of daily ATR below that low. It compares daily volume with a volume moving average, plots daily SMA and EMA distance, and draws an optional ATR-width price cloud. Labels c

Indicator v6 Support & resistanceVolatility & bands
Updated 2 days ago · None stated GitHub repository of LoD Intraday Entry

RS: Market Profile

by agejevasv
12 stars

This indicator plots a Market Profile on the price chart using time-price opportunity letters or symbols. It marks the point of control, a configurable value area, and the initial balance, and it can highlight a volume-profile point of control and session VWAP

Indicator v5 VolumeSupport & resistance
Updated 2 years ago · None stated GitHub repository of RS: Market Profile

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