Hello,
I hope someone can help me and can convert the attached source code from tradingview. I want to use this SRChannel indicator in prorealtime. Many thanks in advance!
Regards
14S
Hi,
Is there anyone who can help me? It would be really appreciated.
Regards
Hi!
I will try to convert it, but there are few codes more to translate.
Thanks in advance for your effort.
Hi Ivan, any luck with my request above. Thanks
Hi,
It´s not easy translation. I’m on it
Here it is:
https://www.prorealcode.com/prorealtime-indicators/demand-supply-zones-indicator/
//--------------------------------------------------------//
//PRC_Demand/Supply Zones
//version = 0
//08.04.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//--------------------------------------------------------//
//-----inputs--------------------------------------------//
prd = 10 //Pivot period
ppsrc = 1// 1 = "high/low" // 0 = "close/open"
showpp = 1//Show Pivot Points
channelw = 5 //Maximum channel width %
maxnumsr = 6 //Maximum Number of S/R
loopback = 290 //Loopback Period
ShowEMA = 0 //Show moving averages
ma1len = 50 //MA 1
ma1type = 0 //sma=0 ema=1
ma2len = 200 //MA 2
ma2type = 0 //sma=0 ema=1
//-------------------------------------------------------//
//-----AVERAGES------------------------------------------//
if ShowEMA then
ma1 = average[ma1len,ma1type](close)
ma2 = average[ma2len,ma2type](close)
else
ma1 = undefined
ma2 = undefined
endif
//-------------------------------------------------------//
//-----Get Pivot high / low------------------------------//
if ppsrc then
src1 = low
src2 = high
else
src1 = max(close,open)
src2 = min(close,open)
endif
//-----pivots low
if 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+1
endif
//-----pivots high
if 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+1
endif
//-------------------------------------------------------//
//-----Draw pivot points---------------------------------//
if showpp and z <> z[1] then
drawpoint($pivotlowx[z],$pivotlowy[z],2)coloured("red",50)
elsif showpp and t <> t[1] then
drawpoint($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+1
elsif t <> t[1] then
$pivotvals[m+1]=src2[prd]
$pivotlocs[m+1]=barindex[prd]
m=m+1
endif
//-------------------------------------------------------//
//-----Calculate Strengs---------------------------------//
if islastbarupdate then
//get levels and strengs
for x=0 to m-1 do
lo=$pivotvals[x]
hi=lo
numpp=0
for Y= 0 to m-1 do
cpp=$pivotvals[y]
if cpp <=hi then
wdth=hi-cpp
else
wdth=cpp-lo
endif
if wdth<=cwidth then
numpp=numpp+20
if cpp<=hi then
lo=min(lo,cpp)
else
hi=max(hi,cpp)
endif
endif
next
$lo[x]=lo
$hi[x]=hi
$strength[x]=numpp
next
//add each HL to strengh
for z=0 to m-1 do
lo2=$lo[z]
hi2=$hi[z]
s=0
for t=0 to loopback do
if (high[t]<=hi2 and high[t]>=lo2) or (low[t]<=hi2 and low[t]>=lo2) then
s=s+1
endif
$strength[z]=$strength[z]+s
next
next
endif
//-------------------------------------------------------//
//-----Support&Resistance levels Array-------------------//
//reset SR levels
unset($suportresistance)
// get strongest SRs
src=0
for i=0 to m-1 do
stv=-1
stl=-1
for j=0 to m-1 do
if $strength[j]>stv and $strength[j]>=20 then
stv=$strength[j]
stl=j
endif
next
if stl>=0 then
//get sr level
hh=$hi[stl]
ll=$lo[stl]
$suportresistance[src*2]=hh
$suportresistance[src*2+1]=ll
$stren[src]=$strength[stl]
// make included pivot points' strength zero
for n=0 to m-1 do
if ($hi[n]<=hh and $hi[n]>=ll) or ($lo[n]<=hh and $lo[n]>=ll) then
$strength[n]=-1
endif
next
src=src+1
if src>=10 then
break
endif
endif
next
//-------------------------------------------------------//
//-----Draw Support&Resistance---------------------------//
for x=0 to min(9,maxnumsr-1) do
//Calculate Top level
if x*2 < LastSet($suportresistance) then
if $suportresistance[x*2] <> 0 then
boxtop = $suportresistance[x*2]
endif
endif
//Calculate Bottom level
if x*2+1 < LastSet($suportresistance) then
if $suportresistance[x*2+1] <> 0 then
boxbot = $suportresistance[x*2+1]
endif
endif
//Color definition
if close > boxtop then
r=0
g=255
b=0
elsif close < boxbot then
r=255
g=0
b=0
else
r=255
g=255
b=50
endif
//Draw rectangle
drawrectangle(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")