共37 条记录, 每页显示 10 条, 页签:
[1]
[2][3][4]
1楼
tanyongde 发表于:2016/12/1 13:56:13
按阿火思路改编,持仓与实盘同步模块,模拟没反应,是什么原因?
input:p(5,1,200,1);
input:length(75,10,300,10);
input:zs(4,1,50,1);
input:k1(4,1,50,1);
globalvariable:myhoiding=0;
line:ma(ref(c,1),30),colorblue,linethick2;
drawnumber(islastbar,line,line,0,colorblue);
tr1 :=max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));
atr:=ma(tr1,length);
zsx:=ifelse(zs*ref(atr,1)<0.02*ref(c,1),0.02*ref(c,1),zs*ref(atr,1));
dstop1:=hhv(h,ttypebar(1,1))-k1*ref(atr,1);//平多价
kstop1:=llv(l,ttypebar(1,3))+k1*ref(atr,1);//平空价
long:=cross(c,line);
short:= cross(line,c) ;
//建立多头的进场条件
if myhoiding<0 and long then myhoiding=p;
if myhoiding>0 and short then myhoiding=-p;
if myhoiding>0 and c<=max(tavgenterpriceex2('6142521','',0)-zsx,dstop1) then myhoiding=0;
if myhoiding<0 and c>=min(tavgenterpriceex2('6142521','',1)+zsx,kstop1) then myhoiding=0;
if myhoiding=0 and long and ref(c,1)>ref(c,4) then myhoiding=p;
if myhoiding=0 and short and ref(c,1)<ref(c,4) then myhoiding=-p;
cc614251:=myhoiding;//账户的下单系数
drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc614251,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or dynainfo(207)<91500 then exit;
///////////////////////////////////////////////////以下是账户800043的下单语句,其他账户下单,修改800043为相应账户,接在程序后面即可
lcc614251:=tbuyholdingex('614251','',1)-tsellholdingex('614251','',1);
xiadan614251:=cc614251-lcc614251;
if lcc614251<>extgbdata('lcc614251') then begin//有单子成交,则下单开关设为0,允许下单 extgbdataset('abb800043',0);
extgbdataset('lcc614251',lcc614251);
end
if tremainqty(0,'614251',stklabel)>=1 or (cc614251<>lcc614251 and timetot0(currenttime)-extgbdata('abb614251')>10) then begin
//下单后10秒内仍发现委托单,则允许下单。可能是堵单,可能是交易账户网络暂时中断
extgbdataset('abb614251',0);
end
if xiadan614251>0 then begin
if lcc614251<0 and extgbdata('abb614251')=0 and tremainqty(0,'614251',stklabel)=0 then begin
tsellshort(1,min(xiadan614251,abs(lcc614251)),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
if tsellholdingex('614251','',1)=0 and tremainqty(4,'614251',stklabel)=0 and tremainqty(1,'614251',stklabel)=0 and extgbdata('abb614251')=0 then begin
tbuy(xiadan614251+min(lcc614251,0)>0,xiadan614251+min(lcc614251,0),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
end
if xiadan614251<0 then begin
if lcc614251>0 and extgbdata('abb614251')=0 and tremainqty(0,'614251',stklabel)=0 then begin
tsell(1,min(abs(xiadan614251),abs(lcc614251)),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
if tbuyholdingex('614251','',1)=0 and tremainqty(2,'614251',stklabel)=0 and tremainqty(3,'614251',stklabel)=0 and extgbdata('abb614251')=0 then begin
tbuyshort(abs(xiadan614251)-max(lcc614251,0)>0,abs(xiadan614251)-max(lcc614251,0),mkt,0,0,'614261'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
end
2楼
jinzhe 发表于:2016/12/1 14:00:58
3楼
tanyongde 发表于:2016/12/1 14:17:19
是根据下面阿火改写:
[原创]多策略多账户下单阿火版_续集(可扩展成无人值守) 发帖心情 post by:2011-8-5 10:13:01 post ip:120.42.45.130[只看该作者]
上次发表了一个 多策略多账户的下单方法
大家知道,一根k线图一个方向只允许下单一次,如果一个k线图内,不同策略前后分别产生信号呢?
举个例子:
//策略1:连续2阳,下一根开盘买入 2阴下一根开盘卖出
//策略2:价格突破前1根高点即买入,前1根低点立即卖出
假如以上2个策略组合,连续2个阳线条件成立,新的k线产生时开盘买入1手,之后又突破前一根k线高点,需再买1手。
这个时候,如何组合起来?用 allowrepeat ,允许重复下单。
主要问题:
1,下单后,委托单产生前,有一个小时间差的控制。tholding =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
4楼
jinzhe 发表于:2016/12/1 14:20:23
if myhoiding<0 and long then myhoiding=p;
if myhoiding>0 and short then myhoiding=-p;
if myhoiding>0 and c<=max(tavgenterpriceex2('6142521','',0)-zsx,dstop1) then myhoiding=0;
if myhoiding<0 and c>=min(tavgenterpriceex2('6142521','',1)+zsx,kstop1) then myhoiding=0;
if myhoiding=0 and long and ref(c,1)>ref(c,4) then myhoiding=p;
if myhoiding=0 and short and ref(c,1)<ref(c,4) then myhoiding=-p;
这里所有的if .... then myhoiding=p/-p/0 ,中间加一个冒号,改成if .... then myhoiding:=p/-p/0
[此贴子已经被作者于2016-12-1 14:20:37编辑过]
5楼
tanyongde 发表于:2016/12/1 14:39:49
加了还是没反应?
input:p(5,1,200,1);
input:length(75,10,300,10);
input:zs(4,1,50,1);
input:k1(4,1,50,1);
globalvariable:myhoiding=0;
line:ma(ref(c,1),30),colorblue,linethick2;
drawnumber(islastbar,line,line,0,colorblue);
tr1 :=max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));
atr:=ma(tr1,length);
zsx:=ifelse(zs*ref(atr,1)<0.02*ref(c,1),0.02*ref(c,1),zs*ref(atr,1));
dstop1:=hhv(h,ttypebar(1,1))-k1*ref(atr,1);//平多价
kstop1:=llv(l,ttypebar(1,3))+k1*ref(atr,1);//平空价
long:=cross(c,line);
short:= cross(line,c) ;
//建立多头的进场条件
if myhoiding<0 and long then myhoiding:=p;
if myhoiding>0 and short then myhoiding:=-p;
if myhoiding>0 and c<=max(tavgenterpriceex2('6142521','',0)-zsx,dstop1) then myhoiding:=0;
if myhoiding<0 and c>=min(tavgenterpriceex2('6142521','',1)+zsx,kstop1) then myhoiding:=0;
if myhoiding=0 and long and ref(c,1)>ref(c,4) then myhoiding:=p;
if myhoiding=0 and short and ref(c,1)<ref(c,4) then myhoiding:=-p;
cc614251:=myhoiding;//账户的下单系数
drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc614251,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or dynainfo(207)<91500 then exit;
///////////////////////////////////////////////////以下是账户800043的下单语句,其他账户下单,修改800043为相应账户,接在程序后面即可
lcc614251:=tbuyholdingex('614251','',1)-tsellholdingex('614251','',1);
xiadan614251:=cc614251-lcc614251;
if lcc614251<>extgbdata('lcc614251') then begin//有单子成交,则下单开关设为0,允许下单 extgbdataset('abb800043',0);
extgbdataset('lcc614251',lcc614251);
end
if tremainqty(0,'614251',stklabel)>=1 or (cc614251<>lcc614251 and timetot0(currenttime)-extgbdata('abb614251')>10) then begin
//下单后10秒内仍发现委托单,则允许下单。可能是堵单,可能是交易账户网络暂时中断
extgbdataset('abb614251',0);
end
if xiadan614251>0 then begin
if lcc614251<0 and extgbdata('abb614251')=0 and tremainqty(0,'614251',stklabel)=0 then begin
tsellshort(1,min(xiadan614251,abs(lcc614251)),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
if tsellholdingex('614251','',1)=0 and tremainqty(4,'614251',stklabel)=0 and tremainqty(1,'614251',stklabel)=0 and extgbdata('abb614251')=0 then begin
tbuy(xiadan614251+min(lcc614251,0)>0,xiadan614251+min(lcc614251,0),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
end
if xiadan614251<0 then begin
if lcc614251>0 and extgbdata('abb614251')=0 and tremainqty(0,'614251',stklabel)=0 then begin
tsell(1,min(abs(xiadan614251),abs(lcc614251)),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
if tbuyholdingex('614251','',1)=0 and tremainqty(2,'614251',stklabel)=0 and tremainqty(3,'614251',stklabel)=0 and extgbdata('abb614251')=0 then begin
tbuyshort(abs(xiadan614251)-max(lcc614251,0)>0,abs(xiadan614251)-max(lcc614251,0),mkt,0,0,'614261'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
end
6楼
jinzhe 发表于:2016/12/1 14:55:22
if myhoiding>0 and c<=max(tavgenterpriceex2('6142521','',0)-zsx,dstop1) then myhoiding:=0;
if myhoiding<0 and c>=min(tavgenterpriceex2('6142521','',1)+zsx,kstop1) then myhoiding:=0;
这里两个帐号错误
7楼
jinzhe 发表于:2016/12/1 14:56:03
8楼
tanyongde 发表于:2016/12/1 15:10:06
9楼
jinzhe 发表于:2016/12/1 15:13:13
1你用我上面链接里面的代码,
2你要用自己找的就先改上面的账户
3为什么不行你要调试下对应的虚拟持仓
10楼
tanyongde 发表于:2016/12/1 15:24:28
帐号改过还没反应,公式加载后应该有持仓,还是要等开市才有?
input:p(5,1,200,1);
input:length(75,10,300,10);
input:zs(4,1,50,1);
input:k1(4,1,50,1);
globalvariable:myhoiding=0;
line:ma(ref(c,1),30),colorblue,linethick2;
drawnumber(islastbar,line,line,0,colorblue);
tr1 :=max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));
atr:=ma(tr1,length);
zsx:=ifelse(zs*ref(atr,1)<0.02*ref(c,1),0.02*ref(c,1),zs*ref(atr,1));
dstop1:=hhv(h,ttypebar(1,1))-k1*ref(atr,1);//平多价
kstop1:=llv(l,ttypebar(1,3))+k1*ref(atr,1);//平空价
long:=cross(c,line);
short:= cross(line,c) ;
//建立多头的进场条件
if myhoiding<0 and long then myhoiding:=p;
if myhoiding>0 and short then myhoiding:=-p;
if myhoiding>0 and c<=max(tavgenterpriceex2('614251','',0)-zsx,dstop1) then myhoiding:=0;
if myhoiding<0 and c>=min(tavgenterpriceex2('614251','',1)+zsx,kstop1) then myhoiding:=0;
if myhoiding=0 and long and ref(c,1)>ref(c,4) then myhoiding:=p;
if myhoiding=0 and short and ref(c,1)<ref(c,4) then myhoiding:=-p;
cc614251:=myhoiding;//账户的下单系数
drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc614251,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or dynainfo(207)<91500 then exit;
///////////////////////////////////////////////////以下是账户800043的下单语句,其他账户下单,修改800043为相应账户,接在程序后面即可
lcc614251:=tbuyholdingex('614251','',1)-tsellholdingex('614251','',1);
xiadan614251:=cc614251-lcc614251;
if lcc614251<>extgbdata('lcc614251') then begin//有单子成交,则下单开关设为0,允许下单 extgbdataset('abb800043',0);
extgbdataset('lcc614251',lcc614251);
end
if tremainqty(0,'614251',stklabel)>=1 or (cc614251<>lcc614251 and timetot0(currenttime)-extgbdata('abb614251')>10) then begin
//下单后10秒内仍发现委托单,则允许下单。可能是堵单,可能是交易账户网络暂时中断
extgbdataset('abb614251',0);
end
if xiadan614251>0 then begin
if lcc614251<0 and extgbdata('abb614251')=0 and tremainqty(0,'614251',stklabel)=0 then begin
tsellshort(1,min(xiadan614251,abs(lcc614251)),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
if tsellholdingex('614251','',1)=0 and tremainqty(4,'614251',stklabel)=0 and tremainqty(1,'614251',stklabel)=0 and extgbdata('abb614251')=0 then begin
tbuy(xiadan614251+min(lcc614251,0)>0,xiadan614251+min(lcc614251,0),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
end
if xiadan614251<0 then begin
if lcc614251>0 and extgbdata('abb614251')=0 and tremainqty(0,'614251',stklabel)=0 then begin
tsell(1,min(abs(xiadan614251),abs(lcc614251)),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
if tbuyholdingex('614251','',1)=0 and tremainqty(2,'614251',stklabel)=0 and tremainqty(3,'614251',stklabel)=0 and extgbdata('abb614251')=0 then begin
tbuyshort(abs(xiadan614251)-max(lcc614251,0)>0,abs(xiadan614251)-max(lcc614251,0),mkt,0,0,'614251'),allowrepeat;
extgbdataset('abb614251',timetot0(currenttime));
end
end
共37 条记录, 每页显示 10 条, 页签:
[1]
[2][3][4]