Mastering Multicurrency Trading with OnTick in MetaTrader 5

Mike 2011.02.02 03:03 40 0 0
Attachments

Hey traders! If you’re looking to streamline your trading strategies with MetaTrader 5, you’re in for a treat with the new multicurrency capability integrated into the OnTick(string symbol) function. This handy feature brings a whole new dimension to your trading experience.

Here’s what you can expect:

  • A genuine multicurrency trading experience on both demo and live accounts.
  • Easy-to-navigate settings to get you started quickly.
  • Configurable event types for OnTick(string symbol) - you can choose between NewTick and/or NewBar.
  • The flexibility to select your symbols from Market Watch or specify your own.
  • Real-time event management while trading with Market Watch symbols.
  • No need to dive deep into complex code; everything you need is neatly packaged in the include file.
  • Compatible with the Strategy Tester, allowing you to backtest your strategies effectively.

Expert Advisor Template Overview:

//+------------------------------------------------------------------+
//| Expert for OnTick(string symbol) |
//| Copyright 2010, Lizar |
//| https://www.mql5.com/en/users/Lizar |
//+------------------------------------------------------------------+
#define VERSION "1.00 Build 1 (01 Fab 2011)"

#property copyright "Copyright 2010, Lizar"
#property link "https://www.mql5.com/en/users/Lizar"
#property version VERSION
#property description "Template of the Expert Advisor with multicurrency OnTick(string symbol) event handler"

//+------------------------------------------------------------------+
//| MULTICURRENCY MODE SETTINGS of OnTick(string symbol) event handler |
//+------------------------------------------------------------------+
#define SYMBOLS_TRADING "EURUSD", "GBPUSD", "USDJPY", "USDCHF"
// Note: Alternatively, you can include all symbols from Market Watch:
//#define SYMBOLS_TRADING "MARKET_WATCH"
// Select only one option.
#define CHART_EVENT_SYMBOL CHARTEVENT_TICK
//+------------------------------------------------------------------+

int OnInit()
  {
   //--- Your initialization code here...
   return(0);
  }

void OnTick(string symbol)
  {
   //--- Your tick handling code here...
   Print("New event on symbol: ", symbol);
  }

//+------------------------------------------------------------------+

Key Features:

1. Settings:
All settings are adjustable using #define directives. To get the OnTick(string symbol) function up and running, you need to configure just two parameters: SYMBOLS_TRADING and CHART_EVENT_SYMBOL. The first parameter lists the symbols for events, while the second defines the event types.

The SYMBOLS_TRADING could look like this:

#define SYMBOLS_TRADING "EURUSD", "GBPUSD", "USDJPY", "USDCHF"

The symbols should be strings separated by commas. You can also define it as:

#define SYMBOLS_TRADING "MARKET_WATCH"

This allows you to use all Market Watch symbols, which you can easily modify on the fly by adding or removing symbols.

2. Include File:
The #include OnTick(string symbol).mqh file is essential as it contains the implementation for the OnTick(string symbol) function. Make sure to declare some standard functions in your Expert Advisor, even if they remain empty.

3. Strategy Tester:
Currently, the OnChartEvent function isn’t supported in the Strategy Tester. Instead, global variables handle events. In the Strategy Tester, the OnTick(string symbol) function operates on the ticks from the specified symbols in your settings.

4. “Spies” Integration:
This setup uses agents-indicators, and the “Spy Control panel MCM.ex5” file should be placed in the \MQL5\Indicators\ folder.

5. File Structure:
Make sure to extract the following files into the \MQL5 directory:

  • /MQL5/Experts/OnTick(string symbol).mq5 - Example of the Expert Advisor source code;
  • /MQL5/Experts/OnTick(string symbol).ex5 - Compiled version of the Expert Advisor;
  • /MQL5/Indicators/Spy Control panel MCM.mq5 - Source code of the agent-indicator;
  • /MQL5/Indicators/Spy Control panel MCM.ex5 - Compiled version of the agent-indicator;
  • /MQL5/Include/OnTick(string symbol).mqh - Include file with necessary functions for OnTick(string symbol).

So, there you have it! By leveraging the OnTick(string symbol) feature, you’re setting yourself up for a more dynamic trading approach. Happy trading!

List
Comments 0