On the demo server I ran it against, the broker's clock read 20:02 while the local clock read 01:02, five hours apart. This indicator puts the server clock, the local clock with its GMT zone, the measured offset and the countdown of the open candle in one panel, refreshed every second.
What it does
- One panel in a chart corner carries four rows: the broker's server clock, the local clock with its GMT zone, the offset between the two, and the countdown to the chart candle's close.
- The broker clock is the largest text on the panel, the local clock the next size, and the offset and the countdown at the base size.
- The local row names the terminal's zone from the difference between local time and GMT time: GMT+0, GMT+7, GMT-5, GMT+5:30.
- The countdown is for the chart's own timeframe, in MM:SS under an hour and H:MM:SS above it, and the row reads Market closed when the last tick is more than ten minutes behind the server clock.
- With a lead in seconds, at least one channel on and a bid on the symbol, it sends one alert per candle after the one it was attached on; at the shipped lead of 0 it stays silent.
How it works
- One pass reads each clock once: TimeTradeServer() for the broker row, the offset and the countdown, TimeLocal() for the local row, and TimeGMT() only for the zone.
- The countdown is the open bar's time plus PeriodSeconds(_Period) minus the server time, and the bar comes from iTime(_Symbol, _Period, 0); a chart with no bars yet reads no data yet.
- The timeframe label is the period enumeration with PERIOD_ cut off, so the row reads M15, H1 or D1.
- Seconds print as MM:SS under an hour and H:MM:SS above it; the close second itself reads 00:00.
- A one-second timer runs the same pass that OnInit runs, and a chart change runs it once more, so a resize or a new DPI re-lays the panel out.
- The alert path returns while the lead is 0 or every channel is off; with a lead and a channel on, the bar in progress at attach is recorded as announced, and each later bar sends once, on the first pass inside the lead window that has a bid.
Inputs
- Panel corner - the chart corner that holds the panel; a value outside the four corners falls back to the top right.
- Base font size in points - 8 to 16; the broker row is drawn two points larger and the local row one point larger, and the panel is 200 by 128 logical pixels at the shipped 9 points.
- Alert lead in seconds - how long before the candle closes the alert goes; 0 turns the alert off, and the value is clamped to 0 to 3600.
- Popup alert - the message appears as a terminal alert.
- Push notification - sends the same line to the terminal's push channel.
- Email - sends the same line by mail.
- Sound - plays alert.wav.
How to use it
- The entry carries three files: Broker_Clock.mq5 and the two headers it includes, Brand.mqh and Common.mqh. Put the headers in MQL5/Include/chimaster, the .mq5 in MQL5/Indicators, and compile it; the shipped build gave 0 errors, 0 warnings on MetaEditor 5.0.0.6328.
- Attach it to any chart: it opens in the top right corner with the base font at 9 points and the alert off.
- Read the broker row first, then the local row and the offset: the offset is broker minus local, so a broker five hours behind prints -5h 00m.
- Set a lead and tick a channel; the panel header then reads alert 300s for a 300-second lead, or alert off.
- Check the download before compiling: Broker_Clock.mq5 is 20,902 B with SHA-256 804531066ea2e79c2e8249615b205309ba98db9891bdab0805ae00a01bc7968a.
Limits
- It reports and draws: it places no order, changes no chart setting and stores nothing between runs.
- The zone is TimeLocal() minus TimeGMT(), the terminal's own idea of your clock; a terminal set to the broker's zone prints the same hour on both rows and an offset of 0h 00m.
- The offset and the zone are rounded to the minute, so a stray second prints the minute a trader reads on a clock.
- The countdown follows the server clock: when the last tick is more than ten minutes old the row reads Market closed, and it does not predict when the market reopens.