Indicator · Pine Script v4 · Own pane

Relative Volume Strength Index (MZ RVSI)

by stonkpunk· code credited to MightyZinger

The Relative Volume Strength Index (MZ RVSI) is a separate-pane oscillator designed to measure volume momentum and trend strength.

View on GitHub

GitHub stars26on the repository
Pine versionv4older, still runs
Lines of code167
Settings18inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago11 Sep 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

167 lines of Pine Script v4 from indicator-mz-rvsi/original.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=4
study(shorttitle="MZ RVSI",title="Relative Volume Strength Index (MZ RVSI)", overlay=false)


uha   =input(true, title="Use Heikin Ashi Candles")
chartResolution = input("",type=input.resolution, title="Chart Resolution")

// Use only Heikinashi Candles for all calculations
haclose = uha ? security(heikinashi(syminfo.tickerid), chartResolution, close) : security(syminfo.tickerid, chartResolution, close)
haopen = uha ? security(heikinashi(syminfo.tickerid), chartResolution, open) : security(syminfo.tickerid, chartResolution, open)
hahigh = uha ? security(heikinashi(syminfo.tickerid), chartResolution, high) : security(syminfo.tickerid, chartResolution, high)
halow = uha ?security(heikinashi(syminfo.tickerid), chartResolution, low) : security(syminfo.tickerid, chartResolution, low)

vol = security(syminfo.tickerid, chartResolution, volume)

// Oscillator Types Input
osc1 = "TFS Volume Oscillator"
osc2 = "On Balance Volume"
osc3 = "Klinger Volume Oscillator"
osc4 = "Cumulative Volume Oscillator"
osc5 = "Volume Zone Oscillator"
osctype = input(title="Volume Oscillator Type", type=input.string, group="Indicator Parameters", defval = osc2, options=[osc1, osc2, osc3, osc4, osc5])

volLen = input(30, minval=1,title="Volume Length", group="Indicator Parameters")
rvsiLen = input(14, minval=1,title="RVSI Period", group="Indicator Parameters")
vBrk = input(50, minval=1,title="RVSI Break point", group="Indicator Parameters")

//Slope calculation to determine whether Volume is in trend, or in consolidation or choppy, or might about to change current trend

slopePeriod = input(34, title="Slope Period", group="Slope Parameters")
slopeInRange = input(25, title="Slope Initial Range", group="Slope Parameters")
flat        = input(17, title="Consolidation area is when slope below:", group="Slope Parameters")

calcslope(_ma,src,slope_period,range)=>
    pi = atan(1) * 4
    highestHigh = highest(slope_period)
    lowestLow = lowest(slope_period)
    slope_range = range / (highestHigh - lowestLow) * lowestLow
    dt = (_ma[2] - _ma) / src * slope_range
    c = sqrt(1 + dt * dt)
    xAngle = round(180 * acos(1 / c) / pi)
    maAngle = iff(dt > 0, -xAngle, xAngle)
    maAngle

// Dynamic coloring function to detect trend

dynColor(_flat, upPara, dnPara, slp, col_1, col_2, col_3, col_4, col_r) =>
    col = color.green
    if slp > _flat and upPara
        col := col_1

    if slp > _flat and not upPara
        col := col_2

    if slp <= _flat and slp > -flat
        col := col_r

    if slp <= -_flat and dnPara
        col := col_3

    if slp <= -_flat and not dnPara
        col := col_4
    col

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////             Volume Oscillator Functions                  //////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

// Volume Zone Oscillator

zone(_src, _type, _len) =>
    vp = _src > _src[1] ? _type : _src < _src[1] ? -_type : _src == _src[1] ? 0 : 0
    z = 100 * (ema(vp, _len) / ema(_type, _len))

vzo(vol_src, _close) =>
    float result = 0
    zLen = input(21, "VZO Length", minval=1, group="Volume Zone Oscillator Parameters")
    result := zone(_close, vol_src, zLen)
    result

//  Cumulative Volume Oscillator

_rate(cond, tw, bw, body) =>
    ret = 0.5 * (tw + bw + (cond ? 2 * body : 0)) / (tw + bw + body)
    ret := nz(ret) == 0 ? 0.5 : ret
    ret

cvo(vol_src, _open, _high, _low, _close) =>
    float result = 0
    ema1len = input(defval = 8, title = "EMA 1 Length", minval = 1, group="Cumulative Volume Oscillator Parameters")
    ema2len = input(defval = 21, title = "EMA 1 Length", minval = 1, group="Cumulative Volume Oscillator Parameters")
    obvl = "On Balance Volume"
    cvdo = "Cumulative Volume Delta"
    pvlt = "Price Volume Trend"
    cvtype = input(defval = pvlt, options = [obvl, cvdo, pvlt], group="Cumulative Volume Oscillator Parameters")

    tw = _high - max(_open, _close)
    bw = min(_open, _close) - _low
    body = abs(_close - _open)

    deltaup =  vol_src * _rate(_open <= _close , tw, bw, body)
    deltadown = vol_src * _rate(_open > _close , tw, bw, body)
    delta = _close >= _open ? deltaup : -deltadown
    cumdelta = cum(delta)
    float ctl = na
    ctl := cumdelta
    cv = cvtype == obvl ? obv : cvtype == cvdo ? ctl : pvt
    ema1 = ema(cv,ema1len)
    ema2 = ema(cv,ema2len)
    result := ema1 - ema2
    result

//  Volume Oscillator function

vol_osc(type, vol_src, vol_Len, _open, _high, _low, _close) =>
    float result = 0
    if type=="TFS Volume Oscillator"
        nVolAccum = sum(iff(_close > _open, vol_src, iff(_close < _open, -vol_src, 0))  ,vol_Len)
        result := nVolAccum / vol_Len
    if type=="On Balance Volume"
        result :=  cum(sign(change(_close)) * vol_src)
    if type=="Klinger Volume Oscillator"
        FastX = input(34, minval=1,title="Volume Fast Length", group="KVO Parameters")
        SlowX = input(55, minval=1,title="Volume Slow Length", group="KVO Parameters")
        xTrend = iff(_close > _close[1], vol * 100, -vol * 100)
        xFast = ema(xTrend, FastX)
        xSlow = ema(xTrend, SlowX)
        result :=  xFast - xSlow
    if type=="Cumulative Volume Oscillator"
        result := cvo(vol_src, _open, _high, _low, _close)
    if type=="Volume Zone Oscillator"
        result := vzo(vol_src, _close)
    result
/////////////////////////////////////////////////////////////////////

// MA of Volume Oscillator Source
volMA = hma(vol_osc(osctype,vol,volLen,haopen,hahigh,halow,haclose) , rvsiLen)

// RSI of Volume Oscillator Data
rsivol = rsi(volMA, rvsiLen)
rvsi = hma(rsivol, rvsiLen)

// RVSI IndicatorPlot
TopBand   = input(80, step=0.01, title="Top Band", group="Indicator Plot Parameters")
LowBand   = input(20, step=0.01, title="Low Band", group="Indicator Plot Parameters")
MidBand   = input(50, step=0.01, title="Middle Band", group="Indicator Plot Parameters")

hline(TopBand, color=color.red,linestyle=hline.style_dotted, linewidth=2)
hline(LowBand, color=color.green, linestyle=hline.style_dotted, linewidth=2)
hline(MidBand, color=color.lime, linestyle=hline.style_dotted, linewidth=1)

volBrkUp = rvsi > vBrk
volBrkDn = rvsi < vBrk
slope = calcslope(rvsi, rsivol, slopePeriod, slopeInRange)   // Slope Calculations
rvsi_col = dynColor(flat, volBrkUp, volBrkDn, slope, color.lime, color.fuchsia, color.red, color.gray, color.yellow)
plot(rvsi, "MZ RVSI", rvsi_col, 4)

hline(0,  "0", color.green, linewidth=1)
hline(100,  "100", color.red, linewidth=1)
hline(125,  "125", color.gray, linewidth=1)

plotchar(rvsi, "MZ RVSI", "", location.top, color.yellow)

Overview

Relative Volume Strength Index (MZ RVSI) allows users to choose between various volume oscillator types, including On Balance Volume, Klinger Volume Oscillator, and Volume Zone Oscillator. The script calculates slope angles to distinguish between trending states and flat consolidation zones. Input options enable custom calculation lengths, Heikin Ashi candle price sources, slope thresholds, and multi-timeframe resolution analysis.

Details

Published by

stonkpunk on GitHub

Code credit

MightyZinger, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Volume, Oscillators & momentum

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
Use Heikin Ashi Candlesbooltrueuha
Chart ResolutiontimeframechartResolution
Volume Oscillator Typestringosc2osctype
Volume Lengthint30volLen
RVSI Periodint14rvsiLen
RVSI Break pointint50vBrk
Slope Periodint34slopePeriod
Slope Initial Rangeint25slopeInRange
Consolidation area is when slope below:int17flat
VZO Lengthint21zLen
EMA 1 Lengthint8ema1len
EMA 1 Lengthint21ema2len
Show all 18 settings
SettingTypeDefaultVariable
cvtypeinputpvltcvtype
Volume Fast Lengthint34FastX
Volume Slow Lengthint55SlowX
Top Bandint80TopBand
Low Bandint20LowBand
Middle Bandint50MidBand
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

Money Flow Index

by everget
948 stars

Calculates the standard Money Flow Index (MFI) oscillator alongside an exponential moving average signal line in a separate pane. The script visually highlights trend conditions through dynamic ribbon filling, optional difference histogram bars, and overbought

Indicator v4 Oscillators & momentumVolume
Updated 10 days ago · GPL-3.0 GitHub repository of Money Flow Index

Commitment Gauge

by harryguiacorn
219 stars

This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete

Indicator v4 VolumeCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Commitment Gauge

Aggregate Signal

by capissimo
114 stars

This indicator builds an aggregate oscillator in a separate pane. It scales open, high, low, close, and volume into a 0 to 1 range, then averages scaled readings from MACD, a MACD histogram, RSI, stochastic, CCI, momentum, OBV, a directional index, volume-weig

Indicator v4 Oscillators & momentumVolume Repaints
Updated 1 year ago · None stated GitHub repository of Aggregate Signal

This indicator calculates the Bill Williams Market Facilitation Index as the high-low range divided by volume, or zero when volume is zero. It compares the index and volume with the previous bar and assigns one of four zones: green for both rising, fade for bo

Indicator v6 VolumeOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Bill Williams Market Facilitation Index

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

Chaikin Oscillator

by be-thomas
65 stars

Calculates the Chaikin Oscillator by taking the difference between a fast exponential moving average and a slow exponential moving average of the Accumulation/Distribution line. It plots the resulting line in a separate pane alongside a dashed zero reference l

Indicator v4 Oscillators & momentumVolume
Updated 4 days ago · GPL-3.0 GitHub repository of Chaikin Oscillator

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