best way to use time based stoploss ?

 

guys best way or easy way to use time based stoploss is what? i wrote this but its weak.

find the time of position opening

put it in mqldatetime structure

extract the minute of position opening

add some minutes to it

and compare it with current time.

it has some problems and blind spots that it doesnt work, for example i cant set it to 4 hours or 2 days.

thanks