Search code examples
mql5metatrader5

How to do datetime arithmetic in MQL5?


I want to calculate how much time has been passed since my last trade.

I have datetime lastExitTime;.

How to subtract from "now" this lastExitTime to get the difference in milliseconds?

Is there something like lastExitTime.toUnixTimestamp?


Solution

  • Values of type datetime are already in Unix Timestamp format (seconds ellapsed since January 1st, 1970). Therefore use either TimeLocal()-lastExitTime or TimeCurrent()-lastExitTime to find the number of seconds since your last trade.