Multi-Currency OnTick (String Notation) Event Handler - MetaTrader 5 Expert - MT4/MT5 Resources
This is the new implementation of the fully functional multi-currency mode in MetaTrader 5. It is implemented in the extended OnTick (string notation) function.
The Expert Advisor template looks like this:
//+------------------------------------------------------------------+ //| OnTick(string symbol).mq5 | //| Copyright 2010, Liza | //| https://www.mql5.com/ru/users/Lizar | //+------------------------------------------------------------------+ #define version "1.00 Build 1 (01 Fab 2011)" #propertycopyright "Copyright 2010, Lizal" #Attribute link "https://www.mql5.com/ru/users/Lizar" #Attribute version version #Attribute description "EA trading template" #Property description "Use multi-currency OnTick (String notation) event handler" //+------------------------------------------------------------------+ //|Multi-currency mode settings | //| OnTick(string symbol) event handler | //| | //| 1.1 List of symbols required for event execution: | #define SYMBOLS_TRADING “EUR/USD” , “GBP/USD” , “USDJPY” , “USD/CHF” //| 1.2 If you want all trading symbols in Market Watch, please use: | //#define SYMBOLS_TRADING “MARKET_WATCH” //| Note: You can only choose one method from 1.1 or 1.2. | //| | //| 2. OnTick event type (string symbol): | #define CHARTEVENT_SYMBOL CHARTEVENT_TICK //| Note: The event type must correspond to | //| ENUM_CHART_EVENT_SYMBOL enumeration. | //| | //| 3. Include files: | #include//+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //|Expert initialization function | //|The function must be declared, even if it is empty. | //+------------------------------------------------------------------+ Integer initialization () { //--- add your code here... return ( 0 ); } //+------------------------------------------------------------------+ //|Expert multi-scale function | //|Use this function instead of the standard OnTick() function | //+------------------------------------------------------------------+ Blank check (symbol of string ) { //--- add your code here... print ( "New event on symbol:" , symbol); } //+------------------------------------------------------------------+ //| ChartEvent function | //|The function must be declared, even if it is empty. | //+------------------------------------------------------------------+ Blank Chart Event ( const integer ID, // event ID constant long &l parameter, // event parameter of type longconst double &d parameter, // event parameter of type double const string and spam) // event parameter of type string { //--- add your code here... } //+------------------------------------------------------------------+ //|Expert de-initialization function | //+------------------------------------------------------------------+ Blank solution initialization ( const integer reason) { //--- add your code here... } //+------------------------------------------------------------------+ //|END ----------------------------------------------------------------+
Some features:
All settings can be configured using #define directives. In order for the OnTick(string symbol) function to work correctly, you only need to specify two parameters: SYMBOLS_TRADING and CHART_EVENT_SYMBOL. The first one (SYMBOLS_TRADING) defines the list of symbols used for the event. The second one (CHART_EVENT_SYMBOL) defines the event type for all symbols.
SYMBOLS_TRADING contains a list of trading symbols, for example:
#define SYMBOLS_TRADING “EUR/USD” , “GBP/USD” , “USDJPY” , “USD/CHF”The list must be prepared as a string and separated by commas. The list ends with the end of the line.
This SYMBOLS_TRADING can be defined as follows :
#define SYMBOLS_TRADING “Market Watch”This approach means that all symbols in Market Watch will be used. This method can be used to change the symbol list "on the fly" . Just add or remove the desired symbols to Market Watch.
The CHART_EVENT_SYMBOL event type is defined by flag or their combination from the ENUM_CHART_EVENT_SYMBOL enumeration. See details here (in Russian).
The following are examples of event types:
//--- Example 1.OnTick event: #define CHARTEVENT_SYMBOL CHARTEVENT_TICK //--- Example 2. New bar M1 and new bar H1: #define CHARTEVENT_SYMBOL CHARTEVENT_NEWBAR_H1|CHARTEVENT_NEWBAR_M1
2. Include files.
3. Strategy tester.
This is a feature. In the Strategy Tester, OnTick(String Symbol) will act on price ticks of the symbol specified in the Strategy Tester settings. In other words, it works like OnTick(), but is also called when a new quote appears for the selected symbol. For use with the strategy tester SYMBOLS_TRADING must be specified as a list of symbols.
It uses "spies" (agent-indicators). The "Spy Control panel MCM.ex5" file must be located in the \MQL5\Indicators\ folder.
5. The files from the archive must be extracted to the \MQL5 folder. Required documents:
Attachment download
Source: MQL5 #280
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •