This function regulates trading times.

Can be extended with Alerts, Stop trading and much more.

TimeFilterStopTrading true/false must be set at Signal or OrderSend Command to allow or disallow orders.

Dear Ixbone Customers, if you have any questions, please feel free to contact us!

//+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
//| Time Filter                                                                                                                                                                                                                                       |
//+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

#property copyright "Copyright © 2004- IXBONE/Michael Orth"
#property link "ixbone.com"
#property strict


extern string Tfilter="=TIME FILTER=";

extern string Tfilter1="=Working Order=";
extern string Tfilter2="=WeekFilter works on the whole week, Sunday to Friday=";
extern string Tfilter3="=TradeSunday overrides the WeekFilter Sunday settings=";
extern string Tfilter4="=MondayFilter overrides the WeekFilter Monday settings=";
extern string Tfilter5="=FridayFilter overrides the WeekFilter Friday settings=";
extern bool TradeSunday=false;
extern bool MondayFilter=false;
extern int MondayHour=10;
extern int MondayMinute=0;
extern bool WeekFilter=false;
extern int StartHour=9;
extern int StartMinute=30;
extern int EndHour=21;
extern int EndMinute=30;
extern bool FridayFilter=false;
extern int FridayHour=12;
extern int FridayMinute=0;
datetime tstart,tend,tfriday,tmonday;
int nstarthour,nendhour,nfridayhour,nmondayhour;
string istarthour,istartminute,iendhour,iendminute,ifridayhour,ifridayminute,imondayhour,imondayminute;

bool TimeFilterStopTrading=false;

 

//+------------------------------------------------------------------+
//| Time Filter Init                                                             |
//+------------------------------------------------------------------+
  if(ContinueOpening==true){
    if(checktime()==true){
      TimeFilterStopTrading=true;
      }
    if(checktime()==false){
      TimeFilterStopTrading=false;
      }
    }

 

//+------------------------------------------------------------------+
//| Time filter functions                                                     |
//+------------------------------------------------------------------+

   bool checktime(){

   string svrdate=IntegerToString(Year())+"."+IntegerToString(Month())+"."+IntegerToString(Day());

   if(MondayFilter){
      nmondayhour=MondayHour;
      if(nmondayhour<10)imondayhour="0"+IntegerToString(nmondayhour);
      if(nmondayhour>9)imondayhour=IntegerToString(nmondayhour);
      if(MondayMinute<10)imondayminute="0"+IntegerToString(MondayMinute);
      if(MondayMinute>9)imondayminute=IntegerToString(MondayMinute);
      tmonday=StrToTime(svrdate+" "+imondayhour+":"+imondayminute);
   }
   if(WeekFilter){
      nstarthour=StartHour;
      if(nstarthour<10)istarthour="0"+IntegerToString(nstarthour);
      if(nstarthour>9)istarthour=IntegerToString(nstarthour);
      if(StartMinute<10)istartminute="0"+IntegerToString(StartMinute);
      if(StartMinute>9)istartminute=IntegerToString(StartMinute);
      tstart=StrToTime(svrdate+" "+istarthour+":"+istartminute);

      nendhour=EndHour;
      if(EndHour<10)iendhour="0"+IntegerToString(nendhour);
      if(EndHour>9)iendhour=IntegerToString(nendhour);
      if(EndMinute<10)iendminute="0"+IntegerToString(EndMinute);
      if(EndMinute>9)iendminute=IntegerToString(EndMinute);
      tend=StrToTime(svrdate+" "+iendhour+":"+iendminute);
   }
   if(FridayFilter){
      nfridayhour=FridayHour;
      if(nfridayhour<10)ifridayhour="0"+IntegerToString(nfridayhour);
      if(nfridayhour>9)ifridayhour=IntegerToString(nfridayhour);
      if(FridayMinute<10)ifridayminute="0"+IntegerToString(FridayMinute);
      if(FridayMinute>9)ifridayminute=IntegerToString(FridayMinute);
      tfriday=StrToTime(svrdate+" "+ifridayhour+":"+ifridayminute);
   }   
   if(WeekFilter)if((nstarthour<=nendhour && (TimeCurrent()<tstart || TimeCurrent()>tend)) || (nstarthour>nendhour && TimeCurrent()<tstart && TimeCurrent()>tend))return(true);
   if(TradeSunday==false)if(DayOfWeek()==0)return(true);
   if(MondayFilter)if(DayOfWeek()==1 && TimeCurrent()<tmonday)return(true);
   if(FridayFilter)if(DayOfWeek()==5 && TimeCurrent()>tfriday)return(true);
   return(false);
   }