自己学写如下,不知哪里出错,请帮忙指出,谢谢!!!
//声明变量
variable: myprice =0 ; //开仓价格
variable: exprice =0 ;
variable:n=0;
variable:m=0;
variable:bj=0;
//准备需要计算的变量
H2 := REF(H,2) ;
L2 := REF(L,2) ;
H1:=ref(H,1);
L1:=ref(L,1);
ZS:=30; //止损,根据不同品种设定
SS:=1 ; //开仓手数
DZY:=L<ref(L,1);//多止盈
KZY:=H>ref(H,1);//空止盈
dzs:=c<myprice-zs;//多止损
kzs:=c>myprice+zs;//空止损
//开多
if h2>=h1 and bj=0 then begin
myprice:=if(o<=h2 and h>h2,h2+mindiff,h2);
myprice:=if(o>h2,o+zs,h2);
buy(n<=2,ss,limitr,myprice);
n:=n+1;
end
//开空
if h2<=h1 and bj=0 then begin
myprice:=if(o>=h2 and h<h2,h2-mindiff,h2);
myprice:=if(o<h2,o-zs,h2);
buyshort(m<=2,ss,limitr,myprice);
m:=m+1;
end
//止损
if dzs then begin
exprice:=if(enterbars<1,myprice-zs,myprice-zs-mindiff);
exprice:=if(enterbars=1 and o<(myprice-zs),o-mindiff,o);
sell(holding>0,0,limitr,exprice);
end
if kzs and enterbars<=1 then begin
exprice:=if(enterbars<1,myprice+zs,myprice+zs+mindiff);
exprice:=if(enterbars=1 and o>(myprice+zs),o+mindiff,o);
sellshort(holding<0,0,limitr,exprice);
end
//止盈
if dzy and enterbars>1 then begin
sell(1,0,market);
end
if kzy and enterbars>1 then begin
sellshort(1,0,market);
end