以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  有条件限制日内开仓次数问题  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=66261)

--  作者:zsg465341578
--  发布时间:2014/6/17 13:24:28
--  有条件限制日内开仓次数问题
老师好,我想限制日内的开仓次数,请问代码怎么实现?
    条件是:
    1、达到止赢条件,如一次赢利3%;
    2、连续三次赢利;
    3、连续两次亏损。

--  作者:jinzhe
--  发布时间:2014/6/17 13:44:07
--  

1.盈利3%的:

多头  (h-enterprice)/enterprice>0.03

空头(enterprice-l)/enterprice>0.03

 

2,3

连赢连亏的思路都是一样的,用全局变量来记录

variable:n=0;

variable:m=0;

if 平多条件 and 持仓判断 then begin

      sell.....;

      if   numprofit(1)>0 then begin

            n:=n+1;

            m:=0;

      end

      if numprofit<0 then begin

           n:=0;

           m:=m+1;

end

 

n是连赢次数,m是连亏次数


--  作者:zsg465341578
--  发布时间:2014/6/17 14:10:59
--  
在上述条件成立的时候,就退出交易,是吗:
if 多头 or 空头 or n>=3 or m>=2 then exit; 

--  作者:zsg465341578
--  发布时间:2014/6/17 14:30:51
--  
请问记录盈亏次数的n和m放在什么地方?是放在每次平仓之后?还是单独放在最后即可?
--  作者:jinzhe
--  发布时间:2014/6/17 14:31:08
--  
。。。。不用退出,直接在开仓条件里面加入连亏连赢的次数判断
--  作者:zsg465341578
--  发布时间:2014/6/17 14:47:42
--  
是否是这样:
if 开多条件 and 持仓判断 and (n<3 or m<2 or not(多赢) or not(空赢)) then begin
   buy......;
end

另外,记录N和M是每次平仓都记录,对吗?


--  作者:jinzhe
--  发布时间:2014/6/17 14:51:06
--  
对的
--  作者:ZSG465341578
--  发布时间:2014/6/18 11:00:02
--  
老师,昨日请教的问题,麻烦你再看一下,下面的逻辑和代码有错没有:怎么和不加限制条件的测试结果完全一样呢?

//限制日内的交易次数,条件是:1、达到止赢条件,如一次赢利3%;2、连续三次赢利;3、连续两次亏损;之后便不再开仓。

//1、盈利3%
dzy:=(c-enterprice)/enterprice*100>3;//多止赢
kzy:=(enterprice-c)/enterprice*100>3;//空止赢
 
//2、3、用全局变量来记录连赢连亏
variable:n=0;   //记录连赢次数n;
variable:m=0;   //记录连亏次数m;
   
kd:=cross(ma(c,10),ma(c,30));
kk:=cross(ma(c,30),ma(c,10));
pd:=cross(ma(c,20),ma(c,10));
pk:=cross(ma(c,10),ma(c,20));   //开平条件
  
//交易系统
if (pk or kd) and holding<0 then begin
      sellshort(1,0,market);
      if numprofit(1)>0 then begin
            n:=n+1;
            m:=0;
      end
      if numprofit(1)<0 then begin
           n:=0;
           m:=m+1;
      end
end
if kd and holding=0 and (n<3 or m<2 or not(dzy) or not(kzy)) then begin
   buy(1,1,market);
end

if (pd or kk) and holding>0 then begin
      sell(1,0,market);
      if numprofit(1)>0 then begin
            n:=n+1;
            m:=0;
      end
      if numprofit(1)<0 then begin
           n:=0;
           m:=m+1;
      end  
end
if kk and holding=0 and (n<3 or m<2 or not(dzy) or not(kzy)) then begin
   buyshort(1,1,market);
end



--  作者:jinzhe
--  发布时间:2014/6/18 11:08:16
--  
平仓条件就是平仓条件,你不要再来个OR 开仓条件
--  作者:ZSG465341578
--  发布时间:2014/6/18 22:29:48
--  
我加上的意思是:平空条件成立(或者开多条件同时成立),都执行平空——表述有问题?老师的意思是怎么修改呢?我去掉那个条件后测试,结果也一样


//限制日内的交易次数,条件是:1、达到止赢条件,如一次赢利3%;2、连续三次赢利;3、连续两次亏损。

//1、盈利3%
dzy:=(c-enterprice)/enterprice*100>3;//多止赢
kzy:=(enterprice-c)/enterprice*100>3;//空止赢
 
//2、3、用全局变量来记录连赢连亏
variable:n=0;   //记录连赢次数n;
variable:m=0;   //记录连亏次数m;
   
kd:=cross(ma(c,10),ma(c,30));
kk:=cross(ma(c,30),ma(c,10));
pd:=cross(ma(c,20),ma(c,10));
pk:=cross(ma(c,10),ma(c,20));   //开平条件
  
//交易系统
if pk and holding<0 then begin
      sellshort(1,0,market);
      if numprofit(1)>0 then begin
            n:=n+1;
            m:=0;
      end
      if numprofit(1)<0 then begin
           n:=0;
           m:=m+1;
      end
end
if kd and holding=0 and (n<3 or m<2 or not(dzy) or not(kzy)) then begin
   buy(1,1,market);
end

if pd and holding>0 then begin
      sell(1,0,market);
      if numprofit(1)>0 then begin
            n:=n+1;
            m:=0;
      end
      if numprofit(1)<0 then begin
           n:=0;
           m:=m+1;
      end  
end
if kk and holding=0 and (n<3 or m<2 or not(dzy) or not(kzy)) then begin
   buyshort(1,1,market);
end