How do I run this code once per day?

 
I have a cycle with Print(). This string should be printed once per day only. There is the code:
int Hour = 20;
int Minute = 20;

int OnInit()
{
Hour = timeTemp.hour;
Minute = timeTemp.min;

EventSetTimer(60);
}

void OnTimer()
{

MqlDateTime ActivationTime;
TimeToStruct(TimeCurrent(), ActivationTime);

if (ActivationTime.hour == hour && ActivationTime.min == minute)
{
Print("This code should be printed once per day");
}
}

void OnDeinit(const int reason)
{ 
}

It has 2 issues:

1) When chart gets alot of ticks, it do more then one Print().

2) When disconnect happens or just there is a end of trading session on current instrument, time in terminal freezes and this cycle run without ending untill it gets tics and time becomes unfreezed.

So how do I run this code once per day even if there is disconnect happens?

 
static datetime timeday=0;
if (timeday!=iTime(_Symbol,PERIOD_D1,0))
   {
   Print("This code should be printed once per day");
   timeday=iTime(_Symbol,PERIOD_D1,0);
   }
 
mr_blond97:
I have a cycle with Print(). This string should be printed once per day only. There is the code:

It has 2 issues:

1) When chart gets alot of ticks, it do more then one Print().

2) When disconnect happens or just there is a end of trading session on current instrument, time in terminal freezes and this cycle run without ending untill it gets tics and time becomes unfreezed.

So how do I run this code once per day even if there is disconnect happens?


1) it doesn't make sense, it is a timer, it is not bound to OnTick()...

2) Use TimeLocal() (your computer's time) if you don't need to rely on server time...

;)