![Rank: 8](static/image/common/star_level3.gif) ![Rank: 8](static/image/common/star_level3.gif)
等级: 超级版主
- 注册:
- 2021-5-18
- 曾用名:
- gxx978
|
参考如下,开仓和平仓语句的第2个参数是报单数量,不是第一个参数;开仓报7手,平仓用holding。
variable:zs=c,hl=c;//声明全局变量zs、hl
ma7:=ma(c,7);
ma21:=ma(c,21);
atr:=ma(h-l,21);//市场平均波动幅度
buycond:=cross(ma7,ma21);//平空开多条件
sellcond:=cross(ma21,ma7);//平多开空条件
if holding>0 then begin
多止损:zs;
if l<zs then sell(1,holding,limitr,min(o,zs)-mindiff);
else if sellcond then sell(1,holding,limitr,c);
end
if holding<0 then begin
空止损:zs;
if h>zs then sellshort(1,holding,limitr,max(o,zs)+mindiff);
else if buycond then sellshort(1,holding,limitr,c);
end
if holding=0 and buycond then begin//多头开仓
buy(1,7,limitr,c);
zs:=c-2*atr;
hl:=c;//hl开仓后的最有利价位,刚买入时,最有利价位为开仓价
end
if holding=0 and sellcond then begin//空头开仓
buyshort(1,7,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 |
|