[PEL] 复制代码 variable:zs:=c,hl:=c;//声明全局变量zs、hl
ma5:=ma(c,5);
ma20:=ma(c,20);
atr:ma(h-l,20);//市场平均波动幅度
buycond:=cross(ma5,ma20);//平空开多条件
sellcond:=cross(ma20,ma5);//平多开空条件
h1:=hhv(h,enterbars+1);//注意 这里是用h统计,你也可以考虑用c
if holding>0 and hl then begin
多止损:zs;
if l<zs and h1-avgenterprice>=50*mindiff then 多回撤止损1:sell(1,1,limitr,min(o,zs)-mindiff);
else if sellcond then sell(1,1,limitr,c);
end
l1:=llv(l,enterbars+1);//注意 这里是用l统计,你也可以考虑用c
if holding<0 then begin
空止损:zs;
if h>zs and avgenterprice-l1>=50*mindiff then 空回撤止损1:sellshort(1,1,limitr,max(o,zs)+mindiff);
else if buycond then sellshort(1,1,limitr,c);
end
if holding=0 and buycond then begin//多头开仓
buy(1,1,limitr,c);
zs:=c-2*atr;
hl:=c;//hl开仓后的最有利价位,刚买入时,最有利价位为开仓价
end
if holding=0 and sellcond then begin//空头开仓
buyshort(1,1,limitr,c);
zs:=c+2*atr;
hl:=c;
end
if holding>0 and enterbars>0 and h>hl then begin//最高价抬升,止损位相应地抬升
hl:=h;
zs:=hl-2*atr;
end
if holding<0 and enterbars>0 and l<hl then begin//最低价下降,止损位相应地下移
hl:=l;
zs:=l+2*atr;
end
效果上应该是差不多的。
|