You are on page 1of 5

//@version=4

study("Banknifty Auto-Support & Resistance - By Prof. D", overlay = true,


max_bars_back = 600)
rb = input(10, title = "Period for Pivot Points", minval = 10)
prd = input(200, title = "Loopback Period", minval = 100, maxval = 500)
nump = input(2, title ="S/R strength", minval = 1)
ChannelW = input(10, title = "Channel Width %", minval = 5)
linestyle = input('Solid', title = "Line Style", options = ['Solid', 'Dotted',
'Dashed'])
linecolor = input('Blue', title = "Line Color", options = ['Blue', 'Red', 'Lime',
'White', 'Black'])
drawhl = input(true, title = "Draw Highest/Lowest Pivots in Period")
showpp = input(false, title = "Show Point Points")

ph = pivothigh(rb, rb)
pl = pivotlow(rb, rb)
plotshape(ph and showpp, text="[H]", style=shape.labeldown, color=color.white,
textcolor=color.black, location=location.abovebar, transp=0, offset = -rb)
plotshape(pl and showpp, text="[L]", style=shape.labelup, color=color.white,
textcolor=color.black, location=location.belowbar, transp=0, offset = -rb)

float sr1 = na, float sr2 = na, float sr3 = na, float sr4 = na, float sr5 = na,
float sr6 = na, float sr7 = na, float sr8 = na, float sr9 = na, float sr10 = na
float sr11 = na, float sr12 = na, float sr13 = na, float sr14 = na, float sr15 =
na, float sr16 = na, float sr17 = na, float sr18 = na, float sr19 = na, float sr20
= na

prdhighest = highest(prd)
prdlowest = lowest(prd)
cwidth = (prdhighest - prdlowest) * ChannelW / 100

a1 = true, a2 = true, a3 = true, a4 = true, a5 = true, a6 = true, a7 = true, a8 =


true, a9 = true, a10 = true
a11 = true, a12 = true, a13 = true, a14 = true, a15 = true, a16 = true, a17 = true,
a18 = true, a19 = true, a20 = true
a21 = true, a22 = true, a23 = true, a24 = true, a25 = true, a26 = true, a27 = true,
a28 = true, a29 = true, a30 = true
a31 = true, a32 = true, a33 = true, a34 = true, a35 = true, a36 = true, a37 = true,
a38 = true, a39 = true, a40 = true

ppavailable(ind)=>
_ret = ind == 1 and a1 ? true : ind == 2 and a2 ? true : ind == 3
and a3 ? true : ind == 4 and a4 ? true : ind == 5 and a5 ? true :
ind == 6 and a6 ? true : ind == 7 and a7 ? true : ind == 8
and a8 ? true : ind == 9 and a9 ? true : ind == 10 and a10 ? true :
ind == 11 and a11 ? true : ind == 12 and a12 ? true : ind == 13
and a13 ? true : ind == 14 and a14 ? true : ind == 15 and a15 ? true :
ind == 16 and a16 ? true : ind == 17 and a17 ? true : ind == 18
and a18 ? true : ind == 19 and a19 ? true : ind == 20 and a20 ? true :
ind == 21 and a21 ? true : ind == 22 and a22 ? true : ind == 23
and a23 ? true : ind == 24 and a24 ? true : ind == 25 and a25 ? true :
ind == 26 and a26 ? true : ind == 27 and a27 ? true : ind == 28
and a28 ? true : ind == 29 and a29 ? true : ind == 30 and a30 ? true :
ind == 31 and a31 ? true : ind == 32 and a32 ? true : ind == 33
and a33 ? true : ind == 34 and a34 ? true : ind == 35 and a35 ? true :
ind == 36 and a36 ? true : ind == 37 and a37 ? true : ind == 38
and a38 ? true : ind == 39 and a39 ? true : ind == 40 and a40 ? true :
false

set_a(t1, a1)=>
_ret = not t1 ? false : a1

u1 = 0.0, u1 := nz(u1[1])
d1 = 0.0, d1 := nz(d1[1])
highestph = 0.0
lowestpl = 0.0
highestph := highestph[1]
lowestpl := lowestpl[1]
if ph or pl

sr1 := na, sr2 := na, sr3 := na, sr4 := na, sr5 := na, sr6 := na, sr7 := na,
sr8 := na, sr9 := na, sr10 := na
sr11 := na, sr12 := na, sr13 := na, sr14 := na, sr15 := na, sr16 := na, sr17 :=
na, sr18 := na, sr19 := na, sr20 := na
highestph := prdlowest
lowestpl := prdhighest
countpp = 0
for x = 0 to prd
if na(close[x])
break
if not na(ph[x]) or not na(pl[x])
highestph := max(highestph, nz(ph[x], prdlowest), nz(pl[x], prdlowest))
lowestpl := min(lowestpl, nz(ph[x], prdhighest), nz(pl[x], prdhighest))
countpp := countpp + 1
if ppavailable(countpp)
upl = (ph[x] ? high[x+rb] : low[x+rb]) + cwidth
dnl = (ph[x] ? high[x+rb] : low[x+rb]) - cwidth
u1 := countpp == 1 ? upl : u1
d1 := countpp == 1 ? dnl : d1

t1 = true, t2 = true, t3 = true, t4 = true, t5 = true, t6 =


true, t7 = true, t8 = true, t9 = true, t10 = true
t11 = true, t12 = true, t13 = true, t14 = true, t15 = true, t16 =
true, t17 = true, t18 = true, t19 = true, t20 = true
t21 = true, t22 = true, t23 = true, t24 = true, t25 = true, t26 =
true, t27 = true, t28 = true, t29 = true, t30 = true
t31 = true, t32 = true, t33 = true, t34 = true, t35 = true, t36 =
true, t37 = true, t38 = true, t39 = true, t40 = true
cnt = 0
tpoint = 0
for xx = 0 to prd
if na(close[xx])
break
if not na(ph[xx]) or not na(pl[xx])
chg = false
cnt := cnt + 1
if ppavailable(cnt)
if not na(ph[xx])
if high[xx+rb] <= upl and high[xx+rb] >= dnl
tpoint := tpoint + 1
chg := true

if not na(pl[xx])
if low[xx+rb] <= upl and low[xx+rb] >= dnl
tpoint := tpoint + 1
chg := true

t1 := iff(chg and cnt == 1, false, t1), t2 := iff(chg and


cnt == 2, false, t2), t3 := iff(chg and cnt == 3, false, t3), t4 := iff(chg and cnt
== 4, false, t4), t5 := iff(chg and cnt == 5, false, t5)
t6 := iff(chg and cnt == 6, false, t6), t7 := iff(chg and
cnt == 7, false, t7), t8 := iff(chg and cnt == 8, false, t8), t9 := iff(chg and cnt
== 9, false, t9), t10 := iff(chg and cnt == 10, false, t10)
t11 := iff(chg and cnt == 11, false, t11), t12 := iff(chg
and cnt == 12, false, t12), t13 := iff(chg and cnt == 13, false, t13), t14 :=
iff(chg and cnt == 14, false, t14), t15 := iff(chg and cnt == 15, false, t15)
t16 := iff(chg and cnt == 16, false, t16), t17 := iff(chg
and cnt == 17, false, t17), t18 := iff(chg and cnt == 18, false, t18), t19 :=
iff(chg and cnt == 19, false, t19), t20 := iff(chg and cnt == 20, false, t20)
t21 := iff(chg and cnt == 21, false, t21), t22 := iff(chg
and cnt == 22, false, t22), t23 := iff(chg and cnt == 23, false, t23), t24 :=
iff(chg and cnt == 24, false, t24), t25 := iff(chg and cnt == 25, false, t25)
t26 := iff(chg and cnt == 26, false, t26), t27 := iff(chg
and cnt == 27, false, t27), t28 := iff(chg and cnt == 28, false, t28), t29 :=
iff(chg and cnt == 29, false, t29), t30 := iff(chg and cnt == 30, false, t30)
t31 := iff(chg and cnt == 31, false, t31), t32 := iff(chg
and cnt == 32, false, t32), t33 := iff(chg and cnt == 33, false, t33), t34 :=
iff(chg and cnt == 34, false, t34), t35 := iff(chg and cnt == 35, false, t35)
t36 := iff(chg and cnt == 36, false, t36), t37 := iff(chg
and cnt == 37, false, t37), t38 := iff(chg and cnt == 38, false, t38), t39 :=
iff(chg and cnt == 39, false, t39), t40 := iff(chg and cnt == 40, false, t40)

if tpoint >= nump


a1 := set_a(t1, a1), a2 := set_a(t2, a2), a3 := set_a(t3, a3),
a4 := set_a(t4, a4), a5 := set_a(t5, a5), a6 := set_a(t6, a6), a7 := set_a(t7, a7),
a8 := set_a(t8, a8), a9 := set_a(t9, a9), a10 := set_a(t10, a10)
a11 := set_a(t11, a11), a12 := set_a(t12, a12), a13 :=
set_a(t13, a13), a14 := set_a(t14, a14), a15 := set_a(t15, a15), a16 := set_a(t16,
a16), a17 := set_a(t17, a17), a18 := set_a(t18, a18), a19 := set_a(t19, a19),
a20 := set_a(t20, a20)
a21 := set_a(t21, a21), a22 := set_a(t22, a22), a23 :=
set_a(t23, a23), a24 := set_a(t24, a24), a25 := set_a(t25, a25), a26 := set_a(t26,
a26), a27 := set_a(t27, a27), a28 := set_a(t28, a28), a29 := set_a(t29, a29),
a30 := set_a(t30, a30)
a31 := set_a(t31, a31), a32 := set_a(t32, a32), a33 :=
set_a(t33, a33), a34 := set_a(t34, a34), a35 := set_a(t35, a35), a36 := set_a(t36,
a36), a37 := set_a(t37, a37), a38 := set_a(t38, a38), a39 := set_a(t39, a39),
a40 := set_a(t40, a40)

sr1 := countpp == 1 ? ph[x] ? high[x+rb] : low[x+rb] : sr1


sr2 := countpp == 2 ? ph[x] ? high[x+rb] : low[x+rb] : sr2
sr3 := countpp == 3 ? ph[x] ? high[x+rb] : low[x+rb] : sr3
sr4 := countpp == 4 ? ph[x] ? high[x+rb] : low[x+rb] : sr4
sr5 := countpp == 5 ? ph[x] ? high[x+rb] : low[x+rb] : sr5
sr6 := countpp == 6 ? ph[x] ? high[x+rb] : low[x+rb] : sr6
sr7 := countpp == 7 ? ph[x] ? high[x+rb] : low[x+rb] : sr7
sr8 := countpp == 8 ? ph[x] ? high[x+rb] : low[x+rb] : sr8
sr9 := countpp == 9 ? ph[x] ? high[x+rb] : low[x+rb] : sr9
sr10 := countpp == 10 ? ph[x] ? high[x+rb] : low[x+rb] : sr10
sr11 := countpp == 11 ? ph[x] ? high[x+rb] : low[x+rb] : sr11
sr12 := countpp == 12 ? ph[x] ? high[x+rb] : low[x+rb] : sr12
sr13 := countpp == 13 ? ph[x] ? high[x+rb] : low[x+rb] : sr13
sr14 := countpp == 14 ? ph[x] ? high[x+rb] : low[x+rb] : sr14
sr15 := countpp == 15 ? ph[x] ? high[x+rb] : low[x+rb] : sr15
sr16 := countpp == 16 ? ph[x] ? high[x+rb] : low[x+rb] : sr16
sr17 := countpp == 17 ? ph[x] ? high[x+rb] : low[x+rb] : sr17
sr18 := countpp == 18 ? ph[x] ? high[x+rb] : low[x+rb] : sr18
sr19 := countpp == 19 ? ph[x] ? high[x+rb] : low[x+rb] : sr19
sr20 := countpp == 20 ? ph[x] ? high[x+rb] : low[x+rb] : sr20

setline( level) =>


LineStyle = linestyle == 'Solid' ? line.style_solid :
linestyle == 'Dotted' ? line.style_dotted :
line.style_dashed
LineColor = linecolor == 'Blue' ? color.blue :
linecolor == 'Red' ? color.red :
linecolor == 'Lime' ? color.lime :
linecolor == 'White' ? color.white :
color.black
_ret = line.new(bar_index - prd , level, bar_index , level, color = LineColor,
width = 2, style = LineStyle, extend = extend.right)

if ph or pl
line highest_ = na, highest_ := highest_[1]
line lowest_ = na, lowest_ := lowest_[1]
line.delete(highest_)
line.delete(lowest_)
if drawhl
highest_ := line.new(bar_index - prd , highestph, bar_index , highestph,
color = color.blue, style = line.style_dashed, width = 1, extend = extend.right)
lowest_ := line.new(bar_index - prd , lowestpl, bar_index , lowestpl, color
= color.blue, style = line.style_dashed, width = 1, extend = extend.right)

line l1 = na, line l2 = na, line l3 = na, line l4 = na, line l5 = na, line l6 =
na, line l7 = na, line l8 = na, line l9 = na, line l10 = na
line l11 = na, line l12 = na, line l13 = na, line l14 = na, line l15 = na, line
l16 = na, line l17 = na, line l18 = na, line l19 = na, line l20 = na

l1 := l1[1], l2 := l2[1], l3 := l3[1], l4 := l4[1], l5 := l5[1], l6 := l6[1],


l7 := l7[1], l8 := l8[1], l9 := l9[1], l10 := l10[1]
l11 := l11[1], l12 := l12[1], l13 := l13[1], l14 := l14[1], l15 := l15[1],
l16 := l16[1], l17 := l17[1], l18 := l18[1], l19 := l19[1], l20 := l20[1]
line.delete(l1), line.delete(l2), line.delete(l3), line.delete(l4),
line.delete(l5), line.delete(l6), line.delete(l7), line.delete(l8),
line.delete(l9), line.delete(l10)
line.delete(l11), line.delete(l12), line.delete(l13), line.delete(l14),
line.delete(l15), line.delete(l16), line.delete(l17), line.delete(l18),
line.delete(l19), line.delete(l20)

l1 := sr1 ? setline(sr1) : na
l2 := sr2 ? setline(sr2) : na
l3 := sr3 ? setline(sr3) : na
l4 := sr4 ? setline(sr4) : na
l5 := sr5 ? setline(sr5) : na
l6 := sr6 ? setline(sr6) : na
l7 := sr7 ? setline(sr7) : na
l8 := sr8 ? setline(sr8) : na
l9 := sr9 ? setline(sr9) : na
l10 := sr10 ? setline(sr10) : na
l11 := sr11 ? setline(sr11) : na
l12 := sr12 ? setline(sr12) : na
l13 := sr13 ? setline(sr13) : na
l14 := sr14 ? setline(sr14) : na
l15 := sr15 ? setline(sr15) : na
l16 := sr16 ? setline(sr16) : na
l17 := sr17 ? setline(sr17) : na
l18 := sr18 ? setline(sr18) : na
l19 := sr19 ? setline(sr19) : na
l20 := sr20 ? setline(sr20) : na

You might also like