上次发表了一个 多策略多账户的下单方法
大家知道,一根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
阿火老师太给力了
阿火老师直比仓老师啊 哈哈
我不是太懂,提个问题,阿火老师别笑话。
您这个版本是不是只能用于单品种的多策略多帐号,而监控多品种的话,则持仓会发生紊乱?
不会啊。多品种、多策略、多账户 也是可以的
阿火老师直比仓老师啊 哈哈
终于明白什么是“仓老师”了