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

 
もしそうなら、私の最初のコードも正しいことになります。問題はトレーリング・ストップ・ロスが正しく動作していないことで、どこに問題があるのかまだ分かっていません。
 
juniorlcq: はカウントダウンループを使いますが、x--を使います。しかし、なぜ --x を提案するのか理解できない.
  1. x++は、値を読み取り、コピーを保存 し、値をインクリメントして、新しい値をxに保存し、その後使用するためにコピーを取得 する。
  2. ++x 値を読み,値をインクリメントし,新しい値をxに格納する。
  3. 整数の場合、ほとんど違いはない。プラットフォームによっては後者が1命令で済むので、数倍速くなります。
  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--" ではなくて "iterator last=end; --end;" をよく見かけます。

 

OrderOpenprice()から価格が600ポイント上がったとすると、= StartTraillinStop (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は:スタートトライリンストップ (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は説明の通りジオで下がっています.

   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. 整数の場合、ほとんど違いはない。プラットフォームによっては後者が1命令で済むので、数倍速くなる。
  4. イテレータのような)クラスでは、コンストラクタとデストラクタの呼び出しが追加され、何倍も速くなります。
    プリフィックス演算子++。
    後置演算子
    STLの実装では、"iterator last=end--" ではなく、"iterator last=end; --end;" をよく見かけます。


おお〜〜〜〜、これは知らなかった.ありがとうWHRoeder :).

ということは、,

例えばOrdersTotal() == 3とすると、カウントダウンのforループで for ( int x = ( OrdersTotal() - 1 ) ; x >= 0 ; x-- ) とします。xは2として最初の値を保存し、それは再びOrdersTotal()を通過せずに、2以降のforループを継続するのですか?

 
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で同じようなことができます。

他の==の条件でも同じようなことができるかもしれません。


これは、"double == calculated double problem" です。SDCのご指摘ありがとうございました。

以前にも同じ問題を指摘していただきありがとうございました。しかし、私は正しい方法で編集していなかったので、問題ではないと思っていました。

私はいくつかの提案を必要とする質問があります、2番目のforループの2番目と3番目のifについて、それはその中に "間 "文を置く方が良いですか?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));
 }}}}}}}}}