NavigationUser loginWho's new
Who's onlineThere are currently 0 users and 24 guests online.
|
Date and Time FunctionsHi folks, We are going to study today a very important set of MQL4 functions; the Date and Time Functions, which are the functions that returns the local (your computer) and server time. As an example to show the importance of these function you can manage the time your expert advisor will enter the market and exist from the market. Another example with the aid of these functions you can know how long a position has been opened by subtracting the order opened time (returned by the function OrderOpenTime) from the current time (returned by he function CurTime which we are going to study it later). Before we dig into studying the date and time function we have to review the datetime data type because it's the cornerstone of understanding how the date and time is calculating in MQL4. datatime data type:datetime data type is a special MQL4 data type, which holds a date and time data. You set the datetime variable by using the keyword (D) followed by two signal quotations ('). Between the two signal quotations you write a character line consisting of 6 parts for value of year, month, date, hour, minutes, and seconds. datetime constant can vary from Jan 1, 1970 to Dec 31, 2037. For example:
We use the keyword datetime to create a datetime variable. For example:
Now, let's give the date and time functions a study trip: CurTime:Syntax:
Description: The CurTime function returns the current server time, it's not always the exact current server time but it's the last know server time that the terminal has been retrieved it from the server with the last price quotation. The return value of the CurTime function is a datetime data type and it's the number of seconds elapsed from 00:00 January 1, 1970. What if you used this function (and all the date & time functions) in the testing mode - Back Testing? Parameters: This function takes no parameters and return datetime value. Example:
Day:Syntax:
Description: The Day function returns the current day of the month (1, 2, 3, 4, ..... 31) of the last known server time. Parameters: This function takes no parameters and return integer value. Example:
DayOfWeek:Syntax:
Description: The DayOfWeek function returns the current day of the week of the last know server time: 0 = Sunday The day of week is modeled in the testing mode. Parameters: This function takes no parameters and return integer value. Example:
DayOfYear:Syntax:
Description: The DayOfYear function returns the current day of the year (1, 2, 3, .... 365 (366) ) of the last know server time. Parameters: This function takes no parameters and return integer value. Example:
Hour:Syntax:
Description: The Hour function returns the current hour (0, 1, 2, .... 23 ) of the last know server time. Note: The hour returned by the Hour function is the hour of the moment the program start and will not change during the execution of the program. Parameters: This function takes no parameters and return integer value. Example:
LocalTime:Syntax:
Description: The LocalTime function returns the current local computer time. The return value of the LocalTime function is a datetime data type and it's the number of seconds elapsed from 00:00 January 1, 1970. Parameters: This function takes no parameters and return datetime value. Example:
Minute:Syntax:
Description: The Minute function returns the current minute (0, 1, 2, .... 59 ) of the last know server time. Like the Hour function the minute returned by the Minute function is the minute of the moment the program start and will not change during the execution of the program. Parameters: This function takes no parameters and return integer value. Example:
Month:Syntax:
Description: The Month function returns the current month (0, 1, 2, 3, .... 12 ) of the last know server time. Parameters: This function takes no parameters and return integer value. Example:
Seconds:Syntax:
Description: The Seconds function returns the current seconds (0, 1, 2, .... 59 ) of the minute of the last know server time. Like the Hour and the Minute functions the seconds returned by the Seconds function is the second of the moment the program start and will not change during the execution of the program. Parameters: This function takes no parameters and return integer value. Example:
Year:Syntax:
Description: The Year function returns the current year of the last know server time. Parameters: This function takes no parameters and return integer value. Example:
TimeDay:Syntax:
Description: The TimeDay function returns the day of the month (1, 2, 3, ... 31) of the given date. It extracts the day of the month from the given date Parameters: datetime date: The date (datetime data type) you want to extract the day of the month from. Example:
TimeDayOfWeek:Syntax:
Description: The TimeDayOfWeek function returns the day of the week (0,1, 2, .... 6) of the given date. It extracts the day of the week from the given date Parameters: datetime date: The date you want to extract the day of the week from. Example:
TimeDayOfYear:Syntax:
Description: The TimeDayOfYear function returns the day of the year (1, 2, 3, .... 365 (366)) of the given date. It extracts the day of the year from the given date Parameters: datetime date: The date you want to extract the day of the year from. Example:
TimeHour:Syntax:
Description: The TimeHour function returns the hour of the day (0,1, 2, .... 23) of the given date. It extracts the hours of the day from the given date Parameters: datetime date: The date you want to extract the hour of the day from. Example:
TimeMinute:Syntax:
Description: The TimeMinute function returns the minute of the hour (0,1, 2, .... 59) of the given date. It extracts the minute of the hour from the given date Parameters: datetime date: The date you want to extract the minute of the hour from. Example:
TimeMonth:Syntax:
Description: The TimeMonth function returns the month of the year (1, 2, 3, .... 12) of the given date. It extracts the month of the year from the given date Parameters: datetime date: The date you want to extract the month of the year from. Example:
TimeSeconds:Syntax:
Description: The TimeSeconds function returns the seconds of the minute (0,1, 2, .... 59) of the given date. It extracts the seconds of the minute from the given date Parameters: datetime date: The date you want to extract the seconds of the minute from. Example:
TimeYear:Syntax:
Description: The TimeYear function returns the year of the given date. It extracts the year from the given date Parameters: datetime date: The date you want to extract the year from. Example:
Hope you enjoyed the lesson! Coders Guru |