Scripts: Clock Diagnostic: TimeCurrent() freezes and steps backwards

Clock Diagnostic: TimeCurrent() freezes and steps backwards:

TimeCurrent() is not a clock. It is the stamp of the LAST TICK. Two consequences break robots in production: 1. It freezes. With no tick it does not move: illiquid instrument, end of session, unstable connection - and any rule based on it stops with it. 2. It steps backwards: on a symbol switch, a reconnection or a tick from another instrument, the value can go back. The case that cost me a whole protection: I compared the date of a daily decision with TimeCurrent() to reject an expired one. The server clock stepped back to the previous day, the comparison matched, and four EAs accepted YESTERDAY's decision as valid. The gate that should have failed closed failed open - without a single error in the log. Rule: TimeLocal() for timestamps, dates, day changes, expiry - all that must always move forward; TimeCurrent() for session hours and market data. The script measures the divergence in your environment and reports both symptoms live. Run it with the market closed.

Clock Diagnostic: TimeCurrent() freezes and steps backwards

Author: Joao Prata Silva Yglesias

Automated-Trading:
Rule: TimeLocal() for timestamps, dates, day changes, expiry - all that must always move forward; TimeCurrent() for session hours and market data.
Let's not forget about TimeTradeServer() which runs an offset clock based on pc time─not tick arrivals.
Documentation on MQL5: TimeTradeServer / Date and Time
Documentation on MQL5: TimeTradeServer / Date and Time
  • www.mql5.com
Returns the calculated current time of the trade server. Unlike TimeCurrent() , the calculation of the time value is performed in the client...