需要帮助来发现一些轻微的错误。 - 页 4

 
如果是这样的话,那么我的第一段代码也是对的,我在第一段for循环后立即调用OrderSelect().....。现在的问题是,跟踪止损不能正常工作,我仍然不知道问题出在哪里。
 
juniorlcq: 使用倒数循环,但用x-- 。我不明白你为什么建议--x。
  1. x++ 读取数值,保存副本,增加数值,将新的数值存储在x中,并检索副本 供以后使用。
  2. ++x 读取数值,增加数值,将新的数值储存在x中。
  3. 对于整数来说,这没有什么区别。在一些平台上,后者是一条指令,使其速度快了几倍。
  4. 对于类(如迭代器),你有一个额外的构造器和析构器调用,使其速度快了许多倍。
    前缀运算符++
    后缀运算符++
    RaRev* RaRev::operator++(void){         // prefix
       ++mPos;
       return GetPointer(this); // Allow (++It).Get()
    }
    
    RaRev RaRev::operator++(int){               // postfix
       RaRev  orig(this); // Make a copy to return.
       ++this;            // Increment myself.
       return orig;       // Return the original position.
    }
    
    在大多数STL实现中,你会经常看到 "iterator last=end; --end; "而不是 "iterator last=end--"

 

假设价格从OrderOpenprice()上升了600点,=StartTraillingStop (200) + 8(xai)*50

代码在这里。

  if ( xai >= 8 ) 
    {
    if ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= ( StartTrailingStop + ( CummulativeValue * xai ) ) )
        {
        if ( OrderStopLoss() == ( OrderOpenPrice() + ( ( TrailingStop + ( CummulativeValue * ( xai - 1 ) ) ) * Figure ) ) )
           {
            Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() + ( ( TrailingStop + ( CummulativeValue * xai ) ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ;
       }
    }

但代码将做所有从0到8的xai,例如代码是在xai = 4;这个条件是真的吗?

if ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= ( StartTrailingStop + ( CummulativeValue * xai ) ) )

是的,那么SL将被设置为:StartTraillinStop (200) + 4(xai)*50 (从以前开始下降)

然后xai 5,SL将被设置在:StartTraillinStop (200) + 5(xai)*50

以此类推,所以一旦设定了SL,就不可能放一个断点。

 

juniorlcq 你的代码现在更容易阅读了,你已经重新格式化了它。 我把它重新格式化了一下,使其更小,以便张贴,我已经强调了可能的问题。我认为你可能有 "double == calculated double "的问题,这使得你的代码无法执行一些轨迹。你有没有读过关于can price != price 的主题

我最怀疑的是第2和第4条,因为它们是比较复杂的计算。

把Print()语句放在这些计算之后,看看它们是否真的做了==。

被称为浮点误差的错误可能使它们成为!!!即使看起来它们应该是==。

==只有在整数情况下才是100%安全的,所以你可以把==改为<=或>=作为测试。

  void ProcessTrailingStop()
 {
  bool Result;
  for(int x=(OrdersTotal()-1); x>=0; x--)
  {if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)==True)
   {PointsDetection();
    if(OrderType()==OP_BUY)
    {for(int xai=0; xai<NumberOfTrail; xai++)
     {if(xai==0)
      {if(((OrderClosePrice()-OrderOpenPrice())/Figure)>=StartTrailingStop)
       {if(( OrderStopLoss()==0) || (OrderStopLoss()<(OrderOpenPrice()+(TrailingStop*Figure))))
        {Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+(TrailingStop*Figure)),OrderTakeProfit(),0,Color);
      }}}
      if(xai==1)
      {if(((OrderClosePrice()-OrderOpenPrice())/Figure)>=(StartTrailingStop+CummulativeValue))
       {if(OrderStopLoss()==(OrderOpenPrice()+(TrailingStop*Figure)))
        {Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+((TrailingStop+CummulativeValue)*Figure)),OrderTakeProfit(),0,Color);
      }}}
      if(xai>=2)
      {if(((OrderClosePrice()-OrderOpenPrice())/Figure)>=(StartTrailingStop+(CummulativeValue*xai)))
       {if(OrderStopLoss()==(OrderOpenPrice()+(( TrailingStop+(CummulativeValue *(xai-1)))*Figure)))
        {Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+(( TrailingStop+(CummulativeValue*xai))*Figure)),OrderTakeProfit(),0,Color);
    }}}}}else
    {if(OrderType()==OP_SELL)
     {for(int xaii=0; xaii<NumberOfTrail; xaii++)
      {if(xaii==0)
       {if(((OrderOpenPrice()-OrderClosePrice())/Figure)>=StartTrailingStop)
        {if(( OrderStopLoss()==0) || (OrderStopLoss()>(OrderOpenPrice() -(TrailingStop*Figure))))
         {Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice() -(TrailingStop*Figure)),OrderTakeProfit(),0,Color);
       }}}
       if(xaii==1)
       {if(((OrderOpenPrice()-OrderClosePrice())/Figure)>=(StartTrailingStop+CummulativeValue))
        {if(OrderStopLoss()==(OrderOpenPrice() -(TrailingStop*Figure)))
         {Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice() -(( TrailingStop+CummulativeValue)*Figure)),OrderTakeProfit(),0,Color);
       }}}
       if(xaii>=2)
       {if(((OrderOpenPrice()-OrderClosePrice())/Figure)>=(StartTrailingStop+(CummulativeValue*xaii)))
        {if(OrderStopLoss()==(OrderOpenPrice() -(( TrailingStop+(CummulativeValue *(xaii-1)))*Figure)))
         {Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice() -(( TrailingStop+(CummulativeValue*xaii))*Figure)),OrderTakeProfit(),0,Color);
 }}}}}}}}}


另外,如果你在OrderSelect()循环开始时调用OrderOpenPrice(), OrderStopLoss(), OrderClosePrice()一次,并将它们的值分配给本地变量,在其余的代码中使用,你的代码会更有效率。本地变量的访问速度比函数调用快得多,所以你应该避免为同一个结果重复调用函数......作为一条经验法则,你的代码中粉红色的书写越多,EA的性能就越慢。

 

我明白,我不能使它工作,这个可能与订单买入的工作,SL是gioing down,如解释。

   extern double CummulativeValue = 50.0 ;
   extern int    NumberOfTrail = 100 ;



  void ProcessTrailingStop()
   {
       double Figure = Point;
    color Color = Yellow;
  
    bool Result ;
         for ( int x =  OrdersTotal(); x >= 0 ; x-- )
         {
         if ( OrderSelect ( x , SELECT_BY_POS , MODE_TRADES ) == false) continue;
        if ( OrderType() == OP_BUY )
           {
                 for ( int xai = 0 ; xai < NumberOfTrail ; xai++ )
                     {
                        if ( xai == 0 )
                        {
                           if ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= StartTrailingStop )
                           {
                              if ( OrderStopLoss() == 0 ) 
                              {
                               Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() + ( TrailingStop * Figure ) ) , OrderTakeProfit() , 0 , Color ) ;
                          } } }                        
                  
                        if ( xai == 1 )
                           {
                           if ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= ( StartTrailingStop + CummulativeValue ) )
                           {
                           Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() + ( ( TrailingStop + CummulativeValue ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ;
                          } }                         
                        
                        if ( xai >= 2 )
                           {
                          if ( ( ( OrderClosePrice() - OrderOpenPrice() ) / Figure ) >= ( StartTrailingStop + ( CummulativeValue * xai ) ) )
                           {
                           Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() + ( ( TrailingStop + ( CummulativeValue * xai ) ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ;
                        } }                         
                     }
                  }
                  
       }}           
 
WHRoeder:
  1. x++ 读取数值,保存副本,增加数值,将新的数值存储在x中,并检索副本 供以后使用。
  2. ++x 读取数值,增加数值,将新的数值储存在x中。
  3. 对于整数来说,这没有什么区别。在一些平台上,后者是一条指令,使其速度快了几倍。
  4. 对于类(如迭代器),你有一个额外的构造器和析构器调用,这使得它的速度快了很多倍。
    前缀运算符++
    后缀运算符++
    在大多数STL实现中,你会经常看到 "iterator last=end; --end; "而不是 "iterator last=end--"


哦,哦,我不知道这一点。谢谢 WHRoeder :).

那么这是否意味着,

假设OrdersTotal()==3,用倒数计时的for循环for ( int x = ( OrdersTotal() - 1 ) ; x >= 0 ; x-- ) 。x将保存第一个值为2,然后继续从2开始的for循环,而不需要再次经过OrdersTotal()。

 
SDC:

juniorlcq 你的代码现在更容易阅读了,你已经重新格式化了它。 我把它重新格式化了一下,使其更小,以便张贴,我已经强调了可能的问题。我认为你可能有 "double == calculated double "的问题,这使得你的代码无法执行一些轨迹。你有没有读过关于can price != price 的主题

我最怀疑的是第2和第4条,因为它们的计算比较复杂。

在这些计算之后放上Print()语句,看看它们是否真的能==。

被称为浮点误差的错误可能使它们成为!!!即使看起来它们应该是==。

==只有在整数情况下才是100%安全的,所以你可以把==改成<=或>=作为一个测试。



不,我以前没有读过那条线。只不过是做了.

你的建议听起来很合乎逻辑。再想一想,有时在MT4的价格属性上画线,它并不真正显示5位数的价格,相反,有时显示比这更多的东西。

但是,这是我在以前的账户上的一个浮动交易,我把它打印出来,看看用简单的打印编码的双倍是什么样子。奇怪的MQL4我想@.@ ?

我还在想我应该如何修改双倍==双倍的部分.....。

SDC:


另外,如果你在OrderSelect()循环开始时调用OrderOpenPrice(), OrderStopLoss(), OrderClosePrice()一次,并将它们的值分配给本地变量,在剩下的代码中使用,你的代码会更有效率。本地变量的访问速度比函数调用快得多,所以你应该避免为同一个结果重复调用函数......作为一个经验法则,你的代码中粉红色的书写越多,EA的性能就越慢。

哦,我不知道在执行速度上会有很大的差别,谢谢你的指导,SDC。我将根据你的指导进行修改,在跟踪停止后开始工作。

 

尝试用这个调试版本替换最后一个代码块。检查 我的代码,我没有编译它。

       if(xaii>=2)
       {if(((OrderOpenPrice()-OrderClosePrice())/Figure)>=(StartTrailingStop+(CummulativeValue*xaii)))
        {Print("debug2.1: first condition true");
         if(OrderStopLoss()==(OrderOpenPrice() -(( TrailingStop+(CummulativeValue *(xaii-1)))*Figure)))
         {Print("debug2.2: second condition true");
          Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice() -(( TrailingStop+(CummulativeValue*xaii))*Figure)),OrderTakeProfit(),0,Color);
         }else
         {Print("debug2.2: second condition false");
          Print("debug2.2: val1=",OrderStopLoss()," val2=",OrderOpenPrice() -(( TrailingStop+(CummulativeValue *(xaii-1)))*Figure));
 }}}}}}}}}

这可能会发现一些问题,你也可以对其他的==条件做类似的事情。

 
SDC:

尝试用这个调试版本替换最后一个代码块。你可以对xa做类似的事情

这可能会发现一些问题,你也可以对其他的==条件做一些类似的处理。


是的,问题出现了,它是 "双倍==计算双倍的问题"。谢谢你指出这个问题,SDC。

谢谢 ffoorr 之前也指出了同样的问题,但我没有以正确的方式编辑,以为这不是问题所在。

我有一个问题需要一些建议,对于第二个for循环中的第2和第3个if,是否最好在其中加入一个 "inter "语句?比如OrderStopLoss() >= x + 1 && x - 1?或者我应该直接使用>=或<=?

 

我希望WHR不要看到这篇文章,他将会大发雷霆,但我要告诉你尝试NormalizeDouble() ....,它应该使这些条件在应该相等的时候相等。应该没有必要对OrderStopLoss()一方也这样做,但如果它在应该相等的时候仍然不相等,你可以尝试对条件的两边都这样做....。

       if(xaii>=2)
       {if(((OrderOpenPrice()-OrderClosePrice())/Figure)>=(StartTrailingStop+(CummulativeValue*xaii)))
        {Print("debug2.0: condition true");
         if(OrderStopLoss()==NormalizeDouble((OrderOpenPrice() -(( TrailingStop+(CummulativeValue *(xaii-1)))*Figure)),Digits));
         {Print("debug2.1: condition true");
          Result=OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice() -(( TrailingStop+(CummulativeValue*xaii))*Figure)),OrderTakeProfit(),0,Color);
         }else
         {Print("debug2.1: condition false");
          Print("debug2.1: val1=",OrderStopLoss()," val2=",OrderOpenPrice() -(( TrailingStop+(CummulativeValue *(xaii-1)))*Figure));
 }}}}}}}}}