請(qǐng)教利潤回撤百分比跟蹤止損的問題
作者:開拓者 TB 來源:cxh99.com 發(fā)布時(shí)間:2013年08月09日
- 咨詢內(nèi)容:
本帖最后由 tonyb2 于 2013-7-20 20:34 編輯
請(qǐng)教利潤回撤百分比跟蹤止損的問題
根據(jù)TB指南中的固定點(diǎn)數(shù)跟蹤止損代碼修改,由原來的高點(diǎn)回落固定點(diǎn)數(shù)修改為 當(dāng)利潤回撤一定百分比時(shí)進(jìn)行跟蹤止盈,
例如多頭開倉后,當(dāng)最大利潤達(dá)到100點(diǎn)后觸發(fā)跟蹤止盈,止盈條件為當(dāng)前盈利< 自入場后的最大利潤的40%即止盈出場。
但為何這段代碼放到代碼中不觸發(fā)跟蹤止盈?百思不得其解....
確認(rèn)行情已經(jīng)超過跟蹤止盈的 TrailingStopstartvalue起始點(diǎn)了。?;爻窌r(shí)沒有止盈信號(hào)。。。
開倉、平倉、初始止損都沒問題,就是不止盈。。。
請(qǐng)版主或高手幫看下代碼問題出在哪里?- 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 (開多倉條件 ){
- Buy(Units,Open+minmove*PriceScale*2);
- Commentary("多頭開倉:"+Text(Open+minmove*PriceScale*2));
- trades1=1;
- }
-
-
- If( 開空倉條件 ){
- SellShort(Units,Open-minmove*PriceScale*2);
- Commentary("空頭開倉:"+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) //利潤回撤百分之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
- ?
- TB技術(shù)人員:
同求
- TB客服:
多頭開倉,跟蹤止盈,代碼上沒有什么問題,不是是否條件不能滿足造成的。
看你的條件是盈利要大于100,并且小于自入場后的最大利潤的40%,不知道入場后的最大利潤的40%,這個(gè)值是不是比100大,而且不知道是如何保證HigherAfterEntry [1]是入場后最高價(jià)的。
樓主再檢查檢查
- 網(wǎng)友回復(fù):
本帖最后由 tonyb2 于 2013-7-19 16:12 編輯
我把完整的代碼貼了出來,有哪位高手能幫看下問題原因嗎?
確認(rèn)是達(dá)到了止盈起始點(diǎn)的。。。