EA operating Time

To add comments, please log in or register
RainyDay
148
RainyDay  

Hi all,

I have a function that checks the time of day in my EA.  It looks like this:

void CheckTime()
{

   static int reset;   

   if(Hour()==NewDay && reset==1)
   {
      TradeTime=True;
      reset=0;   
   }

   if(Hour()==CloseDay && reset==0)
   {
      TradeTime=False;
      reset=1;
   }
}

NewDay/CloseDay are external int variables, 0 and 2 respectively.

TradeTime is an external bool variable that allows trading to occur / not occur.

It functions correctly on every day of the week...except for Mondays. 

Would anyone be able to explain why this is? 

And anything I can do to overcome this and allow trading 5 days a week.

Any advice would be greatly appreciated!

Marco vd Heijden
Moderator
12989
Marco vd Heijden  

Well you can also use

TimeDayOfWeek();
RainyDay
148
RainyDay  
Marco vd Heijden:

Well you can also use

Thanks I'll have a pop at it
William Roeder
22318
William Roeder  
RainyDay: It functions correctly on every day of the week...except for Mondays. Would anyone be able to explain why this is?
static int reset;
It shouldn't work at all because reset has a random value initially. Simplify your code:
bool isTradingTime = NewDay <= Hour() && Hour() < CloseDay;
RainyDay
148
RainyDay  
whroeder1:
It shouldn't work at all because reset has a random value initially. Simplify your code:
As always...thank you!
To add comments, please log in or register