Here is a simplified function to convert server times (also stored times of bars, ticks, or economic calendar events) from one broker's time zone to another.
//+------------------------------------------------------------------+
//| Convert server time from one broker's time zone to another. |
//+------------------------------------------------------------------+
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 function adopts the standard offset notation used in most programming languages (for example, JavaScript). In this convention, positive time zones (such as GMT+3) correspond to positive offsets (e.g., +10800), while negative time zones correspond to negative offsets.
Note that this is the inverse of MQL5’s built-in TimeGMTOffset() function, which represents positive time zones with negative offsets (e.g., -10800) and negative time zones with positive offsets.
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