Simple code to get number of minutes / hours in a trade

Back to topics list To post a new topic, please log in or register
avatar
6
daytradingzoo 2015.08.02 21:54
 

I'm trying to come up with a real simple piece of code that just shows me the number of minutes / hours that I'm in an open position.

Basically what I know I should do is use

TimeCurrent()-OrderOpenTime()

 

But this gives me a Time formatted value from year 1970. I'd rather just have a number of hours / minutes I can work with.

Anyone know if there is a function for this? 

avatar
Moderator
3404
GumRai 2015.08.02 23:43 #
 
  int seconds_in_trade=(int)(TimeCurrent()-OrderOpenTime())

should give you the duration in seconds. 

Then code to convert the seconds into hours and minutes 

avatar
Moderator
3404
GumRai 2015.08.02 23:51 #
 

If you just need the value as a string for a Print, Comment or label

  datetime time_in_trade=TimeCurrent()-OrderOpenTime();
  Print(TimeToStr(time_in_trade,TIME_MINUTES));

 should do it

but I'm not sure what would happen if a trade is open more than 24 hours, so probably only good for short term trades 

 

avatar
6
daytradingzoo 2015.08.03 06:47 #
 
Thanks GumRai.. The first explicit conversion is what I needed.. I didnt know I could do an (<datatype>) conversion. I'm new to MQL4.. Thanks for you help.
Back to topics list  

To add comments, please log in or register