Hi, Peter,
A more simple method of getting all positions by label name using LINQ is shown below.
var positions = positions.Where(x => x.Label == LabelName);
Now to check all open positions for a buy or sell trade type you just use the following code block.
// iterate through the collection of open positions
foreach (var position in positions)
{
if(position.TradeType == TradeType.Buy)
{
// add you code for a buy trade.
}
if (position.TradeType == TradeType.Sell)
{
// add you code for a sell trade.
}
}
Another way of writing the code using LINQ by chaining the where clause expression to only return a collection of buy or sell trades is as follows
// return all buy trades.
var buyPositions =
positions.Where(x => (x.Label == LabelName)).Where(x => x.TradeType == TradeType.Buy);
// return all sell trades.
var sellPositions =
positions.Where(x => (x.Label == LabelName)).Where(x => x.TradeType == TradeType.Sell);
Using Label Name
As you are using the label name of the position in your filter this will only work with an automated trading system (cBot), you specify the label name when you create the order via code, for manual trades this will not work, if you wish to manage all trades you need to remove the label filter.
Filtering by Symbol Name
If you wish to filter by the symbol name only to only manage EURUSD you need to do the following.
var positions = positions.Where(x => x.SymbolName == "EURUSD");
or for current cBot instance or chart to cBot was attached to.
var positions = positions.Where(x => x.SymbolName == this.SymbolName);
This answers the title of the post, if you have more questions please post a new thread with the relevant title.