//------------------------------------------------------//
//PRC_RVI relative volatility Index
//version = 0
//26.11.2024
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//------------------------------------------------------//
// Inputs
//------------------------------------------------------//
stdevLength=10
stdevType=1 //boolean variable 1 means Population
smoothLength=14
obLevel=60
osLevel=40
useRefined=1 //boolean variable
highlightBreakouts=1 //boolean variable
src=close
//------------------------------------------------------//
// Standard deviation calculation
//------------------------------------------------------//
//Type=1 Population else Sample
if stdevType=1 then
selectedStdev=STD[stdevLength](src)
else
dev=src-average[stdevLength](src)
variance=summation[stdevLength](pow(dev,2))/(stdevLength-1)
selectedStdev=sqrt(variance)
endif
//------------------------------------------------------//
// RVI original version (1993)
//------------------------------------------------------//
up=(src>=src[1])*selectedStdev
down=(src<src[1])*selectedStdev
upsum=average[smoothLength,1](up)
downsum=average[smoothLength,1](down)
rviOriginal=100*upsum/(upsum+downsum)
//------------------------------------------------------//
// RVI Refined version (1995)
//------------------------------------------------------//
//---High
upH=(high>=high[1])*selectedStdev
downH=(high<high[1])*selectedStdev
upsumH=average[smoothLength,1](upH)
downsumH=average[smoothLength,1](downH)
rviOriginalH=100*upsumH/(upsumH+downsumH)
//---Low
upL=(low>=low[1])*selectedStdev
downL=(low<low[1])*selectedStdev
upsumL=average[smoothLength,1](upL)
downsumL=average[smoothLength,1](downL)
rviOriginalL=100*upsumL/(upsumL+downsumL)
rviRefined=(rviOriginalH+rviOriginalL)/2
//------------------------------------------------------//
// Plot
//------------------------------------------------------//
//---Rvi selection
if useRefined then
rvi=rviRefined
else
rvi=rviOriginal
endif
//---Rvi color
if rvi>oblevel then
r=14
g=187
b=35
elsif rvi<oslevel then
r=255
g=0
b=0
else
r=244
g=183
b=125
endif
//---HighlightBreakouts
if rvi>oblevel and highlightBreakouts then
rob=0
gob=255
alphaob=40
else
alphaob=0
endif
if rvi<oslevel and highlightBreakouts then
ros=255
gos=0
alphaos=40
else
alphaos=0
endif
colorbetween(100,oblevel,rob,gob,0,alphaob)
colorbetween(0,oslevel,ros,gos,0,alphaos)
//------------------------------------------------------//
return rvi as "RVI" coloured(r,g,b)style(line,2), oblevel as "Overbought Level"coloured("black")style(dottedline),oslevel as "Oversold Level"coloured("black")style(dottedline),50 as "MidLevel" coloured("black")style(dottedline)