According to the documentation, TimeCurrent() “returns the last known server time” and is not dependent on your computer's clock while TimeTradeServer() “returns the calculated current time of the trade server” and is dependent on your computer's clock.
Can somebody explain in detail what the difference is between their return values and how TimeTradeServer() uses the computer’s clock? When should I use one and when should I use the other?
When I print both of them TimeTraderServer() is often (but not always) 1 second behind TimeCurrent().
I assume that the simulated time in the Strategy Tester (x axis) was the trade server time during the period of the backtest and not the computer's simulated local time during the period of the backtest.
I assume this because price data history comes from the broker. Is this wrong?
I believe, but I am not sure, that TimeCurrent() only gets updated when a new Tick arrives. So, if no tick arrives or the connection goes down for a while, it gets stuck. Please note that I have not tested this.
TimeTraderServer() on the other hand "simulates" the server's time using the PC clock, so even when the tick does not come in or when there is delay in communications, the time continues to update.
I believe, it serves the purpose of allowing code to be able to detect the passing of time, even when there is no tick, or maybe to allow the code to detect when there is a delay, either by lack of data or a problem in communications.
However, in the back-test, they are both set to the same time as simulated by the back test.
In regards to part 2 of my original post; if the time axis in the Strategy Tester represents the brokers time (trade server time) and TimeGMT() is always equal to that time, then how would you get the actual GMT at that simulated point in time?
I would think that the Expert needs to be aware of the trade servers time offset from GMT....
This means that the user would need to know the GMT offset of the trade server and input the value each time.
This works but I wonder if there is a way for the EA to get that information automatically.
The only way I can think of doing it is by first running a script on live to write TimeGMT() and TimeCurrent() to a file. The EA being tested would then read this file and calculate the difference in hours between the two times.
No need to write it to a file. Simply write the time difference/offset in seconds (or minutes) to a Global Terminal Variable which can then be read by any EA or Indicator, whether in the tester or not.
EDIT: However, how will you compensate for Daylight Savings time changes in a back-test?
Thats a good idea! I was not aware that timezones differed by seconds and minutes, I thought they were all just an hour apart... ( UTC+0, UTC+1, UTC+2, etc.)
As for DST, does TimeDaylightSavings() work in the Strategy Tester?
If it does then you could find out the standard time (winter time) offset from GMT of the brokers trade server and only use that as the input... assuming we use the previous input idea.
The EA would then adjust this standard offset if TimeDaylightSavings() returned != 0
I wrote seconds because it is the easiest to calculate. I don't know of any broker using minute time zones, but in real life there are places with time zones that differ by the 30 minutes and I believe there are even a few that differ by 15 or 45 minutes.
As for TimeDaylightSavings , I don't think that will work in the Tester just as the TimeGMT does not work because is dependent the computer's settings
Please enable the necessary setting in your browser, otherwise you will not be able to log in.