The bug is not in the code, the bug is in the hour() function. If I comment the line or change hour() by second() it works, so I assume the problem is the hour() function. Maybe it depends on the MT version I have, I do not know.