Positions.FindAll("Label") - Filter for more then 1 Label

Created at 11 Feb 2019, 17:33
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!
TA

TakeProfit

Joined 15.08.2017

Positions.FindAll("Label") - Filter for more then 1 Label
11 Feb 2019, 17:33


Hey,

I would like to know if it's possible to filter for more then 1 Label in the "Positions.FindAll" command.

The situation is, that I have 2 Labels for each trade direction ("Long" and "Short") and want to set stops to breakeven after gaining X amount of Pips. Therefor I would like to do something like this:

var AllPositions = Positions.FindAll("Long" and "Short", Symbol);

Otherwise I will have to let this part run 2 times with "Long" and "Short" labels separate, which would be inefficient as I just want him to find all open positions of this Symbol regardless of the label. 

Please let me know if this is possible under the current API.

Thank you very much


@TakeProfit
Replies

PanagiotisCharalampous
11 Feb 2019, 17:36

Hi TakeProfit,

You can use Linq to achieve this. See below

var AllPositions = Positions.Where(x => x.Label == "Long" || x.Label == "Short");

Best Regards,

Panagiotis


@PanagiotisCharalampous

TakeProfit
11 Feb 2019, 18:12

Hi Panagiotis,

Thank you very much, it works, I went with the following addition to also filter for Symbol.Code.

  1. var OpenPositions = Positions.Where(x => x.SymbolCode == Symbol.Code && x.Label == "Long" || x.Label == "Short");
    foreach (Position position in OpenPositions)
    {...}

@TakeProfit