Search code examples
mql4

How can I get the Time[0] in different timeframes?


How can I get the Time[0] in different timeframe? I am only using one chart, Thank you in advance for helping.

for example, my current open chart is in 1H timeframe, I want to get the candle open time in 1H timeframe, in 30M timeframe and 15min timeframe, without changing the timeframe of current open chart.


Solution

  • To get Time value for the bar of specified timeframe use iTime() function.

    Example (both alerts have same results):

    Alert("Time[0]: ", Time[0]);
    Alert("iTime[0]: ", iTime(Symbol(), PERIOD_CURRENT, 0));
    

    For specified timeframe use enum timeframes.

    Check also iTime docs.