A daily process writes "today's decision" - which strategy runs, or FLAT - to a file the Expert Advisors read at the open. One day the writer did not run. The EAs read yesterday's file, compared its date with TimeCurrent() - the server clock, which had stepped back to the previous day overnight - saw a match, and traded all morning on a decision that was 24 hours old. No error was logged anywhere. The gate that should have failed closed failed open.
Two rules came out of it, and both are encoded in this class:
- Staleness is judged against TimeLocal(), which always moves forward. TimeCurrent() is the last tick's stamp: it freezes without ticks and can step back on reconnect or symbol change.
- When in doubt, the answer is FLAT. A missing file, a malformed date, a wrong day, an empty decision line: every failure path returns "do nothing", and each one is logged once per state change - not on every tick, which drowns the log, and not never, which is how this bug survived for a day.
File format (two lines, in MQL5\Files or the common folder): line 1 is the decision's date in ISO form (yyyy-mm-dd); line 2 is the decision itself, any string, with "FLAT" meaning stand aside. Anything after line 2 is ignored, so the writer may append notes.
How to use it. Include the file, create DecisionWatchdog wd("decision.txt") (pass true as the second argument for the common folder), and call wd.Read(why) where you would otherwise read the file yourself. The return is the decision string or "FLAT"; why carries the reason in words, for your own log or panel.
Demo script input: InpDecision ("StrategyA") - the decision written into the fresh file. The script writes five files - dated today, dated yesterday, with the date in the wrong format, dated today with no decision line, and one that does not exist - reads each through the watchdog, prints what came back and why, and deletes the files. Only the first case is allowed to trade; every other path is FLAT and logged once. Nothing is traded.