欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → 亏三次加仓,盈三次减仓

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有3626人关注过本帖树形打印复制链接

主题:亏三次加仓,盈三次减仓

帅哥哟,离线,有人找我吗?
tanyongde
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:169 积分:0 威望:0 精华:0 注册:2016/8/28 16:11:16
亏三次加仓,盈三次减仓  发帖心情 Post By:2016/10/11 17:39:51    Post IP:116.29.214.160[只看该作者]

下面是突破20日高低点交易策略,初始交易手数为ss,  如连续三次盈利后仓位减为一半, 一直到连续三次亏损仓位增加到原仓位,加载后交易明细帐仓位错乱,请问全局变量那错了,麻烦纠正过来?

input :k(20,5,30,1) 
input:avglen(30,10,100,5);
input : atrlen(20,5,30,1) ;
input : ss(2,1,1000,1) ;

//声明变量
nt := 1 ; //调试信息带时间戳
buyorderthisbar := 0 ; //当前bar有过交易
variable : _debug = 1 ; //是否输出前台交易指令
variable : turtleunits=0 ; //交易单位
variable : myentryprice1=0; 
variable : myentryprice2=0; 
variable : myexitprice=0;
variable : n=0;
variable : m=0;
variable : yk=0; 
//准备需要计算的变量
zhh:ref(high,k);
zll:ref(low,k);
kqls:=enterbars+1;
khh:=hhv(high,kqls);
kll:=llv(low,kqls);

avgtr :=ref(ma(tr,atrlen),1);

//开始执行时 初始化数据
if barpos=1 then begin
position :=0 ;
posnum:=ss; 
end 

//如果当前是没有持仓的状态
if position=0 and  barpos>20 and h>l then begin 
//建立多头进场条件
long:=high>=zhh ;
//多头进场
if long then begin
myentryprice1 :=if(open>zhh+0.2 ,open+0.6 ,zhh+0.6);
buy( _debug,posnum,limitr,myentryprice1);
jqsh:=1;
   position := 1 ;
turtleunits := 1 ;
   n:= avgtr ;
buyorderthisbar := 1;
end
 
//建立空头进场条件
short:=low<=zll ;
//空头进场
if short and position=0 then begin
myentryprice2:= if(open<zll-0.2 ,open-0.6 ,zll-0.6) ;
buyshort( _debug,posnum,limitr,myentryprice2);
jqsh:=1;
position := -1 ;
turtleunits := 1 ;
n := avgtr ;
buyorderthisbar := 1;

 end
 end

//如果当前持有多头仓位的状态

if position=1 and barpos>20 and h>l then begin

//多头加仓条件
{while (close>myentryprice+0.5*n) and turtleunits<4 and jqsh=1 do begin
myentryprice := if(open>myentryprice+0.5*n ,open+0.6 ,myentryprice+0.5*n+0.6 ) ;
myentryprice:= ceiling(myentryprice/mindiff)*mindiff ;
buy( _debug, posnum, limitr,myentryprice );
turtleunits := turtleunits+1 ;
buyorderthisbar := 1;
end }
//建立多头离场条件
longx1 := low<zll-mindiff;
   myexitprice:=zll-mindiff;
     if longx1 and buyorderthisbar=0 then begin
myexitprice := if(open<myexitprice-0.2 ,open-0.6 ,myexitprice-0.6) ;
sell( _debug ,0,limitr,myexitprice);
position := 0 ;
turtleunits := 0 ;
yk:=myexitprice- myentryprice2;
end
if yk>0 then begin 
      n:=0;
      m:=m+1;
      end
     
    if yk<0   then begin
      n:=n+1;
      m:=0;
     end 
      if n>=3 then posnum:=ss;
      if m>=3 then posnum:=0.5*ss;
 
   //建立多头止损条件
longx2 := low<(khh-2*n);
    if longx2 and position=1 and buyorderthisbar=0 then begin
myexitprice := if(open<khh-2*n ,open-0.6 ,khh-2*n-0.6) ;
myexitprice := floor(myexitprice/mindiff)*mindiff ;
sell( _debug ,0,limitr,myexitprice);
position := 0 ;
turtleunits := 0 ;
yk:=myexitprice- myentryprice2;
  end
if yk>0 then begin
  n:=0;
  m:=m+1;
      end
   if yk<0   then begin
      n:=n+1;
      m:=0;
     end
      if n>=3 then posnum:=ss;
      if m>=3 then posnum:=0.5*ss;
end  


//如果当前持有空头仓位的状态

if position = -1 and barpos>20 and h>l then begin

//空头加仓条件
{while (close<myentryprice-0.5*n) and turtleunits<4 and jqsh=1 do begin
myentryprice := if(open<myentryprice-0.5*n ,open-0.6 ,myentryprice-0.5*n-0.6 ) ;
kkj := floor(myentryprice/mindiff)*mindiff ;
buyshort( _debug,posnum, limitr,myentryprice );
turtleunits := turtleunits+1 ;
buyorderthisbar := 1;
end }

   //建立空头离场条件
    shortx1 :=  high>zhh+mindiff;
        myexitprice:=zhh+mindiff;
    if shortx1 and buyorderthisbar=0 then begin
myexitprice := if(open>myexitprice,open+0.6, myexitprice+0.6);
sellshort( _debug,0,limitr,myexitprice);
position := 0 ;
turtleunits := 0 ;
  yk:=myentryprice2-myexitprice;
end
   if yk>0 then begin 
      n:=0;
      m:=m+1;
     end
   if yk<0  then begin
      n:=n+1;
      m:=0;
      end
      if n>=3 then posnum:=ss;
      if m>=3 then posnum:=0.5*ss;
      

//建立空头止损条件
shortx2 := high>kll+2*n ;
    if shortx2 and position = -1 and buyorderthisbar=0  then begin
myexitprice:= if(open>kll+2*n ,open+0.6 ,kll+2*n+0.6) ;
myexitprice := ceiling(myexitprice/mindiff)*mindiff ;
sellshort( _debug,0,limitr,myexitprice);
position := 0 ;
turtleunits := 0 ;
yk:=myentryprice2-myexitprice;
 end
  if yk>0   then begin 
     n:=0;
     m:=m+1;
    end 
  if yk<0   then begin
     n:=n+1;
     m:=0;
    end
    if n>=3 then posnum:=ss;
    if m>=3 then posnum:=0.5*ss;
 end 
        
  
  

  //显示账户状态
continueline@ 资产:asset,linethick0;
可用现金:cash(0),linethick0;
pos:holding,linethick0;
交易次数:totaldaytrade, linethick0 ;


 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/10/12 9:01:04    Post IP:180.169.30.6[只看该作者]

 if shortx1 and buyorderthisbar=0 then begin

像类似这样平仓语句里面有全局变量操作的,要在平仓条件的if里面加上holding判断

比如平多就要加holding>0的判断,平空就要加holding<0的判断



金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
tanyongde
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:169 积分:0 威望:0 精华:0 注册:2016/8/28 16:11:16
  发帖心情 Post By:2016/10/12 17:56:36    Post IP:119.138.131.91[只看该作者]



加上holding 也还是仓位错乱,麻烦你加载一下,加仓减仓能实现吗?








 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/10/13 9:07:01    Post IP:116.226.229.171[只看该作者]

input :k(20,5,30,1)
input:avglen(30,10,100,5);
input : atrlen(20,5,30,1) ;
input : ss(2,1,1000,1) ;


//声明变量
nt := 1 ;   //调试信息带时间戳
buyorderthisbar := 0 ;   //当前bar有过交易
variable : _debug = 1 ;   //是否输出前台交易指令
variable : turtleunits=0 ;   //交易单位
variable : myentryprice1=0;
variable : myentryprice2=0;
variable : myexitprice=0;
variable : n=0;
variable : m=0;
variable : yk=0;
//准备需要计算的变量
zhh:ref(high,k);
zll:ref(low,k);
kqls:=enterbars+1;
khh:=hhv(high,kqls);
kll:=llv(low,kqls);


avgtr :=ref(ma(tr,atrlen),1);


//开始执行时 初始化数据
if barpos=1 then begin
   position :=0 ;
   posnum:=ss;
end


//如果当前是没有持仓的状态
if position=0 and  barpos>20 and h>l then begin
   //建立多头进场条件
   long:=high>=zhh ;
   //多头进场
   if long  and holding=0  then begin
   myentryprice1 :=if(open>zhh+0.2 ,open+0.6 ,zhh+0.6);
   buy( _debug,posnum,limitr,myentryprice1);
   jqsh:=1;
      position := 1 ;
   turtleunits := 1 ;
     // n:= avgtr ;
   buyorderthisbar := 1;
  
   end
   
   //建立空头进场条件
   short:=low<=zll ;
   //空头进场
   if short and position=0 and holding=0 then begin   
   myentryprice2:= if(open<zll-0.2 ,open-0.6 ,zll-0.6) ;
   buyshort( _debug,posnum,limitr,myentryprice2);
   jqsh:=1;
   position := -1 ;
   turtleunits := 1 ;
   //n := avgtr ;
   buyorderthisbar := 1;


    end
 end   


//如果当前持有多头仓位的状态


if position=1 and barpos>20 and h>l then begin


   //多头加仓条件
  
   {while (close>myentryprice+0.5*n) and turtleunits<4 and jqsh=1 do begin
   myentryprice := if(open>myentryprice+0.5*n ,open+0.6 ,myentryprice+0.5*n+0.6 ) ;
   myentryprice:= ceiling(myentryprice/mindiff)*mindiff ;   
   buy( _debug, posnum, limitr,myentryprice );
   turtleunits := turtleunits+1 ;
   buyorderthisbar := 1;
   end }
  
   //建立多头离场条件
   longx1 := low<zll-mindiff;
      myexitprice:=zll-mindiff;
     if longx1 and buyorderthisbar=0 and holding>0 then begin
   myexitprice := if(open<myexitprice-0.2 ,open-0.6 ,myexitprice-0.6) ;   
   sell( _debug ,0,limitr,myexitprice);
   position := 0 ;
   turtleunits := 0 ;
   yk:=myexitprice- myentryprice2;
   
   if yk>0 then begin
         n:=0;
         m:=m+1;
         end
       
       if yk<0   then begin
         n:=n+1;
         m:=0;
        end
        // if n>=3 then posnum:=ss;
 end      //  if m>=3 then posnum:=0.5*ss;
   
   //建立多头止损条件
   longx2 := low<(khh-2*n);
    if longx2 and position=1 and buyorderthisbar=0 and holding>0 then begin
   myexitprice := if(open<khh-2*n ,open-0.6 ,khh-2*n-0.6) ;   
   myexitprice := floor(myexitprice/mindiff)*mindiff ;   
   sell( _debug ,0,limitr,myexitprice);
   position := 0 ;
   turtleunits := 0 ;
   yk:=myexitprice- myentryprice2;
   
   if yk>0 then begin
     n:=0;
     m:=m+1;
         end
      if yk<0   then begin
         n:=n+1;
         m:=0;
        end
      
   end 

  end


//如果当前持有空头仓位的状态


if position = -1 and barpos>20 and h>l then begin


   //空头加仓条件
  
   {while (close<myentryprice-0.5*n) and turtleunits<4 and jqsh=1 do begin
   myentryprice := if(open<myentryprice-0.5*n ,open-0.6 ,myentryprice-0.5*n-0.6 ) ;   
   kkj := floor(myentryprice/mindiff)*mindiff ;   
   buyshort( _debug,posnum, limitr,myentryprice );
   turtleunits := turtleunits+1 ;
   buyorderthisbar := 1;
   end }   


   //建立空头离场条件
    shortx1 :=  high>zhh+mindiff;
        myexitprice:=zhh+mindiff;
    if shortx1 and buyorderthisbar=0 and holding<0 then begin
   myexitprice := if(open>myexitprice,open+0.6, myexitprice+0.6);   
   sellshort( _debug,0,limitr,myexitprice);
   position := 0 ;
   turtleunits := 0 ;
        yk:=myentryprice2-myexitprice;
   
      if yk>0 then begin
         n:=0;
         m:=m+1;
        end
      if yk<0  then begin
         n:=n+1;
         m:=0;
         end
         //if n>=3 then posnum:=ss;
         //if m>=3 then posnum:=0.5*ss;
        
 end 


   //建立空头止损条件
   shortx2 := high>kll+2*n ;
    if shortx2 and position = -1 and buyorderthisbar=0 and holding<0 then begin
   myexitprice:= if(open>kll+2*n ,open+0.6 ,kll+2*n+0.6) ;   
   myexitprice := ceiling(myexitprice/mindiff)*mindiff ;   
   sellshort( _debug,0,limitr,myexitprice);
   position := 0 ;
   turtleunits := 0 ;
   yk:=myentryprice2-myexitprice;
   
     if yk>0   then begin
        n:=0;
        m:=m+1;
       end
     if yk<0   then begin
        n:=n+1;
        m:=0;
       end
      // if n>=3 then posnum:=ss;
       //if m>=3 then posnum:=0.5*ss;
       end
 end
       
  if n>=3 and ref(n,1)=2 then posnum:=ss;
if m>=3 and ref(m,1)=2 then posnum:=0.5*ss;    



金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
tanyongde
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:169 积分:0 威望:0 精华:0 注册:2016/8/28 16:11:16
  发帖心情 Post By:2016/10/13 13:49:51    Post IP:119.138.131.91[只看该作者]

按你的加载还是不行,麻烦你回测一下.全局变量真难用,不知错在哪!


 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/10/13 13:50:56    Post IP:180.169.30.6[只看该作者]

错在哪里,用户截图说明一下


金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
tanyongde
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:169 积分:0 威望:0 精华:0 注册:2016/8/28 16:11:16
  发帖心情 Post By:2016/10/13 14:34:06    Post IP:119.138.131.91[只看该作者]

测试报告,交易明细中仓位错刮

 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/10/13 14:49:49    Post IP:116.226.230.3[只看该作者]

截图一下,并做个说明


金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
tanyongde
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:169 积分:0 威望:0 精华:0 注册:2016/8/28 16:11:16
  发帖心情 Post By:2016/10/13 15:12:00    Post IP:119.138.131.91[只看该作者]

怎样在交易明细截图?

 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/10/13 15:38:10    Post IP:116.226.229.171[只看该作者]

用qq来截图


金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
总数 13 1 2 下一页