Count Total Open Positions by Trade Type and Pair

Created at 02 Jan 2015, 15: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!
deklin's avatar

deklin

Joined 31.12.2014

Count Total Open Positions by Trade Type and Pair
02 Jan 2015, 15:53


How can I get a count of total open positions where the pair is "EURUSD" and the trade type is "Buy"?


@deklin
Replies

9718853
02 Jan 2015, 16:00

var shortPositionsCount = Positions.Count(p => p.TradeType == TradeType.Sell);
            var longPositionsCount = Positions.Count(p => p.TradeType == TradeType.Buy);

Adding 'Symbol' would keep the search to a single currency pair...


@9718853

deklin
02 Jan 2015, 16:13

Thanks.  How can I add support for the Symbol?  This does NOT work:

Print("Count of Open Long EURUSD Positions: " + Positions.Count(p.Symbol.Code == "EURUSD" && p => p.TradeType == TradeType.Buy));

 


@deklin