variable:HigherAfterEntry=0,LowerAfterEntry=999999;
variable:cs_duo=0,bj=0,cs_kong=0;
input:n1(1,1,3,1);
input:n2(14,5,40,1);
input:n3(95,50,100,1);
MA5: MA(CLOSE,5);
MA10:MA(CLOSE,10);
MA20:MA(CLOSE,20);
avvol:ma(ref(vol,2),5),noaxis,linethick0;
dayopen:=valuewhen(date<>ref(date,1),open);
h_1:=ref(h,1);
l_1:=ref(l,1);
lots:=1;
hh:HigherAfterEntry,noaxis,linethick0;
ll:LowerAfterEntry,noaxis,linethick0;
if holding=0 and MA5>=MA10+2 then
begin
buy(1,lots,limitr,open),IGNORECHECKPRICE;
HigherAfterEntry:=enterprice;
LowerAfterEntry:=enterprice;
bj:=1;
end
if holding=0 and MA5<=MA10-2 then
begin
buySHORT(1,lots,limitr,open),IGNORECHECKPRICE;
HigherAfterEntry:=enterprice;
LowerAfterEntry:=enterprice;
bj:=0;
end
if cs_kong=2 then begin
sellshort(1,0,market);
buy(holding=0,1,market);
bj:=1;
cs_kong:=0;
end
if cs_duo=2 then begin
sell(1,0,market);
buyshort(holding=0,1,market);
cs_duo:=0;
bj:=0;
end
If enterbars=0 then
begin
HigherAfterEntry:=enterprice;
LowerAfterEntry:=enterprice;
end;
If enterbars>=1 then
begin
HigherAfterEntry:=max(HigherAfterEntry,h);
LowerAfterEntry:=min(LowerAfterEntry,l);
end;
if holding>0 then price:=EnterPrice+(HigherAfterEntry-EnterPrice)*n3/100;
if holding<0 then price:=EnterPrice - (EnterPrice-LowerAfterEntry)*n3/100;
if holding>0 and enterbars>0 and HigherAfterEntry>=enterprice*(1+N1/100) and low<=price and bj=1 then
begin
sell(1,holding,limitr,min(open,price)) ,IGNORECHECKPRICE;
if numprofit(1)<0 then cs_duo:=cs_duo+1;
if numprofit(1)>0 then cs_duo:=0;
cs_kong:=0;
end;
if holding<0 and enterbars>0 and lowerAfterEntry<=enterprice*(1-N1/100) and high>=price and bj=0 then
begin
sellshort(1,holding,limitr,max(open,price)),IGNORECHECKPRICE;
if numprofit(1)<0 then cs_kong:=cs_kong+1;
if numprofit(1)>0 then cs_kong:=0;
cs_duo:=0;
end;
if holding>0 and l<=ENTERPRICE-n2 and bj=1 then
begin
sell(1,holding,limitr,enterprice-n2),IGNORECHECKPRICE;
if numprofit(1)<0 then begin
cs_duo:=cs_duo+1;
end
cs_kong:=0;
end
if holding<0 and h>=ENTERPRICE+n2 and bj=0 then
begin
sellshort(1,holding,limitr,enterprice+n2),IGNORECHECKPRICE;
if numprofit(1)<0 then begin
cs_kong:=cs_kong+1;
end
cs_duo:=0;
end