设为首页收藏本站

 找回密码
 注册
查看: 5173|回复: 4
打印 上一主题 下一主题

请教利润回撤百分比跟踪止损的问题 [复制链接]

Rank: 3Rank: 3

精华
0
UID
64858
积分
197
帖子
80
主题
23
阅读权限
40
注册时间
2011-9-11
最后登录
2021-3-28
跳转到指定楼层
1#
发表于 2013-7-14 09:11:01 |只看该作者 |倒序浏览
本帖最后由 tonyb2 于 2013-7-20 20:34 编辑

请教利润回撤百分比跟踪止损的问题


根据TB指南中的固定点数跟踪止损代码修改,由原来的高点回落固定点数修改为 当利润回撤一定百分比时进行跟踪止盈,

例如多头开仓后,当最大利润达到100点后触发跟踪止盈,止盈条件为当前盈利< 自入场后的最大利润的40%即止盈出场。

但为何这段代码放到代码中不触发跟踪止盈?百思不得其解....

确认行情已经超过跟踪止盈的 TrailingStopstartvalue起始点了。。回撤时没有止盈信号。。。
开仓、平仓、初始止损都没问题,就是不止盈。。。


请版主或高手帮看下代码问题出在哪里?
  1.   Params
  2. Numeric TrailingStopvalue(40); //percent
  3. Numeric TrailingStopstartvalue(100);//100点为开启止盈的起始点
  4.   
  5. Vars
  6. Numeric MyPrice;
  7. Numeric MinPoint;
  8. NumericSeries  MyExitPrice;
  9. NumericSeries HigherAfterEntry;
  10. NumericSeries LowerAfterEntry;

  11. Begin

  12.      if (BarsSinceEntry == 1)
  13.         {
  14.                 HigherAfterEntry = AvgEntryPrice;
  15.                 LowerAfterEntry = AvgEntryPrice;
  16.         } Else If(BarsSinceEntry > 1)
  17.         {
  18.                 HigherAfterEntry = Max(HigherAfterEntry[1],High[1]);
  19.                 LowerAfterEntry = Min(LowerAfterEntry[1],Low[1]);
  20.         }
  21.         Else
  22.         {
  23.                 HigherAfterEntry = HigherAfterEntry[1];
  24.                 LowerAfterEntry = LowerAfterEntry[1];
  25.         }
  26.         //MinPoint = MinMove * PriceScale;



  27.        If (开多仓条件 ){
  28.              Buy(Units,Open+minmove*PriceScale*2);
  29.    Commentary("多头开仓:"+Text(Open+minmove*PriceScale*2));
  30.                trades1=1;
  31.        }
  32.    

  33.    If( 开空仓条件 ){
  34.                SellShort(Units,Open-minmove*PriceScale*2);
  35.       Commentary("空头开仓:"+Text(Open-minmove*PriceScale*2));
  36.                trades2=1;
  37.        }


  38. If(MarketPosition ==1 && BarsSinceEntry>0)
  39. {

  40.    If(HighestAfterEntry[1] >= AvgEntryPrice + TrailingStopstartvalue*MinPoint) // 多头跟踪止盈起始条件表达式
  41. {

  42.   If( low[1]-AvgEntryPrice-TrailingStopstartvalue>0 and low[1]-AvgEntryPrice-(HigherAfterEntry [1]-AvgEntryPrice)*trailingStopvalue*0.01<0) //利润回撤百分之40时进行止盈
  43.          {
  44.                        MyPrice = low[1];
  45.                        If(Open < MyPrice) MyPrice = Open;
  46.                        Sell(1,MyPrice);
  47. ​      Commentary("多头跟踪止盈:"+Text(MyPrice));
  48.   
  49.         }
  50.    
  51. }   
  52.    

  53.    If(low[1]<=AvgEntryPrice-ATRValue*atrSet)   //多头亏损初始止损
  54.            {  Sell(Units,MIN(open,AvgEntryPrice-ATRValue*atrSet)-minmove*PriceScale*2);
  55.    //SellShort(Units,MIN(open,AvgEntryPrice-ATRValue*atrSet)-minmove*PriceScale*2);
  56.                Commentary("多头亏损止损:"+Text(MIN(open,AvgEntryPrice-ATRValue*atrSet)-minmove*PriceScale*2));
  57.           }

  58. }

  59. If(MarketPosition ==-1 && BarsSinceEntry>0)
  60. {
  61.   If(LowestAfterEntry[1] <= AvgEntryPrice - TrailingStopstartvalue*MinPoint)// 跟踪止盈的条件表达式
  62.    {
  63.      If( AvgEntryPrice-high[1]-TrailingStopstartvalue>0 and AvgEntryPrice-high[1]-(AvgEntryPrice-LowerAfterEntry[1])*trailingStopvalue*0.01<0)
  64.                 {
  65.                         MyPrice =High[1];
  66.                         If(Open > MyPrice) MyPrice = Open;
  67.                       BuyToCover(1,MyPrice);
  68.       Commentary("空头跟踪止盈:"+Text(MyPrice));
  69.   
  70.                  }
  71. }   
  72.    
  73.        if(high>=AvgEntryPrice+ATRValue*atrSet) //空头亏损初始止损

  74.     {
  75.   BuyToCover(Units,max(open,AvgEntryPrice+ATRValue*atrSet)+minmove*PriceScale*2);
  76.   //  Buy(Units,max(open,AvgEntryPrice+ATRValue*atrSet)+minmove*PriceScale*2);
  77.     Commentary("空头亏损止损:"+Text(max(open,AvgEntryPrice+ATRValue*atrSet)+minmove*PriceScale*2));
  78.   }

  79. }

  80. End
复制代码
通向财务自由之路

Rank: 3Rank: 3

精华
0
UID
116148
积分
178
帖子
122
主题
26
阅读权限
40
注册时间
2013-3-2
最后登录
2014-7-31
2#
发表于 2013-7-14 20:49:15 |只看该作者
同求

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
116229
积分
2373
帖子
2247
主题
18
阅读权限
70
注册时间
2013-3-4
最后登录
2019-3-24
3#
发表于 2013-7-15 11:11:35 |只看该作者
多头开仓,跟踪止盈,代码上没有什么问题,不是是否条件不能满足造成的。
看你的条件是盈利要大于100,并且小于自入场后的最大利润的40%,不知道入场后的最大利润的40%,这个值是不是比100大,而且不知道是如何保证HigherAfterEntry [1]是入场后最高价的。
楼主再检查检查

使用道具 举报

Rank: 3Rank: 3

精华
0
UID
64858
积分
197
帖子
80
主题
23
阅读权限
40
注册时间
2011-9-11
最后登录
2021-3-28
4#
发表于 2013-7-19 16:10:30 |只看该作者
本帖最后由 tonyb2 于 2013-7-19 16:12 编辑

我把完整的代码贴了出来,有哪位高手能帮看下问题原因吗?
确认是达到了止盈起始点的。。。

使用道具 举报

Rank: 1

精华
0
UID
269619
积分
24
帖子
23
主题
0
阅读权限
10
注册时间
2018-9-5
最后登录
2018-11-1
5#
发表于 2018-10-16 22:58:19 |只看该作者
mark

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-11 17:51

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部