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


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

   

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


  共有14638人关注过本帖平板打印复制链接

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

帅哥哟,离线,有人找我吗?
阿火
  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编辑过]

[本帖被加为精华]
 回到顶部
总数 11 1 2 下一页