ZigZag Indicator using Highs and Lows
Forums › ProRealTime English forum › ProBuilder support › ZigZag Indicator using Highs and Lows
- This topic has 7 replies, 3 voices, and was last updated 1 year ago by LaMaille.
-
-
09/04/2023 at 2:48 PM #220309
Dear Nicolas, Dear Members of the Forum,
I want to code a ZigZag Indicator that uses highs and lows instead of just the close (as the one included in the Platform does) as a reference point.
I have found some great code for making a ZigZag Indicator (https://www.prorealcode.com/prorealtime-indicators/zigzag-indicator/), but it also uses the close instead of the high for peaks and the low for troughs. Although there is a suggestion of how to incorporate highs/lows in the comments, the version suggested there seems to hardcode the segments to be drawn instead of using arrays, thus limiting the segments that can be drawn. Has anybody got an idea of how the code linked above could be rewritten to use highs/lows instead of the close (or alternatively, how the code in the comments https://www.prorealcode.com/prorealtime-indicators/zigzag-indicator/#comment-12840 could be rewritten to make it possible to adjust the numbers of segments drawn freely)?
Thank you so much for helping me.
Regards, Nils
1 user thanked author for this post.
09/04/2023 at 3:45 PM #22031609/04/2023 at 3:48 PM #220317ZigZag High-Low123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990DEFPARAM DRAWONLASTBARONLY=TRUE//Variabili:Punti=3 * averagetruerange[200] //PipsPercentuale=0.25 //%Tipo=0 //0=pips; 1=perc//VarY=CustomClose //close,tpicalprice, etc//inizializzo primo punto come TOPonce LastPoint = 1once TX0 = barindexonce TY0 = close//Tipo ZZ in Punti o PercentualeIf Tipo=0 then //ZZ in puntiDeltaY=Punti//*pipsizeelsif tipo=1 then //ZZ in %DeltaY=Percentuale/100*Dclose(1)//usato Dclose come rif. per stabilità del valoreendif//ZZ in fase 1if LastPoint=1 then //ultimo punto era un massimoif high>=TY0 then // aggiorno il punto di max e rimango in LastPoint=1TY0=highTX0=barindexelsif low<=TY0-DeltaY then //primo punto definitivo lowrem for i=PI downto 0 do //shift memoria punti precedentiLX4=LX3LY4=LY3LX3=LX2LY3=LY2LX2=LX1LY2=LY1LX1=LX0LY1=LY0LY0=lowLX0=barindexLastPoint=-1endifendif//ZZ in fase -1if LastPoint=-1 then //ultimo punto era un minimoif low<=LY0 then // aggiorno il punto di min e rimango in LastPoint=-1LY0=lowLX0=barindexelsif high>=LY0+DeltaY then //primo punto definitivo topTX4=TX3TY4=TY3TX3=TX2TY3=TY2TX2=TX1TY2=TY1TX1=TX0TY1=TY0TY0=highTX0=barindexLastPoint=1endifendif//—GRAFICA—If lastpoint=1 thendrawsegment (barindex,high,TX0,TY0) style (dottedline,2) COLOURED (0,0,200) //segmento in progressdrawsegment (TX0,TY0,LX0,LY0) style (line,2) COLOURED (0,0,200) //segmenti definitividrawsegment (LX0,LY0,TX1,TY1) style (line,2) COLOURED (0,0,200)drawsegment (TX1,TY1,LX1,LY1) style (line,2) COLOURED (0,0,200)drawsegment (LX1,LY1,TX2,TY2) style (line,2) COLOURED (0,0,200)drawsegment (TX2,TY2,LX2,LY2) style (line,2) COLOURED (0,0,200)drawsegment (LX2,LY2,TX3,TY3) style (line,2) COLOURED (0,0,200)drawsegment (TX3,TY3,LX3,LY3) style (line,2) COLOURED (0,0,200)drawsegment (LX3,LY3,TX4,TY4) style (line,2) COLOURED (0,0,200)drawsegment (TX4,TY4,LX4,LY4) style (line,2) COLOURED (0,0,200)endifIf lastpoint=-1 thendrawsegment (barindex,low,LX0,LY0) style (dottedline,2) COLOURED (0,200,0) //segmento in progressdrawsegment (LX0,LY0,TX0,TY0) style (line,2) COLOURED (0,0,200) //segmenti definitividrawsegment (TX0,TY0,LX1,LY1) style (line,2) COLOURED (0,0,200)drawsegment (LX1,LY1,TX1,TY1) style (line,2) COLOURED (0,0,200)drawsegment (TX1,TY1,LX2,LY2) style (line,2) COLOURED (0,0,200)drawsegment (LX2,LY2,TX2,TY2) style (line,2) COLOURED (0,0,200)drawsegment (TX2,TY2,LX3,LY3) style (line,2) COLOURED (0,0,200)drawsegment (LX3,LY3,TX3,TY3) style (line,2) COLOURED (0,0,200)drawsegment (TX3,TY3,LX4,LY4) style (line,2) COLOURED (0,0,200)drawsegment (LX4,LY4,TX4,TY4) style (line,2) COLOURED (0,0,200)endifreturn1 user thanked author for this post.
09/04/2023 at 4:44 PM #220321Dear JS,
thank you for replying. I have tried the ZigZag Code that you reposted here. The problem that I have is that it draws only 10 Segments, as this is what is hardcoded below line 64. What I want is the possibility to dynamically adjust the amount of segments coded like it can be done with the indicator I linked above (https://www.prorealcode.com/prorealtime-indicators/zigzag-indicator/) just with highs and lows instead of just the close.
Regards, Nils
09/04/2023 at 5:34 PM #22032309/04/2023 at 5:38 PM #22032409/08/2023 at 12:38 PM #220573Here’s the same ZigZag Indicator (https://www.prorealcode.com/prorealtime-indicators/zigzag-indicator/), with the high and lows instead of close.
ZigZag Highs and Lows with Array123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475//17/12/2022 - T.F. - ZigZag code with Array//Sharing ProRealCodeDEFPARAM DRAWONLASTBARONLY=TRUE//Variables://Points=20 //Pips//Perc=0.25 //%//Type=0 //0=pips; 1=perc//Segments=10 //n. segments up/dw to showPI=max(0,(Segments-1)) //points top/low back to storeVarY=CustomClose //close,tpicalprice, etc//inizializzo primo punto come TOPonce LastPoint = 1once $TX[0] = barindexonce $TY[0] = High//Tipo ZZ in Punti o PercentualeIf Type=0 then //ZZ in pipsDeltaY=max(2*pipsize,Points*pipsize)elsif Type=1 then //ZZ in %DeltaY=max(0.001,Perc/100*Dclose(1)*pipsize) //Dclose used as ref.endif//ZZ in fase 1if LastPoint=1 then //lastpoint was a topif High>$TY[0] then //update last top and stay in LastPoint=1$TY[0]=High$TX[0]=barindexelsif Low<=($TY[0]-DeltaY) then //first point in lowfor i=PI downto 0 do //shift memory previous points$LX[i+1]=$LX[i]$LY[i+1]=$LY[i]next$LY[0]=Low //store new low and change lastpoint$LX[0]=barindexLastPoint=-1endifendif//ZZ in fase -1if LastPoint=-1 then //lastpoint was a lowif Low<$LY[0] then //update last low and stay in LastPoint=-1$LY[0]=Low$LX[0]=barindexelsif High>=($LY[0]+DeltaY) then //first point in topfor i=PI downto 0 do //shift memory previous points$TX[i+1]=$TX[i]$TY[i+1]=$TY[i]next$TY[0]=High //store new top and change lastpoint$TX[0]=barindexLastPoint=1endifendif//---GRAPH---If LastPoint=1 thendrawsegment (barindex,Low,$TX[0],$TY[0]) style (dottedline,2) COLOURED (0,0,200) //segment in progressfor i=0 to PI do //final segmentsdrawsegment ($TX[i],$TY[i],$LX[i],$LY[i]) style (line,2) COLOURED (0,0,200)drawsegment ($LX[i],$LY[i],$TX[i+1],$TY[i+1]) style (line,2) COLOURED (0,0,200)nextendifIf LastPoint=-1 thendrawsegment (barindex,High,$LX[0],$LY[0]) style (dottedline,2) COLOURED (0,0,200) //segment in progressfor i=0 to PI do //final segmentsdrawsegment ($LX[i],$LY[i],$TX[i],$TY[i]) style (line,2) COLOURED (0,0,200)drawsegment ($TX[i],$TY[i],$LX[i+1],$LY[i+1]) style (line,2) COLOURED (0,0,200)nextendifreturn4 users thanked author for this post.
09/08/2023 at 12:42 PM #220575 -
AuthorPosts
Find exclusive trading pro-tools on