interval trading not working

 

Hello,

I added interval trading to my EA before the update. I am now updated to build 625 and the interval trading is not working.

can anyone tell me why??

 extern int StartHour1=13;
 extern int EndHour1=16;
 extern int StartHour2=13;
 extern int EndHour2=16;
 extern int CloseTradesHour=17;
 extern bool UseServerTime=true;

 bool InInterval(datetime time, int beginHour, int beginMinute, int endHour, int endMinute)
  {
    return(TimeHour(time)>beginHour || (TimeHour(time)==beginHour && TimeMinute(time)>=beginMinute)
    && TimeHour(time)<endHour || (TimeHour(time)==endHour && TimeMinute(time)<=endMinute));
  }
 
trade4now:

Hello,

I added interval trading to my EA before the update. I am now updated to build 625 and the interval trading is not working.

can anyone tell me why??

extern int StartHour1=13;
extern int EndHour1=16;
extern int StartHour2=13;
extern int EndHour2=16;
extern int CloseTradesHour=17;
extern bool UseServerTime=true;

bool InInterval(datetime time, int beginHour, int beginMinute, int endHour, int endMinute)
{
return(TimeHour(time)>beginHour || (TimeHour(time)==beginHour && TimeMinute(time)>=beginMinute)
&& TimeHour(time)<endHour || (TimeHour(time)==endHour && TimeMinute(time)<=endMinute));
}

1. Use SRC button when posting code, it's much easier for us to read the code.

2. For MT4 buil 600 and above use input instead of extern

input int StartHour1=13;
input int EndHour1=16;
input int StartHour2=13;
input int EndHour2=16;
input int CloseTradesHour=17;
input bool UseServerTime=true;

3. Where is the input for minute ?, I don't see it.

4. This logic is wrong because return command ...

return(TimeHour(time)>beginHour || (TimeHour(time)==beginHour && TimeMinute(time)>=beginMinute)
&& TimeHour(time)<endHour || (TimeHour(time)==endHour && TimeMinute(time)<=endMinute));

... is NOT comparison. Use if statement for comparison and the return the result.

if(TimeHour(time)>beginHour || (TimeHour(time)==beginHour && TimeMinute(time)>=beginMinute)
   && TimeHour(time)<endHour || (TimeHour(time)==endHour && TimeMinute(time)<=endMinute))
  {
   return (true);
  }
  else
  {
   return (false);
  }


 
thank you I removed the minutes as I was not using it. It is trading normally now inside the intervals but will open a trade outside the interval and immediately close it.
 
trade4now:
thank you I removed the minutes as I was not using it. It is trading normally now inside the intervals but will open a trade outside the interval and immediately close it.

All right, lets work on that. Let's simplify things first. Say, for example, that you're not really using that minute. Then this logic will be like this ...

if(TimeHour(time)>= beginHour && TimeHour(time) <= endHour )
  {
   return (true);
  }
  else
  {
   return (false);
  }

Adding some minute, then it will be like this ...

if(   (TimeHour(time) > beginHour || ( TimeHour(time) == beginHour && TimeMinute(time) >= beginMinute ))
   && (TimeHour(time) < endHour   || ( TimeHour(time) == endHour   && TimeMinute(time) <= endMinute   ))  )
  {
   return (true);
  }
  else
  {
   return (false);
  }

That is if I'm reading your logic correctly :D.

 
Wow You are good!!! Thank you so much.
 
trade4now:
Wow You are good!!! Thank you so much.

Nope, just adding what missing from your original code.

And you're welcome, and thank you you too for saying thank you, it's very rare to thank other in this forum .


 
That is very sad We should be thankful for each other. Together we can all help each other. You gave me some of your time, and I appreciate that.
Reason: