私たちのファンページに参加してください
- ビュー:
- 2351
- 評価:
- パブリッシュ済み:
- 2015.11.26 10:43
- アップデート済み:
- 2016.11.22 07:34
-
このコードに基づいたロボットまたはインジケーターが必要なら、フリーランスでご注文ください フリーランスに移動
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" (ロシア)という著書があります。 そこには数多くの手法と方法が記述されており、転換足パターンを Stochastic、 CCI、 MFI、 RSIの条件のもと、焦点を当てていきます。
最も良い方法は、ロウソク足のパターンの確認に、CExpertSignalから導かれるクラスを切り分けて生成することです。ロウソク足のパターンによるトレードシグナルの確認には、CCandlePatternのクラスを書いて、必要な条件例えば、オシレーターの確認など)を追加すれば十分です。
RSIのフィルター付きの"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" のロウソク足の転換パターン
"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" のロウソク足の転換パターン
"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. RSI の条件付きのシグナル
買いポジション・売りポジションのシグナルは、RSI で確認する必要があります。RSI の値は、基準値よりも低いか/大きい必要があります。 (買いポジションは40、売りポジションは60)。
ポジションの決済は RSIの値で行います。2通りのケースがあります:
- RSI が反対の基準点に到達した場合(買いポジションは70。売りポジションは30)
- 逆のシグナルが発生しない(RSIが次の点に達したとき: 買いポジションは30。売りポジションは70)
図3. RSIによる条件付きの"Morning Star"
- int CMS_ES_RSI::LongCondition() - 買いポジションのエントリー条件(80) と 売りポジションの決済条件 (40);
- int CMS_ES_RSI::ShortCondition() - 売りポジションのエントリー条件(80) と 買いポジションの決済条件 (40)。
2.1. 買いポジション/売りポジションの決済
"Morning Star"の条件は、RSI で確認しなければなりません : RSI(1)<40 (直近の確定した足のRSIの値が40よりも小さい)
RSIが基準値 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_RSI::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 RSI<30 if(CheckCandlestickPattern(CANDLE_PATTERN_MORNING_STAR) && (RSI(1)<40)) result=80; //--- checking of conditions to close short position //--- signal line crossover of overbought/oversold levels (upward 30, upward 70) if(((RSI(1)>30) && (RSI(2)<30)) || ((RSI(1)>70) && (RSI(2)<70))) result=40; //--- return result return(result); }
2.2. 売りポジション/買いポジションの決済
"Evening Star"の条件は、RSI で確認しなければなりません: RSI(1)>60 (直近の確定した足のRSI が60よりも大きい)。
RSIが基準値 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_RSI::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 RSI>60 if(CheckCandlestickPattern(CANDLE_PATTERN_EVENING_STAR) && (RSI(1)>60)) result=80; //--- checking of conditions to close long position //--- signal line crossover of overbought/oversold levels (downward 70, downward 30) if(((RSI(1)<70) && (RSI(2)>70)) || ((RSI(1)<30) && (RSI(2)>30))) result=40; //--- return result return(result); }
2.3. MQL5 WizardでEAを生成する
MS_ES_RSI クラスはStandard Libraryには含まれていません。利用するには、acms_es_rsi.mqh をダウンロードして、client_terminal_data_folder\MQL5\Include\Expert\Signal\MySignalsに保存する必要があります。(添付詳細)candlepatterns.mqh も同様の処理が必要です。MQL5 Wizardを使うには、MetaEditorを再起動する必要があります。
エキスパートアドバイザーを生成するには、MQL5 Wizardを立ち上げてください:
図4. MQL5 WizardでEAを生成する
エキスパートアドバイザーの名前を決めましょう:
図5. エキスパートアドバイザーの一般設定
トレードシグナルのモジュールを選択します。
図6. エキスパートアドバイザーのシグナルプロパティ
今回の場合、モジュールは1つだけ使います。
"Signals based on Morning/Evening Stars confirmed by RSI"モジュールの追加:
図7. エキスパートアドバイザーのシグナルプロパティ
シグナルの追加モジュール:
図8. エキスパートアドバイザーのシグナルプロパティ
トレーリングプロパティにも様々なものがありますが、今回は"Trailing Stop not used"にします:
図9. エキスパートアドバイザーのトレーリングプロパティ
資金管理プロパティとして、"Trading with fixed trade volume"(単利)を使います:
図10エキスパートアドバイザーの資金管理プロパティ
"Finish"ボタンを押すと、エキスパートアドバイザーがExpert_AMS_ES_RSI.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.04, PeriodK=47, PeriodD=9, PeriodSlow=13, MA_period=5)。
エキスパートアドバイザーの生成において、今回は固定ロット(Trading Fixed Lot, 0.1), トレーリングストップ(Trailing not used)はなしを選択しました。
図11. Morning/Evening Stars + RSIのテスト結果
パラメーターの最適な設定値は、MetaTrader 5 client terminalのStrategy Testerで探すことができます。
パラメータの検査は3D-Visualization mode of Strategy Testerで単純化できます。419 build (図 12)バージョンより追加:
図12. PeriodRSI と MA_period の比率
MQL5 Wizard で生成したコードは expert_ms_es_rsi.mq5 です。
MetaQuotes Ltdによってロシア語から翻訳されました。
元のコード: https://www.mql5.com/ru/code/324

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

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

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

DRAW_LINEの描写スタイルは、インジケーターのバッファの値を線としてプロットする際に使われます。