input: count(3);
var: x(0), oldest(0), recycle(0), size(99);
array: id[99,3](0); // 0=id, 1=price, 2=count, 3=age
once for x=0 to size begin
id[x,0]=tl_new(d,t,0,d,t,0);
end;
if barstatus(1)=2 then begin
oldest=0;
for x=0 to size begin
if L<=id[x,1] and H>=id[x,1] then begin
id[x,2]=id[x,2]+1;
if id[x,2]=count then begin
id[x,1]=0; id[x,2]=0; id[x,3]=9999999; tl_setend(id[x,0],d,t,0); tl_setbegin(id[x,0],d,t,0); // reset price, count and age
end;
end;
if id[x,1]>0 then tl_setend(id[x,0],d,t,id[x,1]);
id[x,3]=id[x,3]+1;
if id[x,3]>oldest then begin
oldest=id[x,3]; recycle=x;
end;
end;
id[recycle,1]=c; id[recycle,2]=0; id[recycle,3]=0; tl_setend(id[recycle,0],d,t,c); tl_setbegin(id[recycle,0],d,t,c);
end;
|