Greetings,
I'm rather new to MQL5 programming and have a question about candle switch in MQL5.
I did program a simple indicator in MQL4 and it was easy to determine the start of a new candle by looking at the value of the time[0] argument passed to the OnCalculate event.
When looking at the time[0] value of the OnCalculate event in MQL5, however, some things are definitely not the same.
One: The datetime value of time[0] always seems to be in the past. For example "2023-12-12 08:13:00" on a one minute interval and "2022-11-16 16:20:00" on a five minute interval.
Two: This value does not seem to change at all after 1 or 5 minutes!
I did attach my minimal piece of code and I am aware of the fact that my knowledge of MQL5 is not enough at the moment. But eager to learn.
Hope to hear from you what I am overlooking,
With regards,
Aad Slingerland
In MT4, buffers and MT4 predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.
To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
In MT5, you must set the direction.
Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Greetings,
I'm rather new to MQL5 programming and have a question about candle switch in MQL5.
I did program a simple indicator in MQL4 and it was easy to determine the start of a new candle by looking at the value of the time[0] argument passed to the OnCalculate event.
When looking at the time[0] value of the OnCalculate event in MQL5, however, some things are definitely not the same.
One: The datetime value of time[0] always seems to be in the past. For example "2023-12-12 08:13:00" on a one minute interval and "2022-11-16 16:20:00" on a five minute interval.
Two: This value does not seem to change at all after 1 or 5 minutes!
I did attach my minimal piece of code and I am aware of the fact that my knowledge of MQL5 is not enough at the moment. But eager to learn.
Hope to hear from you what I am overlooking,
With regards,
Aad Slingerland