Counting pips (with filters)

Created at 14 Dec 2018, 23:53
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!
DelFonseca's avatar

DelFonseca

Joined 25.06.2017

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.


@DelFonseca
Replies

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

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