Counting pips on all open positions
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..
Replies
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
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