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

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

ビュー:
1029
評価:
(22)
パブリッシュ済み:
2015.11.26 10:36
アップデート済み:
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のクラスを書いて、必要な条件例えば、オシレーターの確認など)を追加すれば十分です。

CCIのフィルター付きの"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. CCIによる条件付きのシグナル

買いポジション・売りポジションのシグナルは、CCIで確認する必要があります。CCIの値は基準値よりも大きい/小さい必要があります。 (買いポジションは-50。売りポジションは50。)

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

  1. CCIが反対側の基準値に達した場合(買いポジションは80。売りポジションは-80)
  2. 逆のシグナルが発生しない (CCIが下記の点に達したとき:買いポジションは-80。売りポジションは80)

図3. CCIによる条件付きの"Evening Star"

図3. CCIによる条件付きの"Evening Star"


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

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

  1. CCI の条件付きの"Morning Star" :CCI(1)<-50 (直近の確定した足のCCIが-50より小さい)。

  2. CCIが-80ラインを上向きにクロスした場合、もしくは80ラインを下向きにクロスした場合、売りポジションは決済します。

//+------------------------------------------------------------------+
//| 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_CCI::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 CCI<-50
   if(CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) && (CCI(1)<-50))
     result=80;
//--- checking of conditions to close short position
//--- signal line crossover of overbought/oversold levels (downward -80, downward -80)
   if(((CCI(1)>-80) && (CCI(2)<-80)) || ((CCI(1)<80) && (CCI(2)>80)))
     result=40;
//--- return result
   return(result);
  }

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

  1. CCIの条件付きの"Evening Star": CCI(1)>50 (直近の確定した足のCCIが50より大きい)。

  2. CCIが-80 か 80を下向きにクロスした場合、買いポジションを決済します。

//+------------------------------------------------------------------+
//| 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_CCI::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 CCI>50
   if(CheckCandlestickPattern(CANDLE_PATTERN_EVENING_STAR) && (CCI(1)>50))
     result=80;
//--- checking of conditions to close long position
//--- signal line crossover of overbought/oversold levels (downward -80, downward 80)
   if(((CCI(1)<80) && (CCI(2)>80)) || ((CCI(1)<-80) && (CCI(2)>-80)))
     result=40;
//--- return result
   return(result);
  }


2.3. MQL5 WizardでEAを生成する

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

"Finish"ボタンを押すと、エキスパートアドバイザーがExpert_AMS_ES_CCI.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, テスト期間: 2009.01.01-2011.03.16, PeriodCCI=25, MA_period=5)。

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

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

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


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

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

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

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

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

MQL5 Wizard - MFIによる条件付きの'Bullish/Bearish Meeting Lines'ロウソク足パターン MQL5 Wizard - MFIによる条件付きの'Bullish/Bearish Meeting Lines'ロウソク足パターン

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

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

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

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

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