//+------------------------------------------------------------------+
//| time_trading.mq4 |
//+------------------------------------------------------------------+
#property library
#property version "1.81"
extern string wt_set="Work time settings";
extern bool use_work_time=false;
extern string start1= "08:00";
extern string stop1 = "16:00";
extern string start2= "";
extern string stop2 = "";
extern string start3= "";
extern string stop3 = "";
int prev_bars;
datetime start_1,stop_1,start_2,stop_2,start_3,stop_3;
///////////////////////////////////////////////
void OnInit()
{
//work time
if(use_work_time) prev_bars=0;
}
/////////////////////////////////////////////////////////////////
bool work_time_f()
{
//no use WT
if(!use_work_time) return(true);
//time current
datetime time_current=TimeCurrent();
//new day
if(iBars(Symbol(),PERIOD_H1)!=prev_bars)
{
prev_bars=iBars(Symbol(),PERIOD_H1);
start_1=StringToTime(start1);
stop_1=StringToTime(stop1);
start_2=StringToTime(start2);
stop_2=StringToTime(stop2);
start_3=StringToTime(start3);
stop_3=StringToTime(stop3);
}
if(//main
(start_1==stop_1 || ((start_1<stop_1 && (time_current<start_1 || time_current>stop_1)) || (start_1>stop_1 && (time_current<start_1 && time_current>stop_1))))
&& (start_2==stop_2 || ((start_2<stop_2 && (time_current<start_2 || time_current>stop_2)) || (start_2>stop_2 && (time_current<start_2 && time_current>stop_2))))
&& (start_3==stop_3 || ((start_3<stop_3 && (time_current<start_3 || time_current>stop_3)) || (start_3>stop_3 && (time_current<start_3 && time_current>stop_3))))
) return(false);
//if work time ok
return (true);
}
//+------------------------------------------------------------------+
Comments