Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共2 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

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

1楼
阿火 发表于: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

2楼
阿火 发表于:2011/9/13 19:49:20

怎么跑到策略发布区了?

这是不同模型组合的模板,碰到仓位相反时,会对冲仓位,实盘时可节约资金、减少手续费。

[此贴子已经被作者于2011-9-13 19:50:42编辑过]
共2 条记录, 每页显示 10 条, 页签: [1]


Powered By Dvbbs Version 8.3.0
Processed in 0.03400 s, 2 queries.