cc:=CLOSE;
oo:=OPEN;
hh:=HIGH;
ll:=LOW;
top:=HIGH;
bot:=LOW;
xx[1]:=1;
kk:=1;
for i=1 to DATACOUNT do begin IF xx[i]=1 then begin top[i]:=hh[i];
end;
IF xx[i-1]=1 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
xx[i]:=2;
end;
end;
IF xx[i-1]=2 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
bot[i]:=ll[i];
xx[i]:=3;
end;
end;
IF xx[i-1]=3 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=4;
end;
end;
IF xx[i-1]=4 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=5;
end;
end;
IF xx[i-1]=5 then begin IF ll[i]<bot[i-1] or hh[i]>top[i-1] then begin top[i]:=hh[i];
bot[i]:=hh[i];
xx[i]:=1;
end;
else begin bot[i]:=bot[i-1];
top[i]:=top[i-1];
xx[i]:=5;
end;
end;
end;
for j=1 to DATACOUNT do begin IF xx[j]=5 and xx[j-1]=4 then begin for k=j-1 downto j-kk do begin top[k]:=top[j];
bot[k]:=bot[j];
end;
end;
IF xx[j-1]=5 and xx[j]=1 then kk:=0;
kk:=kk+1;
end;
cc:=CLOSE;
oo:=OPEN;
hh:=HIGH;
ll:=LOW;
top:=HIGH;
bot:=LOW;
xx[1]:=1;
kk:=1;
for i=1 to DATACOUNT do begin IF xx[i]=1 then begin top[i]:=hh[i];
end;
IF xx[i-1]=1 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
xx[i]:=2;
end;
end;
IF xx[i-1]=2 then begin IF hh[i]>top[i-1] then begin top[i]:=hh[i];
xx[i]:=1;
end;
else begin top[i]:=top[i-1];
bot[i]:=ll[i];
xx[i]:=3;
end;
end;
IF xx[i-1]=3 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=4;
end;
end;
IF xx[i-1]=4 then begin top[i]:=top[i-1];
IF ll[i]<bot[i-1] then begin bot[i]:=ll[i];
xx[i]:=3;
end;
else begin bot[i]:=bot[i-1];
xx[i]:=5;
end;
end;
IF xx[i-1]=5 then begin IF ll[i]<bot[i-1] or hh[i]>top[i-1] then begin top[i]:=hh[i];
bot[i]:=hh[i];
xx[i]:=1;
end;
else begin bot[i]:=bot[i-1];
top[i]:=top[i-1];
xx[i]:=5;
end;
end;
end;
for j=1 to DATACOUNT do begin IF xx[j]=5 and xx[j-1]=4 then begin for k=j-1 downto j-kk do begin top[k]:=top[j];
bot[k]:=bot[j];
end;
end;
IF xx[j-1]=5 and xx[j]=1 then kk:=0;
kk:=kk+1;
end;