Experts: MQL5 Programming for Traders – Source Codes from the Book. Part 4

 

MQL5 Programming for Traders – Source Codes from the Book. Part 4:

In the fourth part of the book, we will focus on mastering built-in functions (MQL5 API) and will gradually delve into specialized subsystems. Any MQL5 program can utilize a plethora of technologies and functionalities. Therefore, it makes sense to begin with the most simple and useful functions that can be utilized in most programs.

MQL5 Programming for Traders – Source Codes from the Book. Part 4

Author: MetaQuotes

 

Hello,

The algorithm used to calculate the broker's GMT offset and daylight savings in the script "TimeSummer.mq5" is totally wrong.

https://www.mql5.com/en/book/common/timing/timing_daylight_saving

The correct algorithm can be found here: https://www.mql5.com/en/code/48650

Determine Broker's Daylight (DST) schedule
Determine Broker's Daylight (DST) schedule
  • www.mql5.com
Script to determine whether your Broker follows the US, UK or AU daylight (DST) schedule.
 

It's possible to sort structs by more than 1 field, if create a slightly modified version of SORT_STRUCT macro. For example, for sorting by 2 fields it can be:

//+------------------------------------------------------------------+
//| Convenient macro to sort 'A'rray of 'T'ype by two 'F'ields       |
//+------------------------------------------------------------------+
#define SORT_STRUCT_2(T,A,F1,F2)                                     \
{                                                                    \
   class InternalSort : public QuickSortStructT<T>                   \
   {                                                                 \
      virtual bool Compare(const T &a, const T &b) override          \
      {                                                              \
         return (a.##F1 > b.##F1)                                    \
            || (a.##F1 == b.##F1 && a.##F2 > b.##F2);                \
      }                                                              \
   } sort;                                                           \
   sort.QuickSort(A);                                                \
}
MQL5 Book: Common APIs / Working with arrays / Comparing, sorting, and searching in arrays
MQL5 Book: Common APIs / Working with arrays / Comparing, sorting, and searching in arrays
  • www.mql5.com
The MQL5 API contains several functions that allow comparing and sorting arrays, as well as searching for the maximum, minimum, or any specific...
 
amrali #:

The algorithm used to calculate the broker's GMT offset and daylight savings in the script "TimeSummer.mq5" is totally wrong.

Feel free to write details to me via PM. Your script does similar actions in more complicated way and is bound to a pre-existed table of rules, which I deliberately did not use, because the whole idea was to detect DST from pure statistics of quotes. Server's setup can be in practice inaccurate and won't fit the standards. This is why your scripts sometimes failed to detect actual timezone of the user's servers, according to their feedback.

An updated version of my server's daylight saving time detector was recently published.

TimeServerDaylightSavings
TimeServerDaylightSavings
  • www.mql5.com
Time-related functions for empirical detection of server time zone and daylight savings mode (DST) from history of quotes