Indicator · Pine Script v6 · Own pane

Volume Price Analysis

by TamTH-Dev· code credited to tamth_

The Volume Price Analysis (VPA) indicator computes the Rate of Flow (RoF) from price and volume data using selected moving average types.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code306
Settings15inputs
LicenceNone statedfile: MPL-2.0
Last update6 weeks ago18 Sep 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

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

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

//@version=6
indicator('Volume Price Analysis', 'VPA', precision = 0, timeframe = '', timeframe_gaps = false, explicit_plot_zorder = true)


//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
// Colors
color TRANSPARENT_COLOR = #ffffff00
color WHITE_COLOR       = #dee2e6
color BLACK_COLOR       = #000000
color RED_COLOR         = #F72585
color ORANGE_COLOR      = #fb5607
color YELLOW_COLOR      = #ffbe0b
color GREEN_COLOR       = #2a9d8f
color AQUA_COLOR        = #4CC9F0
color BLUE_COLOR        = #4361ee
color PURPLE_COLOR      = #3F37C9
color PINK_COLOR        = #B5179E
color LIGHT_GRAY_COLOR  = #364156
color DARK_GRAY_COLOR   = #212d40
color TEXT_COLOR        = #ced4da


//-----------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------
get_average(_data, _len, options) =>
    rs = switch options
        'SMA' => ta.sma(_data, _len) 
        'EMA' => ta.ema(_data, _len) 
        'HMA' => ta.hma(_data, _len) 
        'RMA' => ta.rma(_data, _len) 
        => ta.wma(_data, _len)

// Normalization function - Normalizes values that are not restricted within a zero to 100 range
// This technique provides a scale that is closer to a "human" estimation of value in "bands" 
// as in: low, below average, average, above average, high, super high  
// this also avoids the issue of extreme values when using the stoch() -based technique
// these values are subjective, and can be changed - but slight changes here won't lead to major changes in outcome
// since all is relative to the same data series. 
normalize(_val, _avg) =>
    x = _val / _avg
    rs = 
      x > 1.50 ? 1.00 :
      x > 1.20 ? 0.90 :
      x > 1.00 ? 0.80 :
      x > 0.80 ? 0.70 :
      x > 0.60 ? 0.60 :
      x > 0.40 ? 0.50 :
      x > 0.20 ? 0.25 :
      0.1

//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
grp_1   = 'Rate of Flow (RoF)'
grp_2   = 'Lookback Parameters'
grp_3   = 'Bias / Sentiment'
grp_4   = 'EVEREX Bands'

length    = input.int(10, minval = 1, inline = 'ROF', group = grp_1)
MA_Type   = input.string('RMA', title = 'MA type', options = ['WMA', 'EMA', 'SMA', 'HMA', 'RMA'], inline = 'ROF', group = grp_1) 
smooth    = input.int(3, title = 'Smooth', minval = 1,  inline = 'ROF', group = grp_1)

sig_length  = input.int(5, 'Signal Length', minval = 1, inline = 'Signal', group = grp_1)
S_Type      = input.string(defval = 'RMA', title = 'Signal Type', options = ['WMA', 'EMA', 'SMA', 'HMA', 'RMA'], inline = 'Signal', group = grp_1)

lookback    = input.int(defval = 20, title = 'Length', minval = 1, inline = 'Lookback', group = grp_2)
lkbk_Calc   = input.string(defval = 'Simple', title = 'Averaging', options = ['Simple', 'Same as RRoF'], inline='Lookback', group = grp_2 )

showBias    = input.bool(defval = false, title = 'Bias Plot ? -- ', inline = 'Bias', group = grp_3)
B_Length    = input.int(defval = 30, title = 'Length', minval = 1, inline = 'Bias', group = grp_3)
B_Type      = input.string(defval = 'WMA', title = 'MA type', options = ['WMA', 'EMA', 'SMA', 'HMA', 'RMA'], inline = 'Bias', group = grp_3)

showEVEREX  = input.bool(true, 'Show EVEREX Bands', inline = 'EVEREX', group = grp_4)
bandscale   = str.tonumber(input.string("100", title = "Band Scale", options = ['100', '200', '400'], inline = 'EVEREX', group = grp_4))

DispBias    = showBias ? display.pane : display.none 
DispBands   = showEVEREX ? display.pane : display.none 
showhlines  = showEVEREX ? display.all : display.none 

Disp_vals   = display.status_line + display.data_window

//-----------------------------------------------------------------------------
// Calculations
//-----------------------------------------------------------------------------
// Volume "effort" Calculation  -- will revert to no volume acceleration for instruments with no volume data
v           = na(volume) ? 1 : volume // this part ensures we're not hit with calc issues due to NaN's
NoVol_Flag  = na(volume) ? true : false // this is a flag to use later 

lkbk_MA_Type = lkbk_Calc == 'Simple' ? 'SMA' : MA_Type

Vola        = get_average(v, lookback, lkbk_MA_Type)
Vola_n_pre  = normalize(v, Vola) * 100

// Now trap the case of no volume data - ensure final calculation not impacted 
Vola_n      = NoVol_Flag ? 100 : Vola_n_pre

//-----------------------------------------------------------------------------
// Price "result" calculation
// we'll consider "result" (strength or weakness) to be the outcome (average) of 6 elements: 
// Same (in-)Bar strength elements:
// 1 - Bar Closing: the closing within the bar  --> this will be a direct +100 / -100 value
// 2 - Spread to range: the spread to range ratio (that's BoP formula) --> direct +100 / -100 value
// 3 - Relative Spread: spread relative to average spread during lookback period --> normalized
// 2-bar strength elements:
// 4 - 2-bar closing: the closing within 2-bar range (that accomodates open gap effect)
// 5 - 2-bar Closing Shift to Range: Change in close relative to the 2-bar range     
// 6 - 2-bar Relative Shift: the 2-bar Close (or source price) shift - relative to the average 2-bar shift during lookback period --> normalized

BarSpread = close - open 
BarRange  = high - low
R2        = ta.highest(2) - ta.lowest(2)
SrcShift  = ta.change(close)

sign_shift = math.sign(SrcShift) 
sign_spread = math.sign(BarSpread) 
//-----------------------------------------------------------------------------
// In-bar assessments
//-----------------------------------------------------------------------------
// 1. Calculate closing within bar - should be max value at either ends of the bar range 
barclosing  = 2 * (close - low) / BarRange * 100 - 100

// 2. caluclate spread to range ratio
s2r = BarSpread / BarRange * 100

// 3. Calculate relative spread compared to average spread during lookback
BarSpread_abs   = math.abs(BarSpread)
BarSpread_avg   = get_average(BarSpread_abs, lookback, lkbk_MA_Type)
BarSpread_ratio_n = normalize(BarSpread_abs, BarSpread_avg) * 100 * sign_spread  

//-----------------------------------------------------------------------------
// 2-bar assessments
//-----------------------------------------------------------------------------
// 4. Calculate closing within 2 bar range - should be max value at either ends of the 2-bar range 
barclosing_2  = 2 * (close - ta.lowest(2)) / R2 * 100 - 100

// 5. calculate 2-bar shift to range ratio
Shift2Bar_toR2 = SrcShift / R2 * 100 

// 6. Calculate 2-bar Relative Shift 
SrcShift_abs    = math.abs(SrcShift)
srcshift_avg    = get_average(SrcShift_abs, lookback, lkbk_MA_Type) 
srcshift_ratio_n   = normalize(SrcShift_abs, srcshift_avg) * 100 * sign_shift
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Relative Price Strength combining all strength elements
Pricea_n = (barclosing + s2r + BarSpread_ratio_n + barclosing_2 + Shift2Bar_toR2 + srcshift_ratio_n) / 6

// Let's take Bar Flow as the combined price strength * the volume:avg ratio
// this works in a similar way to a volume-weighted RSI
bar_flow  =   Pricea_n * Vola_n / 100 

// Create a relative index by separating bulls from bears, like in an RSI - my preferred method
// here we have an added benefit of plotting the (average) bulls vs bears separately - as an option 
bulls = math.max(bar_flow, 0)
bears = -1 * math.min(bar_flow, 0)

bulls_avg = get_average(bulls, length, MA_Type)
bears_avg = get_average(bears, length, MA_Type)

dx          = bulls_avg / bears_avg
RROF         = 2 * (100 - 100 / (1 + dx)) - 100
RROF_s      = ta.wma(RROF, smooth)

Signal = get_average(RROF_s, sig_length, S_Type)

// Calculate Bias / sentiment on longer length
dx_b        = get_average(bulls, B_Length, B_Type) / get_average(bears, B_Length, B_Type)
RROF_b      = 2 * (100 - 100 / (1 + dx_b)) - 100
RROF_bs     = ta.wma(RROF_b, smooth)

//-----------------------------------------------------------------------------
// Colors
//-----------------------------------------------------------------------------
c_zero  = color.new(DARK_GRAY_COLOR, 25)
c_band  = color.new(YELLOW_COLOR, 40)

c_up    = AQUA_COLOR
c_dn    = PURPLE_COLOR

c_sup   = color.new(GREEN_COLOR, 70)
c_sdn   = color.new(RED_COLOR, 70)

up      = RROF_s >= 0
s_up    = RROF_bs >=0 

//-----------------------------------------------------------------------------
// Plots
//-----------------------------------------------------------------------------
hline(0, 'Zero Line', c_zero, linestyle = hline.style_solid)
hline(0.25 * bandscale, title = '1/4 Level', color=c_band, linestyle = hline.style_dotted, display = showhlines)
hline(0.50 * bandscale, title = '2/4 Level', color=c_band, linestyle = hline.style_dotted, display = showhlines)
hline(0.75 * bandscale, title = '3/4 Level', color=c_band, linestyle = hline.style_dotted, display = showhlines)
hline(bandscale, title = '4/4 Level', color=c_band, linestyle = hline.style_dotted, display = showhlines)

plot(ta.wma(bulls_avg, smooth), "Bulls", color = GREEN_COLOR, linewidth = 2, display = display.none)
plot(ta.wma(bears_avg, smooth), "Bears", color = RED_COLOR, linewidth = 2, display = display.none)

plot (RROF_bs, "Bias / Sentiment", style=plot.style_area, color = s_up ? c_sup : c_sdn, linewidth = 4, display = DispBias ) 

// =============================================================================
// Plot Price Strength & Relative Volume as stacked "equalizer bands" 
// adding visualization option to make the bands joint or separate at the mid-scale mark 
Eq_band_option = input.string("Joint", title = 'Band Option', options = ["Joint", "Separate"], group = grp_4)

nPrice  = math.max(math.min(Pricea_n, 100), -100)
nVol    = math.max(math.min(Vola_n, 100), -100)

bar = bar_flow

c_vol_grn   = color.new(GREEN_COLOR, 75)
c_vol_red   = color.new(RED_COLOR, 75)

cb_vol_grn  = color.new(GREEN_COLOR, 20)
cb_vol_red  = color.new(RED_COLOR, 20)

c_vol       = bar > 0 ? c_vol_grn : c_vol_red
cb_vol      = bar > 0 ? cb_vol_grn : cb_vol_red

vc_lo       = 0
vc_hi       = nVol * bandscale / 100 / 2

plotcandle(vc_lo, vc_hi, vc_lo, vc_hi , "Volume Band", c_vol, c_vol, bordercolor = cb_vol, display = DispBands)

c_pri_grn   = color.new(BLUE_COLOR, 75)
c_pri_red   = color.new(ORANGE_COLOR, 75)

cb_pri_grn  = color.new(BLUE_COLOR, 20)
cb_pri_red  = color.new(ORANGE_COLOR, 20)

c_pri       = bar > 0 ? c_pri_grn : c_pri_red
cb_pri      = bar > 0 ? cb_pri_grn : cb_pri_red

pc_lo_base  = Eq_band_option == "Joint" ? vc_hi : 0.50 * bandscale


pc_lo       = pc_lo_base
pc_hi       = pc_lo_base + math.abs(nPrice) * bandscale / 100 / 2

plotcandle(pc_lo, pc_hi, pc_lo ,pc_hi , "Price Band", c_pri, c_pri, bordercolor = cb_pri, display = DispBands)

// Print the normalized volume and price values - only on statys line and in the data window
// these values are independant of the band scale or visualization options
plotchar(nVol,    "Normalized Vol",   char = "", color = c_vol, editable = false, display = Disp_vals)
plotchar(nPrice,  "Normalized Price", char = "", color = c_pri, editable = false, display = Disp_vals)

// Plot main plot, smoothed plot and signal line

plot(RROF, 'RROF Raw', BLUE_COLOR, display=display.none)
plot(RROF_s, 'RROF Smooth', color = PINK_COLOR, linewidth = 2)
plot(Signal, "Signal Line", up ? c_up : c_dn, 3)

//-----------------------------------------------------------------------------
// Basic alerts
//-----------------------------------------------------------------------------
Alert_up    = ta.crossover(RROF_s,0)
Alert_dn    = ta.crossunder(RROF_s,0)
Alert_swing = ta.cross(RROF_s,0)

alertcondition(Alert_up,    ".   RROF Crossing 0 Up",      "RROF Up - Buying Action Detected!")
alertcondition(Alert_dn,    "..  RROF Crossing 0 Down",    "RROF Down - Selling Action Detected!")
alertcondition(Alert_swing, "... RROF Crossing 0",         "RROF Swing - Possible Reversal")

//-----------------------------------------------------------------------------
// Adding Markers for Key Patterns
//-----------------------------------------------------------------------------
nPrice_abs = math.abs(nPrice)
ev_ratio = 100 * nPrice_abs / nVol
// initial mapping of return ratios (to be revised)
// -------------------------------------------------------
// Case (1): Price > Vol => ratio > 120  =   Ease of Move (EoM)
// Case (2): Price close to Vol  => ratio between 80 - 120  = Reasonable Balance
// Case (3): Price less than Vol but reasonable => ratio between 80 - 50  = Drift / "nothing much to see here" bar 
// Case (4): Price a lot less than Vol  => 50 or less  = Compression / Squat 
// we're most interested in cases 1 & 4
is_positive     = nPrice > 0

is_Compression  = ev_ratio <= 50
is_EoM          = ev_ratio >= 120

// Provide option to show/hide those EVEREX Markers - and an option for Compression bar 
// - some folks would prefer a cross, others may prefer a circle - can adjust based on feedback
// no option for Ease of Move, guessing the triangle has the right significance 
var showMarkers = input.bool(true, 'Show EVEREX Markers ?')
var Mshape  = input.string("Circles", "Compression Marker", options = ['Circles','Crosses'])

SetShape(_x) =>
    switch _x
        'Circles'    => shape.circle
        'Crosses'    => shape.cross 


// Plot markers
plotshape(showMarkers and is_EoM and is_positive ? 0 : na, "EoM +ve", shape.triangleup, color = color.green, location = location.absolute, size = size.auto, editable = false, display = display.pane)
plotshape(showMarkers and is_EoM and not(is_positive) ? 0 : na, "EoM -ve", shape.triangledown, color = color.red, location = location.absolute, size = size.auto, editable = false, display = display.pane)

plotshape(showMarkers and is_Compression and is_positive ? 0 : na, "Compression +ve", style = SetShape(Mshape), color = GREEN_COLOR, location = location.absolute, size = size.auto, editable = false, display = display.pane)
plotshape(showMarkers and is_Compression and not(is_positive) ? 0 : na, "Compression -ve", style = SetShape(Mshape), color = RED_COLOR, location = location.absolute, size = size.auto, editable = false, display = display.pane)

//-----------------------------------------------------------------------------

Overview

Volume Price Analysis applies smoothing and signals for analysis, with normalization for subjective value levels. Plots appear in a separate pane. Options include bias plot, EVEREX bands, and markers. Settings control RoF length, smoothing, signal length, lookback, MA types, and display flags. The indicator aids in volume-price movement assessment and sentiment shifts but offers no explicit buy/sell signals.

Details

Published by

TamTH-Dev on GitHub

Code credit

tamth_, as written in the script's header

Draws

Separate pane below the chart

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
lengthint10length
MA typestringRMAMA_Type
Smoothint3smooth
Signal Lengthint5sig_length
Signal TypestringRMAS_Type
Lengthint20lookback
AveragingstringSimplelkbk_Calc
Bias Plot ? -- boolfalseshowBias
Lengthint30B_Length
MA typestringWMAB_Type
Show EVEREX BandsbooltrueshowEVEREX
Band Scalestring100Band Scale
Show all 15 settings
SettingTypeDefaultVariable
Band OptionstringJointEq_band_option
Show EVEREX Markers ?booltrueshowMarkers
Compression MarkerstringCirclesMshape
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

PPO ATR Bands

by cryptorife
75 stars

PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l

Indicator v4 Oscillators & momentumMoving averages
Updated 3 years ago · GPL-3.0 GitHub repository of PPO ATR Bands

NFI v6

by koradiyakaushal
12 stars

This Pine v4 study ports early NostalgiaForInfinity V6 conditions onto the price chart. It computes two Bollinger setups, several EMAs and SMAs, RSI, MFI, a percent SMA spread labeled EWO, a 14-period choppiness value, and short and longer volume medians. Fixe

Indicator v4 Moving averagesVolatility & bands
Updated 5 years ago · MIT GitHub repository of NFI v6

This indicator plots On Balance Volume in a separate pane and can overlay a smoothing average of that series. By default it draws a 20-period SMA of OBV with Bollinger Bands set two standard deviations away, plus a fixed 10-period EMA of OBV. A fill between th

Indicator v6 VolumeVolatility & bands
Updated 5 months ago · None stated GitHub repository of On Balance Volume & Bolliner Bands

Koncord + MACD

by Following-BTC
5 stars

This indicator combines the Koncorde oscillator with a traditional Moving Average Convergence Divergence (MACD) indicator in a separate pane. It calculates Koncorde using a mixture of the Relative Strength Index (RSI), Money Flow Index (MFI), Bollinger Bands o

Indicator v5 Oscillators & momentumVolume
Updated 2 years ago · None stated GitHub repository of Koncord + MACD
4 stars

The Fakeout Filter indicator calculates a four-layer signal quality score ranging from 0 to 4 to evaluate trade setups. It assesses four conditions: volume expansion above a moving average multiple, alignment with a higher timeframe EMA trend, price move excee

Indicator v6 TrendVolume Repaints
Updated 2 months ago · MIT GitHub repository of Fakeout Filter [trugurpala]
3 stars

Buy Low Sell High Composite is a pane oscillator that normalizes RSI, a short-versus-long EMA difference, the MACD histogram, and the Money Flow Index onto a shared scale, then sums them into one composite. It plots that composite as a colored area, the MACD s

Indicator v5 Oscillators & momentumMoving averages
Updated 5 months ago · None stated GitHub repository of Buy Low Sell High Composite

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