公式网-网站导航


网站搜索:  

公式指标网 发表于2015/10/25 7:00:30

把不同模型组合成一个模型的范例

金字塔公式 金字塔模型策略源码: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

复制上述代码粘贴到到公式管理器
 



网站搜索:  



Copyright © 2009-2010 gszb.com ™,All Rights Reserved. 
公式网-www.gszx.com.cn-股票指标公式网