现有开多条件kd 开空条件kk 平多仓kk 平空仓kd 每次开平一手
我这个策略是反手策略 开多平仓后开空 开空平仓后开多
现在呢我想加入一个加仓策略 ,那么就是如果上一次平仓后亏损 ,那么这次开仓的手数是上一次开仓手数的N倍,然后跟随一个追踪移动平仓(也就是开仓后当最新高价或者最新低价与开仓均价大于M点回撤X点平仓),次加仓和追踪移动平仓只适合在加仓的情况下使用,也就是说如果上一平仓次盈利出局后再次开仓不适合此策略,则是按照一手去开仓;
以MA为例,如下代码仅做为示例参考。请您结合您的策略进行修改
VARIABLE:scsy=0,p=1; //记录上次平仓亏损还是盈利
N:2;
m:20;
X:5;
m1:=ma(c,5);
m2:=ma(c,10);
kd:=cross(m1,m2);
kk:=cross(m2,m1);
if kd and holding<=0 then
begin
sellshort(1,holding,market);
if (close-enterprice)>0 then
begin
p:=N;
scsy:=1; //上次交易亏损
end
else
begin
p:=1;
scsy:=0;
end
buy(1,1*p,market);
end
if kk and holding>=0 then
begin
sell(1,holding,market);
if (close-enterprice)<0 then
begin
p:=N;
scsy:=1; //上次交易亏损
end
else
begin
p:=1;
scsy:=0;
end
buyshort(1,1*p,market);
end
zd:=llv(l,enterbars+1);// 开仓以来的最低价
zg:=hhv(h,enterbars+1);// 开仓以来的最高价
if zg-enterprice>m and scsy=1 then
begin
if zg-c>x then 多止损:sell(1,holding,market);
scsy:=0;
end
if enterprice-zd>m and scsy=1 then
begin
if c-zd>x then 空止损:sellshort(1,holding,market);
scsy:=0;
end