I will try to explain how I do it.
Declare these variables at the top:
Code:
extern int EndHour = 18;
extern int StartHour = 9;
bool StopTrading;
Then create this method somewhere at the bottom of the EA:
Code:
void CheckTime()
{
int h=TimeHour(TimeCurrent());
if(h>EndHour || h<StartHour)
{
StopTrading=true;
}
}
Then in the start function put this:
Code:
StopTrading = false;
CheckTime();
if(StopTrading==false)
{
//The trading logic of the EA goes here
}
This is for the time filter. I hope to have helped.
By the way, for a day filter it is the same except where it says
Code:
int h=TimeHour(TimeCurrent());
change it to
Code:
int d=TimeDayOfWeek(DayOfWeek());
And change all the "h" to "d" in the check time function. Also declare the variables at the top for StartDay and EndDay (They are an int ranging from 0-6 and 0 is Sunday, 1 being Monday, etc.
Chris