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

MQL5 Wizard - ストキャスティクスをフィルターとした"Morning Star/Evening Star"ロウソク足パターン - MetaTrader 5のためのエキスパート

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

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


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 class の CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) と CheckCandlestickPattern(CANDLE_PATTERN_MORNING_DOJI) methods は、"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. ストキャスティクスによるフィルター付きのシグナル

買いや売りのシグナルは、Stochasticで確認する必要があります。シグナル%Dラインは、それぞれの基準レベルよりも高いか、低くなければなりません。(30 か 70).

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

  1. %Dが反対側の基準レベルに到達した (買いポジションなら80、売りポジションなら20)
  2. 逆のシグナルが発生しなかった(%Dが基準点に達した: 買いポジションなら20、売りポジションなら80)

図3. ストキャスティクスによる条件付きの"Evening Star"

図3. ストキャスティクスによる条件付きの"Evening Star"



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

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

  1. "Morning Star"の条件は、Stochasticで確認する必要があります。: StochSignal(1)<30 (直近の確定足のストキャスティクスのシグナルラインは30よりも低くなければなりません。)

  2. Stochasticのシグナルラインが20か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_Stoch::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 signal line<30
  if (CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) && (StochSignal(1)<30))
     result=80;
//--- checking of conditions to close short position
//--- signal line crossover of overbought/oversold levels (downward 20, upward 80)
   if((((StochSignal(1)>20) && (StochSignal(2)<20)) ||
       ((StochSignal(1)>80) && (StochSignal(2)<80))))
     result=40;
//--- return result
   return(result);
  }

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

  1. "Evening Star"の条件は、Stochasticで確認する必要があります。: StochSignal(1)>70 (直近の確定足のストキャスティクスのシグナルラインは70よりも高くなければなりません。)

  2. Stochasticのシグナルラインが20か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_Stoch::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 and signal line>70
  if (CheckCandlestickPattern(CANDLE_PATTERN_EVENING_STAR) && (StochSignal(1)>70))
     result=80;
//--- checking of conditions to close long position
//--- signal line crossover of overbought/oversold levels (downward 80, upward 20)
   if((((StochSignal(1)<80) && (StochSignal(2)>80)) ||
       ((StochSignal(1)<20) && (StochSignal(2)>20))))
     result=40;
//--- return result
   return(result);
  }


2.3. MQL5 WizardでEAを生成する

CMS_ES_Stoch class は、Standard Libraryには含まれていません。利用するには、acms_es_stoch.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 by Stochastic" モジュールの追加:

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

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

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

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

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

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

図9. エキスパートアドバイザーのトレーリングプロパティTrailing properties of the Expert Advisor

図9. エキスパートアドバイザーのトレーリングプロパティTrailing properties of the Expert Advisor

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

図10エキスパートアドバイザーの資金管理プロパティMoney management properties of the Expert Advisor

図10エキスパートアドバイザーの資金管理プロパティMoney management properties of the Expert Advisor

"Finish"ボタンを押すと、エキスパートアドバイザーがExpert_AMS_ES_Stoch.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, テスト期間: 2000.01.01-2011.03.16, PeriodK=12, PeriodD=8, PeriodSlow=29, MA_period=4).

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

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

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


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

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


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

MQL5 Wizard - RSIによる条件付きの"Dark Cloud Cover/Piercing Line"のロウソク足パターンによるシグナル MQL5 Wizard - RSIによる条件付きの"Dark Cloud Cover/Piercing Line"のロウソク足パターンによるシグナル

RSIによる条件付きの"Dark Cloud Cover/Piercing Line"のロウソク足パターンによるシグナルを検証することができます。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

MQL5 Wizard - MFIによる条件付きの"Dark Cloud Cover/Piercing Line"のロウソク足パターンによるシグナル MQL5 Wizard - MFIによる条件付きの"Dark Cloud Cover/Piercing Line"のロウソク足パターンによるシグナル

MFIによる条件付きの"Dark Cloud Cover/Piercing Line"のロウソク足パターンによるシグナルを検証することができます。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

MQL5 Wizard - ストキャスティクスをフィルターとした"Bullish Engulfing/Bearish Engulfing"ロウソク足パターン MQL5 Wizard - ストキャスティクスをフィルターとした"Bullish Engulfing/Bearish Engulfing"ロウソク足パターン

このトレードシグナルは、ストキャスティクスをフィルターとした"Bullish Engulfing/Bearish Engulfing"ロウソク足パターンです。この戦略のエキスパートのコードは、MQL5ウィザードで自動生成させることができます。

MQL5 Wizard - 商品チャネル指数(CCI)による条件付きの"Bullish Engulfing/Bearish Engulfing"のシグナル MQL5 Wizard - 商品チャネル指数(CCI)による条件付きの"Bullish Engulfing/Bearish Engulfing"のシグナル

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