- 精华
- 0
- 在线时间
- 340 小时
- UID
- 64858
- 积分
- 197
- 帖子
- 80
- 阅读权限
- 40
- 注册时间
- 2011-9-11
- 最后登录
- 2021-3-28
- 精华
- 0
- UID
- 64858
- 积分
- 197
- 帖子
- 80
- 主题
- 23
- 阅读权限
- 40
- 注册时间
- 2011-9-11
- 最后登录
- 2021-3-28
|
本帖最后由 tonyb2 于 2013-7-20 20:34 编辑
请教利润回撤百分比跟踪止损的问题
根据TB指南中的固定点数跟踪止损代码修改,由原来的高点回落固定点数修改为 当利润回撤一定百分比时进行跟踪止盈,
例如多头开仓后,当最大利润达到100点后触发跟踪止盈,止盈条件为当前盈利< 自入场后的最大利润的40%即止盈出场。
但为何这段代码放到代码中不触发跟踪止盈?百思不得其解....
确认行情已经超过跟踪止盈的 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
-
复制代码 |
|