Multi Currency EA

 

Hello

I'm trying to build a multi currency ea that works in the mt5 strategy tester.

i'm not a professional programmer but i tried i've read the articles on this website about that and tried but with no luck i couldn't understand the method because they use about 3-5 include files linking to each other and it became over overwhelming.

so please any one give me an example within a small direct code of how can i use the OnChartEvent() and the OnBookEvent() to check whether there is a tick on the other symbols or not.

Thanks in advance

Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
The MQL5 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL5 program; function name, return type, composition of parameters (if there are any) and their types must strictly conform to the description of the event handler function. The event handler of the client terminal...
 
Multi currency EA ideasthe thread
Multi currency EA ideas
Multi currency EA ideas
  • 2014.02.25
  • www.mql5.com
For quite some time I have been working on a multi currency EA...
 

Multi-Currency Expert Advisors in MT5  - backtesting and optimization

 

The threads/posts

  • Buying or Selling all 7 pairs - the thread with the explanation.
  • Multi-Currency Expert Advisors the post with the examples of backtesting/optimization

The articles

Documentation

  • MetaTrader 5 Help → Algorithmic Trading, Trading Robots → Optimization Types - All Symbols Selected in Market Watch
  • MetaTrader 5 Help → Algorithmic Trading, Trading Robots → Strategy Testing - Multi-Currency Expert Advisors
  • MetaTrader 5 Help - Trading Platform — User Manual
 

CodeBase  

Multi-currency night scalper - Night Scalper Multi
Multi-currency night scalper - Night Scalper Multi
  • www.mql5.com
The Night Scalper Multi multi-currency night scalper trades until 0 am terminal time within a narrow range (r), determined using the Bollinger Bands indicator. Position is opened after the hour specified in Start, and if there are no open positions on the symbol. Buy, if price is lower than the lower boundary of Bollinger Bands and channel is...
 

I've already read all these.

the use of ontick function isn't working well in the tester because when the symbol the multi ea attached to is changed the results change also.

the ontimer function seems to be working but it's very slow in the tester when trying optimization.

so i found that the chart event and book event is going to work somehow but the examples available about it the complex or simple but not explained well

all the examples have a hex number that i don't understand how it check the ticks with.

so please give a simple code that explain how to deal with the event handling for checking ticks for other symbols. 

 
Any one?
 

hi my friend .

The best multi-currency strategy is to use currency correlation and lock profits and losses. In this case, the entry and exit of the market process does not need to know the market direction

 

EA:

string Symbol[]={"AUDUSD","EURUSD","GBPUSD","USDCHF","USDCAD","USDJPY"};
int handle[],size;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   long chartID=ChartID();
   ArrayResize(handle,size=ArraySize(Symbol));
   for(int i=0;i<size;i++)
      if((handle[i]=iCustom(Symbol[i],_Period,"OnTick",chartID,i))==INVALID_HANDLE)
         return(INIT_FAILED);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   for(int i=0;i<size;i++)
      IndicatorRelease(handle[i]);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(const string &symbol,const double &price)
  {
//---
   Print(symbol," ",price);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id>=CHARTEVENT_CUSTOM)
      OnTick(sparam,dparam);
  }
//+------------------------------------------------------------------+

Indicator:

#property indicator_chart_window
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input long     ChartID=0;
input ushort   EventID=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---
   if(prev_calculated)
      ::EventChartCustom(ChartID,EventID,rates_total,price[rates_total-1],_Symbol);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
OnTick.mq5  3 kb
OnTick.mq5  2 kb
 
Ernst Van Der Merwe:

EA:

Indicator:

Thanks for your help.

Reason: