English Русский 中文 Español Deutsch Português
オープンされたポジションの二段階の修正

オープンされたポジションの二段階の修正

MetaTrader 4 | 21 4月 2016, 13:38
1 257 0
Genkov
Genkov

はじめに

"T.DeMark's Approach to Technical Analysis" という記事にて、おすすめの訂正の長さの係数、0.382、0.618などが記載されています。これらの係数をポジションのオープン時に使用することで、トレンドに近い状況での不必要なクロージング、オープンを防ぐことができます。その関数は、逸脱の発生する状況で特に動作します。

このアプローチは、利益値がリセットされている場合、"好ましい"トレンドの発見の役に立ちます。例えば、図1で示され、図2で比較されています。




関数アルゴリズム

その注文の最初の修正は、特定のTraillingStop値にて実行され、その次は、1、2ポイントの差で可能性のある訂正レベルよりも小さいStopLossを設定します。各ステップにてTakeProfit値をTrailinStop値の半分ほどを増大させてください(その他の値も選ぶことができます!)TakeProfit値もまた変更できます。このために、doubel March = 0 オペレーターがそのプログラムの最初に設定される必要があります。

MarginNumber変数をポジションがオープンされているエキスパートアドバイザーのコードに送るために、トレーレィング中に直接実行されるプログラムの特定のアクションの分析サポートを好むトレーダーには良いかもしれませんMQL4.com ウェブサイトにて掲載されている S. Kovalyovの著書 にて特定のアドレスサポートに関する詳細な情報を読むことができます。


EAにて予想される関数の提示されているコードとそれについての詳細なコメントを調べてみましょう:

//+------------------------------------------------------------------+
//|      Two-stage variant of TrailingStop       Modify_2step v5.mq4 |
//|   Orders modification: re-placing StopLoss and TakeProfit        |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, GenKov"
#property link      Genkov@bk.ru
//+------------------------------------------------------------------+

/* Magic=N

Magic=N - このオペレーターは、条件との迎合後のポジションオープンによるプログラムのオペレーターのコントロール時に挿入される必要があります!マーケットの予想不可能性の観点からユニバーサル修飾子を作成できませんでした。そのため、( S/L とT/Pの動きの)追跡やポジションクロージング条件の関数は、(Magic=Nによる)ポジションのオープン条件全ての種類に対して記述される必要があります。

extern double    March         =  1;  // step of increasing TakeProfit 
                                      // step 0 doesn't increase T/P.

S/Lは、S/Lをまさに最初のトリガーにて安全なレベルに持ち込むため、1ポイントTrailingStopよりも小さくなければなりません。そのような中で、起こりうる損失に対して保険をかけます(資産管理)

extern double    StopLoss      = 15;  
extern double    TrailingStop  = 16;  
extern double    TakeProfit    = 60;  // fitting with the tester
//+------------------------------------------------------------------+
//void TrailingStop()
  int start()                                   
   {
   //----------------------------------------------------------------+
   int point  = MarketInfo(Symbol(),MODE_POINT);      // Point size 
   int StopLev= MarketInfo(Symbol(),MODE_STOPLEVEL);  
   double half_Trail = MathRound(TrailingStop/2);//half TrailingStop
   double Step = March*half_Trail;  //value of TakeProfit increase
  if (TrailingStop<0) return;
   { 
   for (int i=0; i<OrdersTotal(); i++)
    {
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
    if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
    if (OrderType()==OP_BUY)
     {

BUYポジションの修正の最初の段階

if(OrderStopLoss()<OrderOpenPrice())//if S/L is less than the order open price
      {   // and if the difference between the current price and the position opening price is greater than T/S
      if(Bid-OrderOpenPrice()>TrailingStop*Point) // && 
       {     // and if OrderStopLoss() is less than the difference between the current price and T/S
       if(OrderStopLoss()<Bid-TrailingStop*Point)
        {    // calculate new T/P value
        double Now_T_P=(OrderTakeProfit()+Step*Point);
       { 
       OrderModify(OrderTicket(),OrderOpenPrice(),
       OrderStopLoss()+TrailingStop*Point,
       OrderTakeProfit()+Step*Point,0,Aqua); // increasing T/P value
      return;
      }
     }
    }
   }

しかし、以下の状況が発生しえます:TakeProfitの変更は、以前予定していた利益レベルよりも2-3ポイント高くなり、ゆっくりと減少していきます。



利益の損失を避けるために、予定された利益レベルの注文をクローズする状況の操作のオペレーターを入力しましょう。もしその価格が増大し続けるなら、StopLossとTakeProfitの変更は続きます。

if(Bid-OrderOpenPrice()>=TakeProfit*Point && (Pr_Op_1-Pr_Op_0)>2*Point) 
   {
    // Print(" Bid= ",Bid," >= ",OrderTakeProfit()," Magic= ",Magic);
    OrderClose(OrderTicket(),Lots,Bid,2,Red);
    }

// Second stage of BUY position modification

  if(OrderStopLoss()>=OrderOpenPrice()) // StopLoss is on a lossless level
   {    // calculate correction coefficient
    double Coeff_up = NormalizeDouble((Bid-OrderOpenPrice())*0.382,Digits);
    // and if the differnece between the current and the open price of the position is greater than corr. coefficient 
    if(Bid-OrderOpenPrice()>Coeff_up) 
     {    // calculate the value of new StopLoss with the margin of 2 points
      double New_S_Loss = Bid-Coeff_up-2*Point;
      // and if the value of new StopLoss is higer than the current one
      if(New_S_Loss-OrderStopLoss()>3*Point)
       {     // move S/L and T/P
        OrderModify(OrderTicket(),OrderOpenPrice(),
        New_S_Loss,OrderTakeProfit()+Step*Point,0,Yellow);
        }
//        Print(" Bid-OrderOpenPrice()= ",Bid-OrderOpenPrice());
//        Print("  2   Coeff_up= ",Coeff_up," Order_S_Los= ",New_S_Loss," Bid= ",Bid);
       return;
       }
      }
     }

ショートポジションに対するアプローチは、上記で記載されているもの同じで、コメントが少し少なくなっています。

// ---------------------------- 1 stage of modification -----SELL-------------&
   else  if(OrderType()==OP_SELL) 
    {
   if(OrderStopLoss()>OrderOpenPrice())//if S/L is greater than order open price
     {
     if(OrderOpenPrice()-Ask>TrailingStop*Point && 
        OrderStopLoss()>Ask+TrailingStop*Point)
     { 
      OrderModify(OrderTicket(),OrderOpenPrice(),
      Ask+TrailingStop*Point,OrderTakeProfit()-Step*Point,0,SkyBlue);
      return;
      }
     }
if(OrderOpenPrice()-Ask>=TakeProfit*Point && (Pr_Op_0-Pr_Op_1)>2*Point) 
   {
    OrderClose(OrderTicket(),Lots,Bid,2,Red);
    }     
// ---------------------------- 2 stage of modification -----SELL-------------&
   if(OrderStopLoss()<=OrderOpenPrice()) // StopLoss is on a lossless level
    { // calculate correction coefficient
     double Coeff_down = NormalizeDouble((OrderOpenPrice()-Ask)*0.382,Digits);
     // and if the difference between the price of position opening and the current price is greater than corr. coefficient 
    if(OrderOpenPrice()-Ask>Coeff_down) 
     {    // calculate the value of new StopLoss with the margin of 2 points
      New_S_Loss = Ask+Coeff_down+2*Point; 
      // and if the value of new StopLoss is less than the current value
      if(New_S_Loss-OrderStopLoss()>3*Point)
       {     // move S/L and T/P   
       OrderModify(OrderTicket(),OrderOpenPrice(),
       New_S_Loss,OrderTakeProfit()-Step*Point,0,Khaki);
      return;
      }
     }
    }
   }
  } 
 //  -----------------------------------------------------------------------------------

このEAを関数に変換するために、そのプログラムの始めに位置しているint start()関数をコメントアウトし、プログラムの初期にあるTrailingStop()関数の記述と置き換えます。その関数の呼び出しのコメント扱いをやめます:

//TrailingStop();

プログラムの最後にあります。

以下に示されているブロックを追加すれば、テスターにてEAとしてそれを用いる関数の効果をチェックできます。

// --------------------------------------------------------------------------------
  
   double Macd_m15_0= iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   double Macd_m15_1= iMACD(NULL,PERIOD_M15,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   
   if(OrdersTotal()<2)
    {
    if(Macd_m15_0<Macd_m15_1)
     {
     OrderSend(Symbol(),OP_SELL,0.1,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"",Magic,0,Red);
     }
    if(Macd_m15_0>Macd_m15_1)
     {
     OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"",Magic,0,Blue);
     }
    return(0);
   }
// --------------------------------------------------------------------------------
//  TrailingStop();
  }
   return(0);
  }
// --- end --- &

上記のコードの詳細なコメントを除去し、実行する関数として作成します:そして、 terminal_folder\experts\include ディレクトリに .mqh 拡張子か、 terminal_folder\librariesディレクトリに mq4 拡張子付きで保存されることが推奨される実行ファイルを取得できます。



//+------------------------------------------------------------------+
//|                                             Modify_2_Step v5.mq4 |
//|                                         Copyright © 2008, GenKov |
//|                                                     Genkov@bk.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, GenKov"
#property link      "Genkov@bk.ru"
extern double    March         =  1;  // the step of TakeProfit increase
                                      // "0" step doesn't increase T/P.
// S/L must be less than TrailingStop by 1 point to bring the S/L  
// on a safe level in the time of the very first triggering
extern double    StopLoss      = 15;  
extern double    TrailingStop  = 16;
extern double Lots             = 0.1;  
extern double    TakeProfit    = 60;  // fitting with the tester
void TrailingStop()
  {
   int Magic=3090;  //  number of condition that opens position
   int point  = MarketInfo(Symbol(),MODE_POINT);      // Point size 
   int StopLev= MarketInfo(Symbol(),MODE_STOPLEVEL);  
   double half_Trail = MathRound(TrailingStop/2);//half TrailingStop
   double Step = March*half_Trail;  //TakeProfit-а increase size
  if (TrailingStop<0) return;
   { 
   for (int i=0; i<OrdersTotal(); i++)
    {//1 +cycle by orders search
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
    if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
    if (OrderType()==OP_BUY)
     {
// --------------------------- 1 stage of modification -----BUY-------------&     
    if(OrderStopLoss()<OrderOpenPrice())//if the S/L is less than the order open price
      {   // and if the difference between the current and the open price is greater than T/S
      if(Bid-OrderOpenPrice()>TrailingStop*Point) // && 
       {     // and if OrderStopLoss() is less than the difference between current price andT/S
       if(OrderStopLoss()<Bid-TrailingStop*Point)
        {    // calculate new T/P value
        double Now_T_P=(OrderTakeProfit()+Step*Point);
       { 
       OrderModify(OrderTicket(),OrderOpenPrice(),
       OrderStopLoss()+TrailingStop*Point,
       OrderTakeProfit()+Step*Point,0,Aqua); // increase T/P value
      return;
      }
     }
    }
   }
  if(Bid-OrderOpenPrice()>=TakeProfit*Point) 
   {
    OrderClose(OrderTicket(),Lots,Bid,2,Red);
    }
//------------------------- 2 stage of modification -----BUY---------------&
  if(OrderStopLoss()>=OrderOpenPrice()) // StopLoss is on the lossless level
   {    // calculate correction coefficient
    double Coeff_up = NormalizeDouble((Bid-OrderOpenPrice())*0.382,Digits);
    // and if the difference between the current and the position price is greater than correction coefficient
    if(Bid-OrderOpenPrice()>Coeff_up) 
     {    // clculate new StopLoss value with the margin of 6 points
      double New_S_Loss = Bid-Coeff_up-6*Point-StopLev*Point;
      // if the value of new StopLoss is greater than the current value
      if((New_S_Loss-OrderStopLoss())<2*Point)
       {     // move S/L and T/P
        OrderModify(OrderTicket(),OrderOpenPrice(),
        OrderStopLoss(),OrderTakeProfit()+Step*Point/2,0,Yellow);
        }
        else
        {
         OrderModify(OrderTicket(),OrderOpenPrice(),
        New_S_Loss+1*Point,OrderTakeProfit()+Step*Point,0,Yellow);
        }
       return;
       }
      }
     }
// ---------------------------- 1 stage of modification -----SELL-------------&
  else if(OrderType()==OP_SELL)
    {
   if(OrderStopLoss()>OrderOpenPrice())//if S/L is greater than the order open price
     {
     if(OrderOpenPrice()-Ask>TrailingStop*Point && 
        OrderStopLoss()>Ask+TrailingStop*Point)
     { 
      OrderModify(OrderTicket(),OrderOpenPrice(),
      Ask+TrailingStop*Point,OrderTakeProfit()-Step*Point,0,SkyBlue);
      return;
      }
     }
if(OrderOpenPrice()-Ask>=TakeProfit*Point) 
   {
    OrderClose(OrderTicket(),Lots,Bid,2,Red);
    }     
// ---------------------------- 2 stage of modification -----SELL-------------&
   if(OrderStopLoss()<=OrderOpenPrice()) // StopLoss is on the lossless level
    if(OrderOpenPrice()-Ask>=OrderTakeProfit()) OrderClose(OrderTicket(),Lots,Ask,2,Red);   
    { // calculate correction coefficient
     double Coeff_down = NormalizeDouble((OrderOpenPrice()-Ask)*0.382,Digits);
     // and if the difference between the position open price and the current price is greater than corr. coefficient
    if(OrderOpenPrice()-Ask>Coeff_down) 
     {   // calculate the value of new StopLoss with the margin of 6 points
      New_S_Loss = Ask+Coeff_down+6*Point; 
      // and if the value of new StopLoss is less than the current value
      if((OrderStopLoss()-New_S_Loss-StopLev*Point)>=10*Point)
       {    // move S/L and T/P
       OrderModify(OrderTicket(),OrderOpenPrice(),
       New_S_Loss-5*Point,OrderTakeProfit()-Step*Point,0,Khaki);
      return;
      }
     }
    }
   }
  } 
return(0);
}
}
// ---end----- void TrailingStop()--------------------------------&
  // this block is only for error controlling in the function code
  //  int start()  
  //   {
  //    if(25>26) TrailingStop();
  //    }
  // --------------------------------

まとめ

Sergey Kravchukによる"A Pattern Trailing Stop and Exit the Market"という記事にて記載されている"exemplary trailing-stop"と比較して、提示されているものは理解しやすく、(デモアカウントですが)私のEAにて動作し、攻撃的、穏健的なトレーリングにも適しています。

添付のバージョン:

v4 - S/Lによるクロージング; v5 - T/Pによる予定されるクロージング; v6 - Magin番号によるアドレスサポート



MetaQuotes Ltdによってロシア語から翻訳されました。
元の記事: https://www.mql5.com/ru/articles/1529

添付されたファイル |
誤った考え、パート2統計は、偽りの科学か、暴落するなくてはならない歴史です。 誤った考え、パート2統計は、偽りの科学か、暴落するなくてはならない歴史です。
統計的なメソッドに客観的な現実、つまり金融上の出来事に適用とする試みは、不十分なデータや、確率分布やプロセスの非定常性に直面し、虚しく失敗してしまっています。この記事では、そのような金融上の出来事ではなく、主観的な意見を記述し、トレーダーがどのようにこれらを防ごうとしたか、トレーダーシステムについて記述します。トレーディング結果の統計的な規則性の抽出は、むしろ大変面白い作業です。時折、このプロセスのそのモデルに関する結論が導かれ、これらがトレーディングシステムに適用されます。
MetaTrader 4とMatlabのDDEによる連携 MetaTrader 4とMatlabのDDEによる連携
MatlabからMetaTrader 4へDDEを用いてのデータの移送方法のステップごとのインストラクション
ショウは続く- または ZigZag 再び。 ショウは続く- または ZigZag 再び。
ZigZag 構成の明確であるがまだサブスタンダートな方法について、そしてそれがどんな結果につながるか:単一のタイムフレーム(TF)にて、3つの大きなものに構築される ZigZag を表現するマルチフレーム フラクタル ZigZag インディケータ、について取り上げます。そこでは、それら大きなは標準的ではなく、範囲は M5~MN1です。
トレーリングストップのパターンとマーケットの退出 トレーリングストップのパターンとマーケットの退出
注文修正やクローッジングのアルゴリズムの開発者は、異なるメソッドから取得された結果をどのように比較するかという不滅の悩みに苦しみます。チェックのメカニズムは、よく知られています - それは、ストラテジーテスターです。しかし、注文のオープン/クローズにおいて等しくEAを動作させるにはどうすれば良いでしょうか?この記事は、トレーリングストップやマーケットの退出のための異なるアルゴリズムの結果を比較するためのプラットフォームを数学的に維持できる注文のオープンの繰り返しを提供するツールを紹介します。