請教利潤回撤百分比跟蹤止損的問題 [開拓者 TB]
- 咨詢內容:
本帖最后由 tonyb2 于 2013-7-20 20:34 編輯
請教利潤回撤百分比跟蹤止損的問題
根據(jù)TB指南中的固定點數(shù)跟蹤止損代碼修改,由原來的高點回落固定點數(shù)修改為 當利潤回撤一定百分比時進行跟蹤止盈,
例如多頭開倉后,當最大利潤達到100點后觸發(fā)跟蹤止盈,止盈條件為當前盈利< 自入場后的最大利潤的40%即止盈出場。
但為何這段代碼放到代碼中不觸發(fā)跟蹤止盈?百思不得其解....
確認行情已經(jīng)超過跟蹤止盈的 TrailingStopstartvalue起始點了。。回撤時沒有止盈信號。。。
開倉、平倉、初始止損都沒問題,就是不止盈。。。
請版主或高手幫看下代碼問題出在哪里?- Params
- Numeric TrailingStopvalue(40); //percent
- Numeric TrailingStopstartvalue(100);//100點為開啟止盈的起始點
-
- 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) // 多頭跟蹤止盈起始條件表達式
- {
-
- If( low[1]-AvgEntryPrice-TrailingStopstartvalue>0 and low[1]-AvgEntryPrice-(HigherAfterEntry [1]-AvgEntryPrice)*trailingStopvalue*0.01<0) //利潤回撤百分之40時進行止盈
- {
- 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)// 跟蹤止盈的條件表達式
- {
- 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技術人員:
同求
- TB客服:
多頭開倉,跟蹤止盈,代碼上沒有什么問題,不是是否條件不能滿足造成的。
看你的條件是盈利要大于100,并且小于自入場后的最大利潤的40%,不知道入場后的最大利潤的40%,這個值是不是比100大,而且不知道是如何保證HigherAfterEntry [1]是入場后最高價的。
樓主再檢查檢查 - 網(wǎng)友回復:
本帖最后由 tonyb2 于 2013-7-19 16:12 編輯
我把完整的代碼貼了出來,有哪位高手能幫看下問題原因嗎?
確認是達到了止盈起始點的。。。
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯(lián)系技術人員 QQ: 1145508240 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容