VPA Analysis - Pinescript R1
VPA Analysis - Pinescript R1
0 at
https://mozilla.org/MPL/2.0/
// © karthikmarar
//@version=4
volAvg = sma(volume,40)
volMean = stdev(volAvg,30)
H = high
L = low
V = volume
C = close
midprice = (H+L)/2
spread = (H-L)
avgSpread = sma(spread,40)
narrowRangeBar = spread<(0.7*avgSpread)
upBar = C>close[1]//C>Ref(C,-1)
downBar = C<close[1]//C<Ref(C,-1)
closeFactor = C-L
clsPosition = spread/closeFactor
midClose = C>((spread*0.3)+L) and C<((spread*0.7)+L)// close is between 30% and 70% of the bar
ClosePos =
iff(C<=((spread*0.2)+L),1,iff(C<=((spread*0.4)+L),2,iff(C<=((spread*0.6)+L),3,iff(C<=((spread*0.8)+L),4,5))
))
//=========================================================================|
// Trend Analysis Module |
//=========================================================================|
RWIHi = max(rshmin,rshmax)
RWILo = max(rslmin,rslmax)
k = RWIHi-RWILo
ground = RWIHi
sky = RWILo
RWILHi = max(rlhmin,rlhmax)
RWILLo = max(rllmin,rllmax)
j = RWILHi-RWILLo
j2 = RWILHi
k2 = RWILLo
ja = crossover(j,1) // The following section check the diffeent condition of the RWi above and below
zero
jc = crossover(-1,j)
jd = crossover(j,-1)
j2a = crossover(j2,1)
j2b = crossover(1,j2)
k2a = crossover(k2,1)
k2b = crossover(1,k2)
upmajor = iff(j>1,1,iff(j<(-1),-1,0))
upminor = iff(j2>1,1,-1)
dnminor = iff(k2>1,1,-1)
plotshape(upmajor ==1 and trind == true , text="",style=shape.triangledown, color= color.lime,
location=location.top,transp=0, size= size.small)
plotshape(upmid != -1 and upmid !=1 and trind == true , text="",style=shape.circle, color= color.yellow,
location=location.top,transp=0,size = size.tiny)
//=========================================================================|
// Slope Calculation |
//=========================================================================|
src = sma(close,5)
//--------------longterm trend---------------
sts = linreg(src, 3, 0)
stsprev = linreg(close[1], 3, 0)
tls = stsslope
//=========================================================================|
//=========================================================================|
upThrustBar = wideRangeBar and downClose and high > high[1] and upmid==1 //WRB and UHS in
midterm trend
nut = wideRangeBar and downClose and freshGndHi and highVolume // NEW SIGNAL - Upthrust
after new short up move
upThrustBartrue = wideRangeBar and ClosePos==1 and upmajor>0 and H>H[1] and volpos < 4//occurs
after a major uptrend
upThrustCond1 = upThrustBar[1] and downBar and not narrowRangeBar // The Bar after Upthrust Bar-
Confirms weakness
upThrustCond2 = upThrustBar[1] and downBar and V>(volAvg*1.3) // The Bar after Upthrust Bar-
Confirms weakness
topRevBar = V[1]>volAvg and upBar[1] and wideRangeBar[1] and downBar and downClose and
wideRangeBar and upmajor>0 and H==highest(H,10)// Top Reversal bar
PseudoUpThrust = (upBar[1])and H>H[1] and V[1]>1.5*volAvg and downBar and downClose and not
upThrustBar
trendChange = upBar[1] and H==highest(H,5) and downBar and (downClose or midClose) and
V>volAvg and upmajor>0 and upmid>0 and not wideRangeBar and not PseudoUpThrust
noDemandBarUt = upBar and narrowRangeBar and lowVolume and (aboveClose or upClose) and
((upminor>=0 and upmid>=0) or (upminor<=0 and upminor>=0))//in a up market
noDemandBarDt = upBar and narrowRangeBar and lowVolume and (aboveClose or upClose) and
(upminor<=0 or upmid<=0)// in a down or sidewayss market
lowVolTest1 = low == lowest(low,5) and V<volAvg and L<L[1] and upClose and upminor>0 and
upmajor>0
sellCond2 = sellCond1[1]==0
strengthDown0 = upmajor<0 and volpos < 4 and downBar[1] and upBar and ClosePos>3 and upminor
<0 and upmid <=0
strengthDown = volpos<4 and downBar[1] and upBar and ClosePos>3 and upmid<=00 and upminor<0
// Strength after a down trend
strengthDown1 = upmajor<0 and V>(volAvg*1.5) and downBar[1] and upBar and ClosePos>3 and
upmid<=00 and upminor<0
strengthDown2 = upmid<=0 and V[1]<volAvg and upBar and veryHighClose and volpos<4
revUpThrust = upBar and upClose and V>V[1] and V>volAvg and wideRangeBar and downBar[1] and
downClose[1] and upminor<0
effortUp = H>H[1] and L>L[1] and C>C[1] and C>=((H-L)*0.7+L) and spread>avgSpread and volpos < 4
effortDown = H<H[1] and L<L[1] and C<C[1] and C<=((H-L)*0.25+L) and wideRangeBar and V>V[1]
bearBar = vb and downClose and downBar and spread>avgSpread and not upflag
//UPTHRUSTS
plotshape((upThrustBar or upThrustBartrue) and not effortUpfail and not sellCond and not bc, "UT1",
style=shape.triangledown, location=location.abovebar, color=#990000, transp=0, text="UT1",
textcolor=#990000, editable=false, size=size.tiny)
plotshape((upThrustCond1 or upThrustCond2 or nut) and not effortUpfail and not sellCond and not bc,
"UT2", style=shape.triangledown, location=location.abovebar, color=#ff0000, transp=0, text="UT2",
textcolor=#ff0000, editable=false, size=size.tiny)
UT = UT1 or UT2
alertcondition(upThrustBar, title='Alert on UT1 an UT2 and UT', message='An Upthrust Bar. A sign of
weakness. High Volume adds weakness. A down bar after Upthrust adds weakness')
plotshape(topRevBar and not sellCond and not UT and not effortUpfail, "TRB",
style=shape.triangledown, location=location.abovebar, color=#ff9900, transp=0, text="TRB",
textcolor=#ff9900, editable=false, size=size.tiny)
alertcondition(lvt , title='Alert on LVT', message='Test for supply.An upBar closing near High after a Test
confirms strength. ')
//-------------------------------------------------
EFD = effortDownFail
ST1 = strengthDown0
strcond = (strengthDown2 and not strengthDown0 and not strengthDown and not strengthDown1)? 1:0
ST3 = strengthDown1
ST4 = strengthDown2 and strcond
plotshape(strengthDown0 and not EFD and not effortUp and not stopVolume, "ST1",
style=shape.triangleup, location=location.belowbar, color=color.lime, transp=0, text="ST1",
textcolor=color.green, editable=false, size=size.tiny)
plotshape(strengthDown and not strengthDown2 and not EFD and not effortUp and not stopVolume,
"ST2", style=shape.triangleup, location=location.belowbar, color=color.lime, transp=0, text="ST1",
textcolor=color.green, editable=false, size=size.tiny)
plotshape(strengthDown1 and not EFD and not effortUp and not stopVolume, "ST3",
style=shape.triangleup, location=location.belowbar, color=color.lime, transp=0, text="ST1",
textcolor=color.green, editable=false, size=size.auto)
plotshape(strengthDown2 and strcond and not EFD and not effortUp and not stopVolume, "ST4",
style=shape.triangleup, location=location.belowbar, color=color.lime, transp=0, text="ST2",
textcolor=color.green, editable=false, size=size.tiny)
alertcondition(ST , title='Alert on ST1, ST2, ST3, ST4 and ST', message='Strength seen returning after a
down trend. ')
//----------------------------------------------
//---------------------------------------------------
plotshape(effortUp and not ST and not buyCond and not effortDownFail, "EU", style=shape.triangleup,
location=location.belowbar, color=color.lime, transp=0, text="EU", textcolor=color.green, editable=false,
size=size.tiny)
plotshape(buyCond and not ST and not effortUp and not lvt, "BYC1", style=shape.triangleup,
location=location.belowbar, color=color.lime, transp=0, text="BYC", textcolor=color.green,
editable=false, size=size.tiny)
rg=(high-close)
arg=wma(rg,30)
Cloc=close-low
x=(high-low)/Cloc
x1=Cloc==0?arg:x
ucls=x1<2
dcls=x1>2
Vlcls=x1>4
Vhcls=x1<1.35
bb1 = upbar and CloseUp and ucls and low > low[1]
bb2 = upbar and VolUp
mcolor = bb and tls>0? color.green : (db and tls<0? color.red: (bkbg == true ? color.white : color.blue))
barcolor(color=mcolor)