欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → [原创]多策略多账户下单——阿火版

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有14633人关注过本帖树形打印复制链接

主题:[原创]多策略多账户下单——阿火版

帅哥哟,离线,有人找我吗?
阿火
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 原leevolvo
等级:版主 帖子:2160 积分:10563 威望:0 精华:11 注册:2010/11/3 11:21:19
[原创]多策略多账户下单——阿火版  发帖心情 Post By:2011/7/23 15:15:11    Post IP:59.61.40.20[只看该作者]

今天大发慈悲,急塔友之所急

把我一直在使用的多策略多账户下单的方法共享给大家:

 

解释:

1,  一个后台程序包含6个策略,控制5个账户下单。

     用ctrl+H,把800043、800167、888888、666666、999999改为自己的模拟账户即可交易

     要多少策略,多少账户,尽管自己添加。

2,下单累计满10手,即延迟一定的时间再来下单,也可删除,看个人喜好

3,可防止日内满仓干反手下单的时候出现保证金不足情况,资金充足的情况下无需这个功能

    需在出现信号的当根K线内平仓完毕,99.999%都可以做到,不建议采用orderqueue处理

4,不同的策略都必须在同一个时间出现各自的信号

    比如:策略一开盘下多单,策略二盘中突破开多。

           由于一根K线只能下一次单,所以策略二的多单不会下单

           当然可以采用allowrepeat避免这个问题,也已经开发完毕,后续再共享给大家。我自己先玩玩

5,以下红色部分为单个账户完整的下单代码

 

 

variable:cc1=0,cc2=0,cc3=0,cc4=0,cc5=0,cc6=0;
if workmode<>1 then exit;
entertime:=time<150000;
exittime:=time>=150000;
//策略1
buycond1:=ref(c,1)>ref(o,1) and ref(c,2)>ref(o,2) and ref(c,3)>ref(o,3);
sellcond1:=ref(c,1)<ref(o,1) and ref(c,2)<ref(o,2) and ref(c,3)<ref(o,3);
//策略2
buycond2:=ref(h,1)>ref(hhv(h,10),2);
sellcond2:=ref(l,1)<ref(llv(l,10),2);
//策略3
ma5:=ma(c,5);
ma15:=ma(c,15);
buycond3:=ref(ma5,1)>ref(ma15,1);
sellcond3:=ref(ma5,1)<ref(ma15,1);
//策略4
buycond4:=ref(l,1)>ref(h,3);
sellcond4:=ref(h,1)<ref(l,3);
//策略5
buycond5:=ref(c,1)>ref(c,15);
sellcond5:=ref(c,1)<ref(c,15);
//策略6
buycond6:=ref(vol,1)>ref(vol,2) and ref(vol,2)>ref(vol,3) and ref(vol,3)>ref(vol,4);
sellcond6:=ref(vol,1)<ref(vol,2) and ref(vol,2)<ref(vol,3) and ref(vol,3)<ref(vol,4);;

if cc1>0 and (sellcond1 or exittime) then cc1:=0;
if cc1<0 and (buycond1 or exittime) then cc1:=0;
if cc1=0 and buycond1 and entertime then cc1:=1;
if cc1=0 and sellcond1 and entertime then cc1:=-1;

 

if cc2>0 and (sellcond2 or exittime) then cc2:=0;
if cc2<0 and (buycond2 or exittime) then cc2:=0;
if cc2=0 and buycond2 and entertime then cc2:=1;
if cc2=0 and sellcond2 and entertime then cc2:=-1;

 

if cc3>0 and (sellcond3 or exittime) then cc3:=0;
if cc3<0 and (buycond3 or exittime) then cc3:=0;
if cc3=0 and buycond3 and entertime then cc3:=1;
if cc3=0 and sellcond3 and entertime then cc3:=-1;

 

if cc4>0 and (sellcond4 or exittime) then cc4:=0;
if cc4<0 and (buycond4 or exittime) then cc4:=0;
if cc4=0 and buycond4 and entertime then cc4:=1;
if cc4=0 and sellcond4 and entertime then cc4:=-1;

 

if cc5>0 and (sellcond5 or exittime) then cc5:=0;
if cc5<0 and (buycond5 or exittime) then cc5:=0;
if cc5=0 and buycond5 and entertime then cc5:=1;
if cc5=0 and sellcond5 and entertime then cc5:=-1;

 

if cc6>0 and (sellcond6 or exittime) then cc6:=0;
if cc6<0 and (buycond6 or exittime) then cc6:=0;
if cc6=0 and buycond6 and entertime then cc6:=1;
if cc6=0 and sellcond6 and entertime then cc6:=-1;

 

cc800043:= 2*cc1 + 1*cc2+2*cc3 + 5*cc4 + 1*cc5 + 0*cc6;//不同账户用不同的下单系数
cc800167:= 3*cc1 + 2*cc2+1*cc3 + 0*cc4 + 2*cc5 + 4*cc6;//不同账户用不同的下单系数
cc888888:= 1*cc1 + 2*cc2+2*cc3 + 1*cc4 + 3*cc5 + 2*cc6;//不同账户用不同的下单系数
cc666666:= 0*cc1 + 3*cc2+5*cc3 + 1*cc4 + 2*cc5 + 2*cc6;//不同账户用不同的下单系数
cc999999:= 2*cc1 + 2*cc2+1*cc3 + 5*cc4 + 3*cc5 + 0*cc6;//不同账户用不同的下单系数

 

lcc800043:=ref(cc800043,1);
lcc800167:=ref(cc800167,1);
lcc888888:=ref(cc888888,1);
lcc666666:=ref(cc666666,1);
lcc999999:=ref(cc999999,1);


if not(islastbar) then exit;
liang:=0;

 

/////////////////////////////下单账户 800043
xiadan800043:=cc800043-lcc800043;
if xiadan800043>0 then begin
 cang:=min(xiadan800043,abs(lcc800043));
 if lcc800043<0 then begin
  tsellshort(1,cang,mkt,0,0,'800043');
  liang:=liang+cang;
  if liang>=10 then begin//下单量累积到10手,则延迟一定的时间
   liang:=0;
   sleep(3000);//延迟3秒
  end
 end
 cang:=(xiadan800043+min(lcc800043,0));
 if tsellholdingex('800043','',1)=0 and tremainqty(4,'800043',stklabel)=0 and cang>0 then begin
 //在空单全部平仓完毕的情况下开多单,防止日内满仓反手下单的时候出现保证金不足 
  tbuy(1,cang,mkt,0,0,'800043');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end
 end
end

if xiadan800043<0 then begin
 cang:=min(abs(xiadan800043),abs(lcc800043));
 if lcc800043>0 then begin
  tsell(1,cang,mkt,0,0,'800043');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
 cang:=(abs(xiadan800043)-max(lcc800043,0));
 if tbuyholdingex('800043','',1)=0 and tremainqty(2,'800043',stklabel)=0 and cang>0 then begin
 //在多单全部平仓完毕的情况下开空单,防止日内满仓反手下单的时候出现保证金不足 
  tbuyshort(1,cang,mkt,0,0,'800043');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
end
//////////////////////////////////////////////
/////////////////////////////下单账户 800167
xiadan800167:=cc800167-lcc800167;
if xiadan800167>0 then begin
 cang:=min(xiadan800167,abs(lcc800167));
 if lcc800167<0 then begin
  tsellshort(1,cang,mkt,0,0,'800167');
  liang:=liang+cang;
  if liang>=10 then begin//下单量累积到10手,则延迟一定的时间
   liang:=0;
   sleep(3000);//延迟3秒
  end
 end
 cang:=(xiadan800167+min(lcc800167,0));
 if tsellholdingex('800167','',1)=0 and tremainqty(4,'800167',stklabel)=0 and cang>0 then begin
 //在空单全部平仓完毕的情况下开多单,防止日内满仓反手下单的时候出现保证金不足 
  tbuy(1,cang,mkt,0,0,'800167');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end
 end
end

if xiadan800167<0 then begin
 cang:=min(abs(xiadan800167),abs(lcc800167));
 if lcc800167>0 then begin
  tsell(1,cang,mkt,0,0,'800167');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
 cang:=(abs(xiadan800167)-max(lcc800167,0));
 if tbuyholdingex('800167','',1)=0 and tremainqty(2,'800167',stklabel)=0 and cang>0 then begin
 //在多单全部平仓完毕的情况下开空单,防止日内满仓反手下单的时候出现保证金不足 
  tbuyshort(1,cang,mkt,0,0,'800167');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
end
//////////////////////////////////////////////
/////////////////////////////下单账户 888888
xiadan888888:=cc888888-lcc888888;
if xiadan888888>0 then begin
 cang:=min(xiadan888888,abs(lcc888888));
 if lcc888888<0 then begin
  tsellshort(1,cang,mkt,0,0,'888888');
  liang:=liang+cang;
  if liang>=10 then begin//下单量累积到10手,则延迟一定的时间
   liang:=0;
   sleep(3000);//延迟3秒
  end
 end
 cang:=(xiadan888888+min(lcc888888,0));
 if tsellholdingex('888888','',1)=0 and tremainqty(4,'888888',stklabel)=0 and cang>0 then begin
 //在空单全部平仓完毕的情况下开多单,防止日内满仓反手下单的时候出现保证金不足 
  tbuy(1,cang,mkt,0,0,'888888');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end
 end
end

if xiadan888888<0 then begin
 cang:=min(abs(xiadan888888),abs(lcc888888));
 if lcc888888>0 then begin
  tsell(1,cang,mkt,0,0,'888888');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
 cang:=(abs(xiadan888888)-max(lcc888888,0));
 if tbuyholdingex('888888','',1)=0 and tremainqty(2,'888888',stklabel)=0 and cang>0 then begin
 //在多单全部平仓完毕的情况下开空单,防止日内满仓反手下单的时候出现保证金不足 
  tbuyshort(1,cang,mkt,0,0,'888888');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
end
//////////////////////////////////////////////
/////////////////////////////下单账户 666666
xiadan666666:=cc666666-lcc666666;
if xiadan666666>0 then begin
 cang:=min(xiadan666666,abs(lcc666666));
 if lcc666666<0 then begin
  tsellshort(1,cang,mkt,0,0,'666666');
  liang:=liang+cang;
  if liang>=10 then begin//下单量累积到10手,则延迟一定的时间
   liang:=0;
   sleep(3000);//延迟3秒
  end
 end
 cang:=(xiadan666666+min(lcc666666,0));
 if tsellholdingex('666666','',1)=0 and tremainqty(4,'666666',stklabel)=0 and cang>0 then begin
 //在空单全部平仓完毕的情况下开多单,防止日内满仓反手下单的时候出现保证金不足 
  tbuy(1,cang,mkt,0,0,'666666');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end
 end
end

if xiadan666666<0 then begin
 cang:=min(abs(xiadan666666),abs(lcc666666));
 if lcc666666>0 then begin
  tsell(1,cang,mkt,0,0,'666666');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
 cang:=(abs(xiadan666666)-max(lcc666666,0));
 if tbuyholdingex('666666','',1)=0 and tremainqty(2,'666666',stklabel)=0 and cang>0 then begin
 //在多单全部平仓完毕的情况下开空单,防止日内满仓反手下单的时候出现保证金不足 
  tbuyshort(1,cang,mkt,0,0,'666666');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
end
//////////////////////////////////////////////
/////////////////////////////下单账户 999999
xiadan999999:=cc999999-lcc999999;
if xiadan999999>0 then begin
 cang:=min(xiadan999999,abs(lcc999999));
 if lcc999999<0 then begin
  tsellshort(1,cang,mkt,0,0,'999999');
  liang:=liang+cang;
  if liang>=10 then begin//下单量累积到10手,则延迟一定的时间
   liang:=0;
   sleep(3000);//延迟3秒
  end
 end
 cang:=(xiadan999999+min(lcc999999,0));
 if tsellholdingex('999999','',1)=0 and tremainqty(4,'999999',stklabel)=0 and cang>0 then begin
 //在空单全部平仓完毕的情况下开多单,防止日内满仓反手下单的时候出现保证金不足 
  tbuy(1,cang,mkt,0,0,'999999');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end
 end
end

if xiadan999999<0 then begin
 cang:=min(abs(xiadan999999),abs(lcc999999));
 if lcc999999>0 then begin
  tsell(1,cang,mkt,0,0,'999999');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
 cang:=(abs(xiadan999999)-max(lcc999999,0));
 if tbuyholdingex('999999','',1)=0 and tremainqty(2,'999999',stklabel)=0 and cang>0 then begin
 //在多单全部平仓完毕的情况下开空单,防止日内满仓反手下单的时候出现保证金不足 
  tbuyshort(1,cang,mkt,0,0,'999999');
  liang:=liang+cang;
  if liang>=10 then begin
   liang:=0;
   sleep(3000);
  end  
 end
end
//////////////////////////////////////////////

[此贴子已经被作者于2011-7-24 0:02:43编辑过]

[本帖被加为精华]
 回到顶部
帅哥哟,离线,有人找我吗?
海边的鱼
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:155 积分:924 威望:0 精华:0 注册:2011/2/19 16:38:54
  发帖心情 Post By:2011/7/23 16:29:16    Post IP:220.176.84.244[只看该作者]

这么牛逼的东西啊?虽然不懂,但还是要顶!!

 回到顶部
帅哥哟,离线,有人找我吗?
miluse
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:51 积分:248 威望:0 精华:0 注册:2010/9/30 11:26:54
  发帖心情 Post By:2011/7/23 16:49:31    Post IP:58.22.195.234[只看该作者]

火哥你太牛了

顶啊。。

先复制了,慢慢看


 回到顶部
帅哥哟,离线,有人找我吗?
rogerhylt
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:86 积分:572 威望:0 精华:0 注册:2010/4/5 17:26:37
  发帖心情 Post By:2011/7/23 17:35:30    Post IP:218.28.119.50[只看该作者]

请问为何不建议用orderqeue 处理 有何不好么? 本来下星期想使用一下的 因为本周再次出现平仓单未成交前如果发出开仓委托单会出现保证金不足的情况造成无法自动开仓的问题。我用的是k线走完模式。谢谢先

 

http://www.weistock.com/bbs/dispbbs.asp?boardid=4&id=7202&page=2&star=2

 


 回到顶部
帅哥哟,离线,有人找我吗?
guotx2010
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:蜘蛛侠 帖子:1366 积分:5210 威望:0 精华:7 注册:2010/12/11 18:00:33
  发帖心情 Post By:2011/7/23 18:08:17    Post IP:183.39.131.196[只看该作者]

这个思路是很不错的。

 

第六个策略:

buycond6:=ref(vol,1)>ref(vol,1) and ref(vol,2)>ref(vol,2) and ref(vol,3)>ref(vol,3);
sellcond6:=ref(vol,1)<ref(vol,1) and ref(vol,2)<ref(vol,2) and ref(vol,3)<ref(vol,3);

是不是一直不成立呀,前一周期的成交量跟前一周期的成交量不可能大于或小于呀。

 

variable:cc1=0,cc2=0,cc3=0,cc4=0,cc5=0,cc6=0; //开仓系数
if workmode<>1 then exit; //如果不在后台程序化交易模式就退出
entertime:=time<150000;    //开仓时间
exittime:=time>=150000;    //非开仓时间
//策略1(连续3根K线收盘价大于开盘价做多,反之做空)
buycond1:=ref(c,1)>ref(o,1) and ref(c,2)>ref(o,2) and ref(c,3)>ref(o,3);
sellcond1:=ref(c,1)<ref(o,1) and ref(c,2)<ref(o,2) and ref(c,3)<ref(o,3);
//策略2(前1最高价大于前10根K线的最高价做多,反之做空)
buycond2:=ref(h,1)>ref(hhv(h,10),2);
sellcond2:=ref(l,1)<ref(llv(l,10),2);
//策略3(5日线高于15日线做多,反之做空)
ma5:=ma(c,5);
ma15:=ma(c,15);
buycond3:=ref(ma5,1)>ref(ma15,1);
sellcond3:=ref(ma5,1)<ref(ma15,1);
//策略4(前1最低价大于3周期前的最高价做多,反之做空)
buycond4:=ref(l,1)>ref(h,3);
sellcond4:=ref(h,1)<ref(l,3);
//策略5(前收大于前15收做多,反之做空)
buycond5:=ref(c,1)>ref(c,15);
sellcond5:=ref(c,1)<ref(c,15);
//策略6(连续3根K线,前1成交量大于前1成交量做多,反之做空)-这个条件好像一直不会成立
buycond6:=ref(vol,1)>ref(vol,1) and ref(vol,2)>ref(vol,2) and ref(vol,3)>ref(vol,3);
sellcond6:=ref(vol,1)<ref(vol,1) and ref(vol,2)<ref(vol,2) and ref(vol,3)<ref(vol,3);

[此贴子已经被作者于2011-7-23 18:38:12编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
luqi
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:156 积分:304 威望:0 精华:0 注册:2010/12/20 16:47:07
  发帖心情 Post By:2011/7/23 23:43:21    Post IP:59.61.40.20[只看该作者]

见过的最好帖子,耳目一新

没想到金字塔还能这样搞

怎么没搞精华?


 回到顶部
帅哥哟,离线,有人找我吗?
阿火
  7楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 原leevolvo
等级:版主 帖子:2160 积分:10563 威望:0 精华:11 注册:2010/11/3 11:21:19
  发帖心情 Post By:2011/7/24 0:01:26    Post IP:59.61.40.20[只看该作者]

呵呵,写得太快,第6个策略写错了

策略不重要,策略是随便瞎写的。做个举例而已


 回到顶部
帅哥哟,离线,有人找我吗?
百色大头
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:11 积分:106 威望:0 精华:0 注册:2010/2/7 3:20:48
  发帖心情 Post By:2011/7/24 10:53:52    Post IP:113.17.52.79[只看该作者]

阿火牛13啊,顶你一个。

 回到顶部
帅哥哟,离线,有人找我吗?
rogerhylt
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:86 积分:572 威望:0 精华:0 注册:2010/4/5 17:26:37
  发帖心情 Post By:2011/7/28 11:02:36    Post IP:218.28.119.116[只看该作者]

以下是引用rogerhylt在2011-7-23 17:35:30的发言:

请问为何不建议用orderqeue 处理 有何不好么? 本来下星期想使用一下的 因为本周再次出现平仓单未成交前如果发出开仓委托单会出现保证金不足的情况造成无法自动开仓的问题。我用的是k线走完模式。谢谢先

 

http://www.weistock.com/bbs/dispbbs.asp?boardid=4&id=7202&page=2&star=2

 

试过才知道 ----不行 。成交不成交好像是随机的。 没有orderqeue 我的账户有时也成交 ,有时不成交。---都是满仓的情况,看来要解决这个问题,只有把资金加大点,不要满仓才好。现在还有一个成交的问题:就是收盘时或盘中间隙前发出信号的话 不能在收盘前成交。你设置成预埋单的话 要小心跳空造成的一系列问题:如不成交。而且实盘可能与你的测试结果不一样。

 回到顶部
帅哥哟,离线,有人找我吗?
阿火
  10楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 原leevolvo
等级:版主 帖子:2160 积分:10563 威望:0 精华:11 注册:2010/11/3 11:21:19
  发帖心情 Post By:2011/7/28 13:30:22    Post IP:120.42.45.130[只看该作者]

可以的,我都实盘的。你再仔细试试,检查检查

[此贴子已经被作者于2011-7-28 13:37:24编辑过]

 回到顶部
总数 11 1 2 下一页