Trade Duration in mins

Created at 01 Apr 2016, 23:39
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CO

commando1

Joined 11.03.2016

Trade Duration in mins
01 Apr 2016, 23:39


Hi all,

How do i calculate trade duration in mins,

Suppose i want to close losing position after 10 mins from entry,

position.entrytime give us time of entry but how to compare it to current time & get answer in mins.

Spotware team please help

   


@commando1
Replies

solark
02 Apr 2016, 00:02

RE:

Either OnBar or OnTick (depends on your situtation) you'll want

if ((x.Robot.Time - p.EntryTime).TotalMinutes >= 10.0) {
    //Over 10 minutes
}

where `p` is your Position


@solark

solark
02 Apr 2016, 00:05

RE: RE:

Sorry I tend to avoid C# and messed up on my on the fly translation, meant:

if ((Time - p.EntryTime).TotalMinutes >= 10.0) {
    //Over 10 minutes
}

 


@solark

commando1
02 Apr 2016, 00:29

Super .... thanks it worked

foreach (var Position in Positions)
            {
                if ((Time - Position.EntryTime).TotalMinutes >= 10.0 && Position.NetProfit < 0)
                {
                    ClosePosition(Position);
                }

 


@commando1