Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
No, that is not the case for MQL5, only for the older MQL4.
Please refer to the documentation:
To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.

- www.mql5.com
- Fernando Carreiro #: No, that is not the case for MQL5, only for the older MQL4.
For MQL4 that is only the case for Time[] not time[].
- dosskaran: I understand to access the open time of the most recent bar inside a custom indicator, in OnCalculate, I need to access time[0].
Wrong. In MT5, you must set the direction.
To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] and other arrays (copyXXXX functions), call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
Hello, I am a newbie MQL5 coder - but not new to coding or trading.
I understand to access the open time of the most recent bar inside a custom indicator, in OnCalculate, I need to access time[0]. However this is giving me a time in May (13), while today is August 22. The data window in the chart is displaying the correct date. Can someone help please?
this is the code...
The output is
Improperly formatted code edited by moderator. Please always use the CODE button (Alt-S) when inserting code.
On MQL5 those variables from OnCalculate() are not set as Series by default. If you want them working as Series like the shift 0 to be the most recent bar you must first SetArrayAsSeries(true).
For example, SetArrayAsSeries(time, true);
This way, time[0] will be the current time.
I disagree! Even on the MQL4 version of the OnCalculate and the use of time[], by default time[0] accesses the current bar, unless you use ArraySetAsSeries() to change it.
On MQL5 the access is reversed by default, where time[rates_total-1] is the current bar, unless you use ArraySetAsSeries() to change it.
I'm quickly looking back in the reference to see if it will help you:
https://www.mql5.com/en/docs/event_handlers/oncalculate
Unfortunately, it might have failed you. I can see how it isn't clear for a newcomer. You may need to read the book instead.
time[rates_total - 1]
is the current (newest) bar in MQL5 as buffers are not in series by default
ArraySetAsSeries(time, true); double currentBarOpenTime = time[0];
Now time[0] references the current bar, and we are lucky this even works because of the fact that the buffer is defined as const and therefore is immutable in theory

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I am a newbie MQL5 coder - but not new to coding or trading.
I understand to access the open time of the most recent bar inside a custom indicator, in OnCalculate, I need to access time[0]. However this is giving me a time in May (13), while today is August 22. The data window in the chart is displaying the correct date. Can someone help please?
this is the code...
The output is
Improperly formatted code edited by moderator. Please always use the CODE button (Alt-S) when inserting code.