您現在的位置:程序化交易>> 期貨公式>> 交易開拓者(TB)>> 開拓者知識>>正文內容

新手請教公式設置 - TradeBlazer公式 [開拓者 TB]

  • 咨詢內容: // 自己新學TB,編了個公式卻不能實現,請高手們指導,謝謝。


    // 以下為均線交易系統,10日均線上穿20均線為買入,10日均線下穿20均線為賣出
    // 均線買入/賣出時機均為平倉反手
    // 開倉為二手,達到盈利預期值時平倉一手,等回落后加倉一手



    Params      
            Numeric Length1(10);        // 10日均線的參數值
            Numeric Length2(20);        // 20日均線的參數值
            Numeric Lots(2);            // 默認的交易數量  
    Vars        
            NumericSeries MA1;
            NumericSeries MA2;
            Numeric MinPoint; // 一個最小變動單位,也就是一跳
            Numeric AddSet(50); // 加倉設置
            Numeric SubSet(50); // 減倉設置
            NumericSeries FirstPrice; // 第一次開倉價格
            NumericSeries LastPrice; // 最后一次開倉價格
            boolSeries Condition1;
            boolSeries Condition2;
    Begin   
            MA1 = XAverage(Close,Length1);  
            MA2 = XAverage(Close,Length2);
            MinPoint = MinMove*PriceScale();
            Condition1 = CrossOver(MA1,MA2);
            Condition2 = CrossUnder(MA1,MA2);
            If(MarketPosition==0) //空倉狀態時
            {
            if(condition1[1])// 當出現10日均線上穿20均線時,下一個bar開盤價買入
            {
            FirstPrice = Open;
            LastPrice = FirstPrice;
            Buy(lots,FirstPrice);
            }else if(condition2[1]) // 當出現10日均線下穿20均線時,下一個bar開盤價賣出
            {
            FirstPrice = Open;
            LastPrice = FirstPrice;
            Sellshort(Lots,Open);  
            }
            }else if(MarketPosition==1) // 有多頭持倉的情況
            {
            If(condition2[1]) // 當出現10日均線下穿20均線時,下一個bar開盤價賣出
            {
            Sellshort(Lots,Open);
            }else if(CurrentContracts==2 && High>= LastPrice+SubSet*MinPoint) // 止贏減倉
            {
            Sell(1,LastPrice+SubSet*MinPoint);
            LastPrice =LastPrice + subSet*MinPoint;
            }else if(CurrentContracts==1 && Low <=LastEntryPrice - AddSet*MinPoint) // 逢低加倉
            {
            buy(1,LastPrice- AddSet*MinPoint);
            LastPrice = LastPrice - addSet*MinPoint;
            }
            }else if(MarketPosition==-1);// 有空頭持倉的情況
            {
            If(condition1[1]) // 當出現10日均線下穿20均線時,下一個bar開盤價平倉并買入
            {
            Sellshort(Lots,Open);
            }Else if(CurrentContracts==2 &&  Low <= LastEntryPrice - subSet*MinPoint) // 止贏減倉
            {
            BuyToCover(1,LastPrice);
            LastPrice = LastPrice - subSet*MinPoint;
            }else if( CurrentContracts==1 && High >=LastPrice + addSet*MinPoint) // 逢高加倉
            {
            sell(1,LastPrice);
            LastPrice = LastPrice + AddSet*MinPoint;
            }
            }
    End

     

  • TB技術人員: 好像是這樣吧


    // 以下為均線交易系統,10日均線上穿20均線為買入,10日均線下穿20均線為賣出
    // 均線買入/賣出時機均為平倉反手
    // 開倉為二手,達到盈利預期值時平倉一手,等回落后加倉一手



    Params      
            Numeric Length1(10);        // 10日均線的參數值
            Numeric Length2(20);        // 20日均線的參數值
            Numeric Lots(2);            // 默認的交易數量  
    Vars        
            NumericSeries MA1;
            NumericSeries MA2;
            Numeric MinPoint; // 一個最小變動單位,也就是一跳
            Numeric AddSet(50); // 加倉設置
            Numeric SubSet(50); // 減倉設置
            NumericSeries FirstPrice; // 第一次開倉價格
            NumericSeries LastPrice; // 最后一次開倉價格
            boolSeries Condition1;
            boolSeries Condition2;
    Begin   
            MA1 = XAverage(Close,Length1);  
            MA2 = XAverage(Close,Length2);
            MinPoint = MinMove*PriceScale();
            Condition1 = CrossOver(MA1,MA2);
            Condition2 = CrossUnder(MA1,MA2);
            If(MarketPosition!=1) //空倉狀態時
            {
            if(condition1[1])// 當出現10日均線上穿20均線時,下一個bar開盤價買入
            {
            FirstPrice = Open;
            LastPrice = FirstPrice;
            Buy(lots,FirstPrice);
            }
                    if(MarketPosition!=-1 and condition2[1]) // 當出現10日均線下穿20均線時,下一個bar開盤價賣出
            {
            FirstPrice = Open;
            LastPrice = FirstPrice;
            Sellshort(Lots,Open);  
            }
            }
                    if(MarketPosition==1) // 有多頭持倉的情況
            {
            If(condition2[1]) // 當出現10日均線下穿20均線時,下一個bar開盤價賣出
            {
            Sellshort(Lots,Open);
            }else if(CurrentContracts>1  and CurrentContracts<3  && High>= LastPrice+SubSet*MinPoint) // 止贏減倉
            {
            Sell(1,LastPrice+SubSet*MinPoint);
            LastPrice =LastPrice + subSet*MinPoint;
            }else if(CurrentContracts<2 && Low <=LastEntryPrice - AddSet*MinPoint) // 逢低加倉
            {
            buy(1,LastPrice- AddSet*MinPoint);
            LastPrice = LastPrice - addSet*MinPoint;
            }
            }
                    if(MarketPosition==-1);// 有空頭持倉的情況
            {
            If(condition1[1]) // 當出現10日均線下穿20均線時,下一個bar開盤價平倉并買入
            {
            Sellshort(Lots,Open);
            }Else if(CurrentContracts>1 and CurrentContracts<3  &&  Low <= LastEntryPrice - subSet*MinPoint) // 止贏減倉
            {
            BuyToCover(1,LastPrice);
            LastPrice = LastPrice - subSet*MinPoint;
            }else if( CurrentContracts<2 && High >=LastPrice + addSet*MinPoint) // 逢高加倉
            {
            sell(1,LastPrice);
            LastPrice = LastPrice + AddSet*MinPoint;
            }
            }
    End

     

  • TB客服: 謝謝,不過好像還是沒達到想要的效果

     

  • 網友回復: 回復 3# 青木


    您的效果是想要怎樣的?
    您可以將各個條件用commentary輸出查看你的條件,一步一步看就知道為什么不是你想要的效果了。
    commentary的各種使用方法請看:http://tradeblazer.net/forum/vie ... B%E4%BD%BF%E7%94%A8
    或者參考幫助文檔中相關函數說明

     

  • 網友回復: 回復 4# lh948

    這個建議非常好,謝謝!
    我按照你的方法把公式調整了,效果出來了。不過奇怪的是有多單時符合預期效果,但惟獨有空單時不能止贏和補倉,只能平倉反手。
    多單和空單的代碼是同理的,為何效果不同捏?
    以下是我修改會的代碼,請幫忙看看:

    // 以下為均線交易系統,10日均線上穿20均線為買入,10日均線下穿20均線為買出
    Params      
            Numeric Length1(10);        // 10日均線的參數值
            Numeric Length2(20);        // 20日均線的參數值
            Numeric Lots(2);            // 默認的交易數量  
    Vars        
            NumericSeries MA1;
            NumericSeries MA2;
            Numeric MinPoint(1); // 一個最小變動單位,也就是一跳
            Numeric AddSet(20); // 加倉設置
            Numeric SubSet(20); // 減倉設置
                    NumericSeries myFirstPrice; // 第一次開倉價格
                    NumericSeries myLastPrice; // 最后一次開倉價格
                    boolSeries Condition1;
                    boolSeries Condition2;
    Begin   
            MA1 = XAverage(Close,Length1);  
            MA2 = XAverage(Close,Length2);
            MinPoint = MinMove*PriceScale;
                    Condition1 = CrossOver(MA1,MA2);
            Condition2 = CrossUnder(MA1,MA2);
                    If(MarketPosition==0 )
                    {
                      if(condition1) //空倉狀態時出現10日均線上穿20均線,當前bar收盤價買入
                       {
                        myFirstPrice = Close;
                        myLastPrice = myFirstPrice;
                        Buy(lots,myFirstPrice);
                        Commentary("空倉狀態下,上穿20均線時,當前bar收盤價買入");
                       }Else if(condition2) // 空倉狀態時出現10日均線下穿20均線時,當前bar收盤價賣出
                       {
                        myFirstPrice = Close;
                        myLastPrice = myFirstPrice;
                Sellshort(Lots,myFirstPrice);
                Commentary("空倉狀態下,下穿20均線時,當前bar收盤價賣出");               
                       }
                    }Else if(MarketPosition==1 )
                       {
                        If(condition2) // 有多單持倉,出現10日均線下穿20均線時,當前bar收盤價賣出
                       {
                        myLastPrice = Close;
                        Sellshort(Lots,myLastPrice);
                            Commentary("多單平倉并反手");                 
                       }Else if(CurrentContracts==2 && High>= myLastPrice+SubSet*MinPoint) // 止贏減倉
                       {
                Sell(1,myLastPrice+SubSet*MinPoint);
                        Commentary("多單止贏1手");
                        myLastPrice =myLastPrice + subSet*MinPoint;
                       }Else if(CurrentContracts==1 && Low <=MA1) // 逢低加倉
               {
                buy(1,IntPart(MA1));
                        Commentary("多單補倉1手");
                    myLastPrice = IntPart(MA1);
                       }
            }Else If(MarketPosition==-1 )
               {
                        if(condition1)// 有空單持倉,出現10日均線上穿20均線時,當前bar收盤價平倉并買入
                       {
                        myLastPrice = Close;
                        Buy(Lots,myLastPrice);
                        Commentary("空單平倉并反手");
                       }Else if(CurrentContracts==2 && Low<=myLastPrice-SubSet*MinPoint) // 止贏減倉
               {
                        BuyToCover(1,myLastPrice-SubSet*MinPoint);
                        Commentary("空單止贏1手");
                        myLastPrice=myLastPrice-SubSet*MinPoint;
                       }Else if(CurrentContracts==1 && High>=MA1) // 逢高加倉
               {
                        sell(1,IntPart(MA1));
                            Commentary("空單補倉1手");               
                        myLastPrice = IntPart(MA1);
                       }
                       }
    End

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

相關文章

    沒有相關內容
主站蜘蛛池模板: 晚上睡不着来b站一次看过瘾| 久久久亚洲欧洲日产国码农村| 触手强制h受孕本子里番 | 人人爽人人澡人人高潮| 美女被免费网在线观看网站| 国产婷婷一区二区三区| 69免费视频大片| 女人18毛片a级毛片免费视频| 中文字幕专区高清在线观看 | 日本黄色一级视频| 亚洲国产一区二区a毛片| 波多野结衣黑丝| 制服丝袜中文字幕在线观看| 色多多在线视频| 国产午夜视频高清| 国产精品三级视频| 国产精品久久久久久久久kt | 调教家政妇第38话无删减| 国产第一页屁屁影院| 538在线精品| 国语自产精品视频在线看| yuijizz| 成人爽爽激情在线观看| 久久96国产精品| 日本一道在线观看| 久久天天躁日日躁狠狠躁| 日韩色视频在线观看| 亚洲av无码一区二区三区在线播放| 欧美性生活网址| 亚洲成a人片在线观看中文| 欧美视频在线观看网站| 亚洲精品影院久久久久久| 特级毛片aaaa级毛片免费| 人妻精品久久久久中文字幕69| 空白tk2一一视频丨vk| 免费毛片在线视频| 精品一区精品二区| 免费观看一级欧美在线视频| 精品久久久久久成人AV| 全黄h全肉远古| 第一福利在线观看|