TimeTradeServer

Returns the calculated current time of the trade server. Unlike TimeCurrent(), the calculation of the time value is performed in the client terminal and depends on the time settings on your computer. There are 2 variants of the function.

Call without parameters

datetime  TimeTradeServer();

Call with MqlDateTime type parameter

datetime  TimeTradeServer(
   MqlDateTime&  dt_struct      // Variable of structure type
   );

Parameters

dt_struct

[out]  Variable of structure type MqlDateTime.

Return Value

Value of datetime type

Note

If the MqlDateTime structure type variable has been passed as a parameter, it is filled accordingly.

To arrange high-resolution counters and timers, use the GetTickCount() function, which produces values in milliseconds.

During testing in the strategy tester, TimeTradeServer() is simulated according to historical data and always equal to TimeCurrent().

Example:

void OnStart()
  {
//--- declare the MqlDateTime variable to be filled with date/time data and get the time of the last quote and the estimated current time of the trade server
   MqlDateTime tm={};
   datetime    time_current=TimeCurrent();                  // first form of call: time of the last quote for one of the symbols in the Market Watch window
   datetime    time_server =TimeTradeServer(tm);            // second form of call: estimated current time of the trade server with filling in the MqlDateTime structure
   int         difference  =int(time_current-time_server);  // difference between Time Current and Time Trade Server
   
//--- display the time of the last quote and the estimated current time of the trade server with the data of the filled MqlDateTime structure in the log
   PrintFormat("Time Current: %s\nTime Trade Server: %s\n- Year: %u\n- Month: %02u\n- Day: %02u\n"+
               "- Hour: %02u\n- Min: %02u\n- Sec: %02u\n- Day of Year: %03u\n- Day of Week: %u (%s)\nDifference between Time Current and Time Trade Server: %+d",
               (string)time_current, (string)time_servertm.yeartm.montm.daytm.hourtm.mintm.sectm.day_of_yeartm.day_of_week,
               EnumToString((ENUM_DAY_OF_WEEK)tm.day_of_week), difference);
   /*
   result:
   Time Current2024.04.18 16:10:14
   Time Trade Server2024.04.18 16:10:15
   - Year2024
   - Month04
   - Day18
   - Hour16
   - Min10
   - Sec15
   - Day of Year108
   - Day of Week4 (THURSDAY)
   Difference between Time Current and Time Trade Server: -1
   */
  }