Is there any way to count number of milliseconds passed since a position has been opened?

 

I want to be able to see how many milliseconds have passed since a particular position has been opened.

If I do

PositionGetInteger(POSITION_TIME)

The returned datetime value does not appear to have millisecond precision, even though I can see the open time for that position down to milliseconds in Metatrader's Trade tab in the Toolbox!

If I do

PositionGetInteger(POSITION_TIME_MSC)

The returned value is Position opening time in milliseconds since 01.01.1970, but then I can't find a way to get the current time in milliseconds since 01.01.1970, therefore I can't know how many milliseconds has passed since the position is opened.

Is this impossible to do, or am I missing something?

Thanks

 
afshin_j:

I want to be able to see how many milliseconds have passed since a particular position has been opened.

If I do

The returned datetime value does not appear to have millisecond precision, even though I can see the open time for that position down to milliseconds in Metatrader's Trade tab in the Toolbox!

If I do

The returned value is Position opening time in milliseconds since 01.01.1970, but then I can't find a way to get the current time in milliseconds since 01.01.1970, therefore I can't know how many milliseconds has passed since the position is opened.

Is this impossible to do, or am I missing something?

Thanks

long now = (long) TimeCurrent() * 1000;
long postime = PositionGetInteger(POSITION_TIME_MSC);

long elapsedmsc = now - postime;
 
Sardion Maranatha:

Thanks, but I don't think this has millisecond precision. TimeCurrent() does not have millisecond accuracy. So what you wrote cannot distinguish between 1 second 999 millisecond, and 1 second 1 millisecond. They are both considered as 1 second as far as TimeCurrent() is concerned, so multiplying by 1000 does not help. Am I right?
 
afshin_j:

Thanks, but I don't think this has millisecond precision. TimeCurrent() does not have millisecond accuracy. So what you wrote cannot distinguish between 1 second 999 millisecond, and 1 second 1 millisecond. They are both considered as 1 second as far as TimeCurrent() is concerned, so multiplying by 1000 does not help. Am I right?
you can use current tick time_msc then to be more precise
 
What I'm trying to say is that your solution increments elapsedmsc by 1000 every 1 second. It's not possible to know exactly how many milliseconds have passed in-between those seconds.
 
Sardion Maranatha:
you can use current tick time_msc then to be more precise

Isn't that the time of the last tick in milliseconds, as opposed to the current time?