Home System Trading Post

Master Your Trading with the MCM Control Panel for MetaTrader 5

Attachments
215.zip (19.4 KB, Download 0 times)

One of the standout features of the MQL5 language is its ability to utilize multicurrency indicators and Expert Advisors (EAs). If you're looking to dive deeper, check out the Multicurrency OnTickMarketWatch tick event handler available in the CodeBase.

However, implementing the concepts proposed in these scripts can get a bit tricky. For instance, with multiple events, you might encounter an overflow in the events queue.

Here’s a helpful note from the MQL5 Reference:

The client terminal adds incoming events to the events queue, processing them sequentially based on their arrival order. The NewTick event is an exception; if there’s already a NewTick event in the queue or one is being processed, the new event won’t be added.

The events queue has a size limit. When it overflows, older events are removed to accommodate new ones. That’s why it’s crucial to write efficient event handlers and avoid infinite loops (with the exception of scripts that handle only the Start event).

Additionally, you may want to recalculate indicator values only when a new bar appears. There are also instances where you might need to disable trading on the fly for a specific symbol in a multicurrency EA or change the timeframe for a symbol.

The "something else" can also include external data inputs. That’s where the MCM (MultiCurrency Mode) Control Panel comes into play.

And it’s worth mentioning that this panel can also be used in single currency trading.

Key Features of the MCM Control Panel (Contest Version):

This panel offers the essential functions needed for using multicurrency mode in your EAs and indicators:

  • Add or remove symbols for trading and analysis.
  • Track "new tick" and "new bar" events for any symbol and timeframe.
  • All settings can be adjusted on the fly without needing to restart your EA or indicator.
  • The panel is compatible with our EAs and indicators.
  • You can integrate it with your own code, and it will load seamlessly.
  • It’s transparent—no need to add extra code for the MCM Control Panel to your EAs or indicators.

Using the MCM Control Panel allows you to add custom features. Keep reading for more details.

Note: Saving and restoring Control Panel settings is not supported in this version.

Getting Started with the MCM Control Panel

There are several ways to launch the MCM Control Panel:

  • Attach the "iControl panel MCM" to your chart.
  • Run the "scControl panel MCM" script, which loads the "iControl panel MCM" indicator.
  • Load the panel from your EA or indicator. Refer to "exControl panel MCM" for details.

In the third case, the panel will be loaded alongside your EA or indicator and attached to the chart.

Your EA needs to have the OnChartEvent() event handler to properly process the MCM Control Panel events.

User Interface

The interface is user-friendly, designed as a straightforward menu. You can customize the size and colors of the menu through input parameters.

Here’s a glance at what it looks like:


 

Design

The panel is designed to configure events for multicurrency EAs and indicators. Its size and position depend on the chart dimensions and font size, which you define in the input parameters. To save space, the panel can be minimized.


 

Adjust the panel size by changing the font size in input parameters (default size is 10):


You can use any color scheme you prefer. For example, here’s a pink scheme:


The EMO scheme looks like this:


 

Easy to Use

The menu is intuitive, making navigation a breeze.

The "MCM Control Panel" button includes additional features (not available in this version):


With the "Chart" button, you can easily switch the current symbol and timeframe—just select it:


 

The "Events" menu allows you to enable or disable events on the fly (no need to restart your EA or indicator) for a specific symbol and specify the desired event. Symbols are drawn from your "Market Watch" menu. You can combine any events, and they will all be processed.

For instance, you don’t have to worry about new ticks or bars for symbols on different timeframes—the panel engine will handle sending the events:


  

Need help? Here’s the "Help" section:


 

Know How and Its Implementation

My solution is outlined in the Multicurrency OnTickMarketWatch tick event handler, but this panel introduces some additional features:

  • The "MCM Control panel MCM" provides an interface not directly implemented in the client terminal. It allows you to leverage the multicurrency mode through the OnChartEvent() handler. Another perk is the ability to change settings on the fly.
  • To generate events for the OnChartEvent() handler, the MCM Control Panel uses its own agents (indicators launched by the panel on specific symbols) to facilitate multicurrency trading.
  • The panel can be integrated into EAs or indicators.
  • The MCM Control Panel offers new opportunities for MQL5 developers.
  • In my humble opinion, the panel exemplifies a new structure for EAs and indicators. I’ll share some examples soon.

Information About Events and Alerts

The panel features a status bar to display events.

Installing the MCM Control Panel

To get started, unpack the archive file mcm_control_panel.zip in your client terminal folder. This will generate the following files:

  • /mql5/experts/exControl panel MCM.mq5 - example of an Expert Advisor;
  • /mql5/scripts/scControl panel MCM.mq5 - example of a Script;
  • /mql5/indicators/iControl panel MCM.mq5 - the main engine for the MCM Control Panel;
  • /mql5/indicators/Spy Control panel MCM.mq5 - MCM Control Panel agent;
  • /mql5/include/Control panel MCM.mqh - a set of classes and functions for the MCM Control Panel.

Next, compile the Indicators, Script, and Expert Advisor.

Launching the MCM Control Panel

To launch the MCM Control Panel, attach the iControl panel MCM.mq5 indicator to any chart.

You can also start the panel from an Expert Advisor by simply attaching the exControl panel MCM EA to the chart:


 

As an example of multicurrency implementation, I created the MultiTrend Expert Advisor. This indicator analyzes the USD trend based on four currency pairs:

Here’s a snippet of the code:

//+------------------------------------------------------------------+ 
//|                                                   MultiTrend.mq5 | 
//|                                                   Copyright 2010, Lizar | 
//|                                                   https://www.mql5.com/ru/users/Lizar | 
//+------------------------------------------------------------------+ 
#define VERSION       "1.00 Build 2 (09 Dec 2010)" 
#property copyright   "Copyright 2010, Lizar"
#property link        "https://www.mql5.com/ru/users/Lizar"
#property version     VERSION
#property description "This Expert Advisor uses the MCM Control Panel"
input color bg_color=Gray;        // Menu color 
input color font_color=Gainsboro; // Text color 
input color select_color=Yellow// Selected text color 
input int font_size=10;          // Font size 
#include <Control panel MCM.mqh> //<--- Include file 
//+------------------------------------------------------------------+ 
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+ 
int OnInit()
  {    //--- MCM Control Panel initialization.     
//--- It isn't necessary to set colors, if not specified, the default colors will be used.      
   InitControlPanelMCM(bg_color,font_color,select_color,font_size);
//---    
  return(0);   
  } 
//+------------------------------------------------------------------+ 
//| Expert deinitialization function                                   | 
//+------------------------------------------------------------------+ 
void OnDeinit(const int reason)
  {
   DeinitControlPanelMCM();   //<--- MCM Control Panel deinitialization  
  }
//+------------------------------------------------------------------+ 
//| OnChartEvent event handler.                                      | 
//| See MQL5 Reference for details.                                  | 
//| Can be used with MCM Control panel for multicurrency trading     | 
//+------------------------------------------------------------------+ 
void OnChartEvent(const int id, // event identifier:                                      
                  // if id-CHARTEVENT_CUSTOM==0 - initialization event (when prev_calculated==0)
                   const long&   lparam, // timeframe 
                   const double& dparam, // price    
                   const string& sparam  // symbol 
                   )
  {
   if(id>=CHARTEVENT_CUSTOM)
     {
      Print(TimeToString(TimeCurrent(),TIME_SECONDS)," -> id=", id-CHARTEVENT_CUSTOM,
                         ":  ",sparam," ",EventDescription(lparam)," price=",dparam);
     }
  }
//+------------------------------------------------------------------+ 

Understanding the OnChartEvent() Parameters

The Control Panel generates custom events that can be processed in your EA or indicator using the OnChartEvent() handler.

The input parameters are as follows:

  • id - event id:
          if id-CHARTEVENT_CUSTOM !=0 - it corresponds to the symbol index in the "Market Watch" window;
  • lparam - event flag. Refer to the ENUM_CHART_EVENT_SYMBOL enumeration in Control panel MCM.mqh.
  • dparam - tick price or opening price of the new bar on a specific timeframe.
  • sparam - symbol name.

Events Supported in the MCM Control Panel

The Control Panel can send up to 64 different custom events per symbol using the lparam parameter. In this version, the following events are supported:

  • "Initialization" event (Initialization);
  • "New tick" event (tick);
  • "New bar" event on M1 chart (M1);
  • "New bar" event on M2 chart (M2);
  • "New bar" event on M3 chart (M3);
  • "New bar" event on M4 chart (M4);
  • "New bar" event on M5 chart (M5);
  • "New bar" event on M6 chart (M6);
  • "New bar" event on M10 chart (M10);
  • "New bar" event on M12 chart (M12);
  • "New bar" event on M15 chart (M15);
  • "New bar" event on M20 chart (M20);
  • "New bar" event on M30 chart (M30);
  • "New bar" event on H1 chart (H1);
  • "New bar" event on H2 chart (H2);
  • "New bar" event on H3 chart  (H3);
  • "New bar" event on H4 chart (H4);
  • "New bar" event on H6 chart (H6);
  • "New bar" event on H8 chart (H8);
  • "New bar" event on H12 chart (H12);
  • "New bar" event on daily chart (D1);
  • "New bar" event on weekly chart (W1);
  • "New bar" event on monthly chart (MN1); 

The event description returned by EventDescription() is displayed in brackets (Initialization, tick, Mxx, etc.). You can find the EventDescription function in Control panel MCM.mqh (along with the ENUM_CHART_EVENT_SYMBOL enumeration).

The "Initialization" event is generated when prev_calculated=0, which can be useful for preparing data—like recalculating indicator values.

Setting Events

To set the events you need, click the "Events" button, select the symbol and event type. The chosen events will be highlighted in yellow (or the selected color in the input parameters). You can select one or multiple events, and they will all be processed by your multicurrency EA. To apply your changes, just click the "Enable/Disable events" button.

Repeat this process for any other symbols you need.


 

Check out the logs from the "Experts" tab:


 

Related Posts

Comments (0)