说明:本公式适用于金字塔程序化交易软件
因为图表交易同一根K线出现2个开多信号的话,只会开一次,另外一个无法执行,但是可以做历时回测
组合起来的模型,加入后台下单语句,就可以用于后台下单,当然,后台下单用“后台下单模板”会更好用。
方法原理:计算每个时点要下单的手数和方向,再根据holding判断出要平仓和开仓的数量,然后再下单。
看起来很多,其实很简单,最基本得模块就是蓝色部分
input:cang1(1,0,10,1),cang2(1,0,10,1);
variable:cc1=0,cc2=0;
/////////////////////////////////模型1——10周期反手
hi:=ref(hhv(h,10),1);
lo:=ref(llv(l,10),1);
if cc1>0 and l<lo then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-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);
cc1:=0;
end
if cc1<0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-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);
cc1:=0;
end
if cc1=0 and h>hi then begin
pc:=min(abs(min(holding,0)),cang1);
kc:=cang1-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);
cc1:=1;
end
if cc1=0 and l<lo then begin
pc:=min(max(holding,0),cang1);
kc:=cang1-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);
cc1:=-1;
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
//有更多的模型,往后面添加即可
如果各个模型都是K线走完模式的,可以这样组合更加方便
variable:lee=0;
kc1:=max(lee,0)-max(holding,0);
kc2:=min(lee,0)-min(holding,0);
if kc1<-0.5 then sell(1,abs(kc1),limitr,open);
if kc2>0.5 then sellshort(1,kc2,limitr,open);
if kc1>0.5 then buy(1,kc1,limitr,open);
if kc2<-0.5 then buyshort(1,abs(kc2),limitr,open);
//模型1
variable:cc1=0;
buycond1:=c>ref(c,1) and ref(c,1)>ref(c,2);
sellcond1:=c<ref(c,1) and ref(c,1)<ref(c,2);
if cc1>0 and sellcond1 then cc1:=0;
if cc1<0 and buycond1 then cc1:=0;
if cc1=0 and buycond1 then cc1:=1;
if cc1=0 and sellcond1 then cc1:=-1;
//模型2
variable:cc2=0;
buycond2:=ma(c,5)>ma(c,20);
sellcond2:=ma(c,5)<ma(c,20);
if cc2>0 and sellcond2 then cc2:=0;
if cc2<0 and buycond2 then cc2:=0;
if cc2=0 and buycond2 then cc2:=1;
if cc2=0 and sellcond2 then cc2:=-1;
//模型3
variable:cc3=0;
buycond3:=ma(c,10)>ma(c,30);
sellcond3:=ma(c,10)<ma(c,30);
if cc3>0 and sellcond3 then cc3:=0;
if cc3<0 and buycond3 then cc3:=0;
if cc3=0 and buycond3 then cc3:=1;
if cc3=0 and sellcond3 then cc3:=-1;
lee:=1*cc1+1*cc2+1*cc3;//每个模型乘以各自的下单系数
|