Loading…

Two Terminal Clock Sync Checker

Running a strategy split across two accounts, or two terminals pointed at different brokers, raises a question that is easy to assume away: are their server clocks actually the same instant? TimeCurrent() reflects each broker's own trade server, not a shared reference clock, and two brokers can disagree by anything from a rounding artefact to several minutes depending on how carefully each one's infrastructure is kept in sync. FILE_COMMON's shared folder (the MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)Common directory under the MetaQuotes install root, not the terminal's own private sandbox) is the one channel two separate terminal installs can read and write without any external transport - no sockets, no third-party service, nothing outside what MQL4 already ships. Both terminals run this identical script, one set to Role A and one to Role B. Each run writes its own record - server time, local time, account company and broker server string - then reads whatever the other role has already left behind and reports the difference. A record is only compared if it is fresh: a record older than InpMaxAgeSeconds is treated as stale rather than silently blamed on clock drift, since a ten-minute-old reading tells you nothing reliable about right now. Run both terminals within a few seconds of each other for a meaningful comparison, and re-run either side to refresh a stale record. Notes and limitations - Both terminals must actually share the same common data folder, which on Windows normally means the same Windows user account - two different MetaQuotes installs under two different Windows accounts do not share one common folder and this script cannot bridge that. - The reported difference includes normal filesystem/scheduling latency between one terminal writing and the other reading, typically well under a second - this is not a sub-second clock synchronisation tool. - If both terminals report the same broker company and server string, any non-trivial server-time difference reported is more likely explained by the gap between when each record was written than a genuine clock disagreement; run both sides closer together and check again. - This is a one-shot comparison per run, not a continuous monitor. Run it again whenever you want a fresh reading.

Script · MT4 · v1.0 · Free

About Two Terminal Clock Sync Checker

Two Terminal Clock Sync Checker is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Role, File prefix and Max age seconds. MQL source code included.

Files in the download: TwoTerminalClockSync.mq4, TwoTerminalClockSync.txt.

Settings

SettingDefaultWhat it does
RoleRoleAWhich side this terminal plays - the other terminal must run the OTHER role
File prefixTwoTerminalClockSyncShared file basename, must match on both terminals
Max age seconds300Other side's record older than this is treated as stale, not compared

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria