Hour()==X doesn't work in tester

 

Hi,

I wrote an EA that I want to be trading at a specific hours. The condition I was using was:


if(Hour() > 8 && Hour() < 18)

{

// buy, sell etc

}


It seems never to go inside the brackets. Any ideas why?


When I leave the condition out, trades are performed few times every hour so there is no issue that open signals are not met, there should be at least couple of trades there.


EDIT: if this is of any importance, I use data downloaded from the history center for EURUSD M5 and "control points" testing, however, changing TF and testing model didn't help

 
allerune wrote >>

Hi,

I wrote an EA that I want to be trading at a specific hours. The condition I was using was:

if(Hour() > 8 && Hour() < 18)

{

// buy, sell etc

}

It seems never to go inside the brackets. Any ideas why?

When I leave the condition out, trades are performed few times every hour so there is no issue that open signals are not met, there should be at least couple of trades there.

EDIT: if this is of any importance, I use data downloaded from the history center for EURUSD M5 and "control points" testing, however, changing TF and testing model didn't help

if (Hour()>=8 && Hour()<=18) .... was working for me.

Put a Print("Hour valid"); after the { and watch the journal.

Maybe some conditions after your { does not meet some conditions?

 
TimeHour(TimeCurrent())
 
Exactly. Hour() is the time NOW which is irrelevant in the tester. You want the hour of the current tick.
 

Yet...

Documentation for Hour() https://docs.mql4.com/dateandtime/Hour says

Note: At the testing, the last known server time is modelled.

Another feature or just on a slightly damaged MT installation?

-BB-

 
WHRoeder:
Exactly. Hour() is the time NOW which is irrelevant in the tester. You want the hour of the current tick.

Not quite sure I understand the point you are making here?


CB

 
TheEconomist:
TimeHour(TimeCurrent())

thanks, this one is working, however the other one should be working too...

 
BarrowBoy:

Yet...

Documentation for Hour() https://docs.mql4.com/dateandtime/Hour says

Note: At the testing, the last known server time is modelled.

Another feature or just on a slightly damaged MT installation?

-BB-


you're right, last time before "start" function on server or time modelled by tester. Everything should work (and it works if we just put Print(Hour()) there)


what do you mean by "damaged MT installation"? Can you please elaborate on that? Are there ways of checking if my installation is damaged?

Reason: