I wrote a small code to demonstrate my problem:
When I switch the chart period I expect the EA to pop up the alert window displaying the current chart period. Interestingly, sometimes it works and sometimes not. Here is the journal of my test:
I started with the daily and the alert was alright. Then I switched to H4 and the alert was also ok. But after switching to the H1 I waited for almost 2 minutes and there was no alert. The M30 period worked again but M15 and M5 didn't work. The weekly was ok again. Why doesn't the EA recognize all period changes?
Can somebody tell me what's wrong with the code? I can't see any mistake here...?!
When you switch from H4 to H1 for example, you can still have the same time for candle 0.
Anyway if you want to check a timeframe change, compare the timeframe, not the time. Or even UninitializeReason().
Can use a switch for example