以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  [原创]多策略多账户下单阿火版_续集(可扩展成无人值守)  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=7437)

--  作者:阿火
--  发布时间:2011/8/5 10:13:01
--  [原创]多策略多账户下单阿火版_续集(可扩展成无人值守)

上次发表了一个 多策略多账户的下单方法

大家知道,一根K线图一个方向只允许下单一次,如果一个K线图内,不同策略前后分别产生信号呢?

举个例子:

//策略1:连续2阳,下一根开盘买入 2阴下一根开盘卖出
//策略2:价格突破前1根高点即买入,前1根低点立即卖出

假如以上2个策略组合,连续2个阳线条件成立,新的K线产生时开盘买入1手,之后又突破前一根K线高点,需再买1手。

 

这个时候,如何组合起来?用allowrepeat,允许重复下单。

 

主要问题:

1,下单后,委托单产生前,有一个小时间差的控制。tolding=0则下单。下单后,tholding依然为0,还会再下单

     因为我们采用的是加减仓的组合手法,信号并非前后分别对应,无法用ttype

     举个例子解释一下加减仓手法的特点:一开始A模型多单3手,B模型出现信号“空2手”。表现在操作上就是:平仓2手。
                                                    之后B模型出现信号“空单平仓2手”,操作上表现就是 买入开仓2手。

 

2,下单瞬间,网络刚好中断。后面网络恢复,也要自动补回正确的持仓。

3,不管什么原因造成的重复下单(比如堵单,以为没成交再次发单成交,之后发现这个堵单也成交了),希望补回正确持仓

 

解决方法如下:

variable:cc1=0,cc2=0,cc3=0;
entertime:=time<150000;
exittime:=time>=150000;
buycond1:=ref(c,1)>ref(o,1) and ref(c,2)>ref(o,2);
sellcond1:=ref(c,1)<ref(o,1) and ref(c,2)<ref(o,2);

buycond2:=h>ref(hhv(h,1),1);
sellcond2:=l<ref(llv(l,1),1);

buycond3:=ref(c>o,1);
sellcond3:=ref(c<o,1);

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;

cc800043:=2*cc1 + 1*cc2 + 2*cc3;//账户的下单系数
cc800167:=3*cc1 + 2*cc2 + 4*cc3;

if not(islastbar) or dynainfo(207)<91500 then exit;

///////////////////////////////////////////////////以下是账户800043的下单语句,其他账户下单,修改800043为相应账户,接在程序后面即可
lcc800043:=tbuyholdingex(\'800043\',\'\',1)-tsellholdingex(\'800043\',\'\',1);
xiadan800043:=cc800043-lcc800043;
if lcc800043<>extgbdata(\'lcc800043\') then begin//有单子成交,则下单开关设为0,允许下单 extgbdataset(\'abb800043\',0);
 extgbdataset(\'lcc800043\',lcc800043);
end

if tremainqty(0,\'800043\',stklabel)>=1 or (cc800043<>lcc800043 and timetot0(currenttime)-extgbdata(\'abb800043\')>10) then begin

//下单后10秒内仍发现委托单,则允许下单。可能是堵单,可能是交易账户网络暂时中断
 extgbdataset(\'abb800043\',0);
end

if xiadan800043>0 then begin
 if lcc800043<0 and extgbdata(\'abb800043\')=0 and tremainqty(0,\'800043\',stklabel)=0 then begin
  tsellshort(1,min(xiadan800043,abs(lcc800043)),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',timetot0(currenttime));
 end
 
 if tsellholdingex(\'800043\',\'\',1)=0 and tremainqty(4,\'800043\',stklabel)=0 and tremainqty(1,\'800043\',stklabel)=0 and extgbdata(\'abb800043\')=0 then begin
  tbuy(xiadan800043+min(lcc800043,0)>0,xiadan800043+min(lcc800043,0),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',timetot0(currenttime));
 end
end

if xiadan800043<0 then begin
 if lcc800043>0 and extgbdata(\'abb800043\')=0 and tremainqty(0,\'800043\',stklabel)=0 then begin
  tsell(1,min(abs(xiadan800043),abs(lcc800043)),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',timetot0(currenttime));
 end
 
 if tbuyholdingex(\'800043\',\'\',1)=0 and tremainqty(2,\'800043\',stklabel)=0 and tremainqty(3,\'800043\',stklabel)=0 and extgbdata(\'abb800043\')=0 then begin
  tbuyshort(abs(xiadan800043)-max(lcc800043,0)>0,abs(xiadan800043)-max(lcc800043,0),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',timetot0(currenttime));
 end
end

[此贴子已经被作者于2011-9-16 14:35:22编辑过]

--  作者:jinzhe
--  发布时间:2011/8/5 10:32:26
--  

阿火老师太给力了图片点击可在新窗口打开查看


--  作者:董小球
--  发布时间:2011/8/5 16:19:06
--  

阿火老师直比仓老师啊 哈哈


--  作者:solarhe2006
--  发布时间:2011/8/16 23:29:52
--  [公告]上海中期北京营业部与金字塔合作
[原创]多策略多账户下单阿火版_续集(可扩展成无人值守)  图片点击可在新窗口打开查看 Post By:2011-8-5 10:13:01

上次发表了一个 多策略多账户的下单方法

大家知道,一根K线图一个方向只允许下单一次,如果一个K线图内,不同策略前后分别产生信号呢?

举个例子:

//策略1:连续2阳,下一根开盘买入 2阴下一根开盘卖出
//策略2:价格突破前1根高点即买入,前1根低点立即卖出

假如以上2个策略组合,连续2个阳线条件成立,新的K线产生时开盘买入1手,之后又突破前一根K线高点,需再买1手。

 

这个时候,如何组合起来?用allowrepeat,允许重复下单。

 

主要问题:

1,下单后,委托单产生前,有一个小时间差的控制。tolding=0则下单。下单后,tholding依然为0,还会再下单

     因为我们采用的是加减仓的组合手法,信号并非前后分别对应,无法用ttype

     举个例子解释一下加减仓手法的特点:一开始A模型多单3手,B模型出现信号“空2手”。表现在操作上就是:平仓2手。
                                                    之后B模型出现信号“空单平仓2手”,操作上表现就是 买入开仓2手。

 

2,下单瞬间,网络刚好中断。后面网络恢复,也要自动补回正确的持仓。

3,不管什么原因造成的重复下单(比如堵单,以为没成交再次发单成交,之后发现这个堵单也成交了),希望补回正确持仓

 

解决方法如下:

variable:cc1=0,cc2=0,cc3=0;
entertime:=time<150000;
exittime:=time>=150000;
buycond1:=ref(c,1)>ref(o,1) and ref(c,2)>ref(o,2);
sellcond1:=ref(c,1)<ref(o,1) and ref(c,2)<ref(o,2);

buycond2:=h>ref(hhv(h,1),1);
sellcond2:=l<ref(llv(l,1),1);

buycond3:=ref(c>o,1);
sellcond3:=ref(c<o,1);

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;

cc800043:=2*cc1 + 1*cc2 + 2*cc3;//账户的下单系数
cc800167:=3*cc1 + 2*cc2 + 4*cc3;

if not(islastbar) or dynainfo(207)<91500 then exit;

///////////////////////////////////////////////////以下是账户800043的下单语句,其他账户下单,修改800043为相应账户,接在程序后面即可
lcc800043:=tbuyholdingex(\'800043\',\'\',1)-tsellholdingex(\'800043\',\'\',1);
xiadan800043:=cc800043-lcc800043;
if lcc800043<>extgbdata(\'lcc800043\') then begin//有单子成交,则下单开关设为0,允许下单 extgbdataset(\'abb800043\',0);
 extgbdataset(\'lcc800043\',lcc800043);
end

if tremainqty(0,\'800043\',stklabel)>=1 or (cc800043<>lcc800043 and time0-extgbdata(\'abb800043\')>10) then begin

//下单后10秒内仍发现委托单,则允许下单。可能是堵单,可能是交易账户网络暂时中断
 extgbdataset(\'abb800043\',0);
end

if xiadan800043>0 then begin
 if lcc800043<0 and extgbdata(\'abb800043\')=0 and tremainqty(0,\'800043\',stklabel)=0 then begin
  tsellshort(1,min(xiadan800043,abs(lcc800043)),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',time0);
 end
 
 if tsellholdingex(\'800043\',\'\',1)=0 and tremainqty(4,\'800043\',stklabel)=0 and tremainqty(1,\'800043\',stklabel)=0 and extgbdata(\'abb800043\')=0 then begin
  tbuy(xiadan800043+min(lcc800043,0)>0,xiadan800043+min(lcc800043,0),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',time0);
 end
end

if xiadan800043<0 then begin
 if lcc800043>0 and extgbdata(\'abb800043\')=0 and tremainqty(0,\'800043\',stklabel)=0 then begin
  tsell(1,min(abs(xiadan800043),abs(lcc800043)),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',time0);
 end
 
 if tbuyholdingex(\'800043\',\'\',1)=0 and tremainqty(2,\'800043\',stklabel)=0 and tremainqty(3,\'800043\',stklabel)=0 and extgbdata(\'abb800043\')=0 then begin
  tbuyshort(abs(xiadan800043)-max(lcc800043,0)>0,abs(xiadan800043)-max(lcc800043,0),mkt,0,0,\'800043\'),allowrepeat;
  extgbdataset(\'abb800043\',time0);
 end
end


--  作者:pancg
--  发布时间:2011/8/31 15:09:59
--  

我不是太懂,提个问题,阿火老师别笑话。

您这个版本是不是只能用于单品种的多策略多帐号,而监控多品种的话,则持仓会发生紊乱?


--  作者:阿火
--  发布时间:2011/9/1 9:20:21
--  

不会啊。多品种、多策略、多账户 也是可以的


--  作者:阿火
--  发布时间:2011/9/16 14:36:03
--  
以下是引用董小球在2011-8-5 16:19:06的发言:

阿火老师直比仓老师啊 哈哈

终于明白什么是“仓老师”了


--  作者:jinzhe
--  发布时间:2011/9/16 15:02:42
--  
仓老师是那个德艺双馨的人民艺术家?
--  作者:阿火
--  发布时间:2011/9/16 15:40:29
--  
心理知道就好了,别说得太明白,就不艺术了
--  作者:smp
--  发布时间:2011/9/17 10:35:43
--  
顶楼上, 但是更顶仓老师. 我的兄弟向她致敬