下面是2個(gè)模型組合,圖表交易。請(qǐng)問老師模型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次
這句話是什么意思呢?
就是模1開倉不超過2次,模2開倉不超過2次。
variable:num=0;// 全局變量,控制交易次數(shù),沒開倉一次把這個(gè)值加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;// 全局變量,控制交易次數(shù),沒開倉一次把這個(gè)值加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加在開倉語句控制交易次數(shù),結(jié)果交易信號(hào)幾乎看不到了;如num:=num+1加在平倉語句中控制交易次數(shù)又控制不住,即交易超過2次,如模型不組合在一起分別運(yùn)行則正常即不超過2次。昨天我已都試過了。老師上面的方法你實(shí)際試驗(yàn)的結(jié)果如何呀?num:=num+1;
end