Indicator · Pine Script v4 · On the chart

Volume Profile + 3EMA

by Azkorb· code credited to kv4coins

A Pine v4 overlay that draws a volume profile on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code164
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update5 years ago10 Jul 2021

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

164 lines of Pine Script v4 from VP + 3ema.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

VP + 3ema.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kv4coins

//@version=4
///////////////////////////////////////////////////////////////////////////////////////////////////
//// STUDY
///////////////////////////////////////////////////////////////////////////////////////////////////
study(title          = "Volume Profile", 
     shorttitle      = "VP + 3EMA", 
     overlay         = true, 
     precision       = 4, 
     linktoseries    = true, 
     max_bars_back   = 1000, 
     max_lines_count = 500)

MM1 = ema(close,10)
MM2 = ema(close,55)
MM3 = ema(close,100)

//Alcista = (MM1 > MM2 and MM2 > MM3)
//Bajista = (MM1 < MM2 and MM2 < MM3)

Alcista = (MM1 > MM2 )
Bajista = (MM1 < MM2 )



///////////////////////////////////////////////////////////////////////////////////////////////////
//// INPUTS
///////////////////////////////////////////////////////////////////////////////////////////////////
vp_lookback   = input(defval = 200, 
                     title   = "Volume Lookback Depth [10-1000]", 
                     type    = input.integer, 
                     minval  = 10, 
                     maxval  = 1000)

vp_max_bars   = input(defval = 500, 
                     title   = "Number of Bars [10-500]",
                     type    = input.integer, 
                     minval  = 10, 
                     maxval  = 500)

vp_bar_mult   = input(defval = 50, 
                     title   = "Bar Length Multiplier [10-100]",
                     type    = input.integer, 
                     minval  = 10, 
                     maxval  = 100)

vp_bar_offset = input(defval = 30, 
                     title   = "Bar Horizontal Offset [0-100]", 
                     type    = input.integer, 
                     minval  = 0, 
                     maxval  = 100)

vp_bar_width  = input(defval = 2, 
                     title   = "Bar Width [1-20]", 
                     type    = input.integer, 
                     minval  = 1, 
                     maxval  = 20)

// As suggested by @NXT2017
vp_delta_type = input(defval = "Both",
                     title   = "Delta Type",
                     type    = input.string,
                     options = ['Both', 'Bullish', 'Bearish'])

vp_poc_show   = input(defval = true, 
                     title   = "Show POC Line", 
                     type    = input.bool)

vp_bar_color  = input(defval = color.new(color.gray, 60) , 
                     title   = "Bar Color", 
                     type    = input.color)

vp_poc_color  = input(defval = color.new(color.orange, 10), 
                     title   = "POC Color", 
                     type    = input.color)


///////////////////////////////////////////////////////////////////////////////////////////////////
//// VARIABLES
///////////////////////////////////////////////////////////////////////////////////////////////////
float vp_Vmax = 0.0
int vp_VmaxId = 0
int vp_N_BARS = vp_max_bars

var int vp_first = time

vp_a_P = array.new_float((vp_N_BARS + 1), 0.0)
vp_a_V = array.new_float(vp_N_BARS, 0.0)
vp_a_D = array.new_float(vp_N_BARS, 0.0)
vp_a_W = array.new_int(vp_N_BARS, 0)

///////////////////////////////////////////////////////////////////////////////////////////////////
//// CALCULATIONS
///////////////////////////////////////////////////////////////////////////////////////////////////
float vp_HH = highest(high, vp_lookback)
float vp_LL = lowest(low, vp_lookback)

if barstate.islast
    float vp_HL = (vp_HH - vp_LL) / vp_N_BARS
    for j = 1 to (vp_N_BARS + 1)
        array.set(vp_a_P, (j-1), (vp_LL + vp_HL * j))
    for i = 0 to (vp_lookback - 1)
        int Dc = 0
        array.fill(vp_a_D, 0.0)
        for j = 0 to (vp_N_BARS - 1)
            float Pj = array.get(vp_a_P, j)
            if low[i] < Pj and high[i] > Pj and (vp_delta_type == "Bullish" ? 
             close[i] >= open[i] : (vp_delta_type == "Bearish" ? close[i] <= open[i] : true))
                float Dj = array.get(vp_a_D, j)
                float dDj = Dj + nz(volume[i])
                array.set(vp_a_D, j, dDj)
                Dc := Dc + 1
        for j = 0 to (vp_N_BARS - 1)
            float Vj = array.get(vp_a_V, j)
            float Dj = array.get(vp_a_D, j)
            float dVj = Vj + ((Dc > 0) ? (Dj / Dc) : 0.0)
            array.set(vp_a_V, j, dVj)
    vp_Vmax := array.max(vp_a_V)
    vp_VmaxId := array.indexof(vp_a_V, vp_Vmax)
    for j = 0 to (vp_N_BARS - 1)
        float Vj = array.get(vp_a_V, j)
        int Aj = round(vp_bar_mult * Vj / vp_Vmax)
        array.set(vp_a_W, j, Aj)

///////////////////////////////////////////////////////////////////////////////////////////////////
//// PLOTING
///////////////////////////////////////////////////////////////////////////////////////////////////
if barstate.isfirst
    vp_first := time
vp_change = change(time)
vp_x_loc = timenow + round(vp_change * vp_bar_offset)

f_setup_bar(n) =>
    x1 = ((vp_VmaxId == n) and vp_poc_show) ? max(time[vp_lookback], vp_first) : 
         (timenow + round(vp_change * (vp_bar_offset - array.get(vp_a_W, n))))
    ys = array.get(vp_a_P, n)
    line.new(x1     = x1, 
             y1     = ys, 
             x2     = vp_x_loc, 
             y2     = ys, 
             xloc   = xloc.bar_time, 
             extend = extend.none, 
             color  = (vp_VmaxId == n ? vp_poc_color : vp_bar_color), 
             style  = line.style_solid, 
             width  = vp_bar_width)

if barstate.islast
    for i = 0 to (vp_N_BARS - 1) by 1
        f_setup_bar(i)

bgcolor( Alcista ? color.green : na )
bgcolor( Bajista ? color.red : na )

plot(MM1, color=#2196F3, linewidth=2)
plot(MM2, color=#9d5f20, linewidth=2)
plot(MM3, color=#e9ff3b, linewidth=2)


   
///////////////////////////////////////////////////////////////////////////////////////////////////
//// END
///////////////////////////////////////////////////////////////////////////////////////////////////

Overview

Volume over a lookback window is split into price bins and shown as horizontal bars, with an optional point of control line at the busiest level. Settings control lookback depth up to 1000 bars, number of bins, bar length, horizontal offset and width, bar and line colours, and whether to count bullish, bearish or both kinds of volume. The script also calculates 10, 55 and 100 period exponential averages and a fast-versus-slow trend state.

Details

Published by

Azkorb on GitHub

Code credit

kv4coins, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Volume, Support & resistance, Moving averages

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
Volume Lookback Depth [10-1000]int200vp_lookback
Number of Bars [10-500]int500vp_max_bars
Bar Length Multiplier [10-100]int50vp_bar_mult
Bar Horizontal Offset [0-100]int30vp_bar_offset
Bar Width [1-20]int2vp_bar_width
Delta TypestringBothvp_delta_type
Show POC Linebooltruevp_poc_show
Bar Colorcolorcolor.new(color.gray, 60)vp_bar_color
POC Colorcolorcolor.new(color.orange, 10)vp_poc_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

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
7 stars

This indicator overlays Bollinger Bands on the price chart and fills the area between upper and lower bands using a color based on Cumulative Volume Delta trend. It plots an EMA 9 line and fills between the EMA 9 and Bollinger basis in green or red depending o

Indicator v6 Volatility & bandsVolume
Updated 5 months ago · None stated GitHub repository of Deep Chart + BB (CVD Internal)

IFA-VP Context

by eddiebelaval
7 stars

This indicator plots a fixed lookback Volume Profile alongside 20, 50, and 200 Simple Moving Averages directly on the price chart. It highlights trend changes via moving average crosses and marks Point of Control reactions, High Volume Nodes, and Value Area bo

Indicator v6 VolumeSupport & resistance
Updated 3 months ago · None stated GitHub repository of IFA-VP Context

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