Rss & SiteMap

金字塔客服中心 - 专业程序化交易软件提供商 http://www.weistock.com/bbs/

专业程序化软件提供商
共22 条记录, 每页显示 10 条, 页签: [1] [2][3]
[浏览完整版]

标题:为什么会重复开仓?

1楼
kiseki_lyo 发表于:2014/4/1 14:30:09

图片点击可在新窗口打开查看此主题相关图片如下:hhh.jpg
图片点击可在新窗口打开查看
后台交易的问题
用股指30秒在做测试,不知道为什么,每次开平仓都会有同样价格,相反方向的单子刷进去,然后几乎同时间马上又出来
请看图片。。。


我用的代码是这样的

Globalvariable:hold=drawnull;

//自有模型


cc807385:=holding;//这句放在信号稳定的地方

drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc807385,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan807385:=cc807385-hold;

 
 cang:=xiadan807385+min(hold,0);
 if cang>0 then begin
  tbuy(1,cang,lmt,委托价,0,'807385'),allowrepeat;
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 开多 %.0f',cang);
 end



 
 
 cang:=abs(xiadan807385)-max(hold,0);
 if cang>0 then begin
  tbuyshort(1,cang,lmt,委托价,0,'807385'),allowrepeat;
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 开空 %.0f',cang);
 end


if xiadan807385<-0.5 then begin
 cang:=min(abs(xiadan807385),abs(hold));
 if hold>0 then begin
  tsell(1,cang,lmt,委托价,0,'807385'),allowrepeat;
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平多 %.0f',cang);
 end
 end
 
 if xiadan807385<-0.5 then begin
 cang:=min(abs(xiadan807385),abs(hold));
 if hold>0 then begin
  tsell(1,cang,lmt,委托价,0,'807385'),allowrepeat;
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平多 %.0f',cang);
 end
end
 

if xiadan807385>0.5 then begin
 cang:=min(xiadan807385,abs(hold));
 if hold<0 then begin
  tsellshort(1,cang,lmt,委托价,0,'807385'),allowrepeat;
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平空 %.0f',cang);
 end
 end
 
 if xiadan807385>0.5 then begin
 cang:=min(xiadan807385,abs(hold));
 if hold<0 then begin
  tsellshort(1,cang,lmt,委托价,0,'807385'),allowrepeat;
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平空 %.0f',cang);
 end
 end

hold:=cc807385;


cc:=holding;
if not(islastbar) or workmode<>1 then exit;
tm:=1;//撤单时间
ac:='807385';//下单账户
wt:=tremainqty(0,ac,stklabel);
buyhold:=tbuyholdingex(ac,stklabel,1);
sellhold:=tsellholdingex(ac,stklabel,1);

if wt>0.5 and tsubmit(0)>tm then tcancelex(1,0,ac,stklabel);//如果用软件自带的撤单功能,这句删除。
if wt<0.5 then begin
 kc1:=max(cc,0)-buyhold;
 kc2:=abs(min(cc,0))-sellhold;
 if kc1<-0.5 then tsell(1,abs(kc1),mkt,0,0,ac),allowrepeat;
 if kc2<-0.5 then tsellshort(1,abs(kc2),mkt,0,0,ac),allowrepeat;
 if sellhold<0.5 and kc1>0.5 then tbuy(1,kc1,mkt,0,0,ac),allowrepeat;
 if buyhold<0.5  and kc2>0.5 then tbuyshort(1,kc2,mkt,0,0,ac),allowrepeat;
end



请问问题出在哪儿?

[此贴子已经被作者于2014/4/1 14:31:31编辑过]
2楼
jinzhe 发表于:2014/4/1 14:39:07
公式里面的委托价是多少?
3楼
kiseki_lyo 发表于:2014/4/1 14:40:38
MAX(OPEN,H1)
min(open,l1)

这样的。。。
4楼
jinzhe 发表于:2014/4/1 14:46:24
两个值?怎么赋值给委托价的?
5楼
kiseki_lyo 发表于:2014/4/1 14:48:35
我有一个图标的程序
套在中间 
后面是后台的模版

6楼
jinzhe 发表于:2014/4/1 15:00:11
发出完整的代码。
7楼
kiseki_lyo 发表于:2014/4/1 15:24:21
我随便写了一个套
大概是这样的代码

Globalvariable:hold=drawnull;



H1:=REF(HHV(H,20),1);
L1:=REF(LLV(L,20),1);


H2:=REF(HHV(H,10),1);
L2:=REF(LLV(L,10),1);



ENTRYLONGCOND:=H>H1 ;
ENTRYSHORTCOND:=L<L1 ;


IF (HOLDING = 0) AND ENTRYLONGCOND THEN
BEGIN
BUY(1,5,LIMITR,MAX(OPEN,H1),1),orderqueue,IGNORECHECKPRICE;
END

IF (HOLDING = 0) AND ENTRYSHORTCOND THEN
BEGIN
BUYSHORT(1,5,LIMITR,MIN(OPEN,L1),1),orderqueue,IGNORECHECKPRICE;
END


IF (HOLDING > 0)  AND  (ENTERBARS > 0) and LOW<=L2 THEN
BEGIN
SELL(1,HOLDING,LIMITR,MIN(OPEN,L2),1),orderqueue,IGNORECHECKPRICE;
END
END

IF (HOLDING < 0)   AND  (ENTERBARS > 0) and HIGH>=H2 THEN
BEGIN
SELLSHORT(1,HOLDING,LIMITR,MA(OPEN,H2),1),orderqueue,IGNORECHECKPRICE;
END
END


cc807385:=holding;

drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc807385,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan807385:=cc807385-hold;

 
 cang:=xiadan807385+min(hold,0);
 if cang>0 then begin
  tbuy(1,cang,lmt,MAX(OPEN,H1),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 开多 %.0f',cang);
 end

 
 cang:=abs(xiadan807385)-max(hold,0);
 if cang>0 then begin
  tbuyshort(1,cang,lmt,MIN(OPEN,L1),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 开空 %.0f',cang);
 end


if xiadan807385<-0.5 then begin
 cang:=min(abs(xiadan807385),abs(hold));
 if hold>0 then begin
  tsell(1,cang,lmt,MIN(OPEN,L2),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平多 %.0f',cang);
 end
 end
 

 

if xiadan807385>0.5 then begin
 cang:=min(xiadan807385,abs(hold));
 if hold<0 then begin
  tsellshort(1,cang,lmt,MAX(OPEN,H2),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平空 %.0f',cang);
 end
 end
 


hold:=cc807385;





cc:=holding;
if not(islastbar) or workmode<>1 then exit;
tm:=1;//撤单时间
ac:='807385';//下单账户
wt:=tremainqty(0,ac,stklabel);
buyhold:=tbuyholdingex(ac,stklabel,1);
sellhold:=tsellholdingex(ac,stklabel,1);

if wt>0.5 and tsubmit(0)>tm then tcancelex(1,0,ac,stklabel);
if wt<0.5 then begin
 kc1:=max(cc,0)-buyhold;
 kc2:=abs(min(cc,0))-sellhold;
 if kc1<-0.5 then tsell(1,abs(kc1),mkt,0,0,ac),allowrepeat;
 if kc2<-0.5 then tsellshort(1,abs(kc2),mkt,0,0,ac),allowrepeat;
 if sellhold<0.5 and kc1>0.5 then tbuy(1,kc1,mkt,0,0,ac),allowrepeat;
 if buyhold<0.5  and kc2>0.5 then tbuyshort(1,kc2,mkt,0,0,ac),allowrepeat;
end

8楼
jinzhe 发表于:2014/4/1 15:34:27

这个策略编译不通过。。。

 

就不能直接点吗。。。不是这里不对就是那里不对。浪费了这么多时间,都收盘了

9楼
kiseki_lyo 发表于:2014/4/1 15:44:50
不好意思啊。。。刚刚代码没检查

这个应该可以了。

Globalvariable:hold=drawnull;



H1:=REF(HHV(H,20),1);
L1:=REF(LLV(L,20),1);


H2:=REF(HHV(H,10),1);
L2:=REF(LLV(L,10),1);



ENTRYLONGCOND:=H>H1 ;
ENTRYSHORTCOND:=L<L1 ;


IF (HOLDING = 0) AND ENTRYLONGCOND THEN
BEGIN
BUY(1,5,LIMITR,MAX(OPEN,H1),1),orderqueue,IGNORECHECKPRICE;
END

IF (HOLDING = 0) AND ENTRYSHORTCOND THEN
BEGIN
BUYSHORT(1,5,LIMITR,MIN(OPEN,L1),1),orderqueue,IGNORECHECKPRICE;
END


IF (HOLDING > 0)  AND  (ENTERBARS > 0) and LOW<=L2 THEN
BEGIN
SELL(1,HOLDING,LIMITR,MIN(OPEN,L2),1),orderqueue,IGNORECHECKPRICE;
END


IF (HOLDING < 0)   AND  (ENTERBARS > 0) and HIGH>=H2 THEN
BEGIN
SELLSHORT(1,HOLDING,LIMITR,MAX(OPEN,H2),1),orderqueue,IGNORECHECKPRICE;
END



cc807385:=holding;

drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc807385,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan807385:=cc807385-hold;

 
 cang:=xiadan807385+min(hold,0);
 if cang>0 then begin
  tbuy(1,cang,lmt,MAX(OPEN,H1),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 开多 %.0f',cang);
 end

 
 cang:=abs(xiadan807385)-max(hold,0);
 if cang>0 then begin
  tbuyshort(1,cang,lmt,MIN(OPEN,L1),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 开空 %.0f',cang);
 end


if xiadan807385<-0.5 then begin
 cang:=min(abs(xiadan807385),abs(hold));
 if hold>0 then begin
  tsell(1,cang,lmt,MIN(OPEN,L2),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平多 %.0f',cang);
 end
 end
 

 

if xiadan807385>0.5 then begin
 cang:=min(xiadan807385,abs(hold));
 if hold<0 then begin
  tsellshort(1,cang,lmt,MAX(OPEN,H2),0,'807385');
  debugfile('D:\807385.txt',numtostr(hold,0)+' '+numtostr(cc807385,0)+' 平空 %.0f',cang);
 end
 end
 


hold:=cc807385;





cc:=holding;
if not(islastbar) or workmode<>1 then exit;
tm:=1;//撤单时间
ac:='807385';//下单账户
wt:=tremainqty(0,ac,stklabel);
buyhold:=tbuyholdingex(ac,stklabel,1);
sellhold:=tsellholdingex(ac,stklabel,1);

if wt>0.5 and tsubmit(0)>tm then tcancelex(1,0,ac,stklabel);
if wt<0.5 then begin
 kc1:=max(cc,0)-buyhold;
 kc2:=abs(min(cc,0))-sellhold;
 if kc1<-0.5 then tsell(1,abs(kc1),mkt,0,0,ac),allowrepeat;
 if kc2<-0.5 then tsellshort(1,abs(kc2),mkt,0,0,ac),allowrepeat;
 if sellhold<0.5 and kc1>0.5 then tbuy(1,kc1,mkt,0,0,ac),allowrepeat;
 if buyhold<0.5  and kc2>0.5 then tbuyshort(1,kc2,mkt,0,0,ac),allowrepeat;
end
10楼
jinzhe 发表于:2014/4/1 15:47:12
这个图表的语句只是用来判断holding的吧?
共22 条记录, 每页显示 10 条, 页签: [1] [2][3]


Powered By Dvbbs Version 8.3.0
Processed in 0.05078 s, 3 queries.