I just added the ability to specify the start and end date of the trading to my EA, however, I discovered a weird behaviour!
If I have specified the starting date for trade from
2016.05.01 00:00:00
and the end date to
2016.05.10 00:00:00
the EA trades from 2015.05.02 00:00
to 2016.05.12 14:02
but if I specified the date from2016.06.01 00:00:00
to 2016.06.10 00:00:00
it trades from 2016.06.01 00:00
to 2016.06.10 14:53
Here is my code:
extern datetime StartDate = __DATETIME__;
extern datetime EndDate = __DATETIME__;
int isTrading = 0;
if ( StartDate < EndDate ) {
if ( TimeCurrent() > StartDate
&& TimeCurrent() < EndDate
) isTrading = 1;
} else {
if ( TimeCurrent() > StartDate
|| TimeCurrent() < EndDate
) isTrading = 1;
}
I don't know what is wrong here, any help will be much appreciated.
Thank you in advance.
The simplest part:
Given the
StartDate == 2016.05.01 00:00
, there indeed the Market is closed ( and the call toTimeCurrent()
function would return just some olddatetime
value from the last tick from the last week of April ).As the Market is closed yet, no
OnTick()
-triggering event ( message ) will arrive ( the less any trading will ever be able to happen ) until2016.05.02
( Monday ) starts and the first "new"QUOTE
message indeed arrives from the Server-side, based on some further details.Documentation warns:
The few harder points:
GMT-offset of the Broker Server-side setup ( not a problem in very this server-side / server-side
datetime
perspective, otherwise yes )FX-instrument (
_Symbol
) trading conditions ( Precious metals and Indices typically start with additional time-offsets and do not follow 24*5 Market Trading Hours of the Majors ).Broker-specific changes of trading hours / outages announced in advance.
MetaTrader Terminal 4 [ Strategy Tester ] may behave surprisingly on incomplete data ( Gaps in History Centre ) and the documentation warns just "indirectly" about this: