Day Of Week – library MetaTrader 5

The “Day of Week” function is designed to determine the number of required month according to data of the week and the day of the week inside this month. For example, we need the third Friday in February, 2000 or the fourth Wednesday in November, 1998. The function allows to determine the number of search day.

The idea of creating this function came to me when I was writing the indicator and came across many dates connected with the definite days of the week in the month. For example, there are such dates as Martin Luther King, Jr. Day which is celebrated on the third Monday of January. I could not find this day using the standard functions. As the days of the week are repeating every 28 years, the idea was just to enter the data for the next 10 years and do not create this function, but I like difficulties that is why I decided to make it anyhow.

Function parameters:

  • int year – a year,
  • int month – a month,
  • int day_o_w – the day of the week required (Monday=1, Tuesday=2,…, Sunday=7),
  • int sequence – the number of the day of the week in this month (from 1 to 5, when enter the fifth day, if this day is absent in this month, then the previous, i.e. the fourth day will output).
Alternative:   Camarilla Equation Modified - indicator MetaTrader 5

The example of using this function in the code:

Required: the second Friday in February, 1980.

The code for obtaining this number:

int day=func_day_o_w(1980,2,5,2);

Required: the last Thursday in December, 2013

The code for obtaining this number:

int day=func_day_o_w(2013,12,4,5);

Also the “DayOfWeek.mq5” script is attached. It uses this function to find the date according to the first example (the second Friday in February, 1980)

Input parameters:


The result:


 

Check the result using Windows OS time bar:



📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks