ちょっとしたミスを発見する手助けが必要です。

 

私はEAをトレイルしていました、私はデモでテストしたとき、私は買い注文だけが正しくそれを得た(と思う)、一方、売り注文は 一度だけストップロスを移動しました。私はまだ問題がどこにあるか見つけることができません。

** コードを編集しました **

 

あなたのコード形式では読みにくいのですが、ひとつには、これをトレーリングストップに使うにはどうしたらいいのか、ということです。注文はまだ開いていなければならないので、OrderClosePrice()は存在しないのです。

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

しかし、買い注文は 問題なく動作する

 
Figureが何なのかわからないけど......OrderClosePrice==0がオープンオーダーで、OrderClosePrice - OrderOpenPriceがまだオープンオーダーだとマイナスになることをわかっていて書いたの?
 

他のスクリプトでは、OrderClosePrice - OrderOpenPrice またはその逆を使用しても問題なく動作しています。

 
さて、私は別の買い注文で試してみましたそれは今失敗しています。また、ストップロスを 1回移動させただけです。
 

OrderClosePriceは、注文がまだ開いているときに現在の 価格に従うので、OrderClosePriceは買い注文の現在のBid価格であるべきだということに気づきませんでした。これは文書化されていない機能なのでしょうね。

 


買い注文は問題ないように見えますが、売り注文はストップロスを1回しか動かしていません ....せめて2回くらいは動かさないと。

 

誰か手を貸してくれませんか、実はもうすぐなんです。私は個人的に私のコーディングで間違っているとは思わないが、私はちょうどそれがすべての時間を正しく動作しない理由を知らない。

私はすべてを1つにまとめてから長いEAです、今私の目がかなりぼやけていることを少し許してください。

図では、各特定のペアのポイントの値を返します。

これはトレーリング部分です。

//+------------------------------------------------------------------+
//| 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を使うのか?

売り 注文の場合はマイナス、買い注文の場合はプラスになるはずなのですが・・・。

理由: