INPUT:P(6,2,150,2),S(12,2,150,2),M(20,2,100,6);
variable:zs=0,hl=10000000;
MA6:MA(C,P);
MA12:MA(C,S);
MA20:MA(C,M);
buycond:C>ref(hhv(h,5),1) AND C>MA20 ;//开多
sellcond:C<ref(llv(l,5),1) AND C<MA20 ;//开空
K1:CROSS(MA12,MA6);
K2:CROSS(MA6,MA12);
if holding=0 and buycond then begin
buy(1,1,limitr,c);
zs:=AVGENTERPRICE-0.01*AVGENTERPRICE;
hl:=c;
end
if holding=0 and sellcond then begin
buyshort(1,1,limitr,c);
zs:=AVGENTERPRICE+0.01*AVGENTERPRICE;
hl:=c;
end
HH:=HHV(H,ENTERBARS+1 );
LL:=LLV(L,ENTERBARS+1 );
if holding>0 and enterbars>0 and HH>=hl+0.02*AVGENTERPRICE then begin
hl:=AVGENTERPRICE;
zs:=hl+0.01*AVGENTERPRICE;
end
if holding<0 and enterbars>0 and LL<=hl-0.02*AVGENTERPRICE then begin
hl:=AVGENTERPRICE;
zs:=hl-0.01*AVGENTERPRICE;
end
if l<enterprice*0.99 and enterbars>0 then 止损多1:sell(1,1,limitr,min(o,zs)-mindiff);
if K1 then 止损多2:sell(1,1,limitr,c);
if hh>enterprice*1.02 and l<enterprice*1.01 and enterbars>0 then 移动止损多:sell(1,1,limitr,open)
if h>enterprice*1.01 and enterbars>0 then 止损空1: sellshort(1,1,limitr,max(o,zs)+mindiff);
if K2 then 止损空2:sellshort(1,1,limitr,c);
if ll<enterprice*0.98 and h>enterprice*0.99 and enterbars>0 then sellshort(1,0,limitr,close);
//盈
if HOLDING>0 AND HH>=AVGENTERPRICE+0.03*AVGENTERPRICE and enterbars>0 then begin//多盈
多赢:sell(1,1,MARKET);
end
if HOLDING<0 AND LL<=AVGENTERPRICE-0.03*AVGENTERPRICE and enterbars>0 then begin //空盈
空赢:sellshort(1,1,MARKET);
end
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;