目的:秒轮询k线结束后马上开仓,到zs止损,止损后同方向不马上开仓.
存在问题:1:有时k线结束开,有时马上开。2:到zs不止损。
s:=1;
zs1:=20;
variable:zs=0,cc=0,hl=0,nn1=0,LK1=0,LK2=0;
NN:=BARSLAST(DATE>REF(DATE,1));
AA1:=REF(hhv(h,1),1);
BB1:=REF(llv(l,1),1);
AA3:=REF(hhv(h,3),3);
BB3:=REF(llv(l,l),3);
LKK1:LK1;
if holding>0 and cc<=0 then begin
sell(1,S,MARKETR); //平多
LK1:=0;
end
if holding<0 and cc>=0 then begin
sellshort(1,S,MARKETR); //平空
LK2:=0;
end
LKKL1:=ENTERBARS>2 OR LK1=0;
if holding=0 and cc>0 AND LKKL1 then begin
// sellshort(1,S,MARKETR);
buy(1,S,MARKETR); //开多
nn1:=nn;
end
LKKL2:=ENTERBARS>2 OR LK2=0;
if holding=0 and cc<0 AND LKKL2 then begin
// sell(1,S,MARKETR);
buyshort(1,S,MARKETR); //开空
nn1:=nn;
end
if cc>0 and l<zs then begin //止损平多
sell(1,1,limitr,min(o,zs-0.6));
cc:=0;
LK1:=1;
end
if cc<0 and h>zs then begin //止损平空
sellshort(1,1,limitr,max(o,zs+0.6));
cc:=0;
LK2:=-1;
end
if cc>0 and AA1<BB1 then cc:=0; //平多
if cc<0 and AA1>BB1 then cc:=0; //平空
if cc=0 and BB1<AA1 AND BB3<AA3 AND TIME<151000 then begin
cc:=1; //开多
zs:=c-zs1;
hl:=h;
LK2:=0;
end
if cc=0 and BB1>AA1 AND BB3>AA3 AND TIME<151000 then begin
cc:=-1; //开空
zs:=c+zs1;
hl:=l;
LK1:=0;
end
if cc>0 and h>hl then begin //创新高后,上移hl
hl:=h;
nn2:=nn-nn1;
nn3:=if(nn2>9,10,nn2);
zs:=hl-zs1+nn3*2;
end
if cc<0 and l<hl then begin //创新低后,下移hl
hl:=l;
nn2:=nn-nn1;
nn3:=if(nn2>9,10,nn2);
zs:=hl+zs1-nn3*2;
end
if time>=151000 then begin
cc:=0;
SELLSHORT( HOLDING<0 ,S ,MARKETR );
SELL( HOLDING>0 ,S , MARKETR );
end
1.在轮询的情况下要实现走完k线,把你的条件都ref1一下,比如条件是c>O就改成ref(c>o,1)
2.你的止损价格是怎么定义的?