-- 作者:阿火
-- 发布时间:2011/9/13 15:54:59
-- 把不同模型组合成一个模型的范例
经常碰到塔友有类似的问题,现举个简单的例子
variable:cc1=0,cc2=0; //第一个模型,大于上10周期最高价买入,低于5周期最低价平仓。做空反之 //第二个模型,连续2根K线收阳线买入,做空反之 //用于测试使用。如果实盘,需用专业版的后台,因为可能同一根K线图产生2个同向信号 //或者信号相反时持仓对冲的处理。 yl:=ref(hhv(h,10),1); zc:=ref(llv(l,10),1); yl1:=ref(hhv(h,5),1); zc1:=ref(llv(l,5),1); b2:=ref(c>o,1) and ref(c>o,2); s2:=ref(c<o,1) and ref(c<o,2);
/////////////////////////////////////////第二个模型是开盘价触发,写在最前面 if cc2>0 and s2 then begin cc2:=0; if holding>0 then sell(1,1,limitr,o); else buyshort(1,1,limitr,o); end
if cc2<0 and b2 then begin cc2:=0; if holding<0 then sellshort(1,1,limitr,o); else buy(1,1,limitr,o); end
if cc2=0 and b2 then begin cc2:=1; if holding<0 then sellshort(1,1,limitr,o); else buy(1,1,limitr,o); end
if cc2=0 and s2 then begin cc2:=-1; if holding>0 then sell(1,1,limitr,o); else buyshort(1,1,limitr,o); end //////////////////////////////////////////////////////////////////////////////////////// if cc1>0 and l<zc1 then begin cc1:=0; if holding>0 then sell(1,1,limitr,min(o,zc1-mindiff)); else buyshort(1,1,limitr,min(o,zc1-mindiff)); end
if cc1<0 and h>yl1 then begin cc1:=0; if holding<0 then sellshort(1,1,limitr,max(o,yl1+mindiff)); else buy(1,1,limitr,max(o,yl1+mindiff)); end
if cc1=0 and h>yl then begin cc1:=1; if holding<0 then sellshort(1,1,limitr,max(o,yl+mindiff)); else buy(1,1,limitr,max(o,yl+mindiff)); end
if cc1=0 and l<zc then begin cc1:=-1; if holding>0 then sell(1,1,limitr,min(o,zc-mindiff)); else buyshort(1,1,limitr,min(o,zc-mindiff)); end
|