Is there any way to convert this indicator to ProRealTime?
Forums › ProRealTime English forum › ProRealTime platform support › Is there any way to convert this indicator to ProRealTime?
- This topic has 3 replies, 3 voices, and was last updated 7 months ago by Iván.
Viewing 4 posts - 1 through 4 (of 4 total)
-
-
03/27/2024 at 9:49 PM #23061403/27/2024 at 10:06 PM #230618
You are best to post the content of the text file as folks may be reluctant to click on the file but may see the code (if you post it) and they may give it a go to convert for you.
Use the ‘Insert PRT Code’ button (blue button, far right in the grey band above a new blank post) … even though it isn’t PRT code it might look better formatted for PRT.
2 users thanked author for this post.
03/27/2024 at 10:14 PM #230619123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190// © Alpha//@version=4study("Demand/Supply Zones", "Alpha D/S Zones", overlay = true, max_bars_back = 501)prd = input(defval = 10, title="Pivot Period", minval = 4, maxval = 30, group = "Settings ", tooltip="Used while calculating Pivot Points, checks left&right bars")ppsrc = input(defval = 'High/Low', title="Source", options = ['High/Low', 'Close/Open'], group = "Settings ", tooltip="Source for Pivot Points")ChannelW = input(defval = 5, title = "Maximum Channel Width %", minval = 1, maxval = 8, group = "Settings ", tooltip="Calculated using Highest/Lowest levels in 300 bars")minstrength = input(defval = 1, title = "Minimum Strength", minval = 1, group = "Settings ", tooltip = "Channel must contain at least 2 Pivot Points")maxnumsr = input(defval = 6, title = "Maximum Number of S/R", minval = 1, maxval = 10, group = "Settings ", tooltip = "Maximum number of Support/Resistance Channels to Show") - 1loopback = input(defval = 290, title = "Loopback Period", minval = 100, maxval = 400, group = "Settings ", tooltip="While calculating S/R levels it checks Pivots in Loopback Period")res_col = input(defval = color.new(color.red, 75), title = "Resistance Color", group = "Colors ")sup_col = input(defval = color.new(color.lime, 75), title = "Support Color", group = "Colors ")inch_col = input(defval = color.new(color.gray, 75), title = "Color When Price in Channel", group = "Colors ")showpp = input(defval = false, title = "Show Pivot Points", group = "Extras ⏶⏷")showsrbroken = input(defval = false, title = "Show Broken Support/Resistance", group = "Extras ⏶⏷")showthema1en = input(defval = false, title = "MA 1", inline = "ma1")showthema1len = input(defval = 50, title = "", inline = "ma1")showthema1type = input(defval = "SMA", title = "", options = ["SMA", "EMA"], inline = "ma1")showthema2en = input(defval = false, title = "MA 2", inline = "ma2")showthema2len = input(defval = 200, title = "", inline = "ma2")showthema2type = input(defval = "SMA", title = "", options = ["SMA", "EMA"], inline = "ma2")ma1 = showthema1en ? (showthema1type == "SMA" ? sma(close, showthema1len) : ema(close, showthema1len)) : nama2 = showthema2en ? (showthema2type == "SMA" ? sma(close, showthema2len) : ema(close, showthema2len)) : naplot(ma1, color = not na(ma1) ? color.blue : na)plot(ma2, color = not na(ma2) ? color.red : na)// get Pivot High/lowfloat src1 = ppsrc == 'High/Low' ? high : max(close, open)float src2 = ppsrc == 'High/Low' ? low: min(close, open)float ph = pivothigh(src1, prd, prd)float pl = pivotlow(src2, prd, prd)// draw Pivot pointsplotshape(ph and showpp, text = "H", style = shape.labeldown, color = na, textcolor = color.red, location = location.abovebar, offset = -prd)plotshape(pl and showpp, text = "L", style = shape.labelup, color = na, textcolor = color.lime, location = location.belowbar, offset = -prd)//calculate maximum S/R channel widthprdhighest = highest(300)prdlowest = lowest(300)cwidth = (prdhighest - prdlowest) * ChannelW / 100// get/keep Pivot levelsvar pivotvals= array.new_float(0)var pivotlocs= array.new_float(0)if ph or plarray.unshift(pivotvals, ph ? ph : pl)array.unshift(pivotlocs, bar_index)for x = array.size(pivotvals) - 1 to 0if bar_index - array.get(pivotlocs, x) > loopback // remove old pivot pointsarray.pop(pivotvals)array.pop(pivotlocs)continuebreak//find/create SR channel of a pivot pointget_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 <= hi ? hi - cpp : cpp - loif wdth <= cwidth // fits the max channel width?if cpp <= hilo := min(lo, cpp)elsehi := max(hi, cpp)numpp := numpp + 20 // each pivot point added as 20[hi, lo, numpp]// keep old SR channels and calculate/sort new channels if we met new pivot pointvar suportresistance = array.new_float(20, 0) // min/max levelschangeit(x, y)=>tmp = array.get(suportresistance, y * 2)array.set(suportresistance, y * 2, array.get(suportresistance, x * 2))array.set(suportresistance, x * 2, tmp)tmp := array.get(suportresistance, y * 2 + 1)array.set(suportresistance, y * 2 + 1, array.get(suportresistance, x * 2 + 1))array.set(suportresistance, x * 2 + 1, tmp)if ph or plsupres = array.new_float(0) // number of pivot, strength, min/max levelsstren = array.new_float(10, 0)// get levels and strengsfor x = 0 to array.size(pivotvals) - 1[hi, lo, strength] = get_sr_vals(x)array.push(supres, strength)array.push(supres, hi)array.push(supres, lo)// add each HL to strenghfor x = 0 to array.size(pivotvals) - 1h = array.get(supres, x * 3 + 1)l = array.get(supres, x * 3 + 2)s = 0for y = 0 to loopbackif (high[y] <= h and high[y] >= l) or(low[y] <= h and low[y] >= l)s := s + 1array.set(supres, x * 3, array.get(supres, x * 3) + s)//reset SR levelsarray.fill(suportresistance, 0)// get strongest SRssrc = 0for x = 0 to array.size(pivotvals) - 1stv = -1. // valuestl = -1 // locationfor y = 0 to array.size(pivotvals) - 1if array.get(supres, y * 3) > stv and array.get(supres, y * 3) >= minstrength * 20stv := array.get(supres, y * 3)stl := yif stl >= 0//get sr levelhh = array.get(supres, stl * 3 + 1)ll = array.get(supres, stl * 3 + 2)array.set(suportresistance, src * 2, hh)array.set(suportresistance, src * 2 + 1, ll)array.set(stren, src, array.get(supres, stl * 3))// make included pivot points' strength zerofor y = 0 to array.size(pivotvals) - 1if (array.get(supres, y * 3 + 1) <= hh and array.get(supres, y * 3 + 1) >= ll) or(array.get(supres, y * 3 + 2) <= hh and array.get(supres, y * 3 + 2) >= ll)array.set(supres, y * 3, -1)src += 1if src >= 10breakfor x = 0 to 8for y = x + 1 to 9if array.get(stren, y) > array.get(stren, x)tmp = array.get(stren, y)array.set(stren, y, array.get(stren, x))changeit(x, y)get_level(ind)=>float ret = naif ind < array.size(suportresistance)if array.get(suportresistance, ind) != 0ret := array.get(suportresistance, ind)retget_color(ind)=>color ret = naif ind < array.size(suportresistance)if array.get(suportresistance, ind) != 0ret := array.get(suportresistance, ind) > close and array.get(suportresistance, ind + 1) > close ? res_col :array.get(suportresistance, ind) < close and array.get(suportresistance, ind + 1) < close ? sup_col :inch_colretvar srchannels = array.new_box(10)for x = 0 to min(9, maxnumsr)box.delete(array.get(srchannels, x))srcol = get_color(x * 2)if not na(srcol)array.set(srchannels, x,box.new(left = bar_index, top = get_level(x * 2), right = bar_index + 1, bottom = get_level(x * 2 + 1),border_color = srcol,border_width = 1,extend = extend.both,bgcolor = srcol))resistancebroken = falsesupportbroken = false// check if it's not in a channelnot_in_a_channel = truefor x = 0 to min(9, maxnumsr)if close <= array.get(suportresistance, x * 2) and close >= array.get(suportresistance, x * 2 + 1)not_in_a_channel := false// if price is not in a channel then check broken onesif not_in_a_channelfor x = 0 to min(9, maxnumsr)if close[1] <= array.get(suportresistance, x * 2) and close > array.get(suportresistance, x * 2)resistancebroken := trueif close[1] >= array.get(suportresistance, x * 2 + 1) and close < array.get(suportresistance, x * 2 + 1)supportbroken := truealertcondition(resistancebroken, title = "Resistance Broken", message = "Resistance Broken")alertcondition(supportbroken, title = "Support Broken", message = "Support Broken")plotshape(showsrbroken and resistancebroken, style = shape.triangleup, location = location.belowbar, color = color.new(color.lime, 0), size = size.tiny)plotshape(showsrbroken and supportbroken, style = shape.triangledown, location = location.abovebar, color = color.new(color.red, 0), size = size.tiny)04/10/2024 at 11:50 AM #231344Hi! Here it is the code translated:
https://www.prorealcode.com/prorealtime-indicators/demand-supply-zones-indicator/PRC_Demand/Supply Zones123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184//--------------------------------------------------------////PRC_Demand/Supply Zones//version = 0//08.04.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//--------------------------------------------------------////-----inputs--------------------------------------------//prd = 10 //Pivot periodppsrc = 1// 1 = "high/low" // 0 = "close/open"showpp = 1//Show Pivot Pointschannelw = 5 //Maximum channel width %minstrength = 1 //minimum strengthmaxnumsr = 6 //Maximum Number of S/Rloopback = 290 //Loopback PeriodShowEMA = 0 //Show moving averagesma1len = 50 //MA 1ma1type = 0 //sma=0 ema=1ma2len = 200 //MA 2ma2type = 0 //sma=0 ema=1//-------------------------------------------------------////-----AVERAGES------------------------------------------//if ShowEMA thenma1 = average[ma1len,ma1type](close)ma2 = average[ma2len,ma2type](close)elsema1 = undefinedma2 = undefinedendif//-------------------------------------------------------////-----Get Pivot high / low------------------------------//if ppsrc thensrc1 = lowsrc2 = highelsesrc1 = max(close,open)src2 = min(close,open)endif//-----pivots lowif src1 > src1[prd] and lowest[prd](src1) > src1[prd] and src1[prd] < lowest[prd](src1)[prd+1] then$pivotlowy[z+1] = src1[prd]$pivotlowx[z+1] = barindex[prd]z=z+1endif//-----pivots highif src2 < src2[prd] and highest[prd](src2)<src2[prd] and src2[prd]>highest[prd](src2)[prd+1] then$pivothighy[t+1]=src2[prd]$pivothighx[t+1]=barindex[prd]t=t+1endif//-------------------------------------------------------////-----Draw pivot points---------------------------------//if showpp and z <> z[1] thendrawpoint($pivotlowx[z],$pivotlowy[z],2)coloured("red",50)elsif showpp and t <> t[1] thendrawpoint($pivothighx[t],$pivothighy[t],2)coloured("blue",50)endif//-------------------------------------------------------////-----Calculate maximum S/R channel width---------------//prdhighest = highest[300](high)prdlowest = lowest[300](low)cwidth = (prdhighest - prdlowest) * ChannelW / 100//-------------------------------------------------------////-----Get/keep Pivot levels-----------------------------//if z <> z[1] then$pivotvals[m+1]=src1[prd]$pivotlocs[m+1]=barindex[prd]m=m+1elsif t <> t[1] then$pivotvals[m+1]=src2[prd]$pivotlocs[m+1]=barindex[prd]m=m+1endif//-------------------------------------------------------////-----Calculate Strengs---------------------------------//if islastbarupdate then//get levels and strengsfor x=0 to m-1 dolo=$pivotvals[x]hi=lonumpp=0for Y= 0 to m-1 docpp=$pivotvals[y]if cpp <=hi thenwdth=hi-cppelsewdth=cpp-loendifif wdth<=cwidth thennumpp=numpp+20if cpp<=hi thenlo=min(lo,cpp)elsehi=max(hi,cpp)endifendifnext$lo[x]=lo$hi[x]=hi$strength[x]=numppnext//add each HL to strenghfor z=0 to m-1 dolo2=$lo[z]hi2=$hi[z]s=0for t=0 to loopback doif (high[t]<=hi2 and high[t]>=lo2) or (low[t]<=hi2 and low[t]>=lo2) thens=s+1endif$strength[z]=$strength[z]+snextnextendif//-------------------------------------------------------////-----Support&Resistance levels Array-------------------////reset SR levelsunset($suportresistance)// get strongest SRssrc=0for i=0 to m-1 dostv=-1stl=-1for j=0 to m-1 doif $strength[j]>stv and $strength[j]>=minstrength*20 thenstv=$strength[j]stl=jendifnextif stl>=0 then//get sr levelhh=$hi[stl]ll=$lo[stl]$suportresistance[src*2]=hh$suportresistance[src*2+1]=ll$stren[src]=$strength[stl]// make included pivot points' strength zerofor n=0 to m-1 doif ($hi[n]<=hh and $hi[n]>=ll) or ($lo[n]<=hh and $lo[n]>=ll) then$strength[n]=-1endifnextsrc=src+1if src>=10 thenbreakendifendifnext//-------------------------------------------------------////-----Draw Support&Resistance---------------------------//for x=0 to min(9,maxnumsr-1) do//Calculate Top levelif x*2 < LastSet($suportresistance) thenif $suportresistance[x*2] <> 0 thenboxtop = $suportresistance[x*2]endifendif//Calculate Bottom levelif x*2+1 < LastSet($suportresistance) thenif $suportresistance[x*2+1] <> 0 thenboxbot = $suportresistance[x*2+1]endifendif//Color definitionif close > boxtop thenr=0g=255b=0elsif close < boxbot thenr=255g=0b=0elser=255g=255b=50endif//Draw rectangledrawrectangle(0,boxtop,barindex,boxbot)coloured(r,g,b,0)fillcolor(r,g,b,50)next//-------------------------------------------------------//return ma1 as "SMA 1" coloured("blue"),ma2 as "SMA 2" coloured("red") -
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
Find exclusive trading pro-tools on
Similar topics: