大伊人青草狠狠久久-大伊香蕉精品视频在线-大伊香蕉精品一区视频在线-大伊香蕉在线精品不卡视频-大伊香蕉在线精品视频75-大伊香蕉在线精品视频人碰人

您現在的位置:程序化交易>> 期貨公式>> 金字塔等>> 金字塔知識>>正文內容

虧三次加倉,盈三次減倉 [金字塔]

  • 咨詢內容: 下面是突破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 ;

     

  • 金字塔客服:

     if shortx1 and buyorderthisbar=0 then begin

    像類似這樣平倉語句里面有全局變量操作的,要在平倉條件的if里面加上holding判斷

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

     

  • 用戶回復:

    加上holding 也還是倉位錯亂,麻煩你加載一下,加倉減倉能實現嗎?






     

  • 網友回復:

    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;    

     

  • 網友回復: 按你的加載還是不行,麻煩你回測一下.全局變量真難用,不知錯在哪!

 

有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友

可聯系技術人員 QQ: 511411198  點擊這里給我發消息進行 有償 編寫!不貴!點擊查看價格!


【字體: 】【打印文章】【查看評論

相關文章

    沒有相關內容
主站蜘蛛池模板: 成人97| 亚洲精品免费在线视频 | 国产香港特级一级毛片 | 亚洲国产精品成人午夜在线观看 | 中国国语毛片免费观看视频 | 亚洲va久久久久综合 | 99爱在线精品视频免费观看9 | 亚洲国产高清人在线 | 中文欧美一级强 | 天天爽夜夜爽精品视频一 | 久久久久久夜精品精品免费 | 久久久久久久99久久久毒国产 | 拍拍拍无挡视频免费观看1000 | 国产第一页福利 | 日韩欧美视频一区 | 玖玖成人网 | 99久久免费视频在线观看 | 国产成+人+亚洲+欧美综合 | 国产成人亚洲综合网站不卡 | 97国内免费久久久久久久久久 | 不卡的中文字幕 | 久久久精品国产四虎影视 | 久久精品久噜噜噜久久 | 久久国产精品亚洲一区二区 | 五月久久亚洲七七综合中文网 | 欧美成人精品免费播放 | 欧美色影院 | 四虎视频国产精品免费入口 | 3级毛片 | 国产精品入口麻豆高清在线 | 欧美日韩免费做爰视频 | 成人国产精品久久久免费 | 精品哟啊呦v视频在线观看 精品哟哟国产在线观看 | 亚洲成色 | 久久色国产| 亚洲九月天 | xxx中国bbbwww | 99热久久久久久久免费观看 | 五月婷婷激情网 | 97视频免费人人观看人人 | 狠狠综合|