hsharghi: Hi, I'm converting an indicator written for MT4 to use it in MT5. It has a lot in small functions which uses Open[], Close[], Low[] and High[] global arrays in MQL4. I found that there are no equivalent of them in MQL5.
Any suggestion how can I use those arrays?
Both for MQL4+ and MQL5, the OnCalculate() event handler for Indicators. offers local arrays for quotes/rates data in the form of arrays. They are however in lowercase (open[], close[], low[], high[] , etc.).
int OnCalculate( const int rates_total, // size of input time series const int prev_calculated, // number of handled bars at the previous call const datetime& time{}, // Time array const double& open[], // Open array const double& high[], // High array const double& low[], // Low array const double& close[], // Close array const long& tick_volume[], // Tick Volume array const long& volume[], // Real Volume array const int& spread[] // Spread array );

Documentation on MQL5: Event Handling / OnCalculate
- www.mql5.com
OnCalculate - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
You can put this before your code. It's not mine but can't remember the origin.
#define SERIES(name,type) \ class C##name \ { \ public: \ type operator[](const int i){return i##name(NULL,0,i);} \ }name; SERIES(Open,double) SERIES(Low,double) SERIES(High,double) SERIES(Close,double) SERIES(Time,datetime) SERIES(Volume,long)
Fernando Carreiro #:
Both for MQL4+ and MQL5, the OnCalculate() event handler for Indicators. offers local arrays for quotes/rates data in the form of arrays. They are however in lowercase (open[], close[], low[], high[] , etc.).
these arrays exists only inside OnCalculate() function. I cannot send all of them as function parameter to each one of functions that requires those values.
For example this function requires close and open arrays.
int getCandleColorIndex(int pos) { return (Close[pos] > Open[pos]) ? 1 : (Close[pos] < Open[pos]) ? -1 : 0; }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I'm converting an indicator written for MT4 to use it in MT5.
It has a lot in small functions which uses Open[], Close[], Low[] and High[] global arrays in MQL4. I found that there are no equivalent of them in MQL5.
Any suggestion how can I use those arrays?
Hadi