Time Function Playground
Every bar timestamp in MQL4 is in the broker's server time, which is neither the trader's local time nor GMT, and rarely matches either one by a round number of hours once daylight saving is involved on one side and not the other. "Is this bar from this morning or is that server time eight hours ahead of me" is a question every trader asks eventually, and working it out by hand from three different clocks is exactly the kind of thing a script should just show. This script reads TimeCurrent(), TimeLocal() and TimeGMT() at the same instant and prints all three, then states the offset between each pair in plain +HH:MM form - server to GMT, local to GMT, and server to local, the one that actually answers "what time did this bar open, in my time." It applies that same offset to the chart's most recent bars, so the comparison is not abstract - it is that specific chart's specific bars, translated. The offset is measured once and applied as a constant across the bars shown. Both server time and local time move at a steady one second per second within a session; there is no reason to re-derive the offset per bar, and doing so would just be slower for the same answer. A short round trip through TimeToStruct and StructToTime is included at the end, mainly because it is the tool most scripts actually need when building or comparing a specific date and time rather than reading the clock, and seeing the struct's fields named against a real timestamp is clearer than reading about them. Notes and limitations - TimeGMT() reflects the terminal's own understanding of GMT, which is derived from the local system clock and Windows time zone database, not fetched from an external time source. - The server-to-local offset can change if Windows daylight saving toggles while the terminal is running, or if the broker's own server observes a different DST schedule to the trader's location - a script that keeps a cached offset across a long-running session should re-measure it periodically rather than assuming it never changes, as this script's own single-run reading does. - Bars shown are limited to whatever history is already loaded for the chart; if fewer bars are available than InpBarsToShow asks for, only the available ones are listed.
Script · MT4 · v1.0 · Free
About Time Function Playground
Time Function Playground is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 1 setting, such as Bars to show. MQL source code included.
Files in the download: TimeFunctionPlayground.ex4, TimeFunctionPlayground.mq4, TimeFunctionPlayground.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Bars to show | 5 | How many of the chart's most recent bars to list |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Script · MQL4 Source Code