aChartsAndMW5Class – library MetaTrader 5

The class allows to easily determine from your MQL5 programs any changes in the Market Watch window (change of symbol sorting, adding, deleting a symbol or a set of symbols), as well as opening and closure of charts, and the availability of the one click trading option on the current chart, on which the program is running. The class sends custom events to the control program.

The following public methods are available in the program:

Method
 Description Returned value
Methods of working with charts
   
bool IsChartOneClick(void)
Returns the flag of the availability of the OneClick panel on the chart
bool true/false
uchar GetChartNumbers(void)
Returns the number of open charts in the terminal
uchar The number of open charts
long GetOpenedChartID(void)
Returns the ID of the newly opened chart
long ChartID()
string GetOpenedSymbol(void)
Returns the symbol name of the newly opened chart
string ChartSymbol()
ENUM_TIMEFRAMES GetOpenedTimeframe(void)
Returns the timeframe of the newly opened chart ENUM_TIMEFRAMES ChartPeriod()
long GetClosedChartID(void)
Returns the ID of the newly closed chart long ChartID()
string GetClosedSymbol(void)
Returns the symbol name of the newly closed chart string ChartSymbol()
ENUM_TIMEFRAMES GetClosedTimeframe(void)
Returns the timeframe of the newly closed chart ENUM_TIMEFRAMES ChartPeriod()
bool IsOpenedIsObject(void)
Returns the sign that the opened chart is an object
bool true/false
bool IsClosedIsObject(void) Returns the sign that the closed chart was an object bool true/false
bool CheckOpenChart(string symbol_name);
Checks whether the symbol chart is open
bool true/false
bool CheckOpenChart(string symbol_name,ENUM_TIMEFRAMES timeframe)
Checks whether the symbol chart with the specified timeframe is open
bool true/false
long OpenChart(string symbol_name,ENUM_TIMEFRAMES timeframe)
Opens the symbol chart
long ChartID()
bool IsOpenedAllCharts(void)
Returns the flag of presence of open charts of all symbols from the Market Watch
bool true/false
Methods of working with the Market Watch


bool PutSymbolToMarketWatch(string symbol_name)
Adds a symbol to the Market Watch
bool true/false
bool IsExistSymbolInMW(string symbol_name, bool select=false)
Returns the flag of presence of a symbol in the Market Watch/on the server
bool true/false
int GetNumSymbolsInMW(void)
Returns the number of symbols in the Market Watch
int The number of symbols in the Market Watch
int GetNumAllSymbols(void)
Returns the number of available symbols
int The number of symbols on the server
void ClearMarketWatch(void) Deletes all possible symbols form the Market Watch void
Custom events that the class sends to the control program:
Alternative:  The class for drawing the MFI using the ring buffer - indicator MetaTrader 5
Identifier
Value
 Description
CHARTEVENT_CHART_OPEN 32 New chart opening event
CHARTEVENT_CHART_CLOSE 33 Chart closing event
CHARTEVENT_MW_SYMBOL_ADD 34 An event of adding a symbol to the Market Watch
CHARTEVENT_MW_FEW_SYMBOL_ADD 35 An event of adding multiple symbols to the Market Watch
CHARTEVENT_MW_SYMBOL_DEL 36 An event of symbol deletion from the Market Watch
CHARTEVENT_MW_FEW_SYMBOL_DEL 37 An event of deletion of multiple symbols from the Market Watch
CHARTEVENT_MW_CHANGE_SORT 38 An event of changing the symbol sorting in the Market Watch
CHARTEVENT_CHART_CHANGE_ONE_CLICK 39 OneClick panel opening/closing event

The identifier values are correlated to the identifiers from the graphical library by Anatoli Kazharski, although you can set them at your discretion.

The values that are passed to the control program along with the event:

Identifier
 lparam dparam
 sparam
CHARTEVENT_CHART_OPEN long ChartID of the open chart
ENUM_TIMEFRAMES Period of the open chart
string Symbol of the open chart
CHARTEVENT_CHART_CLOSE long ChartID of the closed chart ENUM_TIMEFRAMES Period of the closed chart string Symbol of the closed chart
CHARTEVENT_MW_SYMBOL_ADD int The current number of symbols
int The previous number of symbols
string The added symbol
CHARTEVENT_MW_FEW_SYMBOL_ADD int The current number of symbols int The previous number of symbols string The last used symbol
CHARTEVENT_MW_SYMBOL_DEL int The current number of symbols int The previous number of symbols string The deleted symbol
CHARTEVENT_MW_FEW_SYMBOL_DEL int The current number of symbols int The previous number of symbols string The last used symbol
CHARTEVENT_MW_CHANGE_SORT int The current number of symbols int The current number of symbols string The last used symbol
CHARTEVENT_CHART_CHANGE_ONE_CLICK int The X coordinate of the right border of the panel
int The Y coordinate of the right border of the panel
string The description of the panel state:
CHART_IS_ONE_CLICK_ON” – there is a panel
CHART_IS_ONE_CLICK_OFF” – there is no panel

In order to include the class to the program, you must include the file in the global area and create a class instance:

Alternative:  Exp_X2MA - EA MetaTrader 5
#include <aChartsAndMWClass.mqh>
CChartsMW   mw;

Then, in the OnTimer() function of the program, add the class timer:

//+——————————————————————+
//| Timer function                                                   |
//+——————————————————————+
void OnTimer()
  {
//— Adding the class timer
   mw.OnTimerEvent();
  }
//+——————————————————————+

Add the class event handler in OnChartEvent():

//+——————————————————————+
//| ChartEvent function                                              |
//+——————————————————————+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//— Adding the class event handler
   mw.OnEvent(id,lparam,dparam,sparam);
  }
//+——————————————————————+

Now, events returned by the class can be accepted and processed in the program’s OnChartEvent().

The example of receiving events from the class is available in the attached Expert Advisor exTestChartsMWClass.mq5


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks