Download MetaTrader 5
To add comments, please log in or register
Interested in the Market activity? Come and track!
Sherif Hasan
7224
Sherif Hasan 2016.07.18 05:39 

I want to run my ea on following times:

00:15 to 20:30

i have tried following logic. but it does not accept the times like 0015, which takes as 15:00

int datetime800 = TimeCurrent();
    int hour0 = TimeHour(datetime800);
    
    if ((HoursMinutesFrom < HoursMinutesTo && hour0 >= HoursMinutesFrom && hour0 < HoursMinutesTo) ||
    (HoursMinutesFrom > HoursMinutesTo && (hour0 < HoursMinutesTo || hour0 >= HoursMinutesFrom)))
rod178
276
rod178 2016.07.18 05:44  
sheriffonline:

I want to run my ea on following times:

00:15 to 20:30

i have tried following logic. but it does not accept the times like 0015, which takes as 15:00


enter the time(s) as text (string)

convert the string to datetime 

whroeder1
13644
whroeder1 2016.07.18 14:05  
Or define your times.
#define HR0015   900 // 15 * 60
#define HR2030 73800
#define HR2400 86400 // 24 * 3600
datetime now = TimeCurrent();
datetime tod = now % HR2400; // Time of day
if(now >= HR0015 && now < HR2030) ...
Vasyl Nosal
18222
Vasyl Nosal 2016.07.18 19:59  
https://www.mql5.com/en/forum/91432/page2#comment_2662182
Sherif Hasan
7224
Sherif Hasan 2016.10.03 20:29  
WHRoeder:
Or define your times.

Hi WHRoeder,

Sorry i am late. i tried the code as your suggestion. but it doesn't work. sorry i did anything wrong. lloking for your reply.

    datetime now = TimeCurrent();
    #define HR0015   900 // 15 * 60
    #define HR2030 73800
    #define HR2400 86400 // 24 * 3600
    datetime tod = now % HR2400; // Time of day
    
    if ((now > HR0015) && (now < HR2030))
    {
        Comment("TRADING HOURS");
        
    }
Sherif Hasan
7224
Sherif Hasan 2016.10.03 21:38  
sheriffonline:

Hi WHRoeder,

Sorry i am late. i tried the code as your suggestion. but it doesn't work. sorry i did anything wrong. lloking for your reply.

Working fine.

    datetime now = TimeCurrent();
    #define HR0015   900 // 15 * 60
    #define HR2030 73800
    #define HR2400 86400 // 24 * 3600
    datetime tod = now % HR2400; // Time of day
    
    if ((tod > HR0015) && (tod < HR2030))
    {
        Comment("TRADING HOURS");
        
    }
whroeder1
13644
whroeder1 2016.10.04 15:07  
sheriffonline: Working fine.
Almost. You said "00:15 to 20:30" Your test does not include 0:15:00 exactly
/
To add comments, please log in or register