Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? The source code library is at your service!
Patricia_T
268
Patricia_T 2014.05.01 11:26 

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));
  }
onewithzachy
2274
onewithzachy 2014.05.01 11:59  
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);
  }


Patricia_T
268
Patricia_T 2014.05.01 12:45  
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.
onewithzachy
2274
onewithzachy 2014.05.01 14:05  
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.

Patricia_T
268
Patricia_T 2014.05.01 17:55  
Wow You are good!!! Thank you so much.
onewithzachy
2274
onewithzachy 2014.05.01 22:26  
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 .


Patricia_T
268
Patricia_T 2014.05.01 22:35  
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.
/
To add comments, please log in or register