Multi Symbol in OnCalculate()

 

in OnCalculate() function close[] refer to current chart for example EURUSD,

I need to get close[] value for other Symbol in my indicator.

How get other Symbol in OnCalculate() function?

 
fatbody: in OnCalculate() function close[] refer to current chart for example EURUSD,

I need to get close[] value for other Symbol in my indicator. How get other Symbol in OnCalculate() function?

MQL4 Reference - Access to Timeseries and Indicator Data:

MQL5 Reference - Access to Timeseries and Indicator Data:

NB! Also read the following thread for more information on Multi-Symbol usage:

Forum on trading, automated trading systems and testing trading strategies

Anyone know how to develop a multicurrency indicator ?

Fernando Carreiro, 2016.04.21 04:46

In a standard indicator, you would build the buffer arrays with data from the parameters sent via the OnCalulate( ... ) event function. But, for multi-currency and/or multi-time-frame, you will have to use one of two solutions:

  • Using the old method of the "iFunction" variations, such as iTime(), iVolume, iOpen, iClose, etc. but with a different symbol such as "EURUSD", "JPYUSD", etc. instead of the default _Symbol or Symbol().
  • Using the newer method of the first variant of ArrayCopyRates() function together with array pointers of MqlRates.  The "copied" arrays, will not actually take up any space and will just be pointers to the existing data of the various symbols and time-frames.

However, for this to work, one of two conditions have to exist for the multi-symbol and/or multi-time-frame to work:

  • Either the respective charts for the symbols and time-frames are already open, so that no error is generated,
  • or you will get an error 4066 (ERR_HISTORY_WILL_UPDATED) the first time you request the data, and you will have to code a sleep & retry loop, in order to wait for data to download and then request the data again.

My personal suggested solution, which I find as the most efficient as well as easiest way to handle the 4066 error, is the ArrayCopyRates() and MqlRates method.

There is more information about this the MQL4 documentation and help files.

PS! NB! When accessing built-in indicator functions, such as iMA(), iATR(), etc. for the various symbols and time-frames, remember to also implement the sleep and retry loops so as not to get the 4066 error either. Here is a quote from the MQL4 documentaion:


Timeseries and Indicators Access - MQL4 Reference
Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
These are functions for working with timeseries and indicators. A timeseries differs from the usual data array by its reverse ordering - elements of timeseries are indexed from the end of an array to its begin (from the most recent data to the oldest ones). To copy the time-series values and indicator data, it's recommended to use dynamic...
Reason: