Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

MQL5 Wizard - Trading Signals Based on Bullish/Bearish Convergence Lines + Stochastic - MetaTrader 5 Expert

author EAcpu | 2 reads | 0 comments |

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

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

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

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

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

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

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

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

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

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

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

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

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

There is the book "Strategies of the Best Traders " (in Russian), where many trading strategies are considered, we will focus on reversal candlestick patterns, represented by Stochastic , CCI , Micro Institutions and RSI oscillators.

The best way is to create a separate class derived from Expert Signal for checking the formation of candlestick patterns. For the confirmation of trading signals generated by candlestick patterns, it is enough to write a class derived from CCandlePattern and add in it the necessary functionality (for example, confirmation by oscillator).

Here we will consider signals based on the "Bull/Bear Convergence Line" reversal candlestick pattern, powered by the Stochastic indicator. The trading signals module is based on the CC candle pattern class, which is a simple example of creating trading signals using candlestick patterns.

1. “Convergence Line” Reversal Candlestick Pattern

1.1. Bullish Convergence Line

This pattern consists of two candlesticks (bearish and bullish) with equal (or very close) closing prices. The bodies of both candlesticks must be larger than the average body length.

The “Bullish Convergence Line” pattern indicates a reversal of the downtrend.

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

Figure 1. “Bullish Convergence Line” Pattern

The identification of "Bullish Meeting Lines" patterns is implemented in the CheckPatternCheckPatternBullishMeetingLines() method of the CC candle pattern class:

 //+------------------------------------------------------------------------------------------------+
//| Check the Formation of Bullish Convergence Lines " Candlestick Patterns |            
//+------------------------------------------------------------------------------------------------+
Boolean valueCCandlePattern ::CheckPatternBullishMeetingLines()
  { //--- bullish confluence line if ((open( 2 )-close( 2 ))>average body( 1 )) && // long black ((close( 1 )-open( 1 )))>average body( 1 )) && // long white ( mathematical antibody (close( 1 )-close( 2 ))< 0.1 * average body( 1 ))) // doji close return ( true ); //--- return ( error );
  }

CheckCandlestickPattern(CANDLE_PATTERN_BULLISH_MEETING_LINES) method CC Candlestick Pattern class is used to check the formation of "Bullish Convergence Lines" candlestick pattern.

1.1. Bearish Convergence Line

This pattern consists of two candlesticks (bullish and bearish) with equal (or very close) closing prices. The bodies of both candlesticks must be larger than the average body length.

The “Bearish Convergence Line” pattern indicates a reversal in the downtrend.

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

Figure 2. “Bearish Convergence Line” Pattern

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

//+------------------------------------------------------------------------------------------------+
//| Check the formation of " Bearish Convergence Line " candlestick patterns | //+------------------------------------------------------------------------------------------------+
BooleanCCandlePattern ::CheckPatternBearishMeetingLines()
  { //--- bearish confluence line if ((close( 2 )-open( 2 ))>average body( 1 )) && // long white ((open( 1 )-close( 1 )))>average body( 1 )) && // long black ( math antibody (close( 1 )-close( 2 ))< 0.1 * average body( 1 ))) // doji close return ( true ); //--- return ( error );
  }

CheckCandlestickPattern(CANDLE_PATTERN_BEARISH_MEETING_LINES) method CC Candlestick Pattern class is used to check the formation of "Bearish Convergence Lines" candlestick pattern.

2. Trading signals, confirmed by stochastic indicator

The closing of an open position depends on the value of the %D indicator. This can be done in two situations:

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

Figure 3. “Bearish Convergence Line Pattern, Confirmed by Stochastics

2.1. Open long position/close short position

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

If the signal line Stochastic has crossed the 20 or 80 levels upwards.

 //+------------------------------------------------------------------+
//|Check the conditions for entering and exiting the market |
//| 1) Enter the market (open long position, result = 80) |
//| 2) Market Exit (Close Position, Result=40) |
//+------------------------------------------------------------------+
Integer CML_Stoch::LongCondition()
  {
Integer result = 0 ; //--- idx can be used to determine the Expert Advisor working mode
//--- idx=0 - in this case the EA checks the trading conditions on every price move
//--- idx=1 - in this case the EA only checks the trading status of the news bar integer idx =StartIndex(); //--- checks the conditions for opening a long position
//--- Form Bullish Convergence Line Pattern and Signal Line < 30 if (CheckCandlestickPattern(CANDLE_PATTERN_BULLISH_MEETING_LINES) && (StochSignal( 1 ) < 30 ))
    Result = 80 ; //--- check closing conditions
//--- Signal line crossover for overbought/oversold levels (down 20, up 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

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

If the signal line Stochastic has crossed below the 80 or 20 levels.

 //+------------------------------------------------------------------+
//|Check the conditions for entering and exiting the market |
//| 1) Enter the market (short position, result=80) |
//| 2) Market Exit (Close Position, Result=40) |
//+------------------------------------------------------------------+
Integer CML_Stoch::ShortCondition()
  {
Integer result = 0 ; //--- idx can be used to determine the Expert Advisor working mode
//--- idx=0 - in this case the EA checks the trading conditions on every price move
//--- idx=1 - in this case the EA only checks the trading status of the news bar integer idx =StartIndex(); //--- checks the conditions for opening a short position
//--- Form a Bearish Convergence Line Pattern and Signal Line > 70 if (CheckCandlestickPattern(CANDLE_PATTERN_BEARISH_MEETING_LINES) && (StochSignal( 1 ) > 70 ))
    result = 80 ; //--- Check closing conditions
//--- Signal line crossover for overbought/oversold levels (80 down, 20 up) if ((((StochSignal( 1 ) < 80 ) && (StochSignal( 2 ) > 80 )) ||
      ((StochSignal( 1 )< 20 ) && (StochSignal( 2 )> 20 ))))
    result = 40 ; //--- return result return (result);
  }


2.3. Use the MQL5 Wizard to create an Expert Advisor

The CML_Stoch class is not included in the standard library classes, to use it you need to download the acml_stoch.mqh file (see attachment) and save it to client_terminal_data\folder\MQL5\Include\Expert\Signal\MySignals. The same operation should be performed for the candlepatterns.mqh file. After restarting MetaEditor, you can use it in the MQL5 Wizard.

Create Expert Advisor Launch MQL5 Wizard :

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

Figure 4. Creating an Expert Advisor using the MQL5 Wizard

Let's specify the name of the Expert Advisor:

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

Figure 5. General properties of EA trading

After that we need to choose the trading signal module to use.

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

Figure 6. Signal properties of EA trading

In our case we use only one trading signals module.

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

Figure 7. Signal properties of EA trading

Added trading signals module:

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

Figure 8. Signal properties of EA trading

You can choose any trailing attribute, but we will use "Unused Trailing Stop":

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

Figure 9. Tracking properties of Expert Advisor

Regarding the money management properties, we will use "Fixed Volume Trading":

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

Figure 10. Money management attributes of EA trading

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

Default input parameters of the generated Expert Advisor:

 //--- Main signal input
Input integer Signal_ThresholdOpen = 10 ; //Open signal threshold[0...100]
Input integer Signal_ThresholdClose = 10 ; // Close signal threshold [0...100]
Enter double Signal_PriceLevel = 0.0 ; // price level at which to execute the trade
Enter double Signal_StopLevel = 50.0 ; // Stop loss level in pips
Enter double Signal_TakeLevel = 50.0 ; // Take profit level (in pips)

Must be replaced with:

 //--- Main signal input
Input integer Signal_ThresholdOpen = 40 ; //Open signal threshold[0...100]
Input integer Signal_ThresholdClose = 20 ; // Close signal threshold [0...100]
Enter double Signal_PriceLevel = 0.0 ; // price level at which to execute the trade
Enter double Signal_StopLevel = 0.0 ; // Stop loss level in points
Enter double Signal_TakeLevel = 0.0 ; // Take profit level (in pips)

Signal_ThresholdOpen/Signal_ThresholdClose input parameters allow specifying threshold levels for opening and closing positions.

In the code of the LongCondition() and ShortCondition() methods of the trading signal class, we specify the fixed value of the threshold:

The Expert Advisor generates opening and closing positions by the MQL5 Wizard using "votes" in the Trading Signals module. The vote of the main module (which acts as a container and consists of all added modules) is also used, but its LongCondition() and ShortCondition() methods always return 0.

The voting results from the main module are also used for "voting" averaging. In our case we have: main module + 1 trading signals module, so we need to take this fact into account when setting the thresholds. Therefore, ThresholdOpen and ThresholdClose must be set to 40=(0+80)/2 and 20=(0+40)/2.

The value of the Signal_StopLevel and Signal_TakeLevel input parameters is set to 0, which means that the position will be closed only if the closing conditions are met.

2.4. Historical backtest results

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

When creating the EA, we used a fixed trading volume ( fixed lot size for trading , 0.1) and did not use the trailing stop algorithm ( trailing was not used ).

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

Figure 11. EA trading test results based on bullish/bearish confluence line + stochastic indicator

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

The EA trading code created by the MQL5 Wizard is attached in Expert_aml_stoch.mq5 .


Attachment download

📎 acandlepatterns.mqh (20.34 KB)

📎acml_stoch.mqh (8.48 KB)

📎 expert_aml_stoch.mq5 (7.16 KB)

Source: MQL5 #318

Verification code Refresh