Download MetaTrader 5
To add comments, please log in or register
How to buy a product in MetaTrader AppStore? Read the article!
daytradingzoo
44
daytradingzoo 2015.08.02 19: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? 

Keith Watford
Moderator
8007
Keith Watford 2015.08.02 21: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 

Keith Watford
Moderator
8007
Keith Watford 2015.08.02 21: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 

daytradingzoo
44
daytradingzoo 2015.08.03 04: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.
/
To add comments, please log in or register