Download MetaTrader 5

Give an alert at a specific time or after a daily close

To add comments, please log in or register
Herbertioz
28
Herbertioz  

Hi,

I wonder how I can specify an alert at a specific time in the day or an alert after a daily close. Can someone help me with that?

The problem I think is that the functions hour(), minutes() can not be used because it only works when the script/ea loads.

I am going to use it in an EA.

Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
herbertioz:

Hi,

I wonder how I can specify an alert at a specific time in the day or an alert after a daily close. Can someone help me with that?

The problem I think is that the functions hour(), minutes() can not be used because it only works when the script/ea loads.

I am going to use it in an EA.

You can use TimeHour() and TimeMinute() with TimeCurrent() to get the current hour and current minute and then alert as appropriate.
Herbertioz
28
Herbertioz  
RaptorUK:
You can use TimeHour() and TimeMinute() with TimeCurrent() to get the current hour and current minute and then alert as appropriate.

Can this code work?
if ( TimeHour(TimeCurrent()) == 18 && TimeMinute(TimeCurrent()) == 43 ) 
{
 Alert ("It worked!");
}
Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
herbertioz:
Can this code work?

Yes, and it will alert for every tick that occurs during 6:43 pm, you probably only want one alert ?
Herbertioz
28
Herbertioz  
RaptorUK:

Yes, and it will alert for every tick that occurs during 6:43 pm, you probably only want one alert ?

Very good, I can make a boolean variable so that I do get only one alert. Thanks for help, Raptor UK!
Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
herbertioz:

Very good, I can make a boolean variable so that I do get only one alert. Thanks for help, Raptor UK!

One other thing . . . if there is no tick during 6:43 pm you won't get an alert, you might want to check for . . .

if ( TimeHour(TimeCurrent()) == 18 && TimeMinute(TimeCurrent()) >= 43 ) 
{
 Alert ("It worked!");
}

. . . and the reset your bool when the hour is > 18

To add comments, please log in or register