Download MetaTrader 5
To add comments, please log in or register
Have you found a good programmer? Make a targeted order!
mrjaywilliams
31
mrjaywilliams 2015.01.16 06:12 

Hi Guys

How do you add or subtract time in MQL4?

eg if I wanted to add or subtract 68 minutes to/from 06:04 

Thanks in advance

Jay 

Biantoro Kunarto
14613
Biantoro Kunarto 2015.01.16 10:01  

Try this :

      datetime TimeNow = TimeCurrent();
      Print ( "TimeNow = ", TimeNow );
      int AddNumber = 68; // in minute
      datetime AddTime = TimeNow + AddNumber*60;
      Print ( "AddTime = ", AddTime );
Tonny Obare
27007
Tonny Obare 2015.01.16 10:43  

1.) Change the time to be added or substracted to seconds

2.) change the time 6:04 from string to time format

3.) Carry out the operation

 

int TimeToAdd=68*60; // change minutes to seconds

datetime NewTime=StrToTime("6:04")+TimeToAdd;   // Change time to datetime from string(hh:mm) format and carry out addition

string NewEasyToReadTime=TimeToStr(NewTime);    // Revert new time to string format of hh:mm:ss
Maryann Emmanuel
2296
Maryann Emmanuel 2015.07.28 22:07  

Hi there, How can i input time in hours on screen.

similar to c programming , scanf.....

Stuart Browne
5721
Stuart Browne 2015.07.29 01:33  
MaryAnn Emmanuel:

Hi there, How can i input time in hours on screen.

similar to c programming , scanf.....

https://docs.mql4.com/dateandtime/hour

https://docs.mql4.com/dateandtime/timehour 

https://book.mql4.com/functions/datetime 

Hour - MQL4 Documentation
  • docs.mql4.com
Hour - MQL4 Documentation
Maryann Emmanuel
2296
Maryann Emmanuel 2015.07.29 01:46  
Thank you, it possible to time display on Screen and user keys in required time. example: (Time: user keys in desired time, example , 10.00).
Stuart Browne
5721
Stuart Browne 2015.07.29 01:57  
MaryAnn Emmanuel:
Thank you, it possible to time display on Screen and user keys in required time. example: (Time: user keys in desired time, example , 10.00).
The easiest way to display it would be to use the Comment() function. Other ways would be with Text or Label objects. You could do the desired time in many ways, personally I'd give them a list of choices in a drop down menu in the inputs.
Comment - MQL4 Documentation
  • docs.mql4.com
Comment - MQL4 Documentation
/
To add comments, please log in or register