Professional Documents
Culture Documents
Dynamic Support Resstanc
Dynamic Support Resstanc
Dynamic Support Resstanc
0 at
https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue
//@version=4
study("Support Resistance - Dynamic", overlay = true, max_bars_back = 600)
rb = input(10, title = "Period for Pivot Points", minval = 10)
prd = input(284, 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('Dashed', title = "Line Style", options = ['Solid', 'Dotted',
'Dashed'])
LineColor = input(color.blue, title = "Line Color", type = input.color)
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)
// S/R levels
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
// if number of bars is less then the loop then pine highest() fundtion brings
'na'. we need highest/lowest to claculate channel size
// so you cannot see S/R until the number of bars is equal/greater then the
"Loopback Period"
prdhighest = highest(prd)
prdlowest = lowest(prd)
cwidth = (prdhighest - prdlowest) * ChannelW / 100
ppavailable(ind)=> // is PP available?
_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
if not na(pl[xx])
if low[xx+rb] <= upl and low[xx+rb] >= dnl // PP
is in the channel?
tpoint := tpoint + 1
chg := true
// set if PP is used in the channel
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 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 := 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
float lbl1 = na, float lbl2 = na, float lbl3 = na, float lbl4 = na, float lbl5 =
na, float lbl6 = na, float lbl7 = na, float lbl8 = na, float lbl9 = na, float lbl10
= na
float lbl11 = na, float lbl12 = na, float lbl13 = na, float lbl14 = na, float lbl15
= na, float lbl16 = na, float lbl17 = na, float lbl18 = na, float lbl19 = na, float
lbl20 = na
// set labels
lb1 := lbl1 ? label.new(x = time + chper * 30, y = lbl1, text = tostring(lbl1),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb2 := lbl2 ? label.new(x = time + chper * 30, y = lbl2, text = tostring(lbl2),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb3 := lbl3 ? label.new(x = time + chper * 30, y = lbl3, text = tostring(lbl3),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb4 := lbl4 ? label.new(x = time + chper * 30, y = lbl4, text = tostring(lbl4),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb5 := lbl5 ? label.new(x = time + chper * 30, y = lbl5, text = tostring(lbl5),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb6 := lbl6 ? label.new(x = time + chper * 30, y = lbl6, text = tostring(lbl6),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb7 := lbl7 ? label.new(x = time + chper * 30, y = lbl7, text = tostring(lbl7),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb8 := lbl8 ? label.new(x = time + chper * 30, y = lbl8, text = tostring(lbl8),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb9 := lbl9 ? label.new(x = time + chper * 30, y = lbl9, text = tostring(lbl9),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb10 := lbl10 ? label.new(x = time + chper * 30, y = lbl10, text = tostring(lbl10),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb11 := lbl11 ? label.new(x = time + chper * 30, y = lbl11, text = tostring(lbl11),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb12 := lbl12 ? label.new(x = time + chper * 30, y = lbl12, text = tostring(lbl12),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb13 := lbl13 ? label.new(x = time + chper * 30, y = lbl13, text = tostring(lbl13),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb14 := lbl14 ? label.new(x = time + chper * 30, y = lbl14, text = tostring(lbl14),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb15 := lbl15 ? label.new(x = time + chper * 30, y = lbl15, text = tostring(lbl15),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb16 := lbl16 ? label.new(x = time + chper * 30, y = lbl16, text = tostring(lbl16),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb17 := lbl17 ? label.new(x = time + chper * 30, y = lbl17, text = tostring(lbl17),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb18 := lbl18 ? label.new(x = time + chper * 30, y = lbl18, text = tostring(lbl18),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb19 := lbl19 ? label.new(x = time + chper * 30, y = lbl19, text = tostring(lbl19),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
lb20 := lbl20 ? label.new(x = time + chper * 30, y = lbl20, text = tostring(lbl20),
color = color.lime, textcolor=color.black, style=label.style_labeldown, xloc =
xloc.bar_time, yloc=yloc.price) : na
hlabel := drawhl ? label.new(x = time + chper * 60, y = highestph, text = "Highest
PH " + tostring(highestph), color = color.silver, textcolor=color.black,
style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price) : na
llabel := drawhl ? label.new(x = time + chper * 60, y = lowestpl, text = "Lowest PL
" + tostring(lowestpl), color = color.silver, textcolor=color.black,
style=label.style_labeldown, xloc = xloc.bar_time, yloc=yloc.price) : na