Download MetaTrader 5
To add comments, please log in or register
Documentation is available in CHM and PDF. Download it in any convenient form!
mikegreen
236
mikegreen 2015.10.13 14:32 

Hi,

 

I have a fully functioning EA, however I want to add a time of day trading filter so that the EA only trades within certain times of the day. I would also like to optimise this time function for best results.

Can some one on this forum please direct me to the section of code base that provides such code and or supply me with such so I can add it to my EA.

Many thanks....Mickey. 

DeanDeV
330
DeanDeV 2015.10.13 18:48  
mickeyferrari:

Hi,

 

I have a fully functioning EA, however I want to add a time of day trading filter so that the EA only trades within certain times of the day. I would also like to optimise this time function for best results.

Can some one on this forum please direct me to the section of code base that provides such code and or supply me with such so I can add it to my EA.

Many thanks....Mickey. 

Simply:

extern int StartTrade=X;
extern int StopTrade=Y;


int start()
 {
  if(Hour()>=StartTrade && Hour()<=StopTrade)
   {

   }
 }

It is very basic but I still use it and it works fine. But you cannot use the code for over mid night. ie 11pm to 3am or 5pm to 2am. If you plan on keeping the times for the same trading day then it will work fine. You can also add in minutes and seconds for accuracy. :)

Cheers! 

whroeder1
13597
whroeder1 2015.10.15 17:12  
DeanDeV: You can also add in minutes and seconds for accuracy. :)
Or just use seconds.
Not compiled, not tested.
string StartTrade = "10:00";    // minutes
string StopTrade  = "17:00:00"; // second
datetime now = TimeCurrent();
if(now >= StringToTime(StartTrade) && now < StringToTime(StopTrade)
Not compiled, not tested.
mikegreen
236
mikegreen 2015.11.07 18:20  
thanks for the tips
/
To add comments, please log in or register