Detect last trading day of the month - page 2

 

this worked for me mql5, I posted it to help anyone with same kind of problem, however its subject to improvements

bool checkclose()
{
   //check for last day of week or last day of month
   MqlDateTime datestruc,tomorrow,nextweek;
   TimeToStruct(TimeCurrent(),datestruc);    
   TimeToStruct(iTime(_Symbol,PERIOD_D1,0)+(24*60*60),tomorrow); //plus 1 day
   TimeToStruct(iTime(_Symbol,PERIOD_D1,0)+(3*24*60*60),nextweek); //plus 3 day  
   int dow = datestruc.day_of_week;
   int dom = datestruc.day;
   int tom = tomorrow.day;
   int nxt = nextweek.day;
   
   datetime weektime=StringToTime(TimeToString(TimeCurrent(),TIME_DATE)+" "+daytimeclose);
   datetime monthtime=StringToTime(TimeToString(TimeCurrent(),TIME_DATE)+" "+monthtimeclose);
   if(dow==5&&TimeCurrent()>=weektime)return true; //if today is friday
   
   if(dom<25)return false;
   if(dom>tom&&TimeCurrent()>=monthtime)return true; //if tomorrow is a new month
   if(dow==5&&dom>nxt&&TimeCurrent()>=monthtime)return true; //if nxt week mon is a new month
      
return false;
}