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

MQL5 Wizard - Candlestick Pattern Class - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 6 reads | 0 comments |

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 the CCandlePattern class, which allows to simplify the creation of the candlestick pattern trading signal class of the MQL5 Wizard.

CCandlePattern class

Class CCandlePattern: Folk Expert Signal { protected :
//--- indicator CiMA m_MA;
//--- time series CiOpen m_open;
  CiHigh m_high;
  CiLow m_low;
  CiClose m_close;
//--- Input parameter integer m_ma_period; people : //--- Constructor CCandlePattern();
//--- Input parameter setting method is blank MAP period ( integer period) { m_ma_period=period; } 
//--- Initialization method virtual boolean ValidationSet();
Virtual boolean InitIndicators(CIndicators *indicators);

//--- Check the formation of a specific candlestick pattern boolean CheckCandlestickPattern(ENUM_CANDLE_PATTERNS CandlePattern);
//--- Check the formation of bullish/bearish candlestick patterns Boolean CheckPatternAllBullish();
Boolean CheckPatternAllBearish(); protected :
//--- Initialization Boolean values ​​for indicators and time series InitMA(CIndicators *indicators);
Boolean InitOpen(CIndicators *indicators);
Boolean InitHigh(CIndicators *indicators);
Boolean InitLow(CIndicators *indicators);
Boolean InitClose(CIndicators *indicators);
//--- Method for candlestick checking double the average body size ( integer industry);
Double MA ( integer industrial) constant { return (m_MA.Main(ind)); }
double open( integer ind) const { return (m_open.GetData(ind)); }
double high ( integer industrial) constant { return (m_high.GetData(ind)); }
double low ( integer industrial) constant { return (m_low.GetData(ind)); }
double close ( integer ind) const { return (m_close.GetData(ind)); }
double closing average( IntegerIndustrial ) const { return (MA(Industrial));}
double midpoint ( integer ind) const { returns ( 0.5 * (high(ind) + low(ind))); }
Double mid open close ( integer industry) constant { return ( 0.5 *(open(ind)+close(ind)))); }
//--- Method to check a certain candlestick model Boolean value CheckPatternThreeBlackCrows();
Boolean CheckPatternThreeWhiteSoldiers();
Boolean CheckPatternDarkCloudCover();
Boolean CheckPatternPiercingLine();
Boolean CheckPatternMorningDoji();
Boolean CheckPatternEveningDoji();
Boolean CheckPatternBearishEngulfing();
Boolean CheckPatternBullishEngulfing();
Boolean CheckPatternEveningStar();
Boolean CheckPatternMorningStar();
boolean checkModeHammer();
Boolean CheckPatternHangingMan(); Boolean valueCheckPatternBearishHarami (); Boolean valueCheckPatternBullishHarami (); Boolean valueCheckPatternBearishMeetingLines (); Boolean valueCheckPatternBullishMeetingLines (); };


Using CCandlePattern in the Trading Signals class of the MQL5 Wizard

The CCandlePattern class can be used as a parent class for the trading signals class of the MQL5 Wizard. It was necessary to derive the trading signals class from the CCandlePattern class and also to add methods for checking long/short opening/closing (in addition to indicators, etc.).

The formation of a reversal candlestick pattern can be used as a trading signal, but it is better to check for confirmation (for example, using an oscillator).

Take a look at this line:

 //|Parameter=MAPeriod,int,12 |

in the wizard description section.

The MAPeriod method is used in the CCandlePattern parent class to calculate the average closing price and the average of the candle body. By default, m_ma_period=12 is set in the CCandlePattern() class constructor. However, it is better to set it using input parameters so that you can use it in the strategy tester MetaTrader 5.

Don’t forget to call ValidationSettings() and InitIndicators() of the parent class

Note that the CCandlePattern::ValidationSettings and CCandlePattern::InitIndicators methods of the parent class need to be called in the corresponding class method.

It's better to call these methods first:

 Boolean CSampleCandleSignal::ValidationSettings()
  { //--- Call the ValidationSettings of the parent CCandlePattern class if (!CCandlePattern::ValidationSettings()) returns ( wrong ); //--- your code
.. // - - OK return ( true );
  }

The same goes for the InitIndicators() method:

 Boolean value CSampleCandleSignal::InitIndicators(CIndicators *indicators)
  { //--- Call the InitIndicators of the parent CCandlePattern class if (!CCandlePattern::InitIndicators(indicators)) returns ( false ); //--- your code ... // - - good returns ( true );
  }


Check candlestick patterns

To check the formation of a certain candlestick pattern, call the CheckCandlestickPattern(ENUM_CANDLE_PATTERNS CandlePattern) method and pass the pattern to the function.

You can also check the formation of one of the bullish/bearish candlestick patterns using the CheckPatternAllBullish() and CheckPatternAllBearish() methods.

To simplify working with candlestick patterns, use the ENUM_CANDLE_PATTERNS enumeration:

 Enumeration ENUM_CANDLE_PATTERNS // List of candlestick patterns {
  CANDLE_PATTERN_THREE_BLACK_CROWS = 1 ,
  CANDLE_PATTERN_THREE_WHITE_SOLDIERS = 2 ,
  CANDLE_PATTERN_DARK_CLOUD_COVER = 3 ,
  CANDLE_PATTERN_PIERCING_LINE = 4 ,
  CANDLE_PATTERN_MORNING_DOJI = 5 ,
  CANDLE_PATTERN_EVENING_DOJI = 6 ,
  CANDLE_PATTERN_BEARISH_ENGULFING = 7 ,
  CANDLE_PATTERN_BULLISH_ENGULFING = 8 ,
  CANDLE_PATTERN_EVENING_STAR = 9 ,
  CANDLE_PATTERN_MORNING_STAR = 10 ,
  CANDLE_PATTERN_HAMMER = 11 ,
  CANDLE_PATTERN_HANGING_MAN = 12 ,
  CANDLE_PATTERN_BEARISH_HRAMI = 13 ,
  CANDLE_PATTERN_BULLISH_HARAMI = 14 ,
  CANDLE_PATTERN_BEARISH_MEETING_LINES = 15 ,
  CANDLE_PATTERN_BULLISH_MEETING_LINES = 16 };

Check Bullish Candlestick Patterns:

///--- Check for the formation of the "3 White Soldiers" pattern: Check for the formation of the "Piercing Line" pattern: Check for the formation of the "Piercing Line" pattern : Check for the formation of the "Morning Doji" pattern: Check for the formation of the "Morning Doji" pattern : Check for the formation of the "Piercing Line" pattern (CANDLE_PATTERN_MORNING_DOJI) ///---Check for the formation of a "Bullish Engulfing" pattern : Check for the formation of a "Bullish Engulfing" pattern: Check for the formation of a "Bullish Engulfing" pattern : Check for the formation of a "Bullish Engulfing" pattern: Check for the formation of a "Bullish Engulfing" pattern: Check for the formation of a "Morning Star" pattern: Check for the formation of a "Bullish Harami" pattern (CANDLE_PATTERN_MORNING_STAR) /// --- Check for the formation of a "Bullish Converging Lines" pattern: Check for the formation of a "Bullish Converging Lines" pattern: Check for the formation of a "Hammer" pattern : Check for the formation of a "Hammer" pattern: CheckPatternAllBullish();

Check Bearish Candlestick Patterns:

 ///--- Check the formation of the "3 Black Crows" pattern: Check the formation of the Candlestick Pattern (CANDLE_PATTERN_THREE_BLACK_CROWS) /// --- Check the formation of the "Dark Clouds" pattern: Check the formation of the "Evening Doji" pattern: Check the formation of the "Evening Doji" pattern: Check for the Candlestick Pattern (CANDLE_PATTERN_EVENING_DOJI) ///--- Check for the formation of the "Bearish Engulfing" pattern: Check for the formation of the Candlestick Pattern (CANDLE_PATTERN_BEARISH_ENGULFING) ///--- Check for the formation of the "Evening Star" pattern: Check for Candlestick Pattern (CANDLE_PATTERN_EVENING_STAR) ///--- Check for the formation of the "Hanging Man" pattern: Check for the formation of the "Bearish Convergence Line" pattern: Check for the formation of the "Bearish Convergence Line" pattern: Check for the formation of the "Bearish Convergence Line" pattern: Check for Candlestick Patterns (CANDLE_PATTERN_BEARISH_MEETING_LINES) /// --- Check for the formation of one of the bearish patterns CheckPatternAllBearish();

Here are examples of usage of these methods:

1. Open a long position

 //+------------------------------------------------------------------+
//|Check the status of long positions |
//+------------------------------------------------------------------+
Boolean CSampleCandleSignal::CheckOpenLong( double &price, double &sl, double &tp, datetime &expiry)
  { //--- Check the conditions for opening a long position
//--- In addition to indicator checking, it is better to use this code
 //--- For example, let's check the formation of the "3 White Soldiers" pattern: if checking candlestick patterns (CANDLE_PATTERN_THREE_WHITE_SOLDIERS) returns ( true ): //--- no signal returns ( false );
  }

2. Long position closing

//------------------------------------------------------------------------------------------------+
//|Check long position closing status|
//+------------------------------------------------------------------+
boolean CSampleCandleSignal::CheckCloseLong( double &price)
  { //--- Check closing conditions
//--- For example, let us check the formation of one of the bearish patterns: if CheckPatternAllBearish() returns ( true ): //--- no signal returns ( false );
  }

3. Open a short position

 //------------------------------------------------------------------------------------------------+
//|Check the status of short positions |
//+------------------------------------------------------------------+
Boolean CSampleCandleSignal::CheckOpenShort( double &price, double &sl, double &tp, datetime &expiry)
  { //--- Check the conditions for opening a short position
//--- In addition to indicator checking, it is better to use this code
 //--- For example, let's check the formation of the "3 Black Crows" pattern: if checking candlestick patterns (CANDLE_PATTERN_THREE_BLACK_CROWS) returns ( true ): //--- no signal returns ( false );
  }

4. Close position

 //------------------------------------------------------------------------------------------------+
//|Check short position closing status|
//+------------------------------------------------------------------+
boolean CSampleCandleSignal::CheckCloseShort( double &price)
  { //--- Check closing conditions
//--- In addition to indicator checking, it is better to use this code //--- For example, let's check the formation of one of the bullish patterns: If CheckPatternAllBullish() returns ( true ): //--- No signal returns ( false );
  }

suggestion

To reduce false signals, reversal candlestick patterns must be confirmed by other indicators, such as oscillators.

The book "Strategies for Best Traders" considers the following patterns:

Confirmer Stochastic , CCI , MFI and Relative Strength Index oscillators.

Later we will provide categories of trading signals for use in the MQL5 Wizard.


Attachment download

📎 candlepatterns.mqh (24.31 KB)

Source: MQL5 #291

MQL5 Wizard - Candlestick Pattern Class - Important points before using the MetaTrader 5 library

This page has been supplemented with structured instructions, focusing on the purpose of EA source code, MQL4/MQL5 platform compatibility, testing process and risk control. Before downloading or deploying, it is recommended to first determine whether it is consistent with your own variety, cycle and account environment.

Suitable for who to use

  • Users who want to quickly screen EA source code and are willing to do simulation disk verification first.
  • People who need to compare MT4/MT5 EAs, indicators, scripts or source code projects.
  • Traders who wish to record backtests, parameters and risk boundaries before placing a trade.

Testing and risk control suggestions

  • First verify the default parameters in the strategy tester or demo account, and then adjust the symbol, period, spread and trading period one by one.
  • Scalping, grid, martin, and high-frequency strategies should focus on observing maximum drawdowns, consecutive losses, slippage, and trading frequency.
  • It is not recommended to run any document directly on the real disk. At least observe the simulated disk performance for 2-4 weeks first.

FAQ

Can MT4 and MT5 be used interchangeably?
Usually cannot be used directly. EX4/MQ4 corresponds to MT4, EX5/MQ5 corresponds to MT5, and the source code needs to be compiled in the corresponding MetaEditor.

Is this resource guaranteed to be profitable?
cannot. EAs, indicators and scripts can only be used as trading tools, and the results depend on parameters, market environment, spreads, slippage and risk control.

What else can I continue to watch?
Forex EA download , foreign exchange indicator download , EA evaluation , MQL5 CodeBase .

English Search Notes

This page is also optimized for English search intent around MQL5 Wizard - Candlestick Pattern Class - MetaTrader 5 Library . Related search terms include: MQL4 source code, MQL5 source code. Test any Forex EA, Expert Advisor, MT4/MT5 indicator, script or MQL source code with historical data and a demo account before live trading.

Verification code Refresh