Counting pips (with filters)
14 Dec 2018, 23:53
Good night,
I have this line to count and filter open positions by layer and trade type in account collection.
LongPositionsCount = Positions.Where(pos => pos.Label == LabelBuy).Where(pos => pos.TradeType == TradeType.Buy).Count();
i need someone to help me make the same filter but making the sum of profit/loss in pips in account collection, by layer and trade type. Something like the code below, but this doesnt work.
LongPositionsInPips = Positions.Where(pos => pos.Label == LabelBuy).Where(pos => pos.TradeType == TradeType.Buy).pips();
Thank you so much and im sorry for my English.
Replies
PanagiotisCharalampous
17 Dec 2018, 11:24
Hi DelTrader,
Try something like this
var LongPositionsInPips = Positions.Where(pos => pos.Label == "Label" && pos.TradeType == TradeType.Buy).Sum(x => x.Pips);
Best Regards,
Panagiotis
@PanagiotisCharalampous
DelFonseca
17 Dec 2018, 20:33
Hi Panagiotis,
Thank you so much. Perfect.
Merry Christmas and Happy New Year. Cheers
@DelFonseca

DelFonseca
15 Dec 2018, 20:47
Hi,
This code make sense to close all trades when sum of account pips by layer are >= -100 or >= 300 ?
Thank you
private void PermissionToClose() { //CONDITIONS TO CLOSE LONG POSITIONS int? a = null; int? b = null; foreach (var LongPositions in Positions.FindAll(LabelBuy)) a++; foreach (var LongPositions in Positions.FindAll(LabelBuy)) if (LongPositions.Pips >= 300 || LongPositions.Pips <= -100) b++; if (a == b) foreach (var LongPositions in Positions.FindAll(LabelBuy)) { ClosePositionAsync(LongPositions); } //CONDITIONS TO CLOSE SHORT POSITIONS int? c = null; int? d = null; foreach (var ShortPositions in Positions.FindAll(LabelSell)) c++; foreach (var ShortPositions in Positions.FindAll(LabelSell)) if (ShortPositions.Pips >= 300 || ShortPositions.Pips <= -100) d++; if (c == d) foreach (var ShortPositions in Positions.FindAll(LabelSell)) { ClosePositionAsync(ShortPositions); } }@DelFonseca