VARIABLE: fc:=close,fh:=h,fl:=l,fcolor:=0,ft1:=0,fb1:=0,fi:=0,t[4]=0,b[4]=0,pt=1,pb=1;
if datacount<2 then exit;
for i=1 to 4 do begin
t[i]:=i;
b[i]:=1;
end
for i=2 to datacount do begin
if fc[i]>fc[t[pt]] then begin
fh[i]:=fc[i];
fl[i]:=fc[t[1]];
fcolor[i]:=1;
b[4]:=b[3];
b[3]:=b[2];
b[2]:=b[1];
b[1]:=t[1];
t[4]:=t[3];
t[3]:=t[2];
t[2]:=t[1];
t[1]:=i;
pt:=1;
pb:=if(pb=3,3,pb+1);
end
else if fc[i]<fc[b[pb]] then begin
fh[i]:=fc[b[1]];fl[i]:=fc[i];
fcolor[i]:=-1;
t[4]:=t[3];
t[3]:=t[2];
t[2]:=t[1];
t[1]:=b[1];
b[4]:=b[3];
b[3]:=b[2];
b[2]:=b[1];
b[1]:=i;
pb:=1;
pt:=if(pt=3,3,pt+1);
end
else if fc[i]<=fc[t[pt]] and fc[i]>=fc[b[pb]] then begin
fh[i]:=fh[i-1];
fl[i]:=fl[i-1];
fcolor[i]:=fcolor[i-1];
end
ft1[i]:=t[1];
fb1[i]:=b[1];
fi[i]:=i;
end
STICKLINE(fcolor=1,fh,fl,10,0),colorred;
STICKLINE(fcolor=-1,fh,fl,10,0),colorgreen;