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

MQL5 Wizard - MFIの条件付きの Morning/Evening Stars - MetaTrader 5のためのエキスパート

ビュー:
1025
評価:
(23)
パブリッシュ済み:
2015.11.26 10:40
アップデート済み:
2016.11.22 07:34
\MQL5\Include\Expert\Signal\MySignals\
このコードに基づいたロボットまたはインジケーターが必要なら、フリーランスでご注文ください フリーランスに移動

MQL5 Wizardを使えば、クライアントターミナルにあるStandard libraryのエキスパートアドバイザーを自動生成することができます。(詳細は、Creating Ready-Made Expert Advisors in MQL5 Wizardを参照)トレードシグナルのクラスを生成しさせすれば、トレードアイディアをすぐに確認することができますクラスの例と構造については MQL5 Wizard: How to Create a Module of Trading Signalsを参照してください。

一般的な考え方は下記の通りです:CExpertSignalがシグナルのクラスです。そして、LongCondition()ShortCondition() を上書きする必要があります。

"Strategies of best traders" (ロシア)という著書があります。 そこには数多くの手法と方法が記述されており、転換足パターンを StochasticCCIMFIRSIの条件のもと、焦点を当てていきます。

最も良い方法は、ロウソク足のパターンの確認に、CExpertSignalから導かれるクラスを切り分けて生成することです。ロウソク足のパターンによるトレードシグナルの確認には、CCandlePatternのクラスを書いて、必要な条件例えば、オシレーターの確認など)を追加すれば十分です。

MFIのフィルター付きの"Morning Star/Evening Star" (Morning Doji Star/Evening Doji Star) の転換足パターンのシグナルを考えてみましょう。トレードシグナルのモジュールは、CCandlePattern クラスに基づいています。ロウソク足のパターンによるシグナルの生成のシンプルな一例です。


1. "Morning Star" と "Evening Star" のロウソク足の転換パターン

1.1. Morning Star

3つのロウソク足からなる下降トレンドの転換を表します。(図1)長い黒いロウソク足の後、実体の小さいロウソク足(色は重要ではありません)が、黒い足の実体の外側に発生します。ロウソク足が小さい実体ということは、ブルとベアの力が拮抗していて、相場が転換期に来ているということを意味します。

3つ目のロウソク足がブル型のロウソク足で、その実態が2本目のロウソク足の実体と重ならず、終値が1本目のロウソク足の実体の範囲にある。ロウソク足のモデルは図1のようになります。

2本目のロウソク足がdoji-like-candleの場合、"Morning Doji Star"となります。

図1. "Morning Star" と "Morning Doji Star" のロウソク足の転換パターン

図1. "Morning Star" と "Morning Doji Star" のロウソク足の転換パターン

"Morning Star"は、 CCandlePatternのCheckPatternMorningDoji() と CheckPatternMorningStar() に実装されています:

//+------------------------------------------------------------------+
//| Check formation of the "Morning Star" pattern                    |
//+------------------------------------------------------------------+
bool CCandlePattern::CheckPatternMorningStar()
  {
//--- Morning Star
   if((Open(3)-Close(3)>AvgBody(1))             && // bearish candle, its body greater than average candle body
      (MathAbs(Close(2)-Open(2))<AvgBody(1)*0.5) && // second candle has small body (lower than half of the average body)
      (Close(2)<Close(3))                       && // close of the second candle is lower than close of the first 
      (Open(2)<Open(3))                         && // open of the second canlde is lower than open of the first
      (Close(1)>MidOpenClose(3)))                  // close of the last completed candle is higher than center of the first 
      return(true);
//---
   return(false);
  }
//+------------------------------------------------------------------+
//| Check formation of the "Morning Doji Star" pattern               |
//+------------------------------------------------------------------+
bool CCandlePattern::CheckPatternMorningDoji()
  {
//--- Morning Doji Star
   if((Open(3)-Close(3)>AvgBody(1)) && // bearish candle with body greater than average candle body 
      (AvgBody(2)<AvgBody(1)*0.1)   && // the second candle has a very small body (doji) 
      (Close(2)<Close(3))           && // close of the second candle is lower than close of the first 
      (Open(2)<Open(3))             && // open of the second candle is lower than open of the first
      (Open(1)>Close(2))            && // up gap at the last completed candle
      (Close(1)>Close(2)))             // close of the last completed candle is higher than close of the second
      return(true);
//---
   return(false);
  }

CCandlePattern クラスの CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) と CheckCandlestickPattern(CANDLE_PATTERN_MORNING_DOJI) メソッドは、"Morning Star" と "Morning Doji Star" で使います。


1.2. Evening Star

3つのロウソク足からなる上昇トレンドの転換を表します。(図2). 長い白いロウソク足の後、実体の小さいロウソク足(色は重要ではありません)が、白い足の実体の外側に発生します。ロウソク足が小さい実体ということは、ブルとベアの力が拮抗していて、相場が転換期に来ているということを意味します。

3つ目のロウソク足がベア型のロウソク足で、その実態が2本目のロウソク足の実体と重ならず、終値が1本目のロウソク足の実体の範囲にある。ロウソク足のモデルは図2のようになります。

2本目のロウソク足がdoji-like-candleの場合、"Evening Doji Star"となります。

図2. "Evening Star" と "Evening Doji Star"  のロウソク足の転換パターン

図2. "Evening Star" と "Evening Doji Star" のロウソク足の転換パターン

"Evening Star" と "Evening Doji Star" のメソッドです:

//+------------------------------------------------------------------+
//| Check formation of the "Evening Star" pattern                    |
//+------------------------------------------------------------------+
bool CCandlePattern::CheckPatternEveningStar()
  {
//--- Evening Star
   if((Close(3)-Open(3)>AvgBody(1))             && // bullish candle with body higher than average body 
      (MathAbs(Close(2)-Open(2))<AvgBody(1)*0.5) && // second candle has a small body (less than half of the average)
      (Close(2)>Close(3))                       && // close of the second candle is higher than close of the first
      (Open(2)>Open(3))                         && // open of the second candle is higher than open of the first
      (Close(1)<MidOpenClose(3)))                  // close of the last completed candle is lower than center of the first 
      return(true);
//---
   return(false);
  }
//+------------------------------------------------------------------+
//| Check formation of the "Evening Doji Star" pattern               |
//+------------------------------------------------------------------+
bool CCandlePattern::CheckPatternEveningDoji()
  {
//--- Evening Doji Star
   if((Close(3)-Open(3)>AvgBody(1)) && // bullish candle with body higher than average 
      (AvgBody(2)<AvgBody(1)*0.1)   && // second candle has a very small body (doji) 
      (Close(2)>Close(3))           && // close of the second candle is higher than close of the first
      (Open(2)>Open(3))             && // opend of the second candle is higher than open of the first
      (Open(1)<Close(2))            && // down gap at the last completed candle
      (Close(1)<Close(2)))             // close of the last completed candle is lower than close of the second 
      return(true);
//---
   return(false);
  }

CCandlePattern の CheckCandlestickPattern(CANDLE_PATTERN_EVENING_STAR) と CheckCandlestickPattern(CANDLE_PATTERN_EVENING_DOJI) は、"Evening Star" と "Evening Doji Star" の確認に使います。


2. MFI条件付きのシグナル

買いポジション・売りポジションのシグナルは、MFIで確認する必要があります。MFIの値は、40 (買いポジションの場合)よりも低く、60 (売りポジションの場合)よりも高くなければなりません。

ポジションの決済はMFIの値で行います。2通りのケースがあります:

  1. MFIが反対の基準値に到達した場合 (買いポジションは70。売りポジションは30)
  2. 逆のシグナルが発生しない (MFIが次の値に到達: 買いポジションは30、売りポジションは70)

図3. MFIによる条件付きの"Morning Star"

図3. MFIによる条件付きの"Morning Star"


  • int CMS_ES_MFI::LongCondition() - 買いポジションのエントリー条件(80) と 売りポジションの決済条件 (40);
  • int CMS_ES_MFI::ShortCondition() - 売りポジションのエントリー条件(80) と 買いポジションの決済条件 (40)。

2.1. 買いポジション/売りポジションの決済

  1. "Morning Star" の状態はMFIで確認する必要があります: MFI(1)<40 (直近の確定した足のMFIの値が40よりも小さい)

  2. MFIが基準値(70 か 30)を上抜けした場合、売りポジションを決済します。

//+------------------------------------------------------------------+
//| Checks conditions for entry and exit from market                 |
//| 1) Market entry (open long position, result=80)                  |
//| 2) Market exit (close short position, result=40)                 |
//+------------------------------------------------------------------+
int CMS_ES_MFI::LongCondition()
  {
   int result=0;
//--- idx can be used to determine Expert Advisor work mode
//--- idx=0 - in this case EA checks trade conditions at each tick
//--- idx=1 - in this case EA checks trade consition only at news bars
   int idx   =StartIndex();
//--- checking of conditions to open long position
//--- formation of Morning Star pattern and MFI<40
  if(CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) && (MFI(1)<40))
     result=80;
//--- checking of conditions to close short position
//--- signal line crossover of overbought/oversold levels (upward 30, upward 70)
  if(((MFI(1)>30) && (MFI(2)<30)) || ((MFI(1)>70) && (MFI(2)<70)))
     result=40;
//--- return result
   return(result);
  }


2.2. 売りポジション/買いポジションの決済

  1. "Evening Star"の状態はMFIで確認する必要があります: MFI(1)>60 (直近の確定した足のMFIの値が60よりも大きい)。

  2. MFIが基準値 (70 か 30)を上抜けした場合、買いポジションを決済します。

//+------------------------------------------------------------------+
//| Checks conditions for entry and exit from market                 |
//| 1) Market entry (open short position, result=80)                 |
//| 2) Market exit (close long position, result=40)                  |
//+------------------------------------------------------------------+
int CMS_ES_MFI::ShortCondition()
  {
   int result=0;
//--- idx can be used to determine Expert Advisor work mode
//--- idx=0 - in this case EA checks trade conditions at each tick
//--- idx=1 - in this case EA checks trade consition only at news bars
   int idx   =StartIndex();
//--- checking of conditions to open short position
//--- formation of Evening Star pattern and MFI>60
  if(CheckCandlestickPattern(CANDLE_PATTERN_EVENING_STAR) && (MFI(1)>60))
     result=80;
//--- checking of conditions to close long position
//--- signal line crossover of overbought/oversold levels (upward 70, downward 30)
   if(((MFI(1)>70) && (MFI(2)<70)) || ((MFI(1)<30) && (MFI(2)>30)))
     result=40;
//--- return result
   return(result);
  }


2.3. MQL5 WizardでEAを生成する

CMS_ES_MFI クラスはStandard Libraryには含まれていません。利用するには、ams_es_mfi.mqh をダウンロードして、client_terminal_data_folder\MQL5\Include\Expert\Signal\MySignalsに保存する必要があります。(添付詳細)同様の操作が acandlepatterns.mqh にも必要です。MQL5 Wizardを使うには、MetaEditorを再起動する必要があります。

エキスパートアドバイザーを生成するには、MQL5 Wizardを立ち上げてください:

図4. MQL5 WizardでEAを生成する

図4. MQL5 WizardでEAを生成する

エキスパートアドバイザーの名前を決めましょう:

図5. エキスパートアドバイザーの一般設定

図5. エキスパートアドバイザーの一般設定

トレードシグナルのモジュールを選択します。

図6. エキスパートアドバイザーのシグナルプロパティ

図6. エキスパートアドバイザーのシグナルプロパティ

今回の場合、モジュールは1つだけ使います。

"Signals based on Morning Star/Evening Star confirmed by MFI"モジュールの追加:

図7. エキスパートアドバイザーのシグナルプロパティ

図7. エキスパートアドバイザーのシグナルプロパティ

シグナルの追加モジュール:

図8. エキスパートアドバイザーのシグナルプロパティ

図8. エキスパートアドバイザーのシグナルプロパティ

トレーリングプロパティにも様々なものがありますが、今回は"Trailing Stop not used"にします:

図9. エキスパートアドバイザーのトレーリングプロパティ

図9. エキスパートアドバイザーのトレーリングプロパティ

資金管理プロパティとして、"Trading with fixed trade volume"(単利)を使います:

図10エキスパートアドバイザーの資金管理プロパティ

図10エキスパートアドバイザーの資金管理プロパティ

"Finish"ボタンを押すと、エキスパートアドバイザーがExpert_AMS_ES_MFI.mq5に生成されます。保存場所は、terminal_data_folder\MQL5\Experts\です。

生成後のエキスパートアドバイザーのデフォルトのパラメーター:

//--- inputs for main signal
input int            Signal_ThresholdOpen   =10;     // Signal threshold value to open [0...100]
input int            Signal_ThresholdClose  =10;     // Signal threshold value to close [0...100]
input double         Signal_PriceLevel      =0.0;    // Price level to execute a deal
input double         Signal_StopLevel       =50.0;   // Stop Loss level (in points)
input double         Signal_TakeLevel       =50.0// Take Profit level (in points)

上記は下記にしなければなりません:

//--- inputs for main signal
input int            Signal_ThresholdOpen   =40;     // Signal threshold value to open [0...100]
input int            Signal_ThresholdClose  =20;     // Signal threshold value to close [0...100]
input double         Signal_PriceLevel      =0.0;    // Price level to execute a deal
input double         Signal_StopLevel       =0.0;    // Stop Loss level (in points)
input double         Signal_TakeLevel       =0.0;    // Take Profit level (in points)

Signal_ThresholdOpen/Signal_ThresholdClose パラメーターは、ポジションのオープン、決済の最初のレベルを決めます。

LongCondition() と ShortCondition() のメソッドのコードの中に、デフォルトの固定値が入っています:

  • エントリー: 80;
  • 決済: 40。

MQL5 Wizard で生成したエキスパートアドバイザーは、トレードシグナルのモジュールの"ボート"を使ってエントリー、決済を行います。メインモジュール(コンテナとして、すべての追加モジュールを含む)のボートもまた、使われますが、 LongCondition() と ShortCondition() メソッドは常に0を返します。

メインモジュールの評価結果は、"ボート"平均が使われます。今回の場合、メインモジュールとシグナルのモジュールがあるので、初期値を与えるときには、このことを考慮に入れなければいけません。そのことにより、ThresholdOpen と ThresholdClose は、 40=(0+80)/2 and 20=(0+40)/2に設定しなければなりません。

Signal_StopLevel と Signal_TakeLevel パラメーターの値は、0にします。これは、ポジションの決済は、決済条件がtrueのときにのみ行われるということを表します。


2.4. バックテスト結果

過去データでエキスパートアドバイザーをテストしてみましょう (EURUSD H1, テスト期間: 2010.01.01-2011.03.16, PeriodMFI=49, MA_period=3)。

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

図11. Morning/Evening Stars + MFIのテスト結果

図11. Morning/Evening Stars + MFIのテスト結果


パラメーターの最適な設定値は、MetaTrader 5 client terminalのStrategy Testerで探すことができます。

MQL5 Wizard で生成したコードは expert_ams_es_mfi.mq5 です。

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

MQL5 Wizard - CCIの条件付きの Morning/Evening Stars MQL5 Wizard - CCIの条件付きの Morning/Evening Stars

商品チャネル指数(CCI)による条件付きの"Morning Star/Evening Star"のシグナルを試すことができます。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

MQL5 Wizard - RSIによる条件付きの Bullish/Bearish Meeting Lines MQL5 Wizard - RSIによる条件付きの Bullish/Bearish Meeting Lines

RSIによる条件付きの"Bullish/Bearish Meeting Lines"のシグナルを試すことができます。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

MQL5 Wizard - RSIの条件付きの Morning/Evening Stars MQL5 Wizard - RSIの条件付きの Morning/Evening Stars

RSIによる条件付きの"Morning Star/Evening Star"のシグナルを試すことができます。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

MQL5 Wizard - ストキャスティクスによる条件付きのロウソク足の転換パターン MQL5 Wizard - ストキャスティクスによる条件付きのロウソク足の転換パターン

このトレードシグナルは、ストキャスティクスをフィルターとしたロウソク足パターンです。