请老师帮忙检查一下下面语句的错误之处,为什么加仓之后会的平仓信号会把首仓的仓位都平掉?
VARIABLE:w:=0,mkwz1:=0,mkwz2:=0;
开空条件:=ama<ama1&&cross(下轨,c);
if 开空条件 and holding=0 then
begin
空1:BUYSHORT(1,x1,market);
w:=1;
mkwz1:=close;
hh1:=l;
end
if l<hh1 then hh1:=L;
cz1:=intpart(mkwz1+(mkwz1*mm));
初止条件1:=c>=cz1;
if w=1 then begin
止5:sellshort(a15,x1,MARKETR );
止损1:sellshort(初止条件1,x1,MARKET);
end
if w=1 then begin
if z2<=41z then
begin
止4:sellshort(b41,x1, marketr);
end
else begin
if a14 then begin
盈14:sellshort(1,x1,marketr);
end
end
end
if w=1 then begin
if z5<=31z then
begin
止3:sellshort(b31,x1, marketr);
end
else begin
if a13 then begin
盈13:sellshort(1,x1,marketr);
end
end
end
if w=1 then begin
if z10<=21z then
begin
止2:sellshort(b21,x1, marketr);
end
else begin
if a12 then begin
盈12:sellshort(1,x1,marketr);
end
end
end
if w=1 then begin
if z20<=11d then
begin
止1:sellshort(b11,x1, marketr);
end
else begin
if a11 then begin
盈11:sellshort(1,x1,marketr);
end
end
end
//第二仓信号;
yy:=intpart(mkwz1-mkwz1*MM);
jc1:=hh1<=yy;
if w=1 and jc1 and 开空条件 then
begin
空2:BUYSHORT(1,s1,market);
w:=2;
hh2:=l;
mkwz2:=c;
end
if l<hh2 then hh2:=l;
cz:=intpart(mkwz2+(mkwz2*0.04));
初止条件:=c>=cz;
全平条件:=ama>ama1;
if w=2 then begin
止损:sellshort(初止条件,s1,MARKET);
止盈5:sellshort(a5,s1,MARKETR );
end
if w=2 then begin
if z2<=4z then
begin
止盈4:sellshort(b4,s1, marketr);
end
else begin
if a4 then begin
盈4:sellshort(1,s1,marketr);
end
end
end
if w=2 then begin
if z5<=3z then
begin
止盈3:sellshort(b3,s1, marketr);
end
else begin
if a3 then begin
盈3:sellshort(1,s1,marketr);
end
end
end
if w=2 then begin
if z10<=2z then
begin
止盈2:sellshort(b2,s1, marketr);
end
else begin
if a2 then begin
盈2:sellshort(1,s1,marketr);
end
end
end
if w=2 then begin
if z20<=1d then
begin
止盈1:sellshort(b1,s1, marketr);
end
else begin
if a1 then begin
盈1:sellshort(1,s1,marketr);
end
end
end
if holding<0 and 全平条件 then begin
全平:sellshort(1,0,market);
w:=0;
end