[MQL4 Coding Help] Trouble with Time Filter

dzungsua

Trader
Jul 19, 2020
6
2
19
66
Hello Enivid or any coder here ;
I have a simple EA that has been working very good for me ; the only problem I have with it is
the Time Filter ;the Hour funtion is OK but the Minute function is not ;if I set it to trade from
7:15 to 11:20 it still start to trade from 7 :00 and stop trading at 11:59
I have been trying to fix it myself but I have not been able to do that .
Hopefully you or any coder here can help me ; attached is the EA .
Thanks in advance.
 

Attachments

  • TSYaMa.mq4
    14.8 KB · Views: 7

Enivid

Administrator
Staff member
Nov 30, 2008
18,622
1,367
144
Odesa
www.earnforex.com
MQL4:
      double From_Time = From_Hour +  From_Min/60 ;
      double To_Time = To_Hour +  To_Min/60 ;
      double Cur_Time = Hour() +  Minute()/60 ;

When you divide an int that is less than 60 (and your minutes should always be in the 0-59 range), you always get 0. You need to divide using doubles. In this case, it's enough to replace 60 with 60.0.
 
  • 👍
Reactions: shanmugapradeep

dzungsua

Trader
Jul 19, 2020
6
2
19
66
Thank you Enivid ; it works great. I have been struggling with it for more than 10 years
but couldn't do it .
By the way this EA is a very good template for anyone who wants to make his own EA ;
just put in the right buffer of your indicators it will triggers the correct entry plus it has
trailing stop with ATR option . You can put in as many buffer as you want .
Hopefully it can help you to make your own EA ;if you can't do it just put a note here and I will
give you another example .
 
  • 👍
Reactions: Enivid