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 | Time in microseconds (µs) since 01/01/1970

Simple class for getting the number of microseconds (µs) elapsed since January 1, 1970.
The error of this method is about 0.5 milliseconds. This is due to the temporal discreteness of updating the TimeLocal() function.

At the very beginning of your program (script, indicator or advisor), you need to create an instance of the class:

#include <TimeUs.mqh>    CTimeμs t;

There are three methods in this class, the names of which explain their purpose:

ulong GetTimeLocal();  ulong GetTimeTradeServer();  ulong GetTimeGMT();

A test script demonstrating the work of this class is provided:

#include <TimeUs.mqh>    CTimeμs t;    void OnStart() {     while(!IsStopped()) {        Comment("Local   - "       + string(t.GetTimeLocal()) +                " µs\nGMT   - "    + string(t.GetTimeGMT()) +                " µs\nServer - "   + string(t.GetTimeTradeServer()) + " µs");     }     Comment("");  }  //+------------------------------------------------------------------+  

MetaTrader Experts, Indicators, Scripts and Libraries

35815