/*[[ Name := Fractal ZigZag Author := Ginger © 2004, Company Link := http://www.company.com/ Separate Window := No First Color := Cyan First Draw Type := Line First Symbol := 158 Use Second Data := Yes Second Color := Red Second Draw Type := Symbol Second Symbol := 158 ]]*/ Variable : shift(0),FU(0),FD(0),PU(0),PD(0),Trend(0),F(0),n(0),hFile(0),p1(0),t1(0),p2(0),t2(0),p3(0),t3(0),alpha(0); Inputs : Level(2),nBars (400),BuildChanel(0); SetLoopCount(0); // loop from first bar to current bar (with shift=0) Trend=2; shift=nBars; while shift>Level-1 begin SetIndexValue(shift,0); SetIndexValue2(shift,0); F=L[shift]; for n=1 to Level Begin if L[shift+n]0 then begin if FD<>0 then switch Trend Begin case 1: if FFD then Begin SetIndexValue(PD,FD); Trend=1; if PU>=PD then begin FU=0; PU=0; end; end; end; FD=F; PD=shift; SetIndexValue2(PD,FD); end; F=H[shift]; for n=1 to Level Begin if H[shift+n]>H[shift] or H[shift-n]>H[shift] then F=0; end; if F>0 then begin if FU<>0 then switch Trend Begin case 1: if F=PU then begin FD=0; PD=0; end; end; case 2: if F>FU then Begin SetIndexValue(PD,FD); Trend=1; end; end; FU=F; PU=shift; SetIndexValue2(PU,FU); end; shift--; End; if Trend=1 then SetIndexValue(PU,FU) else SetIndexValue(PD,FD); if BuildChanel=1 then Begin p1=0; t1=0; p2=0; t2=0; p3=0; t3=0; shift=nBars; while shift>=0 begin FU-=alpha; FD-=alpha; F=GetIndexValue(shift); if F>0 and shift>Level-1 then Begin p1=p2;t1=t2; p2=p3;t2=t3; p3=F;t3=shift; alpha=(p1-p3)/(t1-t3); print(alpha); FU=F; FD=p2-(t2-t3)*alpha; if FU0 then Begin SetIndexValue(shift,FU); SetIndexValue2(shift,FD); end; shift--; end; end;