Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Libraries | ConvertServerTime

Here is a simplified function to convert server time (also bars and tick times) from one broker's time zone to another.

//+------------------------------------------------------------------+
//| Convert server time from one server TZ to another server TZ.     |
//+------------------------------------------------------------------+
datetime  ConvertServerTime(
   const datetime   aTime,                             // source server time to convert
   const int        sourceOffsetUTC = 0,               // source server standard (winter) UTC offset in seconds
   const int        destinationOffsetUTC = 0,          // destination server standard (winter) UTC offset in seconds
   ENUM_RULE_DST    sourceRuleDST = DST_NONE,          // source server daylight savings schedule
   ENUM_RULE_DST    destinationRuleDST = DST_NONE      // destination server daylight savings schedule
  )

To be able to identify the DST schedules for the source and destination servers (US, EU, or no schedule), you can use that script https://www.mql5.com/en/code/48650


This is a sample of running the function:


The output:


The complete library (TimeZoneInfo.mqh) with more features can be found here. https://www.mql5.com/en/code/48419

65102

Best MetaTrader Indicators + Profitable Expert Advisors