Merrill patterns

2 October 2019, 13:26
Alexander Fedosov
32 397



The first attempt to create a system of price patterns was made by Robert Levy in 1971. He applied five-point price fluctuation patterns and then checked if they had any significance. He did not achieve any notable results, but Arthur Merrill continued his work 10 years later. 

He divided the patterns into two categories resembling M and W letters. Each category contains 16 patterns and its own subcategories. Merrill highlighted 6 subcategories:

  • Uptrend
  • Downtrend
  • Triangle
  • Expansion
  • Head and shoulders
  • Inverted head and shoulders

We are going to define the current relevance of the Merrill patterns using the application for testing them. Besides, it would be interesting to apply this model to various types of data — such as Close, High and Low price, as well as oscillators.

Definition and application

In order to clarify how and for what data we are going to apply Merrill patterns, we need to understand what they actually are. The main two categories are the patterns resembling the letters M and W. They are called M and W patterns. Each of the categories contains 16 patterns.

Fig. 1 represents 16 M patterns. As we can see, the difference is in the mutual arrangement of the five points that make up the pattern.  

Fig. 1. Visual representation of М patterns

Fig. 2 displays 16 W patterns. We will search for these two groups on price charts and indicators, as well as study, evaluate and look for possible regularities.

Fig. 2. Visual representation of W patterns

The idea behind any pattern boils down to the fact that when a particular formation appears, we can expect the price moving in a certain direction and make profit from that.

To make it as clear as possible in what area and how Merrill patterns are to be studied, here are a few examples. Fig. 3 displays a usual linear USDCAD H1 price chart. This type of representation is used not so frequently, because candles and bars have become more popular.

Fig. 3. Linear USDCAD H1 chart based on Close prices

Here we can already see a few patterns described above. This is to be the first area of study — applying to the linear chart based on Close prices. Also, we are going to check linear charts based on Open, High and Low prices. 

The second area of study is to be consisted of oscillators, such as:

The method I have suggested in the article Studying candlestick analysis techniques (Part I): Checking existing patterns is to be used as a method of evaluating patterns to be applied both to the price and to the oscillators mentioned above. The idea behind it is simple:

  • Identifying the analyzed pattern on a specified sample section.
  • Analyzing the price movement after identification.
  • Collecting the data and calculating the pattern efficiency.

Developing the testing tool

Before starting the development, we need to define what settings it should contain. The tool is to consist of the panel with Analysis and Settings tabs. The parameters from the EA settings window are to be used as well. Totally, we are to have three sections featuring tools for working with patterns. Now let's describe the settings in each of the sections.

The Analysis tab contains:

  1. Two sets of buttons for selecting the types of tested patterns. There are also the All M and All W buttons for quick selection/deselection of М and W patterns.
  2. The set of buttons for selecting tested timeframes and the ALL button for selecting/deselecting the entire button group.
  3. The "Trend threshold (points)" input field. This is a profit in points the price should reach within a maximum of three candles after an analyzed Merrill pattern is identified.
  4. The button opening the dialog window for selecting Start and End dates, as well as the test time. 
  5. The input field with the checkbox and the button is a filter for finding necessary trading symbols. It has one preset — Major. It displays major currency pairs. The check box disables the filter and shows all available trading symbols.
  6. Trading symbols selected in the table with the filter. After selecting them from the list, the pattern analysis is performed.
  7. The result table consisting of seven columns: 
    • Figure name. The column displays a name of an analyzed Merrill pattern, for example, M10 or W12.
    • Found. Number of detected patterns of a specified type on a selected sample.
    • Timeframe. A timeframe a specified pattern was analyzed on.
    • P, Uptrend. A probability the price moves upwards by the "Trend threshold (points)" value after a pattern appears.
    • P, Dntrend. A probability the price moves downwards by the "Trend threshold (points)" value after a pattern appears.
    • K, UpTrend/K, DnTrend. This is a ratio described in my article Studying candlestick analysis techniques (Part I): Checking existing patterns. It evaluates how quickly the price reaches a specified profit after an analyzed pattern appears in the upward or downward direction of a trend.

Fig. 4 provides a visual implementation of all symbols and parameters described above.

Fig. 4. Analysis tab

Now let's consider the Settings tab:

  1. Used indicator. Select an indicator the search and analysis of Merrill patterns is to be applied to.
  2. Weighting coefficients are used when calculating K, UpTrend/DnTrend ratios described above. 
  3. Interface language. The drop-down list of selecting the interface language: English or Russian.

The tab appearance with the settings is displayed on Fig. 5 below:

Fig. 5. Settings tab

The last section applies the "EA settings" window (F7 hotkey) and features the settings of applied indicators listed in "Used indicator." Fig. 6 displays the window of the settings last section.

Fig. 6. Settings window of used indicators

We should consider the following nuances when defining the settings in the window:

  • The first one ("Applied price") applies the ENUM_APPLIED_PRICE enumeration type variable having seven values: Open price, Close price, High price and Low price, as well as median, typical and weighted average prices. When performing an analysis based on a chart price, the first four values should be used because the last three ones are designed for calculating indicators.
  • If you want to use indicators in analyzing patterns, the "Applied price" setting affects the indicators using the ENUM_APPLIED_PRICE type variable in their calculations, namely: ATR, CCI and RSI.

Now let's consider the implementation of the app interface, as well as the methods of searching and analyzing the Merrill patterns.

To develop the GUI, we use the CreateGUI() method consisting of the CreateWindow() methods creating the interface main window and the CreateWindowSetting1() dialog window for selecting a time range for studying.

//| Create the program GUI                                           |
bool CProgram::CreateGUI(void)
//--- Create the panel
   if(!CreateWindow("Merrill Patterns"))
//--- Create the dialog window
   if(!CreateWindowSetting1("Setting dates"))
//--- Complete GUI creation

Now let's see what each method consists of. We will focus our attention on the interface main window first. It consists of the implementation of the Analysis tab made of the elements described in Fig. 4.

//| Analyze tab                                                      |
//--- Create the pattern set buttons
//--- Timeframe header
//--- Create the timeframe set buttons
//--- Field for searching the symbol filter 
//--- Create the button for selecting a date range
//--- Create the field for entering the profit threshold value
//--- Create the symbol table
//--- Create the result table

And of the Settings tab described in Fig. 5.

//| Settings tab                                                     |
//--- Text labels
//--- Input fields
//--- Status bar

More detailed implementation of each of the applied methods adding interface elements can be found in the attached source codes.

The method implementing the dialog window for setting a temporary sampling looks as follows:

//| Create the dialog window for selecting the range of dates in the Analysis tab   |
bool CProgram::CreateWindowSetting1(const string caption_text)
//--- Add the window pointer to the window array
//--- Coordinates
   int x=m_request3.X();
   int y=m_request3.Y()+m_request3.YSize();
//--- Properties

//--- Create the form

Now let's turn our attention to the methods of searching, studying and evaluating the patterns. To achieve this, we need to track the entire sequence of the algorithm actions. First, have a look at the MerrillPatterns.mq5 file where this algorithm starts.

//--- Include the application class
#include "Program.mqh"
CProgram program;
//| EA inputs                                                        |
input ENUM_APPLIED_PRICE   Inp_Price1              =  PRICE_CLOSE;   // Applied price
input int                  Inp_ATR_Peroid          =  5;             // ATR Period
input int                  Inp_CCI_Peroid          =  5;             // CCI Period
input int                  Inp_DeM_Peroid          =  5;             // DeMarker Period
input int                  Inp_ForcePeriod         =  13;            // ForceIndex Period
input ENUM_MA_METHOD       Inp_ForceMAMethod       =  MODE_SMA;      // ForceIndex MA method
input ENUM_APPLIED_PRICE   Inp_ForceAppliedPrice   =  PRICE_CLOSE;   // ForceIndex Applied price
input ENUM_APPLIED_VOLUME  Inp_ForceAppliedVolume  =  VOLUME_TICK;   // ForceIndex Volumes
input int                  Inp_WPR_Period          =  5;             // WPR Period
input int                  Inp_RSI_Period          =  5;             // RSI Period
//| Expert initialization function                                   |
int OnInit(void)
//--- Set the trading panel
      ::Print(__FUNCTION__," > Failed to create GUI!");

Apart from the indicator inputs, the search for a graphical shell is performed in the OnInit() section followed by initializing the data set in the Properties window. All methods pass the external settings to the internal variables.

   void              InitializePrice(ENUM_APPLIED_PRICE price)    { m_applied_price=price;        }
   void              InitializeATR(int period)                    { m_atr_period=period;          }
   void              InitializeCCI(int period)                    { m_cci_period=period;          }
   void              InitializeDeM(int period)                    { m_dem_period=period;          }
   void              InitializeWPR(int period)                    { m_wpr_period=period;          }
   void              InitializeRSI(int period)                    { m_rsi_period=period;          }
//|                                                                  |
void CProgram::InitializeForce(int period,ENUM_MA_METHOD ma_method,ENUM_APPLIED_PRICE price,ENUM_APPLIED_VOLUME volume)

After that, the application is ready to be used, while the remaining settings are passed to the created GUI. I have already mentioned that launching the calculation is performed by choosing a currency symbol from the symbol table (pos. 6 in Fig. 4). It is also performed after setting the "Trend threshold" (pos. 3 in Fig. 4). Both events launch the ChangeSymbol1() method to start collecting detected data to prepare it for analysis.

//| Select a symbol in the Analysis tab                              |
bool CProgram::ChangeSymbol1(const long id)
//--- Check the element ID
//--- Exit if the string is not highlighted
      //--- Show full description of a symbol in the status bar
      m_status_bar.SetValue(0,"Symbol for analysis not selected");
//--- Get a selected symbol
   string symbol=m_symb_table1.GetValue(0,m_symb_table1.SelectedItem());
//--- Show the full symbol description in the status bar
   string val=(m_lang_index==0)?"Выбранный символ: ":"Selected symbol: ";

The essence of its work is to define a selected trading symbol from the symbol table and pass its value to the status bar and the GetResult() method. Let's consider the method in more details since all the main work takes place in it.

//| Handle pattern search results                                    |
bool CProgram::GetResult(const string symbol)
//--- Structure for evaluating pattern efficiency
   RATING_SET m_coef[];
//--- Figure types
   PATTERN_TYPE pattern_types[];
   for(int i=0;i<33;i++)
//--- Define selected timeframes
   int total=ArraySize(m_cur_timeframes);
//--- Check for at least one selected timeframe
         MessageBox("Вы не выбрали рабочий таймфрейм!","Ошибка",MB_OK);
      else if(m_lang_index==1)
         MessageBox("You have not selected working timeframe!","Error",MB_OK);
   int count=0;
//--- Remove all strings
//--- Get date range
   datetime start=StringToTime(TimeToString(m_calendar1.SelectedDate(),TIME_DATE)+" "+(string)m_time_edit1.GetHours()+":"+(string)m_time_edit1.GetMinutes()+":00");
   datetime end=StringToTime(TimeToString(m_calendar2.SelectedDate(),TIME_DATE)+" "+(string)m_time_edit2.GetHours()+":"+(string)m_time_edit2.GetMinutes()+":00");
//--- Check selected dates
   if(start>end || end>TimeCurrent())
         MessageBox("Неправильно выбран диапазон дат!","Ошибка",MB_OK);
      else if(m_lang_index==1)
         MessageBox("Incorrect date range selected!","Error",MB_OK);
   for(int k=0;k<33;k++)
      //--- Get selected patterns for analysis
         //--- Calculate by timeframes
         for(int j=0;j<total;j++)
            double arr[];
            //--- Get data for analysis
            int copied=GetData(m_buttons_group1.SelectedButtonIndex(),symbol,m_cur_timeframes[j],start,end,arr);
               MessageBox("Insufficient data for analysis","Error",MB_OK);
            for(int i=0;i<copied;i++)
               //--- Pattern search condition
               double A=arr[i];
               double B=arr[i+1];
               double C=arr[i+2];
               double D=arr[i+3];
               double E=arr[i+4];
            //--- Add the result to the table
      //--- Update the table
         MessageBox("Вы не выбрали паттерн!","Ошибка",MB_OK);
      else if(m_lang_index==1)
         MessageBox("You have not chosen a pattern!","Error",MB_OK);

First, I need to explain the types of entered variables at the very start of the method. The first one is the RATING_SET structure.

   int               a_uptrend;
   int               b_uptrend;
   int               c_uptrend;
   int               a_dntrend;
   int               b_dntrend;
   int               c_dntrend;

It contains 6 int type variables and is necessary for adding data on how often the price moves in a specified direction after identifying a pattern and how quickly the price reaches it. For example, suppose that we have an uptrend and the trend threshold set to 100 points on 5 digits, while the price covers this value within a single candle. In this case, the a_uptrend variable receives the value of one. If the price reaches 100 points within 2 candles, then the value is passed to the b_uptrend variable. We will use the m_coef[] structure array in our method.

The second variable type is PATTERN_TYPE. This is an enumeration gathering all types of Merrill patterns.

//| Figure type                                                      |

The pattern_types[] enumeration array is applied in the method. Next goes the check — what timeframes were selected for working in the application. This data is handled by the GetTimeframes() method.

//| Get the array of selected timeframes                             |
void  CProgram::GetTimeframes(CButton &buttons[],ENUM_TIMEFRAMES &timeframe[])
   string tf[22]=
   int j=0;
   for(int i=0;i<22;i++)

The method writes this to the preliminarily set m_cur_timeframes[] timeframe array. Next, get the time range for work.

In the first loop, we start checking pressing the selected button responsible for the pattern types and defining a set of studied patterns. In the next loop, each of the patterns is studied on timeframes selected before that. At this stage, the question arises, which data the preliminarily set pattern and timeframe settings should be applied to. The GetData() method is responsible for that, as it defines the settings you have set in the EA properties window, as well as the applied indicator (pos.1 in Fig. 5) in the application settings tab.

//|                                                                  |
int CProgram::GetData(int index,string symb,ENUM_TIMEFRAMES tf,datetime start,datetime end,double &arr[])
   int Handle=INVALID_HANDLE,copied;
//--- Close price
      MqlRates rt[];
      for(int i=0;i<copied;i++)
         else if(m_applied_price==PRICE_CLOSE)
         else if(m_applied_price==PRICE_HIGH)
         else if(m_applied_price==PRICE_LOW)
//--- ATR
//--- CCI
//--- DeMarker
//--- Force Index
//--- WPR
//--- RSI
      Print("Failed to get indicator handle");

After receiving data for analysis, the algorithm moves on to the GetPatternType() method used to search for all previously set patterns on selected timeframes. 

//| Define the patterns                                              |
PATTERN_TYPE CProgram::GetPatternType(double A,double B,double C,double D,double E)
//--- M1
   if(B>A && A>D && D>C && C>E)
//--- M2
   if(B>A && A>D && D>E && E>C)
//--- M3
   if(B>D && D>A && A>C && C>E)
//--- M4
   if(B>D && D>A && A>E && E>C)
//--- M5
   if(D>B && B>A && A>C && C>E)
//--- M6
   if(D>B && B>A && A>E && E>C)
//--- M7
   if(B>D && D>C && C>A && A>E)
//--- M8
   if(B>D && D>E && E>A && A>C)
//--- M9
   if(D>B && B>C && C>A && A>E)
//--- M10
   if(D>B && B>E && E>A && A>C)
//--- M11
   if(D>E && E>B && B>A && A>C)
//--- M12
   if(B>D && D>C && C>E && E>A)
//--- M13
   if(B>D && D>E && E>C && C>A)
//--- M14
   if(D>B && B>C && C>E && E>A)
//--- M15
   if(D>B && B>E && E>C && C>A)
//--- M16
   if(D>E && E>B && B>C && C>A)
//--- W1
   if(A>C && C>B && B>E && E>D)
//--- W2
   if(A>C && C>E && E>B && B>D)
//--- W3
   if(A>E && E>C && C>B && B>D)
//--- W4
   if(A>C && C>E && E>D && D>B)
//--- W5
   if(A>E && E>C && C>D && D>B)
//--- W6
   if(C>A && A>B && B>E && E>D)
//--- W7
   if(C>A && A>E && E>B && B>D)
//--- W8
   if(E>A && A>C && C>B && B>D)
//--- W9
   if(C>A && A>E && E>D && D>B)
//--- W10
   if(E>A && A>C && C>D && D>B)
//--- W11
   if(C>E && E>A && A>B && B>D)
//--- W12
   if(E>C && C>A && A>B && B>D)
//--- W13
   if(C>E && E>A && A>D && D>B)
//--- W14
   if(E>C && C>A && A>D && D>B)
//--- W15
   if(C>E && E>D && D>A && A>B)
//--- W16
   if(E>C && C>D && D>A && A>B)

When detecting the pattern, it is evaluated using the GetCategory() method. The previously defined RATING_SET type structure array is used here.

//| Define the profit categories                                     |
bool CProgram::GetCategory(const string symbol,const int shift,RATING_SET &rate,ENUM_TIMEFRAMES timeframe,int threshold)
   MqlRates rt[];
   datetime start=StringToTime(TimeToString(m_calendar1.SelectedDate(),TIME_DATE)+" "+(string)m_time_edit1.GetHours()+":"+(string)m_time_edit1.GetMinutes()+":00");
   int copied=CopyRates(symbol,timeframe,start,4,rt);
//--- Get the data of previous candles
   double high1,high2,high3,low1,low2,low3,close0,point;

//--- Check for Uptrend
   else if((int)((high2-close0)/point)>=threshold)
   else if((int)((high3-close0)/point)>=threshold)

//--- Check for Downtrend
   else if((int)((close0-low2)/point)>=threshold)
   else if((int)((close0-low3)/point)>=threshold)

Handled evaluation data is passed to the AddRow() method, which calculates probability values and efficiency rates and adds them to the result table.

//|                                                                  |
void CProgram::AddRow(CTable &table,string pattern_name,RATING_SET &rate,int found,ENUM_TIMEFRAMES timeframe)
   int row=m_total_row;
   double p1,p2,k1,k2;
   int sum1=0,sum2=0;

To eliminate potential questions related to using the application, the video below shows examples of calculations with different settings.

Recommendations for testing Merrill patterns:

  • To allow the application work correctly, we need historical data for testing on a specified trading symbol to be downloaded.
  • It is not recommended to download all patterns and all timeframes at the same time, since handling the results may take a long time.
  • The most common scenarios that may cause difficulties are accompanied by tips. Such scenarios include not setting a timeframe or a pattern, as well as invalid date.
  • Be careful when setting EA properties (Fig. 6). If the settings are not clear, re-read the article.
  • The article has covered the topic of a pattern efficiency calculation method twice. The link to the article dwelling on the topic has been provided. Keep in mind that you need clear understanding of how the weighting coefficients in the settings tab affect the patterns evaluation.


The archive attached below contains all described files arranged into appropriate folders. For correct operation, place the MQL5 folder to the terminal's root directory. To open the terminal root directory, in which the MQL5 folder is located, press the Ctrl+Shift+D key combination in the MetaTrader 5 terminal or use the context menu as shown in Fig. 7 below.

Fig. 7. Opening the MQL5 folder in the MetaTrader 5 terminal root

Translated from Russian by MetaQuotes Software Corp.
Original article:

Attached files | (1736.93 KB)
Last comments | Go to discussion (5)
Carl Schreiber
Interesting article(!) but haven't you run at least a basic test of the performance of the patterns and share it here like: timeframe, timespan, found, threshold, how often threshold touched?
Alexander Fedosov
Carl Schreiber:
Interesting article(!) but haven't you run at least a basic test of the performance of the patterns and share it here like: timeframe, timespan, found, threshold, how often threshold touched?

What's the point of this? There are a lot of configuration options. Everyone can choose something of their own.

AliDu | 22 Oct 2019 at 14:25
Good article, but I found a mistake.
In the GetCategories function on line 1055 of MainWindow.mqh, you calculate the number of days (or other timeframe). That's different than the number of candles.
I have tested it with the D1 Chart (EURUSD), Pattern M1. GetCategories returns the result of 37 candles backwards from the patterns. M1 Pattern on 1.7.2019, GetCategories returns the result of 9.5.2019 (Highs and Lows).

I don't know how to correct this. 



Hi Alex,

What a great article and i'm interesting to try it. 

I opened the your project in MQL5 editor. 

I have placed all the files on the location and run the program. found below errors 

resource file '\Images\EasyAndFastGUI\Candles\passive_2.bmp' not found MainWindow.mqh 1244 11

resource file '\Images\EasyAndFastGUI\Candles\pressed_2.bmp' not found MainWindow.mqh 1245 11

'iATR' - wrong parameters count MainWindow.mqh 850 14

3 errors and 18 warnings. is anything missing?

Alexander Fedosov
Wan Hasanul:
resource file '\Images\EasyAndFastGUI\Candles\passive_2.bmp' not found MainWindow.mqh 1244 11

resource file '\Images\EasyAndFastGUI\Candles\pressed_2.bmp' not found MainWindow.mqh 1245 11
A New Approach to Interpreting Classic and Hidden Divergence. Part II A New Approach to Interpreting Classic and Hidden Divergence. Part II
The article provides a critical examination of regular divergence and efficiency of various indicators. In addition, it contains filtering options for an increased analysis accuracy and features description of non-standard solutions. As a result, we will create a new tool for solving the technical task.
Optimization management (Part II): Creating key objects and add-on logic Optimization management (Part II): Creating key objects and add-on logic
This article is a continuation of the previous publication related to the creation of a graphical interface for optimization management. The article considers the logic of the add-on. A wrapper for the MetaTrader 5 terminal will be created: it will enable the running of the add-on as a managed process via C#. In addition, operation with configuration files and setup files is considered in this article. The application logic is divided into two parts: the first one describes the methods called after pressing a particular key, while the second part covers optimization launch and management.
Library for easy and quick development of MetaTrader programs (part XV): Collection of symbol objects Library for easy and quick development of MetaTrader programs (part XV): Collection of symbol objects
In this article, we will consider creation of a symbol collection based on the abstract symbol object developed in the previous article. The abstract symbol descendants are to clarify a symbol data and define the availability of the basic symbol object properties in a program. Such symbol objects are to be distinguished by their affiliation with groups.
Library for easy and quick development of MetaTrader programs (part XIV): Symbol object Library for easy and quick development of MetaTrader programs (part XIV): Symbol object
In this article, we will create the class of a symbol object that is to be the basic object for creating the symbol collection. The class will allow us to obtain data on the necessary symbols for their further analysis and comparison.