Code for the ZigZag indicator version V.1 simplified without the use of array.
(see previous: https://www.prorealcode.com/prorealtime-indicators/zigzag-indicator/ )
Similar to the previous one, but draws a fixed number of segments (in the version below, the last 10, between 5 tops and 5 lows – can be increased adding lines in the code as needed).
Easier to use within a strategy, (e.g. Ross’ 1-2-3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
//08/01/2023 - T.F. - V1: ZigZag Version V1: simplified without arrays - draws the last 9 segments (between 5 tops and 5 lows, can be increased as needed) //Sharing on ProRealCode DEFPARAM DRAWONLASTBARONLY=TRUE //Variables: //Points=20 //Pips //Perc=0.25 //% //Type=0 //0=pips; 1=perc VarY=CustomClose //close,tpicalprice, etc //initilaize first point as a "TOP" once LastPoint = 1 once TX0 = barindex once TY0 = VarY //Type ZZ in Points o Perc If Type=0 then //ZZ in pips DeltaY=Points*pipsize elsif Type=1 then //ZZ in % DeltaY=Perc/100*Dclose(1)////Dclose used as ref. endif //ZZ in fase 1 if LastPoint=1 then //lastpoint was a top if VarY>=TY0 then //update last top and stay in LastPoint=1 TY0=VarY TX0=barindex endif if VarY<=TY0-DeltaY then //first point in low LX4=LX3 //shift memory previous points LY4=LY3 LX3=LX2 LY3=LY2 LX2=LX1 LY2=LY1 LX1=LX0 LY1=LY0 LY0=VarY LX0=barindex LastPoint=-1 endif endif //ZZ in fase -1 if LastPoint=-1 then //lastpoint was a low if VarY<=LY0 then //update last low and stay in LastPoint=-1 LY0=VarY LX0=barindex endif if VarY>=LY0+DeltaY then //first point in top TX4=TX3 //shift memory previous points TY4=TY3 TX3=TX2 TY3=TY2 TX2=TX1 TY2=TY1 TX1=TX0 TY1=TY0 TY0=VarY TX0=barindex LastPoint=1 endif endif //---GRAPH--- If lastpoint=1 then drawsegment (barindex,close,TX0,TY0) style (dottedline,2) COLOURED (0,0,200) //segment in progress drawsegment (TX0,TY0,LX0,LY0) style (line,2) COLOURED (0,0,200) //segments definitive drawsegment (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) endif If lastpoint=-1 then drawsegment (barindex,close,LX0,LY0) style (dottedline,2) COLOURED (0,200,0) //segment in progress drawsegment (LX0,LY0,TX0,TY0) style (line,2) COLOURED (0,0,200) //segments definitive drawsegment (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) endif return |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
hI . THIS LOOKS GOOD. Thanks. Just one doubt: is this kind of impulse indicator – does it shows impulses in future as per impulse theory or simply on prices on chart shown?