Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

MQL5 Wizard - Trade Signals Based on Bullish/Bearish Meeting Lines + Stochastic - expert for MetaTrader 5

Views:
7108
Rating:
(19)
Published:
2011.03.23 17:45
Updated:
2016.11.22 07:32
\MQL5\Include\Expert\Signal\MySignals\
acml_stoch.mqh (8.48 KB) view
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The MQL5 Wizard allows creating ready-made Expert Advisors based on the Standard library classes delivered together with the client terminal (see Creating Ready-Made Expert Advisors in MQL5 Wizard for the details). It allows to check your trade ideas quickly, all you need is to create your own trading signals class. The structure of this class and example can be found in the article MQL5 Wizard: How to Create a Module of Trading Signals.

The generic idea is the following: the class of trading signals is derived from CExpertSignal, the next, it's necessary to override the LongCondition() and ShortCondition() virtual methods with your own methods.

There is a book "Strategies of best traders" (in Russian), there are many trading strategies are considered there, we will focus on reversal candlestick patterns, confirmed by Stochastic, CCI, MFI and RSI oscillators.

The best way is to create the separate class, derived from CExpertSignal for checking of formation of candlestick patterns. For confirmation of trade signals, generated by candlestick patterns, it's sufficient to write the class, derived from CCandlePattern and add the necessary features (for example, confirmation by oscillators) there.

Here we will consider the signals, based on "Bullish/Bearish Meeting Lines" reversal candlestick patterns, confirmed by Stochastic indicator. The module of trade signals is based on the CCandlePattern class, it's simple example of its use for creation of trade signals with candlestick patterns.


1. "Meeting Lines" reversal candlestick patterns

1.1. Bullish Meeting Lines

The pattern consist of two candlesticks (bearish and bullish) with equal (or very close) close prices. The body of two candlesticks must be greater than average body length.

The "Bullish Meeting Lines" pattern indicates the reversal of a downward trend.

Fig. 1. "Bullish Meeting Lines" pattern

Figure 1. "Bullish Meeting Lines" pattern

The recognition of "Bullish Meeting Lines" pattern is implemented in CheckPatternCheckPatternBullishMeetingLines() method of CCandlePattern class:

//+--------------------------------------------------------------------+
//| Checks formation of "Bullish Meeting Lines" candlestick pattern    |            
//+--------------------------------------------------------------------+
bool CCandlePattern::CheckPatternBullishMeetingLines()
  {
//--- Bullish Meeting Lines
   if((Open(2)-Close(2)>AvgBody(1))              && // long black
     ((Close(1)-Open(1))>AvgBody(1))             && // long white
      (MathAbs(Close(1)-Close(2))<0.1*AvgBody(1)))   // doji close
      return(true);
//---
   return(false);
  }

The CheckCandlestickPattern(CANDLE_PATTERN_BULLISH_MEETING_LINES) method of CCandlePattern class is used to check formation of "Bullish Meeting Lines" candlestick pattern.


1.1. Bearish Meeting Lines

The pattern consist of two candlesticks (bullish and bearish) with equal (or very close) close prices. The body of two candlesticks must be greater than average body length.

The "Bearish Meeting Lines" pattern indicates the reversal of a downward trend.

Figure 2. "Bearish Meeting Lines" pattern

Figure 2. "Bearish Meeting Lines" pattern

The recognition of "Bearish Meeting Lines" pattern is implemented in CheckPatternBearishMeetingLines() method of CCandlePattern class:

//+--------------------------------------------------------------------+
//| Checks formation of "Bearish Meeting Lines" candlestick pattern    |
//+--------------------------------------------------------------------+
bool CCandlePattern::CheckPatternBearishMeetingLines()
  {
//--- Bearish Meeting Lines
   if((Close(2)-Open(2)>AvgBody(1))             && // long white
     ((Open(1)-Close(1))>AvgBody(1))            && // long black
      (MathAbs(Close(1)-Close(2))<0.1*AvgBody(1)))  // doji close
      return(true);
//---
   return(false);
  }

The CheckCandlestickPattern(CANDLE_PATTERN_BEARISH_MEETING_LINES) method of CCandlePattern class is used to check formation of "Bearish Meeting Lines" candlestick pattern.


2. Trade signals, confirmed by Stochastic indicator

The trading signals to open long or short position must be confirmed by Stochastic oscillator. The signal %D line must be greater/lower then corresponding critical level (30 or 70).

The closing of opened position depends on the values of %D indicator. It can be done in 2 cases:

  1. if %D line has reached the opposite critical level (80 for long position and 20 for short position)
  2. if the reverse signal isn't confirmed (when %D line reaches the following levels: 20 for long position and 80 for short position)

Fig. 3. "Bearish Meeting Lines" pattern, confirmed by Stochastic indicator

Fig. 3. "Bearish Meeting Lines pattern, confirmed by Stochastic indicator

  • int CML_Stoch::LongCondition() - checks conditions to open long position (returns 80) and close of the short position (returns 40);
  • int CML_Stoch::ShortCondition() - checks conditions to open short position (returns 80) and close of the long position (returns 40).

2.1. Open long position/Close short position

  1. The formation of "Bullish Meeting Lines" pattern must be confirmed by Stochastic indicator: StochSignal(1)<30 (the value of the signal line of Stochastic indicator of the last completed bar must be less than 30).

  2. The short position must be closed if the signal line of Stochastic indicator has crossed upward the 20 or 80 levels.

//+------------------------------------------------------------------+
//| 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 CML_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 Bullish Meeting Lines pattern and signal line<30
  if (CheckCandlestickPattern(CANDLE_PATTERN_BULLISH_MEETING_LINES) && (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. Open short position/Close long position

  1. The formation of "Bearish Meeting Lines" pattern must be confirmed by Stochastic indicator: StochSignal(1)>70 (the value of the signal line of Stochastic indicator of the last completed bar must be greater than 70).

  2. The long position must be closed if the signal line of Stochastic indicator has crossed downward the 80 or 20 levels.

//+------------------------------------------------------------------+
//| 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 CML_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 Bearish Meeting Lines pattern and signal line>70
  if (CheckCandlestickPattern(CANDLE_PATTERN_BEARISH_MEETING_LINES) && (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. Creating Expert Advisor using MQL5 Wizard

The CML_Stoch class isn't included in the Standard Library classes, to use it, it's necessary to download the acml_stoch.mqh file (see attachments) and save it to the client_terminal_data\folder\MQL5\Include\Expert\Signal\MySignals. The same should be done with the candlepatterns.mqh file. You can use it in MQL5 Wizard after restart of the MetaEditor.

To create an Expert Advisor launch MQL5 Wizard:

Fig. 4. Creating Expert Advisor using MQL5 Wizard

Fig. 4. Creating Expert Advisor using MQL5 Wizard

Let's specify the name of the Expert Advisor:

Fig. 5. General properties of the Expert Advisor

Fig. 5. General properties of the Expert Advisor

After that we need to select the modules of trade signals used.

Fig. 6. Signal properties of the Expert Advisor

Fig. 6. Signal properties of the Expert Advisor

In our case we use only one module of trade signals.

Adding the "Signals based on Bullish/Bearish Meeting Lines confirmed by Stochastic" module of trading signals:

Fig. 7. Signal properties of the Expert Advisor

Fig. 7. Signal properties of the Expert Advisor

Module of trade signals added:

Fig. 8. Signal properties of the Expert Advisor

Fig. 8. Signal properties of the Expert Advisor

You can select any trailing properties, but we will use "Trailing Stop not used":

Fig. 9. Trailing properties of the Expert Advisor

Fig. 9. Trailing properties of the Expert Advisor

Concerning the money management properties, we will use "Trading with fixed trade volume":

Fig. 10. Money management properties of the Expert Advisor

Fig. 10. Money management properties of the Expert Advisor

By pressing the "Finish" button, we will get the code of the generated Expert Advisor, located in Expert_AML_Stoch.mq5, it will be saved in terminal_data_folder\MQL5\Experts\.

The default input parameters of the generated Expert Advisor:

//--- 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)

must be replaced to:

//--- 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)

The Signal_ThresholdOpen/Signal_ThresholdClose input parameters allow to specify threshold levels for open and close of positions.

In code of the LongCondition() and ShortCondition() methods of the trade signals class we have specified the fixed values of the threshold:

  • Open position: 80;
  • Close position: 40.

The Expert Advisor, generated by MQL5 Wizard open and close position using the "votes" from the modules of trade signals. The vote of the main module (as container, it consist of all the modules added) is also used, but its LongCondition() and ShortCondition() methods always return 0.

The vote results of the main module is also used in "votes" averaging. In our case we have:  main module + 1 module of trade signals, so we need to take this fact into account when setting of the threshold values. Because of this fact the ThresholdOpen and ThresholdClose must be set as 40=(0+80)/2 and 20=(0+40)/2.

The values of  Signal_StopLevel and Signal_TakeLevel input parameters is set to 0, it means that closing of the positions will be done only when closing conditions will be true.


2.4. History backtesting results

Let's consider backtesting of the Expert Advisor on historical data (EURUSD H1, testing period: 2005.01.01-2010.03.16, PeriodK=6, PeriodD=3, PeriodSlow=36, MA_period=3).

In creation of Expert Advisor we used the fixed volume (Trading Fixed Lot, 0.1), Trailing Stop algorithm is not used (Trailing not used).

Fig. 11. Testing results of the Expert Advisor, based on Bullish/Bearish Meeting Lines + Stochastic"

Fig. 11. Testing results of the Expert Advisor, based on Bullish/Bearish Meeting Lines + Stochastic"


The best set of input parameters can be found using the Strategy Tester of MetaTrader 5 client terminal.

The code of the Expert Advisor, created by MQL5 Wizard is attached in expert_aml_stoch.mq5.


Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/318

MQL5 Wizard - Trade Signals Based on Hammer/Hanging Man + RSI MQL5 Wizard - Trade Signals Based on Hammer/Hanging Man + RSI

Trade signals based on "Hammer/Hanging Man" candlestick pattern, confirmed by Relative Strength Index (RSI) indicator is considered. The code of the Expert Advisor based on this strategy can be generated automatically using the MQL5 Wizard.

MQL5 Wizard - Trade Signals Based on Hammer/Hanging Man + MFI MQL5 Wizard - Trade Signals Based on Hammer/Hanging Man + MFI

Trade signals based on "Hammer/Hanging Man" candlestick pattern, confirmed by Market Facilitation Index (MFI) indicator is considered. The code of the Expert Advisor based on this strategy can be generated automatically using the MQL5 Wizard.

MQL5 Wizard - Trade Signals Based on Bullish/Bearish Meeting Lines + CCI MQL5 Wizard - Trade Signals Based on Bullish/Bearish Meeting Lines + CCI

Trade signals based on "Bullish/Bearish Meeting Lines" candlestick pattern, confirmed by Commodity Channel Index (CCI) indicator is considered. The code of the Expert Advisor based on this strategy can be generated automatically using the MQL5 Wizard.

MQL5 Wizard - Trade Signals Based on Bullish/Bearish Meeting Lines + MFI MQL5 Wizard - Trade Signals Based on Bullish/Bearish Meeting Lines + MFI

Trade signals based on "Bullish/Bearish Meeting Lines" candlestick pattern, confirmed by Market Facilitation Index (MFI) indicator is considered. The code of the Expert Advisor based on this strategy can be generated automatically using the MQL5 Wizard.