cd1:c>o;
cd2:c<o;
kd:ref(cd1,1) and ref(cd2,2) and ref(h,2)>ref(h,1) and ref(l,2)>ref(l,1);
buy(kd and holding=0,1,limit,VALUEWHEN(cd1,c));
zs:=c<ref(l,ENTERBARS+2);
zy:=c>AVGENTERPRICE+2*(AVGENTERPRICE-ref(l,ENTERBARS+2));//止盈按照2倍止损价差(持仓均价-止损价位)
止损:sell(zs,holding,market);
止盈:sell(zy,holding,market);