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 Trend Indicator")
//=========================================================================|
// Trend Analysis Module |
//=========================================================================|

psmin = input(2,"Short term Min periods", input.integer, minval=1, maxval=9,


step=1)
psmax = input(8,"Short term Max Periods", input.integer, minval=1, maxval=9,
step=1)

rshmin = (high - nz(low[psmin])) / (atr(psmin) * sqrt(psmin))


rshmax = (high - nz(low[psmax])) / (atr(psmax) * sqrt(psmax))
RWIHi = max(rshmin,rshmax)

rslmin = (nz(high[psmin]) - low) / (atr(psmin) * sqrt(psmin))


rslmax = (nz(high[psmax]) - low) / (atr(psmax) * sqrt(psmax))
RWILo = max(rslmin,rslmax)

k = RWIHi-RWILo
ground = RWIHi
sky = RWILo

plmin = input(10,"Long Term Min Periods", type=input.integer, minval=1, maxval=32,


step=1)
plmax = input(40,"Long term Max Periods", type=input.integer, minval=1, maxval=64,
step=1)

rlhmin = (high - nz(low[plmin])) / (atr(plmin) * sqrt(plmin))


rlhmax = (high - nz(low[plmax])) / (atr(plmax) * sqrt(plmax))
RWILHi = max(rlhmin,rlhmax)

rllmin = (nz(high[plmin]) - low) / (atr(plmin) * sqrt(plmin))


rllmax = (nz(high[plmax]) - low) / (atr(plmax) * sqrt(plmax))
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
jb = crossover(1,j) // In oder to check which trend is doing what
jc = crossover(-1,j)
jd = crossover(j,-1)
j2a = crossover(j2,1)
j2b = crossover(1,j2)
k2a = crossover(k2,1)
k2b = crossover(1,k2)
//Define the Major, Minor and Immediate trend Status
upmajoron = j > 1 and ja[1]
upmajoroff = j < 1 and jb[1]
upminoron = j2 > 1 and j2a[1]
upminoroff = j2 < 1 and j2b[1]
dnmajoron = j < -1 and jc[1]
dnmajoroff = j > -1 and jd[1]
dnminoron = k2 > 1 and k2a[1]
dnminoroff = k2 < 1 and k2b[1]
upmid = iff(ground > 1, 1,0)
dnmid = iff(sky > 1, 1, 0)
upmajor = iff(j>1,1,iff(j<(-1),-1,0))
upminor = iff(j2>1,1,-1)
dnminor = iff(k2>1,1,-1)

majcolor = upmajor ==1 ? color.lime : upmajor == -1? color.red : color.yellow


midcolor = upmid ==1 ? color.lime : upmid == -1? color.red : color.yellow
mincolor = upminor ==1 ? color.lime : upminor == -1? color.red : color.yellow
baxis = 0
min = 100
mid = 60
maj = 30
taxis = 130

fill(plot(0), plot(30), majcolor, transp= 0, editable = false)


fill(plot(30), plot(60), midcolor, transp= 0, editable = false)
fill(plot(60), plot(100), mincolor, transp= 0, editable = false)
plot(taxis,"", color= color.black)
plot(baxis,"", color= color.black)
plot(maj,"", color= color.black, transp= 0, linewidth = 3)
plot(mid,"", color= color.black, transp= 0, linewidth = 3)
plot(min,"", color= color.black, transp= 0, linewidth = 3)

You might also like