Counting pips on all open positions

Created at 01 May 2013, 19:05
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!
kricka's avatar

kricka

Joined 13.03.2013

Counting pips on all open positions
01 May 2013, 19:05


Hi,

Is there a way to count total positions pips on all open positions?

I know there is count on the last position but how about the total.

if (position.Pips < 1) 

or

if (position.Pips > 0) 

 

Thanks..


@kricka
Replies

kricka
04 May 2013, 19:19

Hi,

the robot calculating this is not making any orders or positions only closing positions.

Hoping for a answer on this.

Thanks..


@kricka

cAlgo_Fanatic
07 May 2013, 09:54

To calculate the total pips for all open positions you can use this loop:

    double totalPips = 0;
    foreach (var position in Account.Positions)
    {
        totalPips += position.Pips;
    }




@cAlgo_Fanatic

kricka
09 May 2013, 10:08

Hi,

great, works just fine!

I do have another question regarding pips.

What if I would like to calculate pips on all open positions and also on all closed positions.

Total pips with other words, since I started the robot.

Hope to get a reply on this too :)

Thanks for all your fantastic support!


@kricka

cAlgo_Fanatic
09 May 2013, 16:50

You can have a robot that calculates the pips of all positions closed that were opened by the same robot. To do this add the positions in a List (see List example) in the OnPositionClosed event:

private readonly List<Position> _closedPositions = new List<Position>();
//...
protected override void OnPositionClosed(Position closedPosition)
{
    _closedPositions.Add(closedPosition);
}
//...
protected override void OnTick()
{
    double totalPipsClosed = 0.0;

    foreach(Position pos in _closedPositions)
    {
        totalPipsClosed += pos.Pips;
    }
   //...
}

Calculating the pips of all closed positions of the account is not currently possible. Access to historical orders will be added soon to the API.


@cAlgo_Fanatic

kricka
11 May 2013, 17:05

Hi,

good to hear you are working on adding it to the API. Then it will be possible to calculate this for a robot, not making any orders. Is this the case if you would like to calculate total commission as well?

Thanks..


@kricka

cAlgo_Fanatic
14 May 2013, 11:56

Yes, it applies to commission as well.


@cAlgo_Fanatic