How to always refer to M1 Time[] array, even when viewing a higher timeframe?

 

My indicator is supposed to draw lines from and to bars in the M1 timeframe, which it does fine using the Time[] arrays etc.

However, I'd like to view the same lines when switching to a higher timeframe, say, M5.

Instead, my indicator will deinit and init again, when switching timeframes, redrawing lines based on the M5 arrays.

Is there a way to let the code always refer to the values of the Time[] array for the M1 candles, even when switching to a higher timeframe.

Thanks a lot for your help! 

 
You have to use iTime() function instead of Time[] predefined array. Check documentation of iTime.
 
Use iTime,iOpen, iClose, iHigh, iLow.
 

Thanks so much guys, that seems to do it!

Still learning MQL4, always great to see when the language has another thing already prepared!

 

Or you can use the new and to mql5 pointing MqlRates rates[] and CopyRates(...).


 

The iTime etc. variants work fine!

However, when switching to another timeframe, the processing takes a multiple times longer than in the original M1 timeframe, even though there are no additional tasks.

@Carl I will have a look at MqlRates to learn about it, thanks a lot 

 
ZetaTrader:

The iTime etc. variants work fine!

However, when switching to another timeframe, the processing takes a multiple times longer than in the original M1 timeframe, even though there are no additional tasks.

@Carl I will have a look at MqlRates to learn about it, thanks a lot 

The first call to iTime, iLow etc takes significantly more time than accessing the current period Time array. Then subsequent calls in the same tick processing cycle can be quicker

Another option to save cycles is to use CopyTime and get multiple bars at once

Reason: