您現在的位置:程序化交易>> 期貨公式>> 交易開拓者(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

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

相關文章

    沒有相關內容
主站蜘蛛池模板: 亚洲成人app| 国产主播福利精品一区二区| 两个人一起差差差30分| 欧美―第一页―浮力影院 | 国产成人精品一区二区三在线观看| xxxxx国产| 日本成人在线网址| 国产成人久久久精品二区三区| sao货水真多好浪好紧视频| 日本韩国三级在线| 亚洲图片欧美日韩| 精品乱码久久久久久久| 国产又粗又猛又爽又黄的免费视频| 91av在线导航| 日韩在线播放全免费| 亚洲精品乱码久久久久66| 绿巨人黑科技地址入口| 国产孕妇孕交视频| 521a成v视频网站在线入口| 好男人好影视在线观看视频| 亚洲а∨天堂久久精品| 狠狠色香婷婷久久亚洲精品| 国产一级一国产一级毛片| a级高清观看视频在线看| 新梅金瓶之爱奴1国语在线观看| 亚洲av无码国产一区二区三区| 波多野结衣中文字幕一区二区三区| 卡一卡二卡三在线入口免费| 黄网站欧美内射| 国产精品无码久久综合网| a级成人毛片完整版| 成年人在线看片| 久久无码精品一区二区三区 | 好黄好猛好爽好痛的视频| 久久久久人妻精品一区蜜桃| 最近免费中文字幕大全高清大全1 最近免费中文字幕大全高清大全1 | 色橹橹欧美在线观看视频高清| 国产欧美久久一区二区| 337p人体韩国极品| 在线天堂bt种子| eeuss影院天堂影院|