下面是2个模型组合,图表交易。请问老师模型1与模型2分别交易不超过2次,如何改编呢?
input: cang2(1,0,10,1);
variable:cc1=0,cc2=0;
runmode:0;
variable:zs=0,cc1=0;
ma5:=ma(c,5);
ma20:=ma(c,20);
entertime:=time>100000 and time<144500;
if holding>0 and cc1<=0 then sell(1,1,limitr,o);
if holding<0 and cc1>=0 then sellshort(1,1,limitr,o);
if holding=0 and cc1>0 then buy(1,1,limitr,o);
if holding=0 and cc1<0 then buyshort(1,1,limitr,o);
if cc1>0 and l<zs then begin
sell(1,1,limitr,min(o,zs-0.6));
cc1:=0;
end
if cc1<0 and h>zs then begin
sellshort(1,1,limitr,max(o,zs+0.6));
cc1:=0;
end
if cc1>0 and ma5<ma20 then cc1:=0;
if cc1<0 and ma5>ma20 then cc1:=0;
if cc1=0 and ma5>ma20 and entertime then begin
cc1:=1;
zs:=c-10;
end
if cc1=0 and ma5<ma20 and entertime then begin
cc1:=-1;
zs:=c+10;
end
if time>=150000 then begin
cc1:=0;
end
/////////////////////////////////以上是模型1
/////////////////////////////////模型2——20周期反手
hi:=ref(hhv(h,20),1);
lo:=ref(llv(l,20),1);
if cc2>0 and l<lo then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=0;
end
if cc2<0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=0;
end
if cc2=0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang2);
kc:=cang2-pc;
if pc>0 then sellshort(1,pc,limitr,max(o,hi+0.2)+0.6);
if kc>0 then buy(1,kc,limitr,max(o,hi+0.2)+0.6);
cc2:=1;
end
if cc2=0 and l<lo then begin
pc:=min(max(holding,0),cang2);
kc:=cang2-pc;
if pc>0 then sell(1,pc,limitr,min(o,lo-0.2)-0.6);
if kc>0 then buyshort(1,kc,limitr,min(o,lo-0.2)-0.6);
cc2:=-1;
end
/////////////////////////////////以上是模型2
模型1与模型2分别交易不超过2次
这句话是什么意思呢?
模型1与模型2分别交易不超过2次
这句话是什么意思呢?
variable:num=0;// 全局变量,控制交易次数,没开仓一次把这个值加1。
if holding=0 and cc1>0 and num<2 then
begin
buy(1,1,limitr,o);
num:=num+1;
end
if holding=0 and cc1<0 and num<2 then
being
buyshort(1,1,limitr,o);
num:=num+1;
end
variable:num=0;// 全局变量,控制交易次数,没开仓一次把这个值加1。
if holding=0 and cc1>0 and num<2 then
begin
buy(1,1,limitr,o);
num:=num+1;
end
if holding=0 and cc1<0 and num<2 then
being
buyshort(1,1,limitr,o);
num:=num+1;
num:=num+1加在开仓语句控制交易次数,结果交易信号几乎看不到了;如num:=num+1加在平仓语句中控制交易次数又控制不住,即交易超过2次,如模型不组合在一起分别运行则正常即不超过2次。昨天我已都试过了。老师上面的方法你实际试验的结果如何呀?end
因为num到2之后就不会再开仓了,你得加上个条件什么时候把num重置为0
因为num到2之后就不会再开仓了,你得加上个条件什么时候把num重置为0
if time=closetime(0) then num:=0;// 在代码后加上这句当time等于收盘时num重置为0
你开仓语句里加上一个开仓历时的判断ENTERBARS>0,这样如果当前k线出现开仓信号那么ENTERBARS=0,之后的开仓语句不会执行。