How to: Alert every hour

 

I want to have an alert every hour, when the broker time is 10:00, 11:00, 12:00 so on.

How can i do that in mql4?

 

It can be done this way:


if(Minute()==0)
Alert("Its ", Hour(), " o clock ");

 

Hi Georgebaker,

Will given code work in both MT4 and MT5?

 
Paul75:
Hi Georgebaker, Will given code work in both MT4 and MT5?

I haven't tried it in MT5, but there's something wrong with the code, it give 1, 2 or sometimes 3 alerts at the same time.

Here is the correct code and it doesn't work in MT5.


bool isNewHour()
{
static datetime BarTime;
if (BarTime==0) {BarTime=iTime(NULL,PERIOD_M1,0);}
//----
bool res=false;
if (BarTime!=iTime(NULL,PERIOD_M1,0)) {
BarTime=iTime(NULL,PERIOD_M1,0);
res=true;
}
return(res);
}

int start()
{
if (isNewHour())
Alert("The time is now: ", Minute());
}

 

Thanks Georgebaker to share correct code and update about its supported trading platform.

 

You're welcome Paul

Reason: