Time function -

 

Wondering some help here,  I using a function controling time filter . It means, trades are placed according to time set. 

However, struggling to add days to the week also.. For example. Trade will be placed Wednesday to friday ..start time and end time. 

Function has start time and end time.working without problems... but, need to add days of the week also .. Anyone could help ? 

Thanks in advanced!

input string Time_Filter          = "--------------------< Time Filter >--------------------";........................................................................................................... 
input bool   Use_Time_Filter      = 0;      // Use Time Filter
input string Time_Start           = "06:00";// Time Start
input string Time_End             = "16:00";// Time End
input time   TimeType             = 1;      // Used Time Type

bool GoodTime()
{
  if(!Use_Time_Filter)return(true);
  if(Use_Time_Filter && StrToTime(Time_Start) < StrToTime(Time_End) && TimeType==0)
    {
    if(TimeCurrent() >= StrToTime(Time_Start) && TimeCurrent() < StrToTime(Time_End))
    return(true);
    }
  if(Use_Time_Filter && StrToTime(Time_Start) > StrToTime(Time_End) && TimeType==0)
    {
    if((TimeCurrent() >= StrToTime(Time_Start) && TimeCurrent() < StrToTime("23:59"))
    || (TimeCurrent() < StrToTime(Time_End) && TimeCurrent() >= StrToTime("00:01")))
    return(true);
    }    
  if(Use_Time_Filter && StrToTime(Time_Start) < StrToTime(Time_End) && TimeType==1)
    {
    if(TimeLocal() >= StrToTime(Time_Start) && TimeLocal() < StrToTime(Time_End))
    return(true);
    }
  if(Use_Time_Filter && StrToTime(Time_Start) > StrToTime(Time_End) && TimeType==1)
    {
    if((TimeLocal() >= StrToTime(Time_Start) && TimeLocal() < StrToTime("23:59"))
    || (TimeLocal() < StrToTime(Time_End) && TimeLocal() >= StrToTime("00:01")))
    return(true);
    }     
   return(false);
}   
 
Diego Castilho:

Wondering some help here,  I using a function controling time filter . It means, trades are placed according to time set. 

However, struggling to add days to the week also.. For example. Trade will be placed Wednesday to friday ..start time and end time. 

Function has start time and end time.working without problems... but, need to add days of the week also .. Anyone could help ? 

Thanks in advanced!


DayOfWeek()

DayOfWeek - Date and Time - MQL4 Reference
DayOfWeek - Date and Time - MQL4 Reference
  • docs.mql4.com
DayOfWeek - Date and Time - MQL4 Reference
 
Alexander Voronkov:

DayOfWeek()

Thanks. Will take a look