Technically you can do it via loop, that is true, but now I don't see the logic behind that. Why not using the timeframe you need instead of searching for that info? In your example, if you select the 5M timeframe all candles will be of a XX:X5 type.