請(qǐng)教利潤(rùn)回撤百分比跟蹤止損的問(wèn)題 [開拓者 TB]
- 咨詢內(nèi)容:
本帖最后由 tonyb2 于 2013-7-20 20:34 編輯
請(qǐng)教利潤(rùn)回撤百分比跟蹤止損的問(wèn)題
根據(jù)TB指南中的固定點(diǎn)數(shù)跟蹤止損代碼修改,由原來(lái)的高點(diǎn)回落固定點(diǎn)數(shù)修改為 當(dāng)利潤(rùn)回撤一定百分比時(shí)進(jìn)行跟蹤止盈,
例如多頭開倉(cāng)后,當(dāng)最大利潤(rùn)達(dá)到100點(diǎn)后觸發(fā)跟蹤止盈,止盈條件為當(dāng)前盈利< 自入場(chǎng)后的最大利潤(rùn)的40%即止盈出場(chǎng)。
但為何這段代碼放到代碼中不觸發(fā)跟蹤止盈?百思不得其解....
確認(rèn)行情已經(jīng)超過(guò)跟蹤止盈的 TrailingStopstartvalue起始點(diǎn)了。。回撤時(shí)沒有止盈信號(hào)。。。
開倉(cāng)、平倉(cāng)、初始止損都沒問(wèn)題,就是不止盈。。。
請(qǐng)版主或高手幫看下代碼問(wèn)題出在哪里?- Params
- Numeric TrailingStopvalue(40); //percent
- Numeric TrailingStopstartvalue(100);//100點(diǎn)為開啟止盈的起始點(diǎn)
-
- Vars
- Numeric MyPrice;
- Numeric MinPoint;
- NumericSeries MyExitPrice;
- NumericSeries HigherAfterEntry;
- NumericSeries LowerAfterEntry;
-
- Begin
-
- if (BarsSinceEntry == 1)
- {
- HigherAfterEntry = AvgEntryPrice;
- LowerAfterEntry = AvgEntryPrice;
- } Else If(BarsSinceEntry > 1)
- {
- HigherAfterEntry = Max(HigherAfterEntry[1],High[1]);
- LowerAfterEntry = Min(LowerAfterEntry[1],Low[1]);
- }
- Else
- {
- HigherAfterEntry = HigherAfterEntry[1];
- LowerAfterEntry = LowerAfterEntry[1];
- }
- //MinPoint = MinMove * PriceScale;
-
-
-
- If (開多倉(cāng)條件 ){
- Buy(Units,Open+minmove*PriceScale*2);
- Commentary("多頭開倉(cāng):"+Text(Open+minmove*PriceScale*2));
- trades1=1;
- }
-
-
- If( 開空倉(cāng)條件 ){
- SellShort(Units,Open-minmove*PriceScale*2);
- Commentary("空頭開倉(cāng):"+Text(Open-minmove*PriceScale*2));
- trades2=1;
- }
-
-
- If(MarketPosition ==1 && BarsSinceEntry>0)
- {
-
- If(HighestAfterEntry[1] >= AvgEntryPrice + TrailingStopstartvalue*MinPoint) // 多頭跟蹤止盈起始條件表達(dá)式
- {
-
- If( low[1]-AvgEntryPrice-TrailingStopstartvalue>0 and low[1]-AvgEntryPrice-(HigherAfterEntry [1]-AvgEntryPrice)*trailingStopvalue*0.01<0) //利潤(rùn)回撤百分之40時(shí)進(jìn)行止盈
- {
- MyPrice = low[1];
- If(Open < MyPrice) MyPrice = Open;
- Sell(1,MyPrice);
- ? Commentary("多頭跟蹤止盈:"+Text(MyPrice));
-
- }
-
- }
-
-
- If(low[1]<=AvgEntryPrice-ATRValue*atrSet) //多頭虧損初始止損
- { Sell(Units,MIN(open,AvgEntryPrice-ATRValue*atrSet)-minmove*PriceScale*2);
- //SellShort(Units,MIN(open,AvgEntryPrice-ATRValue*atrSet)-minmove*PriceScale*2);
- Commentary("多頭虧損止損:"+Text(MIN(open,AvgEntryPrice-ATRValue*atrSet)-minmove*PriceScale*2));
- }
-
- }
-
- If(MarketPosition ==-1 && BarsSinceEntry>0)
- {
- If(LowestAfterEntry[1] <= AvgEntryPrice - TrailingStopstartvalue*MinPoint)// 跟蹤止盈的條件表達(dá)式
- {
- If( AvgEntryPrice-high[1]-TrailingStopstartvalue>0 and AvgEntryPrice-high[1]-(AvgEntryPrice-LowerAfterEntry[1])*trailingStopvalue*0.01<0)
- {
- MyPrice =High[1];
- If(Open > MyPrice) MyPrice = Open;
- BuyToCover(1,MyPrice);
- Commentary("空頭跟蹤止盈:"+Text(MyPrice));
-
- }
- }
-
- if(high>=AvgEntryPrice+ATRValue*atrSet) //空頭虧損初始止損
- {
- BuyToCover(Units,max(open,AvgEntryPrice+ATRValue*atrSet)+minmove*PriceScale*2);
- // Buy(Units,max(open,AvgEntryPrice+ATRValue*atrSet)+minmove*PriceScale*2);
- Commentary("空頭虧損止損:"+Text(max(open,AvgEntryPrice+ATRValue*atrSet)+minmove*PriceScale*2));
- }
-
- }
-
- End
- ?
- Params
- TB技術(shù)人員:
同求
- TB客服:
多頭開倉(cāng),跟蹤止盈,代碼上沒有什么問(wèn)題,不是是否條件不能滿足造成的。
看你的條件是盈利要大于100,并且小于自入場(chǎng)后的最大利潤(rùn)的40%,不知道入場(chǎng)后的最大利潤(rùn)的40%,這個(gè)值是不是比100大,而且不知道是如何保證HigherAfterEntry [1]是入場(chǎng)后最高價(jià)的。
樓主再檢查檢查 - 網(wǎng)友回復(fù):
本帖最后由 tonyb2 于 2013-7-19 16:12 編輯
我把完整的代碼貼了出來(lái),有哪位高手能幫看下問(wèn)題原因嗎?
確認(rèn)是達(dá)到了止盈起始點(diǎn)的。。。
有思路,想編寫各種指標(biāo)公式,程序化交易模型,選股公式,預(yù)警公式的朋友
可聯(lián)系技術(shù)人員 QQ: 1145508240 進(jìn)行 有償 編寫!(不貴!點(diǎn)擊查看價(jià)格!)
相關(guān)文章
-
沒有相關(guān)內(nèi)容