Hi, Jiggy,
This is the perfect type of question for this forum, please find your answer below, it was implemented in the simplest form for you to understand, but the code could also have been written with fewer lines of code.
protected override void OnTick()
{
// this will get all positions with the same label
var positions = Positions.FindAll("my-label");
// get all positions that are trade type buy
var buyPositions = positions.Where(x => x.TradeType == TradeType.Buy);
// this uses LINQ and lambda expressions to get the sum total of net profit
double totalProfit = buyPositions.Sum(x => x.NetProfit);
if (totalProfit > 1000)
{
foreach (var position in buyPositions)
{
ClosePosition(position);
}
}
}
This will check for the condition on each price change or tick of data, you can find out more about LINQ below.
https://www.tutorialsteacher.com/linq/what-is-linq