设为首页收藏本站

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

这个公式编译通过也触发不了跟踪止损,有没有大神指点一下问题在哪里 [复制链接]

Rank: 1

精华
0
UID
273669
积分
16
帖子
8
主题
1
阅读权限
10
注册时间
2018-12-15
最后登录
2024-1-3
跳转到指定楼层
1#
发表于 2018-12-22 17:13:00 |只看该作者 |倒序浏览
            Params
        //此处添加参
      Numeric StartPer1(5);  //1级跟踪止盈,盈利10%启动
      Numeric StopPer1(20); //1级跟踪止盈,盈利回撤100%触发
      Numeric StartPer2(10); //2级跟踪止盈,盈利20%启动
      Numeric StopPer2(30);  //2级跟踪止盈,盈利回撤50%触发        
      Numeric StartPer3(30); //3级跟踪止盈,盈利30%启动
      Numeric StopPer3(30);  //3级跟踪止盈,盈利回撤30%触发
      Numeric StartPer4(50); //3级跟踪止盈,盈利50%启动
      Numeric StopPer4(15);  //3级跟踪止盈,盈利回撤15%触发        
      Numeric StopLoss(1); // 止损2%
     
Vars
        //此处添加变量
     NumericSeries HighestAfterEntry;        // 开仓后出现的最高价
     NumericSeries LowestAfterEntry;         // 开仓后出现的最低价
    //记录开仓后高低点
     if (BarsSinceEntry == 1)
        {
                HighestAfterEntry = High;
                LowestAfterEntry = Low;
        } Else If(BarsSinceEntry > 1)
        {
                HighestAfterEntry = Max(HighestAfterEntry[1],High[1]);
                LowestAfterEntry = Min(LowestAfterEntry[1],Low[1]);
        }
        Else
        {
                HighestAfterEntry = HighestAfterEntry[1];
                LowestAfterEntry = LowestAfterEntry[1];
        }
            Commentary("HighestAfterEntry="+Text(HighestAfterEntry));
            Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
   
      //1级跟踪止盈,盈利10%启动,盈利回撤100%触发
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer1) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer1)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer1));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer1) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer1)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer1));
        }

        //2级跟踪止盈,盈利20%启动,盈利回撤50%触发        
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer2) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer2)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer2));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer2) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer2)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer2));
        }
        
        //3级跟踪止盈,盈利30%启动,盈利回撤30%触发
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer3) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer3)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer3));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer3) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer3)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer3));
        }        
        
        //4级跟踪止盈,盈利50%启动,盈利回撤15%触发
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer4) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer4)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer4));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer4) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer4)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer4));
        }        
        
        // 启动止损
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && High>=LastEntryPrice*(1+StopLoss*0.01))
        {
                BuyToCover(0,Max(LastEntryPrice*(1+StopLoss*0.01),Open));
                Commentary(Text(StopLoss)+"%止损");
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && Low<=LastEntryPrice*(1-StopLoss*0.01))
        {
                Sell(0,Min(LastEntryPrice*(1-StopLoss*0.01),Open));
                Commentary(Text(StopLoss)+"%止损");
        }
        End

Rank: 10Rank: 10Rank: 10

精华
3
UID
5
积分
26584
帖子
12686
主题
49
阅读权限
200
注册时间
2007-7-20
最后登录
2021-11-3
2#
发表于 2018-12-26 15:21:54 |只看该作者
可以使用commentary等注释语句,对信号条件的值进行注释输出,以人工对比判断到底是什么条件没有满足,从而没有按原想法出信号。

使用道具 举报

Rank: 1

精华
0
UID
273839
积分
3
帖子
3
主题
0
阅读权限
10
注册时间
2018-12-20
最后登录
2020-6-5
3#
发表于 2018-12-27 21:06:11 |只看该作者
(1)没有进场的指令。BarsinceEntry根本无法执行,因为没有Entry
(2)另外,这个止盈的分级没有任何意义。只要最低的条件符合,后面这些都没有用。

使用道具 举报

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

bottom

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

GMT+8, 2024-4-25 14:41

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部