- During testing in the strategy tester, TimeCurrent() is simulated according to historical data.
Date and Time / TimeCurrent - Reference on algorithmic/automated trading language for MetaTrader 5 -
Simulation of Time in the Strategy Tester
During testing, the local time TimeLocal() is always equal to the server time TimeTradeServer(). In turn, the server time is always equal to the time corresponding to the GMT time - TimeGMT(). This way, all of these functions display the same time during testing.
The lack of a difference between the GMT, the Local, and the server time in the Strategy Tester is done deliberately in case there is no connection to the server. The test results should always be the same, regardless of whether or not there is a connection. Information about the server time is not stored locally, and is taken from the server.
MQL5 programs / Testing Trading Strategies - Reference on algorithmic/automated trading language for MetaTrader 5
Option 1: global variable
datetime currentTick = iTime(_Symbol,0,0);2020.12.02 01:12:00
Option 2: create a testfile and get the timestamp of file creation
string tmpFileName = "_TEMP_FILE"; int handleTmpFile = FileOpen(tmpFileName, FILE_WRITE); if(handleTmpFile==INVALID_HANDLE); datetime now = (datetime)FileGetInteger(handleTmpFile, FILE_CREATE_DATE); MqlDateTime nowMql; TimeToStruct(now,nowMql); FileClose(handleTmpFile); FileDelete(tmpFileName);
I found Option 2 once in this forum...
I found this useful when using the debugger on historical trading cases with Strategy Tester:
A typical case is noticing an interesting trading case unfolding at a specific time and you want to analyze how your trading strategy code best handles it to accomplish some profit.
Let's say something interesting is beginning to happen at
2024 11 19 at 18:30:00 in the historical data chart.
In this case you would specify a date range in Strategy Tester such as 2024-11-19 to 2024-11-21
// Provide a debugger breakpoint to stop at // a given time in the trading range where a trading // case needs to be examined in detail. datetime now=TimeCurrent(); datetime here=D'2024.11.19 18:30:00'; if (now >= here) { bool match=true; // Stop at 11:45:00 ! }
then in MetaEditor you launch debugging:
Debug->Start on History Data
This causes launch of Strategy Tester in the Debugger
beginning in 2024-11-19 at 00:00.00
and as soon as tester time has reached 2024-11-19 at 11:45:00
the breakpoint will trigger.
Then simply place a breakpoint on the match=true line where you can begin further debugging
at 11:45:00 in the historical data range:
I found this useful when using the debugger on historical trading cases with Strategy Tester:
A typical case is noticing an interesting trading case unfolding at a specific time and you want to analyze how your trading strategy code best handles it to accomplish some profit.
Let's say something interesting is beginning to happen at
2024 11 19 at 18:30:00 in the historical data chart.
beginning from 11:45:00 :

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everybody,
I need to get the current datetime in a string, possibly in a SQL format (e.g. 2019-04-07 15:37:02).
I've tried three methods of MQL5 standard library:
but during backtest they all return the same date that is not the actual date.
I need to get the current datime (not an historical datetime referred to backtest).
Do you have any advices?
Thanks in advance,
Robert