以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  请问怎么解决反手不开仓的问题  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=58808)

--  作者:zsg465341578
--  发布时间:2013/11/15 0:06:40
--  请问怎么解决反手不开仓的问题
老师你好,下面是我的交易代码示例,其中,平多条件(PD)想表达的意思是:如果开空条件已成立,即使持有多单也马上平多开空(PK亦然),这时候系统就只有平仓,没有开仓,请问是什么原因?

dif:=ema(c,12)-ema(c,26);
dea:=ema(dif,9);
macd:=2*(dif-dea);
cpx:=ma(c,14);
entertime:=time<150000 and time>091600;
exittime:=time>=151400;

//交易条件
kd:=cross(c,cpx) and cpx>ref(cpx,1) and macd>0 and entertime;//开多条件
kk:=cross(cpx,c) and cpx<ref(cpx,1) and  macd<0 and entertime;//开空条件
pd:=(macd<0 and cpx<ref(cpx,1)) or kk or exittime;//平多条件(如果开空条件成立,即使持有多单,马上平多开空
pk:=(macd>0 and cpx>ref(cpx,1)) or kd or exittime;//平空条件(如果开多条件成立,即使持有空单,马上平空开多

//交易系统 
if holding<>0 then begin
   sell(pd,0,limit,c),orderqueue;
   sellshort(pk,0,limit,c),orderqueue;
end

if holding=0 then begin
   buy(kd,1,limit,c),orderqueue;
   buyshort(kk,1,limit,c),orderqueue;
end

--  作者:jinzhe
--  发布时间:2013/11/15 9:10:54
--  
if holding<>0 then begin
   sell(pd,0,limit,c),orderqueue;
   sellshort(pk,0,limit,c),orderqueue;
end

if holding=0 then begin
   buy(kd,1,limit,c),orderqueue;
   buyshort(kk,1,limit,c),orderqueue;
end

 

 

这样的顺序是不正确的,软件的公式编辑界面有说明是如何写的。而且,用户是不是不明白ORDERQUEUE是用来干什么的?加上来是不是为了好看?

 

dif:=ema(c,12)-ema(c,26);
dea:=ema(dif,9);
macd:=2*(dif-dea);
cpx:=ma(c,14);
entertime:=time<150000 and time>091600;
exittime:=time>=151400;
 
kd:=cross(c,cpx) and cpx>ref(cpx,1) and macd>0 and entertime;//开多条件
kk:=cross(cpx,c) and cpx<ref(cpx,1) and  macd<0 and entertime;//开空条件
pd:=(macd<0 and cpx<ref(cpx,1)) or exittime;//平多条件(如果开空条件成立,即使持有多单,马上平多开空
pk:=(macd>0 and cpx>ref(cpx,1)) or exittime;//平空条件(如果开多条件成立

 

if kd then begin

   sellshort(1,0,thisclose);

   buy(holding=0,1,thisclose);

end

 

if kk then begin

   sell(1,0,thisclose);

   buyshort(holding=0,1,thisclose);

end

 

if pd then sell(1,0,thisclose);

if pk then sellshort(1,0,thisclose);

 


--  作者:zsg465341578
--  发布时间:2013/11/18 15:46:42
--  
谢谢老师,我改过来了!如果我加上移动止赢的全局变量(YDZY),麻烦老师看一下下面的格式和逻辑对不对呢?


if ydzy=1 and holding<>0 then begin
   if h>highprice then highprice:=h;
   if (highprice-enterprice>=49 and highprice-h>=6) or (highprice-enterprice>=19 and h-enterprice<=17) then sell(1,0,limitr,c);
   if l<lowprice then lowprice:=l;
   if (enterprice-lowprice>=30 and l-lowprice>=16) or (enterprice-lowprice>=19 and enterprice-l<=13) then sellshort(1,0,limitr,c);
end

--  作者:zsg465341578
--  发布时间:2013/11/18 15:54:31
--  
谢谢老师,我改过来了,如果加上移动止赢变量,麻烦老师再看看下面的公式格式和逻辑对不对?谢谢!

variable:ydzy=1;                 //移动止盈开关
variable:highprice=0,lowprice=0; //记录开仓价

if kd  then begin
   sellshort(1,0,limitr,c);
   buy(holding=0,1,limitr,c);
   highprice:=enterprice; 
end
 
if kk  then begin
   sell(1,0,limitr,c);
   buyshort(holding=0,1,limitr,c);
   lowprice:=enterprice;
end
 
if pd or enterprice-c>=10 then sell(1,0,limitr,c);
if pk or c-enterprice>=10 then sellshort(1,0,limitr,c);

if ydzy=1 and holding<>0 then begin
   if h>highprice then highprice:=h;
   if (highprice-enterprice>=49 and highprice-h>=6) or (highprice-enterprice>=19 and h-enterprice<=17) then sell(1,0,limitr,c);
   if l<lowprice then lowprice:=l;
   if (enterprice-lowprice>=30 and l-lowprice>=16) or (enterprice-lowprice>=19 and enterprice-l<=13) then sellshort(1,0,limitr,c);
end


--  作者:jinzhe
--  发布时间:2013/11/18 16:06:45
--  
现在是哪里不对的问题?
--  作者:zsg465341578
--  发布时间:2013/11/19 13:25:13
--  
改后,现在仍是反手不开单:若一根K线上同时出现平仓和开仓的信号时,只有平,没有开,持仓同步也报错。
--  作者:jinzhe
--  发布时间:2013/11/19 13:29:46
--  

反手不开?资金够不够?

贴上来下单日志


--  作者:zsg465341578
--  发布时间:2013/11/19 13:41:24
--  
遇到反手的时候,是不是要有2手的资金才会开?(不好意思,忘记记录下单日志了?)


--  作者:jinzhe
--  发布时间:2013/11/19 13:43:47
--  
是的,如果只有一手的资金,那么平空开多这样的反手动作是做不了的,因为平仓还没收到成交回报,当前账户资金不足以开反手仓
--  作者:zsg465341578
--  发布时间:2013/11/19 13:47:52
--  
我只有1手的资金,但平仓后,系统自带的持仓同步应该马上恢复持仓呀