Does the MT4 tester recognize time?

 

I have written an experimental EA that has to do a transaction at a certain hour. Here is an extract of the code,

the "if" statement is completely ignored when I do a backtest in the tester. Can anybody please help me?

int TradeHour = TimeHour(TimeLocal());
int TradeMinutes = TimeMinute(TimeLocal());
int TradeSeconds = TimeSeconds(TimeLocal());

if (TradeHour == 15 & TradeMinutes == 0 & TradeSeconds > 0)
 
https://docs.mql4.com/dateandtime/timelocal
 
zzuegg:
https://docs.mql4.com/dateandtime/timelocal

I already had a look at that particular page, but it did not help me. I am missing something?

Please could you be patient with me and be more specific?

 
Note: At the testing, local time is modelled and is the same as the modelled last known server time.

taken from the doc

btw, why using timelocal and not TimeCurrent()?

 

Is TimeLocal modelled correctly ? Add a Print to find out . . .

int TradeHour = TimeHour(TimeLocal());
int TradeMinutes = TimeMinute(TimeLocal());
int TradeSeconds = TimeSeconds(TimeLocal());



Print("Hours: ", TradeHour , " Mins: ", TradeMinutes," Seconds: ", TradeSeconds);  //  <---- Print added

if (TradeHour == 15 & TradeMinutes == 0 & TradeSeconds > 0)
 

I am using TimeLocal since that time is fixed no matter which broker in which time zone I use.

I have put in a Print statement just after the "if" statement - that is why I know that the 'if" statement does not filter out the wrong times - it lets every thing through, iow all different times are printed out - not just the time I am asking for in the 'if' statement. That is why I started wondering if the tester actually uses time in backtesting.

 

You are using a bitwise AND not a logical AND . . .

if (TradeHour == 15 & TradeMinutes == 0 & TradeSeconds > 0)

should be . . . . .

if (TradeHour == 15 && TradeMinutes == 0 && TradeSeconds > 0)
 
RaptorUK:

You are using a bitwise AND not a logical AND . . .

Raptor you are absolutely right! What is wrong with me? I have not programmed for a few months and have forgotten that there should bee TWO "&" for a logical "AND".

Thanks a lot! I am embarrassed!

 
ernest02:

Thanks a lot! I am embarrassed!

Don't be . . . we all miss stuff now and again . . . did you read about the Strategy Tester "bug" I found ? LOL (bug = problem in my code)
 

ernest02:

the "if" statement is completely ignored when I do a backtest in the tester. Can anybody please help me?

int TradeHour = TimeHour(TimeLocal());
int TradeMinutes = TimeMinute(TimeLocal());
int TradeSeconds = TimeSeconds(TimeLocal());
  1. & vs &&
  2. What does your local time have to do with the time of the bar the tester is showing? NOTHING! (If will always be false until you are testing after 3pm local time.)
    datetime now = TimeCurrent();
    int TradeHour = TimeHour(now);
    int TradeMinutes = TimeMinute(now);
    int TradeSeconds = TimeSeconds(now);
    Or if you meant 1500 local time, convert now (server time) to local then compare.
  3. if (TradeHour == 15 & TradeMinutes == 0 & TradeSeconds > 0)
    Alternatively:
    datetime now = TimeCurrent();
    #define HR150000 54000 // 15 * 3600 15:00:00
    //if (TradeHour == 15 & TradeMinutes == 0 & TradeSeconds > 0)
    if (now > HR150000)

  4. Instead of local time you should be doing everything in UTC to be broker independent and adjusting server time to UTC