TimeCurrent() returns corrupted future timestamps!

TimeCurrent() returns corrupted future timestamps, while TimeLocal / TimeGMT / TimeTradeServer / iTime are all correct

Problem

TimeCurrent() returns absurd future values (year 2033, even year ~69,000), while every other time source returns the correct time. Note: Print(t) itself outputs the literal string wrong datetime — the terminal refuses to format the value because it's outside the valid datetime range.

Environment

  • MT5, latest build
  • Symbol: EURUSD, H1

Reproduction

void OnStart()
{
   datetime tBar0 = iTime(_Symbol, PERIOD_CURRENT, 0);
   datetime tBar1 = iTime(_Symbol, PERIOD_CURRENT, 1);

   Print("iTime Bar[0]: ", TimeToString(tBar0, TIME_DATE|TIME_SECONDS), "  (", (long)tBar0, ")");
   Print("iTime Bar[1]: ", TimeToString(tBar1, TIME_DATE|TIME_SECONDS), "  (", (long)tBar1, ")");

   Print("TimeLocal      : ", TimeToString(TimeLocal(),      TIME_DATE|TIME_SECONDS), "  (", (long)TimeLocal(),      ")");
   Print("TimeGMT        : ", TimeToString(TimeGMT(),        TIME_DATE|TIME_SECONDS), "  (", (long)TimeGMT(),        ")");
   Print("TimeTradeServer: ", TimeToString(TimeTradeServer(), TIME_DATE|TIME_SECONDS), "  (", (long)TimeTradeServer(), ")");
   Print("TimeCurrent    : ", TimeToString(TimeCurrent(),    TIME_DATE|TIME_SECONDS), "  (", (long)TimeCurrent(),    ")");
}

Output from a single run

2026.10.28 13:29:23.353 Scripts Test Idea (EURUSD,H1)   iTime Bar[0]: 2026.10.28 11:00:00  (1793185200)
2026.10.28 13:29:23.353 Scripts Test Idea (EURUSD,H1)   iTime Bar[1]: 2026.10.28 10:00:00  (1793181600)
2026.10.28 13:29:23.353 Scripts Test Idea (EURUSD,H1)   TimeLocal      : 2026.10.28 13:29:23  (1793194163)
2026.10.28 13:29:23.353 Scripts Test Idea (EURUSD,H1)   TimeGMT        : 2026.10.28 09:59:23  (1793181563)
2026.10.28 13:29:23.353 Scripts Test Idea (EURUSD,H1)   TimeTradeServer: 2026.10.28 11:59:23  (1793188763)
2026.10.28 13:29:23.353 Scripts Test Idea (EURUSD,H1)   TimeCurrent    :   (2199093514239) <-- broken

Previous run of the same script:

TimeCurrent    : 2033.10.18 01:19:24  (2013211164)        <-- broken


Even simpler — this alone reproduces it:

void OnStart()
{
   datetime t = TimeCurrent();
   Print("datetime: ", t);
   Print("As long: ", (long)t);
}

Output:

2026.10.28 13:19:51.115 Scripts Test Idea (EURUSD,H1)   datetime: wrong datetime
2026.10.28 13:19:51.115 Scripts Test Idea (EURUSD,H1)   As long: 2199093514239

Observations

  1. Only TimeCurrent() is wrong. TimeLocal , TimeGMT , TimeTradeServer , and iTime are all correct and consistent.
  2. iTime(bar 0) = 11:00 and TimeTradeServer = 11:38 — consistent, so candle data is fine.
  3. TimeCurrent() value changes between runs, and TimeToString(TimeCurrent()) also shows a future date — so this is not a cast/conversion bug; the source value itself is corrupted.
  4. Deleting ticks via Ctrl+U → Ticks → Delete and restarting did not fix it.

Questions

  1. Is this a broker-side tick stamping issue or a terminal-side cache issue?
  2. Recommended workaround? I currently use TimeTradeServer() everywhere, but that doesn't reflect incoming ticks (breaks bar-close detection based on TimeCurrent() ).
  3. Any supported way to force TimeCurrent() to resync from the server?

Any official confirmation from MetaQuotes would be appreciated.

matinz: Any official confirmation from MetaQuotes would be appreciated.
None required. Time comes from your broker. Contact them.
William Roeder #:
None required. Time comes from your broker. Contact them.
> Not just broker-side — I can reproduce this on **MetaQuotes-Demo** too. `TimeCurrent()` also has a history of terminal-side bugs (the 1970.01.01 bug fixed in build 231, and 15-min lag reports on demo). And the terminal itself prints `wrong datetime` when formatting the value — a bad broker tick alone shouldn't cause that.

In a script, TimeCurrent() uses the last quote time from any symbol in Market Watch. Inside OnTick() , it uses the handled tick’s time. That distinction does not explain or validate the invalid timestamp. Documentation.

For your bar-close logic, you can detect the next bar without calculating its boundary from TimeCurrent() . In the chart symbol’s OnTick() , track iTime(_Symbol, your_timeframe, 0) and process bar 1 when the opening time advances. Establish a baseline on the first valid read, check for zero/data errors, and define how to handle missed bars after reconnection. The official OnTick example shows the basic comparison.

This detects the transition when a tick makes the new bar available, not at the exact clock boundary. It depends on valid bar data and does not repair the timestamp problem. I could not find a documented MQL5 function to force TimeCurrent() to resynchronise.

Documentation on MQL5: TimeCurrent / Date and Time
Documentation on MQL5: TimeCurrent / Date and Time
  • www.mql5.com
Returns the last known server time, time of the last quote receipt for one of the symbols selected in the "Market Watch" window. In the...
Sayed Ali Ordibehesht #:

In a script, TimeCurrent() uses the last quote time from any symbol in Market Watch. Inside OnTick() , it uses the handled tick’s time. That distinction does not explain or validate the invalid timestamp. Documentation.

For your bar-close logic, you can detect the next bar without calculating its boundary from TimeCurrent() . In the chart symbol’s OnTick() , track iTime(_Symbol, your_timeframe, 0) and process bar 1 when the opening time advances. Establish a baseline on the first valid read, check for zero/data errors, and define how to handle missed bars after reconnection. The official OnTick example shows the basic comparison.

This detects the transition when a tick makes the new bar available, not at the exact clock boundary. It depends on valid bar data and does not repair the timestamp problem. I could not find a documented MQL5 function to force TimeCurrent() to resynchronise.

Thanks, but I'm not looking for a workaround. My point is the bug itself.

The "last quote time from any symbol in Market Watch" explanation doesn't cover what's happening here. If it were just a stale or non-tick-synced value, it would still be a valid timestamp. Instead:

  • (long)TimeCurrent() returns 2199093514239 (year ~69,000) and 2013211164 (year 2033) — different every run.
  • Print(TimeCurrent()) itself outputs the literal string wrong datetime — the terminal refuses to format it because it's outside the valid datetime range.
  • TimeTradeServer() , TimeGMT() , TimeLocal() , and iTime() are all correct and consistent.

A "last quote time" value should never leave the datetime domain. That's not a design distinction — that's corruption of the value before it reaches the script. And it reproduces on MetaQuotes-Demo, not just a third-party broker.

I'd like to know: is this a known terminal-side issue, and is anyone from MetaQuotes able to confirm what writes into the TimeCurrent() cache that can produce a value outside the valid range?

matinz #:

Thanks, but I'm not looking for a workaround. My point is the bug itself.

The "last quote time from any symbol in Market Watch" explanation doesn't cover what's happening here. If it were just a stale or non-tick-synced value, it would still be a valid timestamp. Instead:

  • (long)TimeCurrent() returns 2199093514239 (year ~69,000) and 2013211164 (year 2033) — different every run.
  • Print(TimeCurrent()) itself outputs the literal string wrong datetime — the terminal refuses to format it because it's outside the valid datetime range.
  • TimeTradeServer() , TimeGMT() , TimeLocal() , and iTime() are all correct and consistent.

A "last quote time" value should never leave the datetime domain. That's not a design distinction — that's corruption of the value before it reaches the script. And it reproduces on MetaQuotes-Demo, not just a third-party broker.

I'd like to know: is this a known terminal-side issue, and is anyone from MetaQuotes able to confirm what writes into the TimeCurrent() cache that can produce a value outside the valid range?

Just run your code on MetaQuotes-Demo.

2026.10.28 11:21:35.688    __forum__ (GBPUSD,D1)    datetime: 2026.10.28 17:21:34
2026.10.28 11:21:35.688    __forum__ (GBPUSD,D1)    As long: 1793208094
2026.10.28 11:24:03.978    __forum__ (GBPUSD,D1)    iTime Bar[0]: 2026.10.28 00:00:00  (1793145600)
2026.10.28 11:24:03.979    __forum__ (GBPUSD,D1)    iTime Bar[1]: 2026.10.27 00:00:00  (1793059200)
2026.10.28 11:24:03.979    __forum__ (GBPUSD,D1)    TimeLocal      : 2026.10.28 11:24:03  (1793186643)
2026.10.28 11:24:03.979    __forum__ (GBPUSD,D1)    TimeGMT        : 2026.10.28 15:24:03  (1793201043)
2026.10.28 11:24:03.979    __forum__ (GBPUSD,D1)    TimeTradeServer: 2026.10.28 17:24:03  (1793208243)
2026.10.28 11:24:03.979    __forum__ (GBPUSD,D1)    TimeCurrent    : 2026.10.28 17:24:03  (1793208243)

So which server are using to get the value you reported ?

In the Strategy Tester TimeTradeServer() is always equal to TimeCurrent(), so if your values differ this isn't the tester. Outside OnTick() the value comes from any symbol in the Market Watch, so one broken symbol can corrupt it. Print the tick time of each Market Watch symbol.

Use the CODE button (Alt-S) when inserting code.

A moderator corrected the formatting this time. Please format code properly in future; posts with improperly formatted code may be removed.

for(int i=0; i<SymbolsTotal(true); i++)
  {
   string sym = SymbolName(i, true);
   MqlTick t;
   if(SymbolInfoTick(sym, t))
      Print(sym, " ", TimeToString(t.time, TIME_DATE|TIME_SECONDS));
  }