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

 

我在做一个跟踪的EA,当我在演示中测试时,我注意到只有买入订单是正确的(我想),而卖出订单 只移动了一次止损。但我仍然无法发现问题所在。

** 编辑了代码 **

 

你的代码格式让人很难看懂,但有一点,你怎么能在追踪止损中使用这个。订单必须仍然是开放的,所以不存在OrderClosePrice()。

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

买入订单 工作正常

 
在不知道Figure是什么的情况下,.....,你写的代码知道OrderClosePrice == 0,因此OrderClosePrice - OrderOpenPrice有一个负值,如果订单仍然是开放的?
 

不,我没有,我所有的其他脚本只使用OrderClosePrice - OrderOpenPrice或反之亦然,工作正常。

 
好吧,我尝试了另一个买入订单,现在失败了。它也只是移动止损 一次。
 

好的,是的,你是对的,我没有意识到OrderClosePrice在订单仍未完成时跟随当前价格,所以OrderClosePrice应该是买入订单的当前Bid价格。我想这一定是一个没有记录的功能。

 


买入订单看起来不错,但卖出订单只移动了一次止损......。它至少应该移动两次。

 

谁能帮我一把,我其实已经很接近了。我个人认为我的编码没有问题,但我就是不知道为什么它总是不能正常工作。

我已经很久没有把所有的东西合并到一起了,请原谅我现在的眼睛有点模糊了。

图中返回每个特定货币对的点值。

这是尾随部分。

//+------------------------------------------------------------------+
//| Program's global variables                                       |
//+------------------------------------------------------------------+
   extern double StartTrailingStop = 15.0 ;
   extern double TrailingStop = 5.0 ;
   extern double CummulativeValue = 5.0 ;
   extern int    NumberOfTrail = 10 ;
   double Figure ;
//+------------------------------------------------------------------+

   
//+------------------------------------------------------------------+
//| Program's sub-function                                           |
//+------------------------------------------------------------------+
   double PointsDetection()    {              Figure = 0.0 ;                                             if ( MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.01 || MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.001 )          {             Figure = 0.01 ;          }          else          {             if ( MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.0001 || MarketInfo ( OrderSymbol() , MODE_POINT ) == 0.00001 )             {                Figure = 0.0001 ;             }          }             return ( Figure ) ;    }


//+------------------------------------------------------------------+
//| Program's sub-function                                           |
//+------------------------------------------------------------------+
   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 ) && ( ( 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 ) ) && ( 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 ) ) ) && ( 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 ) && ( ( 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 ) ) && ( 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 ) ) ) && ( OrderStopLoss() == ( OrderOpenPrice() - ( ( TrailingStop + ( CummulativeValue * ( xaii - 1 ) ) ) * Figure ) ) ) )
                              {
                                 Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() - ( ( TrailingStop + ( CummulativeValue * xaii ) ) * Figure ) ) , OrderTakeProfit() , 0 , Color ) ;
                              }
                           }
                        }
                     }
                  }

            }
         }
 

也许有:

 ( OrderStopLoss() == ( OrderOpenPrice() - ( TrailingStop * Figure ) )

https://forum.mql4.com/45053

也许它应该这样编码,以避免服务器错误。

 figure = PointsDetection();

if ( ( ( ( OrderOpenPrice() - OrderClosePrice() ) / Figure ) >= StartTrailingStop ) && ( ( OrderStopLoss() == 0 ) || ( OrderStopLoss() >= OrderOpenPrice() ) || ( OrderStopLoss() > ( OrderOpenPrice() - ( TrailingStop * Figure ) ) ) ) )
                              {
                                 Result = OrderModify ( OrderTicket() , OrderOpenPrice() , ( OrderOpenPrice() - ( TrailingStop * Figure ) ) , OrderTakeProfit() , 0 , Color ) ;
                                 if( result == true ) break;                               
 }


对于买入订单

( OrderStopLoss() < ( OrderOpenPrice() + ( TrailingStop * Figure ) )
 

我试过了,但还是没有成功,....为什么在if语句中使用break?

对于卖出指令...应该是减号,对于买入指令应该是加号 ....