首先,你自己添加的2个下单语句,你没有给他合理控制的呀,几乎是无条件的。自然会触发出来。
直接利用你现有的hl这个全局变量,平仓后 赋值作为标记 下次开仓时候判断下
[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);//平多开空条件
hx:=hhv(h,enterbars+1);//注意 这里是用h统计,你也可以考虑用c
if holding>0 then begin
多止损:zs;
if l<zs and hx-avgenterprice>=50*mindiff then
begin
多回撤止损1:sell(1,1,limitr,min(o,zs)-mindiff);
hl:=1;//止损触发后 给hl赋值,作为一个标记
end
if sellcond then sell(1,1,limitr,c);
end
lx:=llv(l,enterbars+1);//注意 这里是用l统计,你也可以考虑用c
if holding<0 then begin
空止损:zs;
if h>zs and avgenterprice-lx>=50*mindiff then
begin
空回撤止损1:sellshort(1,1,limitr,max(o,zs)+mindiff);
hl:=-1;//止损触发后 给hl赋值,作为一个标记
end
if buycond then sellshort(1,1,limitr,c);
end
if holding=0 and buycond and hl<>1 then begin//多头开仓
buy(1,1,limitr,c);
zs:=c-2*atr;
hl:=c;//hl开仓后的最有利价位,刚买入时,最有利价位为开仓价
end
if holding=0 and sellcond and hl<>-1 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 |