Please help on my code?

 

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)))
 
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 

 
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) ...
 
https://www.mql5.com/en/forum/91432/page2#comment_2662182
 
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");
        
    }
 
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");
        
    }
 
sheriffonline: Working fine.
Almost. You said "00:15 to 20:30" Your test does not include 0:15:00 exactly
Reason: