Support and resistance zones with variables arrays
Forums › ProRealTime English forum › ProBuilder support › Support and resistance zones with variables arrays
- This topic has 23 replies, 4 voices, and was last updated 1 year ago by Aragorna.
Tagged: array, resistance, support, support and resistance
-
-
04/14/2020 at 7:28 PM #126151
I don’t really get your point 1. My array is not sorted, so if I want to compare one item with all items, I can’t do z=x, otherwise you compare only with smaller and smaller items.
On the other hand, your second point seems indeed to solve the issue, thx I wouldn’t have found it!!!
Now the point I would like to improve is around the fractal, to filter the reversal points and retain only the most relevant one… Would need your help on that too;)
I’m noticing also that the most recent overlap is sometimes blinking with each new change of price, weird…
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125DEFPARAM DRAWONLASTBARONLY =TRUEdefparam calculateonlastbars=500barlimit = 400ATR=averagetruerange[20](close)cp=2ATRfactor=2index1=0index2=0if high[cp] >= highest[(cp)*2+1](high) and barindex-$TOPx2[max(0,lastset($TOPx2))]>1 then //new fractal high found$TOPy[lastset($TOPy)+1] = high[cp] //store fractal value$TOPx[lastset($TOPx)+1] = barindex[cp] //store fractal barindex//drawpoint(barindex[cp],high[cp],1) coloured(100,75,150) bordercolor (100,75,150)$TOPx2[lastset($TOPx2)+1] = barindexendifif low[cp] <= lowest[(cp)*2+1](low) and barindex-$BOTx2[max(0,lastset($BOTx2))]>1 then //new fractal low found$BOTy[lastset($BOTy)+1] = low[cp] //store fractal value$BOTx[lastset($BOTx)+1] = barindex[cp] //stire fractal barindex//drawpoint(barindex[cp],low[cp],1) coloured(100,75,150) bordercolor (100,75,150)$BOTx2[lastset($BOTx2)+1] = barindexendifif(islastbarupdate and isset($topy[0]) and isset($boty[0])) then//check points in a range of X percentfor i = 0 to lastset($TOPy) do //loop through the topsfor y = 0 to lastset($BOTy) do //check first top with other topsif y<>i thenchange=abs($BOTy[y]-$topy[i])//percent range between the 2 topsif change<=ATR/ATRfactor and barindex-$BOTx[y]<barlimit and $topx[i]<>$BOTx[y] then$overlap[index1]=($BOTy[y]+$TOPy[i])/2$overlapx1[index1]=min($BOTx[y],$TOPx[i])$overlapx2[index1]=max($BOTx[y],$TOPx[i])index1=index1+1endifendifnextnextendif//test=index1// drawtext(" #test#",barindex,high+50,SansSerif,standard,10)if islastbarupdate and isset($overlap[0]) thenfor x=index1 downto 1 dofor z=index1 downto 1 doif x=index1 thencount=0endifif x<>z thenif abs($overlap[x]-$overlap[z])<ATR thencount=count+1endifendifnextif count=0 then$overlapfinal[index2]=$overlap[x]$overlapfinalx1[index2]=$overlapx1[x]$overlapfinalx2[index2]=$overlapx2[x]index2=index2+1elseif index2=0 then$overlapfinal[index2]=$overlap[x]$overlapfinalx1[index2]=$overlapx1[x]$overlapfinalx2[index2]=$overlapx2[x]index2=index2+1endiffor zz = 0 to index2 doif zz=0 thencount=0endifif x<>zz thenif abs($overlap[x]-$overlapfinal[zz])<ATR thencount=count+1endifendifnextif count=0 then$overlapfinal[index2]=$overlap[x]$overlapfinalx1[index2]=$overlapx1[x]$overlapfinalx2[index2]=$overlapx2[x]index2=index2+1endifendifnextendifif islastbarupdate and isset($overlapfinal[0]) thenfor x=0 to index2 doif $overlapfinal[x] > close thenif highest[barindex-$overlapfinalx2[x]-1](high)<$overlapfinal[x]+ATR/ATRfactor thendrawsegment($overlapfinalx1[x],$overlapfinal[x],barindex,$overlapfinal[x]) coloured(0,75,150) STYLE (dottedline,3)drawpoint($overlapfinalx2[x],$overlapfinal[x],2) coloured(0,75,150) bordercolor (0,75,150)endifelseif lowest[barindex-$overlapfinalx2[x]-1](low)>$overlapfinal[x]-ATR/ATRfactor thendrawsegment($overlapfinalx1[x],$overlapfinal[x],barindex,$overlapfinal[x]) coloured(0,75,150) STYLE (dottedline,3)drawpoint($overlapfinalx2[x],$overlapfinal[x],2) coloured(0,75,150) bordercolor (0,75,150)endifendif//drawsegment($overlapfinalx1[x],$overlapfinal[x],barindex,$overlapfinal[x]) coloured(0,75,150) STYLE (dottedline,3)//drawpoint($overlapfinalx2[x],$overlapfinal[x],2) coloured(0,75,150) bordercolor (0,75,150)nextendif//plot the zonereturn1 user thanked author for this post.
04/14/2020 at 10:07 PM #12616804/14/2020 at 10:44 PM #126180To put things into perspective for those who not benefit yet from the V11, please find in attachment what the indicator is drawing automatically on the Dow Future 15min.
Awesome! Still needs further work in my view however.
Nicolas, I hope arrays are available for probacktest?
2 users thanked author for this post.
04/15/2020 at 8:58 AM #126210Very very nice stefou! Well done. This proves the efficiency and the necessity of data arrays to build stunning indicator!
to filter the reversal points and retain only the most relevant one…
Ok, but how do you consider a ‘relevant one’?
You can use arrays in ProBacktest, but you’ll have to put your whole code into the strategy!
04/15/2020 at 6:39 PM #126324The relevant one =
- min distance between a high and low fractal to avoid extreme created during low volatility period
- if there are two consecutive lows without a high in between, only takes into account the lowest one, and disregard the other. Same for top
I have tried somethings for point 2 but this isn’t working, code is very slow and doesn’t do what I want.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586defparam calculateonlastbars=4000once index1=0once index2=0once cp=2index3=0index4=0//fractal high, but only if the previous bar wasn't already a topif high[cp] >= highest[(cp)*2+1](high) and barindex-$TOPx2[max(0,index1)]>1 then$TOPy1[index1] = high[cp]$TOPx1[index1] = barindex[cp]$TOPx2[index1] = barindexdrawpoint($TOPx1[index1],$TOPy1[index1]+20,1) coloured(0,0,0) bordercolor (0,0,0)index1=index1+1endifif low[cp] <= lowest[(cp)*2+1](low) and barindex-$BOTx2[max(0,index2)]>1 then //new fractal low found$BOTy1[index2] = low[cp]$BOTx1[index2] = barindex[cp]$BOTx2[index2] = barindexdrawpoint($BOTx1[index2],$BOTy1[index2]-20,1) coloured(0,0,0) bordercolor (0,0,0)index2=index2+1endifif index1>0 and index2>0 thenfor x=index2 downto 1 dofor y=index1 downto 1 do//I'm looking for the barindex of the previous topif $TOPx1[y]>$BOTx1[x] and $TOPx1[y-1]<$BOTx1[x] thenlasttopx=$TOPx1[y]breakendifnextif lasttopx<>0 then// if distance between two lows is bigger then between the last top and bottom, I save the bottomIf $BOTx1[x]-$BOTx1[x-1]>lasttopx-$BOTx1[x-1] then$BOTy[index3] = $BOTy1[x]$BOTx[index3] = $BOTx1[x]index3=index3+1//otherwise I save again the previous bottomelse$BOTy[index3] = $BOTy1[x-1]$BOTx[index3] = $BOTx1[x-1]endifendifnextendifif index1>0 and index2>0 thenfor x=index1 downto 1 dofor y=index2 downto 1 doif $BOTx1[y]>$TOPx1[x] and $BOTx1[y-1]<$TOPx1[x] thenlastbottomx=$BOTx1[y]breakendifnextif lastbottomx<>0 thenIf $TOPx1[x]-$TOPx1[x-1]>lastbottomx-$TOPx1[x-1] then$TOPy[index4] = $TOPy1[x]$TOPx[index4] = $TOPx1[x]index4=index4+1else$TOPy[index4] = $TOPy1[x-1]$TOPx[index4] = $TOPx1[x-1]index4=index4+1endifendifnextendifif(islastbarupdate and index3>0 and index4>0) thenfor xx=0 to index4 dodrawpoint($TOPx[xx],$TOPy[xx],1) coloured(100,75,150) bordercolor (100,75,150)nextfor yy=0 to index3 dodrawpoint($BOTx[yy],$BOTy[yy],1) coloured(100,75,150) bordercolor (100,75,150)nextendifreturn1 user thanked author for this post.
04/16/2021 at 3:05 PM #167269Hi @stefou102, congrats for your work. Any updates on this interesting indicator?
06/30/2022 at 11:22 AM #19645711/02/2022 at 11:43 AM #20340304/27/2023 at 1:37 PM #213801Hi Stefou, I was thinking about the possibility to compare tops and bottoms and the only idea I had was to put both Tops and bottoms in the same array. The problem of not having overlapping of too many lows and highs remain. I tried to reset the array with a counter, in order to keep the highs and lows only after a specific bars but for some reason it does not work. the variable Barlimit is useless. I put what I did here as it follows.
// https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/
// (please do not remove the link above for future reference)
// Example #1: support and resistance example, based on fractals points// — settings
fractalP = 10
percent = 0.5
barlimit = 500
// — end of settings
DLS =(Date >= 20220101)
//fractals
cp=fractalP
if high[cp] >= highest[(cp)*2+1](high) then //new fractal high found
$FRACTy[lastset($FRACTy)+1] = high[cp] //store fractal value
$FRACTx[lastset($FRACTx)+1] = barindex[cp] //store fractal barindex
ELSE
if low[cp] <= lowest[(cp)*2+1](low) then //new fractal low found
$FRACTy[lastset($FRACTy)+1] = low[cp] //store fractal value
$FRACTx[lastset($FRACTx)+1] = barindex[cp] //stire fractal barindex
endifif(islastbarupdate and isset($FRACTy[0])) then
//check points in a range of X percent
for i = 0 to lastset($FRACTy) do //loop through the tops
for y = 0 to lastset($FRACTy) do //check first top with other tops
change=abs(($FRACTy[y]-$FRACTy[i])/$FRACTy[i]) //percent range between the 2 tops
if change<=percent/100 and barindex-$FRACTx[y]<barlimit and DLS and $FRACTx[i]<>$FRACTx[y] then
if close>min($FRACTy[y],$FRACTy[i]) then //define the color
r=0
g=255
else
r=255
g=0
//if $FRACTx[y]>barlimit and $FRACTx[i]>barlimit then
//$FRACTY[y]=0 and $FRACTY[i]=0
//endif
endif
//plot points at each tops
DRAWPOINT($FRACTx[i],$FRACTy[i],2) COLOURED (r,g,0) BORDERCOLOR (r,g,0)
DRAWPOINT($FRACTx[y],$FRACTy[y],2) COLOURED (r,g,0) BORDERCOLOR (r,g,0)
midlevel=($FRACTy[i]+$FRACTy[y])/2
//display the mid level price
DRAWTEXT(“#midlevel#”, barindex+8, midlevel, monospaced, standard, 14)
//plot the zone
drawrectangle(min($FRACTx[y],$FRACTx[i]),$FRACTy[y],barindex,$FRACTy[i]) coloured(r,g,50,50) bordercolor(r,g,0)
endif
next
next
endif
endif
return -
AuthorPosts
Find exclusive trading pro-tools on