Download MetaTrader 5

Help ! Time Function Coding

To add comments, please log in or register
mikegreen
285
mikegreen  

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  
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
16103
whroeder1  
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
285
mikegreen  
thanks for the tips
To add comments, please log in or register