How do I know tomorrow is the first Friday of current month?

 

I suppose it needs a calendar, a file, from which the algorythm can read and compare dates, and verify if this is the first Fryday of the month.

Alternatively, should be built the algorythm of the weeks, determination of the day of the week, but finding a 1st specific day is different mattert.

 

A trick can be to compute first how many such Fryday(s) are within a month, it can be 4 or 5, (for example this June have 5 Fry, 1,8,15,22,29; instead this May have 4 Fry: 4,11,18,25),

and then determine when (day number) by picking up the first one of the 4 or the 5, but in this sense, it's a problem that return to it's source, and not solved in this way.

 

Only thing that you can do, or implement Gregorian caldendar algorythms in the mql5 code, and once have data, can experiment with it,

or have a calendar file with the next N years (10, 100.. 1000? etc.), then only read by it, and find if a month have 4 or 5 Fry, and pick up the first.

 

Try this, is JavaScript, you should have no problem to convert to mql5, or can ask a programmer on Jobs

function gregdaynumber(year,month,day){ 

// computes the day number since 0 January 0 CE (Gregorian) 

y=year; 
m=month; 
if(month < 3) y=y-1; 
if(month < 3) m=m+12; 
return Math.floor(365.25*y)-Math.floor(y/100)+Math.floor(y/400)+Math.floor(30.6*(m+1))+day-62; 
}

function isocalendar1(){ 

// computes the ISO calendar date from the current Gregorian date 

var today = new Date(); 

year=today.getFullYear(); 
month=today.getMonth(); // 0=January, 1=February, etc. 
day=today.getDate(); 
wday=today.getDay(); 

weekday=((wday+6)%7)+1; // weekdays will be numbered 1 to 7 

isoyear=year; 

d0=gregdaynumber(year,1,0); 
weekday0=((d0+4)%7)+1; 

d=gregdaynumber(year,month+1,day); 
isoweeknr=Math.floor((d-d0+weekday0+6)/7)-Math.floor((weekday0+3)/7); 

// check whether the last few days of December belong to the next year's ISO week 

if((month == 11) && ((day-weekday) > 27)){ 
isoweeknr=1; 
isoyear=isoyear+1; 
} 

// check whether the first few days of January belong to the previous year's ISO week 

if((month == 0) && ((weekday-day) > 3)){ 
d0=gregdaynumber(year-1,1,0); 
weekday0=((d0+4)%7)+1; 
isoweeknr=Math.floor((d-d0+weekday0+6)/7)-Math.floor((weekday0+3)/7); 
isoyear=isoyear-1; 
} 

if(isoweeknr < 10) return isoyear+"-W0"+isoweeknr+"-"+weekday; 
if(isoweeknr > 9) return isoyear+"-W"+isoweeknr+"-"+weekday; 
}

 The fact, that in a month there are or 4 or 5 specific day (in this example Fry), and the fact that months structure are like following, can help in the determination of the first specific day in a month.

 

31, 28(29), 31,   30,    31,   30,   31,    31,     30,    31,     30,     31

J       F        M      A      M      J      J      A        S       O       N        D

 

  • script
  • alert if tomorrow 1st Friday of current month
  • use local time of a computer
//+------------------------------------------------------------------+
//| Alert if tomorrow 1st Friday of current month                    |
//+------------------------------------------------------------------+
void OnStart()
  {

   MqlDateTime time;

   datetime Tomorrow=TimeLocal()+24*60*60;

   TimeToStruct(Tomorrow,time);

   if(time.day_of_week==5 && time.day<8) Alert("Tomorrow is the 1st Friday of current month!");

  }

 
FinGeR:

  • script
  • alert if tomorrow 1st Friday of current month
  • use local time of a computer

Perfection.

MQL5 power. 

 
FinGeR: cool code!
Reason: