-- 作者:阿火
-- 发布时间:2011/7/23 15:15:11
-- [原创]多策略多账户下单——阿火版
今天大发慈悲,急塔友之所急
把我一直在使用的多策略多账户下单的方法共享给大家:
解释:
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编辑过]
|
-- 作者:guotx2010
-- 发布时间:2011/7/23 18:08:17
--
这个思路是很不错的。
第六个策略:
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编辑过]
|