Convert “Support Resistance – Dynamic v2” from tradingview to prorealtime
Forums › ProRealTime English forum › ProBuilder support › Convert “Support Resistance – Dynamic v2” from tradingview to prorealtime
- This topic has 0 replies, 1 voice, and was last updated 3 years ago by datageek.
Viewing 1 post (of 1 total)
-
-
05/12/2021 at 10:52 PM #169539Support Resistance - Dynamic v2123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © LonesomeTheBlue//@version=4study("Support Resistance - Dynamic v2", "SRv2", overlay = true)prd = input(defval = 10, title="Pivot Period", minval = 4, maxval = 30)ppsrc = input(defval = 'High/Low', title="Source", options = ['High/Low', 'Close/Open'])maxnumpp = input(defval = 20, title =" Maximum Number of Pivot", minval = 5, maxval = 100)ChannelW = input(10, title = "Maximum Channel Width %", minval = 1)maxnumsr = input(5, title =" Maximum Number of S/R", minval = 1, maxval = 10)min_strength = input(2, title =" Minimum Strength", minval = 1, maxval = 10)linestyle = input(defval = 'Dashed', title = "Line Style", options = ['Solid', 'Dotted', 'Dashed'])linewidth = input(defval = 2, title = "Line Width", minval = 1, maxval = 4)resistancecolor = input(defval = color.red, title = "Resistance Color", type = input.color)supportcolor = input(defval = color.lime, title = "Support Color", type = input.color)showpp = input(false, title = "Show Point Points")float ph = na, float pl = nafloat src1 = ppsrc == 'High/Low' ? high : max(close, open)float src2 = ppsrc == 'High/Low' ? low: min(close, open)ph := pivothigh(src1, prd, prd)pl := pivotlow(src2, prd, prd)plotshape(ph and showpp, text = "H", style = shape.labeldown, color = na, textcolor = color.red, location = location.abovebar, transp = 0, offset = -prd)plotshape(pl and showpp, text = "L", style = shape.labelup, color = na, textcolor = color.lime, location = location.belowbar, transp = 0, offset = -prd)//calculate maximum S/R channel zone widthprdhighest = highest(300)prdlowest = lowest(300)cwidth = (prdhighest - prdlowest) * ChannelW / 100var pivotvals= array.new_float(0)if ph or plarray.unshift(pivotvals, ph ? ph : pl)if array.size(pivotvals) > maxnumpp // limit the array sizearray.pop(pivotvals)get_sr_vals(ind)=>float lo = array.get(pivotvals, ind)float hi = loint numpp = 0for y = 0 to array.size(pivotvals) - 1float cpp = array.get(pivotvals, y)float wdth = cpp <= lo ? hi - cpp : cpp - loif wdth <= cwidth // fits the max channel width?lo := cpp <= lo ? cpp : lohi := cpp > lo ? cpp : hinumpp := numpp + 1[hi, lo, numpp]var sr_up_level = array.new_float(0)var sr_dn_level = array.new_float(0)sr_strength = array.new_float(0)find_loc(strength)=>ret = array.size(sr_strength)if ret > 0for i = array.size(sr_strength) - 1 to 0if strength <= array.get(sr_strength, i)breakret := iretcheck_sr(hi, lo, strength)=>ret = trueif array.size(sr_up_level) > 0for i = 0 to array.size(sr_up_level) - 1//included?if array.get(sr_up_level, i) >= lo and array.get(sr_up_level, i) <= hi orarray.get(sr_dn_level, i) >= lo and array.get(sr_dn_level, i) <= hiif strength >= array.get(sr_strength, i)array.remove(sr_strength, i)array.remove(sr_up_level, i)array.remove(sr_dn_level, i)retelseret := falsebreakret//get min timevar int btime = timebtime := na(time[1]) ? btime : min(btime, time - time[1])round_it(value)=>round(value / syminfo.mintick) * syminfo.mintickdraw_line(ycoor, Lstyle)=>line.new(x1 = bar_index,y1 = ycoor,x2 = bar_index - 1,y2 = ycoor,extend = extend.both,color = ycoor >= close ? resistancecolor : supportcolor,style = Lstyle,width = linewidth)st = security(syminfo.tickerid, 'D', time)cl = security(syminfo.tickerid, 'D', time_close)opened = timenow > st and timenow < cldraw_label(ycoor)=>rate = 100 * (ycoor - close) / closelabel.new(x = opened ? time + btime * 30 : time[100],y = ycoor, text = tostring(ycoor) + "(" + tostring(rate,'#.##') + "%)",color = ycoor >= close ? color.red : color.lime,textcolor = ycoor >= close ? color.white : color.black,style = ycoor >= close ? label.style_labeldown : label.style_labelup,xloc = xloc.bar_time,yloc = yloc.price)set_lx(lab, lin)=>rate = 100 * (label.get_y(lab) - close) / closelabel.set_text(lab, text = tostring(label.get_y(lab)) + "(" + tostring(rate,'#.##') + "%)")label.set_x(lab, x = opened ? time + btime * 30 : time[100])label.set_color(lab, color = label.get_y(lab) >= close ? color.red : color.lime)label.set_textcolor(lab, textcolor = label.get_y(lab) >= close ? color.white : color.black)label.set_style(lab, style = label.get_y(lab) >= close ? label.style_labeldown : label.style_labelup)line.set_color(lin, color = line.get_y1(lin) >= close ? resistancecolor : supportcolor)var line l1 = na, var line l2 = na, var line l3 = na, var line l4 = na, var line l5 = na, var line l6 = na, var line l7 = na, var line l8 = na, var line l9 = na, var line l10 = navar label lb1 = na, var label lb2 = na, var label lb3 = na, var label lb4 = na, var label lb5 = na, var label lb6 = na, var label lb7 = na, var label lb8 = na, var label lb9 = na, var label lb10 = naset_lx(lb1, l1), set_lx(lb2, l2), set_lx(lb3, l3), set_lx(lb4, l4), set_lx(lb5, l5), set_lx(lb6, l6), set_lx(lb7, l7), set_lx(lb8, l8), set_lx(lb9, l9), set_lx(lb10, l10)if ph or pl//because of new calculation, remove old S/R levelsarray.clear(sr_up_level)array.clear(sr_dn_level)array.clear(sr_strength)//find S/R zonesfor x = 0 to array.size(pivotvals) - 1[hi, lo, strength] = get_sr_vals(x)if check_sr(hi, lo, strength)loc = find_loc(strength)// if strength is in first maxnumsr sr then insert it to the arraysif loc < maxnumsr and strength >= min_strengtharray.insert(sr_strength, loc, strength)array.insert(sr_up_level, loc, hi)array.insert(sr_dn_level, loc, lo)// keep size of the arrays = 5if array.size(sr_strength) > maxnumsrarray.pop(sr_strength)array.pop(sr_up_level)array.pop(sr_dn_level)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)label.delete(lb1), label.delete(lb2), label.delete(lb3), label.delete(lb4), label.delete(lb5), label.delete(lb6), label.delete(lb7), label.delete(lb8), label.delete(lb9), label.delete(lb10)if array.size(sr_up_level)Lstyle = linestyle == 'Dashed' ? line.style_dashed :linestyle == 'Solid' ? line.style_solid :line.style_dottedfor x = 0 to array.size(sr_up_level) - 1float mid = round_it((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)if x == 0l1 := draw_line(mid, Lstyle)lb1 := draw_label(mid)if x == 1l2 := draw_line(mid, Lstyle)lb2 := draw_label(mid)if x == 2l3 := draw_line(mid, Lstyle)lb3 := draw_label(mid)if x == 3l4 := draw_line(mid, Lstyle)lb4 := draw_label(mid)if x == 4l5 := draw_line(mid, Lstyle)lb5 := draw_label(mid)if x == 5l6 := draw_line(mid, Lstyle)lb6 := draw_label(mid)if x == 6l7 := draw_line(mid, Lstyle)lb7 := draw_label(mid)if x == 7l8 := draw_line(mid, Lstyle)lb8 := draw_label(mid)if x == 8l9 := draw_line(mid, Lstyle)lb9 := draw_label(mid)if x == 9l10 := draw_line(mid, Lstyle)lb10 := draw_label(mid)f_crossed_over()=>ret = falseif array.size(sr_up_level) > 0for x = 0 to array.size(sr_up_level) - 1float mid = round_it((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)if close[1] <= mid and close > midret := trueretf_crossed_under()=>ret = falseif array.size(sr_up_level) > 0for x = 0 to array.size(sr_up_level) - 1float mid = round_it((array.get(sr_up_level, x) + array.get(sr_dn_level, x)) / 2)if close[1] >= mid and close < midret := trueretalertcondition(f_crossed_over(), title='Resistance Broken', message='Resistance Broken')alertcondition(f_crossed_under(), title='Support Broken', message='Support Broken')
Is it possible to convert this indicator for use in prorealtime.
https://www.tradingview.com/script/va09eWAp-Support-Resistance-Dynamic-v2/
-
AuthorPosts
Viewing 1 post (of 1 total)