私たちのファンページに参加してください
- ビュー:
- 1617
- 評価:
- パブリッシュ済み:
- 2015.11.06 09:47
- アップデート済み:
- 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 の条件付きの "Bullish Harami/Bearish Harami"の転換足パターンのシグナルを考えてみましょう。トレードシグナルのモジュールは、CCandlePattern classに基づいています。ロウソク足のパターンによるシグナルの生成のシンプルな一例です。
1. "Bullish Harami and "Bearish Harami"
1.1. Bullish Harami
Bullish Haramiでは、大きなロウソク足が下降トレンドで形成され、その後、大きなロウソク足の実体の範囲内に実体がある小さなロウソク足が発生します。このパターンは、下降トレンドが転換することを表し、買いエントリーするタイミングであることを示します。2本目のロウソク足は上窓と同時に始まります。
2本目が小さければ小さいほど、転換する確率が上がります。
図1. "Bullish Harami"
"Bullish Harami"は、 CCandlePatternのCCheckPatternBullishHarami() method に実装されています。:
//+------------------------------------------------------------------+ //| Checks formation of "Bullish Harami" candlestick pattern | //+------------------------------------------------------------------+ bool CCandlePattern::CheckPatternBullishHarami() { //--- Bullish Harami if((Close(1)>Open(1)) && // the last completed bar is bullish (white day) ((Open(2)-Close(2))>AvgBody(1)) && // the previous candle is bearish, its body is greater than average (long black) ((Close(1)<Open(2)) && // close price of the bullish candle is lower than open price of the bearish candle (Open(1)>Close(2))) && // open price of the bullish candle is higher than close price of the bearish candle (MidPoint(2)<CloseAvg(2))) // down trend return(true); //--- return(false); }
CCandlePattern の CheckCandlestickPattern(CANDLE_PATTERN_BULLISH_HARAMI) method を "Bullish Harami"で使います。
1.2. Bearish Harami
Bearish Harami では、大きなロウソク足が上昇トレンドで形成され、その後、大きなロウソク足の実体の範囲内に実体がある小さなロウソク足が発生します。. このパターンは、上昇トレンドが転換することを表し、売りエントリーするタイミングであることを示します。2本目のロウソク足は下窓と同時に始まります。
2本目が小さければ小さいほど、転換する確率が上がります。
図2. "Bearish Harami"
"Bearish Harami"は、 CCandlePatternのCheckPatternBearishHarami() method に実装されています。:
//+------------------------------------------------------------------+ //| Checks formation of "Bearish Harami" candlestick pattern | //+------------------------------------------------------------------+ bool CCandlePattern::CheckPatternBearishHarami() { //--- Bearish Harami if((Close(1)<Open(1)) && // last completed bar is bearish (black day) ((Close(2)-Open(2))>AvgBody(1)) && // the previous candle is bullish, its body is greater than average (long white) ((Close(1)>Open(2)) && // close price of the bearish candle is higher than open price of the bullish candle (Open(1)<Close(2))) && // open price of the bearish candle is lower than close price of the bullish candle (MidPoint(2)>CloseAvg(2))) // up trend return(true); //--- return(false); }
CCandlePattern の CheckCandlestickPattern(CANDLE_PATTERN_BEARISH_HARAMI) method を "Bearish Harami"で使います。
2. RSI の条件付きのシグナル
買いポジション・売りポジションのシグナルは、RSI で確認する必要があります。RSI の値は、基準値よりも低いか/大きい必要があります。 (買いポジションは40、売りポジションは60).
ポジションの決済は RSIの値で行います。2通りのケースがあります。:
- RSI が反対の基準点に到達した場合(買いポジションは70。売りポジションは30)
- 逆のシグナルが発生しない(RSIが次の点に達したとき: 買いポジションは30。売りポジションは70)
図3. "RSI による条件付きの"Bullish Harami
- int CBH_BH_RSI::LongCondition() - 買いポジションのエントリー条件(80) と 売りポジションの決済条件 (40);
- int CBH_BH_RSI::ShortCondition() - 売りポジションのエントリー条件(80) と 買いポジションの決済条件 (40).
2.1. 買いポジション/売りポジションの決済
"Bullish Harami"の条件は、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 CBH_BH_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 Bullish Harami pattern and RSI<30 if(CheckCandlestickPattern(CANDLE_PATTERN_BULLISH_HARAMI) && (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. 売りポジション/買いポジションの決済
"Bearish Harami"の条件は、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 CBH_BH_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 Bearish Harami pattern and RSI>60 if(CheckCandlestickPattern(CANDLE_PATTERN_BEARISH_HARAMI) && (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を生成する
CBH_BH_RSI class はStandard Libraryには含まれていません。利用するには、acml_rsi.mqh をダウンロードして、client_terminal_data\folder\MQL5\Include\Expert\Signal\MySignalsに保存する必要があります。(添付詳細)同様の操作が acandlepatterns.mqh にも必要です。MQL5 Wizardを使うには、MetaEditorを再起動する必要があります。
エキスパートアドバイザーを生成するには、MQL5 Wizardを立ち上げてください。:
図4. MQL5 WizardでEAを生成する
エキスパートアドバイザーの名前を決めましょう。:
図5. エキスパートアドバイザーの一般設定
トレードシグナルのモジュールを選択します。
図6. エキスパートアドバイザーのシグナルプロパティ
今回の場合、モジュールは1つだけ使います。
"Signals based on Bullish Harami/Bearish Harami confirmed by RSI" のモジュールを追加:
図7. エキスパートアドバイザーのシグナルプロパティ
シグナルの追加モジュール:
図8. エキスパートアドバイザーのシグナルプロパティ
トレーリングプロパティにも様々なものがありますが、今回は"Trailing Stop not used"にします。:
図9. エキスパートアドバイザーのトレーリングプロパティTrailing properties of the Expert Advisor
資金管理プロパティとして、"Trading with fixed trade volume"(単利)を使います。:
図10エキスパートアドバイザーの資金管理プロパティMoney management properties of the Expert Advisor
"Finish"ボタンを押すと、エキスパートアドバイザーがExpert_ABH_BH_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.11, PeriodRSI=37, MA_period=7).
エキスパートアドバイザーの生成において、今回は固定ロット(Trading Fixed Lot, 0.1), トレーリングストップ(Trailing not used)はなしを選択しました。
図11. Bullish Harami/Bearish Harami + RSIのテスト結果
パラメーターの最適な設定値は、MetaTrader 5 client terminalのStrategy Testerで探すことができます。
MQL5 Wizard で生成したコードはexpert_aml_rsi.mq5.です。
MetaQuotes Ltdによってロシア語から翻訳されました。
元のコード: https://www.mql5.com/ru/code/313

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

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

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

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