You are on page 1of 2

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © karthikmarar

//@version=4
study("VPA Volume")

//=========================================================================|
// Slope Calculation |
//=========================================================================|
src = sma(close,5)
//--------------longterm trend---------------
lts = linreg(src, 40, 0)
ltsprev = linreg(close[3], 40, 0)
ltsslope = ((lts - ltsprev) / 3 )
//-------------Medium Term Trend-------------
mts = linreg(src, 20, 0)
mtsprev = linreg(close[3], 20, 0)
mtsslope = ((mts - mtsprev) / 3 )
//-------------short Term Trend-------------
sts = linreg(src, 3, 0)
stsprev = linreg(close[1], 3, 0)
stsslope = ((sts - stsprev) / 2 )
tls = ltsslope

//-----------------------------Bar coloring
Code-------------------------------------------------

//Vlp=Param("Volume lookback period",150,20,300,10);


Vrg=sma(volume,30)// average volume
rg=(high-close)
arg=wma(rg,30)
Vh=volume>volume[1] and volume[1]>volume[2]
Cloc=close-low
x=(high-low)/Cloc
x1=Cloc==0?arg:x
Vb1 = volume >Vrg or volume > volume[1]
ucls=x1<2
dcls=x1>2
mcls=x1<2.2 and x1>1.8
Vlcls=x1>4
Vhcls=x1<1.35
upbar = close > close[1]
dnbar = close < close[1]
CloseUp = close > close[1]
CloseDn = close < close[1]
VolUp = volume > volume[1]
VolDn = volume < volume[1]
bb1 = upbar and CloseUp and ucls and low > low[1]
bb2 = upbar and VolUp
bb3 = dnbar and CloseDn and VolDn
bb4 = dnbar and CloseDn and close > close[1]
db1 = dnbar and CloseDn and dcls
db2 = dnbar and VolUp
db3 = upbar and CloseDn and VolUp
db4 = upbar and CloseDn and close<low[1] and dcls
db5 = upbar and CloseUp and ucls and low<low[1]
db6 = upbar and CloseUp and dcls
bb=(bb1 or bb2 or bb3 or bb4)
db=(db1 or db2 or db3 or db4 or db5 or db6)
//Mcolor = IIf(bb AND tls>0, colorLime,IIf(db AND tls<0,colorRed,colorWhite)) ;

mcolor = bb and tls>0? color.green : (db and tls<0? color.red:color.blue)

//mcolor = bb and upminor> 0? color.green : (db and upminor<0?


color.red:color.blue)

//barColour = lowVolTest?color.aqua : lowVolTest2 ? #E12BD8 : bc ? #A60800 :


upThrustBar ? color.yellow : bullBar?color.lime : bearBar ? color.red :
(noDemandBarUt or noDemandBarDt) ? color.white : noSupplyBar ? color.silver : upBar
? color.green : downBar ? color.orange : color.navy
//barcolor(color=barColour)
showMA = input(true)
barcolor(color=mcolor)

plot(showMA ? sma(volume,60) : na, style=plot.style_area, color=#ffff00,


title="Volume MA", transp=60)
plot(volume, color = mcolor, style=plot.style_columns, title="Volume", transp=0)
plot(showMA ? sma(volume,60) : na, style=plot.style_line,linewidth=2,
color=color.red,title="Volume MA", transp=0)
bgcolor(color.black)

You might also like