Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Views:
278
Rating:
(3)
Published:
\MQL5\Include\Tools\Custom\
DateTimeMsc.mqh (5.31 KB) view
\MQL5\Expert\Test\DateTimeMsc\
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

When I recently started to intensively test the functionality of CopyTicksRange(), I encountered a few unfavourable problems when handling millisecond times:

  1. I actually wanted to use CDateTime, since it is derived from MqlTimeStruct and you can edit the different time units very easily using the included increment and decrement methods.
  2. At the same time, I needed a way to smoothly translate millisecond times (seconds since 1 January 1970 times 1000 in ulong format) back and forth.

Here I encountered the difficulty that the number of milliseconds, for example, is a very vague number that does not tell you very much about the exact date. However, if you use CDateTime or TimeStruct, all the time units are easy to change, but the format tears them apart and the result is also very unclear. This CDateTimeMsc class was created to solve this problem.

#include <Tools\DateTime.mqh>

struct CDateTimeMsc: public CDateTime
  {
public:
   int               msc;               // additional variable for msc storage
   datetime          check_datetime;    // for convenient observation a little overhead is required.

   //--- CDateTimeMsc methods

   ulong             MscTime(void) {return(ulong(double(CDateTime::DateTime()) * 1000) + msc);}
   void              MscTime(ulong a_msc_time);  // input (datetime*1000)
   void              Msc(int value);
   //bool IsNumInt(const int num);
   void              MscDec(int delta = 1);
   void              MscInc(int delta = 1);
   void              SecTime(int a_int_time);
   ulong             SecTime(void);
   void              UpdateDateTime();   // updates the observation variable check_datetime
   void              DateTime(datetime a_datetime) {CDateTime::DateTime(a_datetime); UpdateDateTime();}
   datetime          DateTime(void) {return(CDateTime::DateTime());}

  };

The new methods were inserted under the inheritance of the old structure.

Now the class, which is actually a structure (see Structures/Classes), can also work with milliseconds, provided that such exact times are available.

Furthermore, the increment and decrement methods have been extended to the msc property.

One could now argue whether the additional variable "check_datetime" is really necessary, as it creates a certain overhead (for some people this is very important). However, I assumed that usually not many CDateTime objects are used, but only a few in the important places where time units such as hours, minutes, seconds or days need to be changed. I also had a few doubts about the UpDateTime() method, which is called unnecessarily with every increment/decrement.

All in all, however, the handling factor was the main focus.


The test
You no longer have to query the time with an additional datetime variable if you want to know the exact date, but can simply place the variable "check_datetime" under supervision: (TestEA see above)


obs2

The millisecond time was automatically translated into the datetime format.


Translated from German by MetaQuotes Ltd.
Original code: https://www.mql5.com/de/code/48156

Intraday Triple Performance Intraday Triple Performance

Set three crosses and monitor the daily percentage performance starting from a given time (that can also be set).

Stochastic Momentum Colour Candles Stochastic Momentum Colour Candles

Idea by Andrey F. Zelinsky, based on an indicator by William Blau

Range Vector Fibo Logic (Indicator) - One Candle Strategy Range Vector Fibo Logic (Indicator) - One Candle Strategy

A professional visual indicator for the popular "One Candle" Daily Breakout strategy (0.9 SL / 1.25 TP). Automates the vector analysis for Gold (XAUUSD).

AIS Central Axis AIS Central Axis

The indicator implements one of the non-linear smoothing algorithms