無料でロボットをダウンロードする方法を見る
Facebook上で私たちを見つけてください。
私たちのファンページに参加してください
興味深いスクリプト?
それではリンクにそれを投稿してください。-
他の人にそれを評価してもらいます
記事を気に入りましたか?MetaTrader 5ターミナルの中でそれを試してみてください。
エキスパート

MQL5 Wizard - ADXによる条件付きの移動平均と価格のクロスによるトレードロジックX - MetaTrader 5のためのエキスパート

ビュー:
1706
評価:
(30)
パブリッシュ済み:
2015.10.29 11:26
アップデート済み:
2016.11.22 07:34
このコードに基づいたロボットまたはインジケーターが必要なら、フリーランスでご注文ください フリーランスに移動

MQL5 Wizardは、エキスパートアドバイザーを自動生成することができます。詳細はCreating Ready-Made Expert Advisors in MQL5 Wizardを参照してください。

ADXを確認した上で、移動平均と価格のクロスによるトレードロジックを検証してみます。(MQL5 WizardでEAを自動生成する際 )"Signals based on price crossover with MA confirmed by ADX" と呼ばれる手法です。

トレードシグナル:

  • 買い: 直近の確定した足の終値が移動平均線よりも高い、かつ、現在と確定した足において移動平均線が増加している。
  • 売り: 直近の確定した足の終値が移動平均線よりも低い、かつ、現在と確定した足において移動平均線が減少している。
  • ダマシを減らすため、トレンド強度 (ADX>ADXmin) と、DI+とDI-を使ったトレンド方向を確認します。

この戦略は、 CSignalADX_MA クラスに実装されています。 (terminal_data_folder\MQL5\Include\Expert\Signal\SignalADX-MA.mqh に置く必要があります。)

図1. ADXを確認した上での、移動平均と価格のクロスによるトレード手法

図1. ADXを確認した上での、移動平均と価格のクロスによるトレード手法

トレードシグナル

このトレード手法は CSignalADX_MA クラスで実装されており、インジケーターと価格の値に簡単にアクセスできるやり方が入っています。:

double   PlusADX(int ind)     // returns the value of DI+ line of the bar
double   MainADX(int ind)     // returns the value of main line of the bar
double   MinusADX(int ind)    // returns the value of DI- line of the bar
double   EMA(int ind)         // returns the value of moving average of the bar
double   Close(int ind)       // returns the value of closing price of the bar
double   StateADX(int ind)    // returns the difference between the DI+ and DI- lines
double   StateEMA(int ind)    // returns the positive value if EMA increases and negative if it decreases
double   StateClose(int ind)  // returns the difference between the closing price and moving average
この方法の特徴は、トレンド圧力を追加で確認できることにあります。(Directional Movement Indicator併用)これによりダマシを減らし、現在(確定)足の値を使ってトレード条件を確認することができます。


1. 買いポジション

買いポジションの条件:

  1. StateEMA(0)<0 и StateEMA(1)>0: 移動平均が現在足と直近の確定した足で増加;
  2. StateClose(1)>0: 直近の確定した足の終値が移動平均よりも高い;
  3. MainADX(0)>minimum_ADX: 現在足のADXが特定の最小値よりも大きい。 (トレンド圧力の確認);
  4. StateADX(0)>0: 現在足においてDI+ が DI- よりも大きい。
//+------------------------------------------------------------------+
//| Checks conditions to open long position (buy)                    |
//+------------------------------------------------------------------+
bool CSignalADX_MA::CheckOpenLong(double& price,double& sl,double& tp,datetime& expiration)
  {
//--- condition 1: moving average increases on the current and last completed bars 
   bool Buy_Condition_1=(StateEMA(0)>0 && StateEMA(1)>0);
//--- condition 2: closing price of the last completed bar is higher than moving average 
   bool Buy_Condition_2=(StateClose(1)>0);
//--- condition 3: the ADX value of the current bar is greater than specified minimal value (trend threshold) 
   bool Buy_Condition_3=(MainADX(0)>m_minimum_ADX);
//--- condition 4: the value of DI+ is greater than DI- of the current bar
    bool Buy_Condition_4=(StateADX(0)>0);
//---
   price=0.0;
   sl   =m_symbol.Ask()-m_stop_loss*m_adjusted_point;
   tp   =m_symbol.Ask()+m_take_profit*m_adjusted_point;
//--- checking of all conditions
   return(Buy_Condition_1 && Buy_Condition_2 && Buy_Condition_3 && Buy_Condition_4);
  }


2. 買いの決済

買いポジションの決済条件:

  1. StateEMA(0)<0 и StateEMA(1)<0: 移動平均が現在足と直近の確定した足で減少;
  2. StateClose(1)<0: 直近の確定した足の終値が移動平均よりも低い;
  3. MainADX(0)>minimum_ADX: 現在足のADXが特定の最小値よりも大きい。 (トレンド圧力の確認);
  4. StateADX(0)<0: 現在足においてDI- が DI+ よりも大きい。
//+------------------------------------------------------------------+
//| Checks conditions to close long position                         |
//+------------------------------------------------------------------+
bool CSignalADX_MA::CheckCloseLong(double& price)
  {
//--- condition 1: the moving average decreases on the current and last completed bars 
   bool Sell_Condition_1=(StateEMA(0)<0 && StateEMA(1)<0);
//--- condition 2: closing price of the completed bar is lower than moving average 
   bool Sell_Condition_2=(StateClose(1)<0);
//--- condition 3: the ADX value of the current bar is greater than specified minimal value (trend threshold) 
   bool Sell_Condition_3=(MainADX(0)>m_minimum_ADX);
//--- condition 4: the value of DI- is greater than DI- of the current bar
   bool Sell_Condition_4=(StateADX(0)<0);
//---
   price=0.0;
//--- checking of all conditions
   return(Sell_Condition_1 && Sell_Condition_2 && Sell_Condition_3 && Sell_Condition_4);
  }


3. 売りポジション

売りポジションの条件は買いポジションの決済と同じです。

//+------------------------------------------------------------------+
//| Checks conditions to open short position (sell)                  |
//+------------------------------------------------------------------+
bool CSignalADX_MA::CheckOpenShort(double& price,double& sl,double& tp,datetime& expiration)
  {
//--- condition 1: the moving average decreases on the current and last completed bars 
   bool Sell_Condition_1=(StateEMA(0)<0 && StateEMA(1)<0);
//--- condition 2: closing price of the completed bar is lower than moving average 
   bool Sell_Condition_2=(StateClose(1)<0);
//--- condition 3: the ADX value of the current bar is greater than specified minimal value (trend threshold) 
   bool Sell_Condition_3=(MainADX(0)>m_minimum_ADX);
//--- condition 4: the value of DI- is greater than DI- of the current bar
   bool Sell_Condition_4=(StateADX(0)<0);
//---
   price=0.0;
   sl   =m_symbol.Bid()+m_stop_loss*m_adjusted_point;
   tp   =m_symbol.Bid()-m_take_profit*m_adjusted_point;
//--- checking of all conditions
   return(Sell_Condition_1 && Sell_Condition_2 && Sell_Condition_3 && Sell_Condition_4);
  }


4. 売りポジションの決済

売りポジションの決済は買いポジションのエントリーと同じです。

//+------------------------------------------------------------------+
//| Checks conditions to close short position                        |
//+------------------------------------------------------------------+
bool CSignalADX_MA::CheckCloseShort(double& price)
  {
//--- condition 1: moving average increases on the current and last completed bars
   bool Buy_Condition_1=(StateEMA(0)>0 && StateEMA(1)>0);
//--- condition 2: closing price of the last completed bar is higher than moving average 
   bool Buy_Condition_2=(StateClose(1)>0);
//--- condition 3: the ADX value of the current bar is greater than specified minimal value (trend threshold)
    bool Buy_Condition_3=(MainADX(0)>m_minimum_ADX);
//--- condition 4: the value of DI+ is greater than DI- of the current bar
   bool Buy_Condition_4=(StateADX(0)>0);
//---
   price=0.0;
//--- checking of all conditions
  return(Buy_Condition_1 && Buy_Condition_2 && Buy_Condition_3 && Buy_Condition_4);
  }

MQL5 WizardでEAを生成する

このトレード手法のトレードロボットを生成するには、 MQL5 Wizardの"Creating Ready-Made Expert Advisors"の"Signals based on price crossover with MA confirmed by ADX"を選択してください。:

図2. MQL5 Wizard の "Signals based on price crossover with MA confirmed by ADX" を選択してください。

図2. MQL5 Wizard の "Signals based on price crossover with MA confirmed by ADX" を選択してください。

次に、trailing stopmoney and risk management の有無を選択します。エキスパートアドバイザーのコードは自動的に生成されるので、コンパイルすれば、MetaTrader 5 client terminalの Strategy Testerでテスト可能です。


テスト結果

過去データでエキスパートアドバイザーをテストしてみましょう。 (EURUSD H1, テスト期間: 1.1.2010-05.01.2011,  PeriodADX=33, MinimumADX=22, PeriodMA=39, StopLoss=400, TakeProfit=900).

エキスパートアドバイザーの生成において、今回は固定ロット(Trading Fixed Lot, 0.1), トレーリングストップ(Trailing not used)はなしを選択しました。

図3. ADXを確認した上での、移動平均と価格のクロスに基づいたエキスパートアドバイザーのバックテスト結果

図3. ADXを確認した上での、移動平均と価格のクロスに基づいたエキスパートアドバイザーのバックテスト結果


アタッチメント: The SignalADX-MA.mqh と CSignalADX_MA クラスは terminal_data_folder\MQL5\Include\Expert\Signal\ になければなりません。

MQL5 Wizardを使って生成したエキスパートアドバイザーのコードは、ma_crossover_adx.mq5です。


MetaQuotes Ltdによってロシア語から翻訳されました。
元のコード: https://www.mql5.com/ru/code/258

MQL5 Wizard - 3つの移動平均線に基づいたシグナル MQL5 Wizard - 3つの移動平均線に基づいたシグナル

3つの移動平均線に基づいたシグナルです。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

An Expert Advisor template An Expert Advisor template

このコードは、ATC-2010用にValery Mazurenko氏が作ったエキスパートアドバイザーのテンプレートです。

MQL5 Wizard - 2つのEMAのクロスによるトレードシグナル MQL5 Wizard - 2つのEMAのクロスによるトレードシグナル

2つのEMAのクロスによるトレードシグナルを検証できます。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

MQL5 Wizard - MACDのメインラインとシグナルラインのクロスに基づいたトレードシグナル MQL5 Wizard - MACDのメインラインとシグナルラインのクロスに基づいたトレードシグナル

MACD(CSignalMACD from MQL5 Standard Library)のメインラインとシグナルラインのクロスに基づいたトレードシグナルを検証することができます。 この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。