Close first and last positions
Close first and last positions
03 Feb 2020, 13:22
Good day,
How can i find and close the first an last openned positions?
Thank`s!
Replies
netmstnet
03 Feb 2020, 14:06
RE:
PanagiotisCharalampous said:
Hi netmstnet,
You can use First() and Last() functions. See below an example
Positions.First().Close();
Best Regards,
Panagiotis
Thank you, Panagiotis.
@netmstnet
netmstnet
03 Feb 2020, 14:24
RE:
PanagiotisCharalampous said:
Hi netmstnet,
You can use First() and Last() functions. See below an example
Positions.First().Close();
Best Regards,
Panagiotis
hm, i think need more help, here is the code:
// Close all buy positions if all buy positions' target profit is met
if (Positions.Count(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName && x.Label == ThiscBotLabel) >= 2)
{
if (Positions.Where(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName && x.Label == ThiscBotLabel).Average(x => x.NetProfit) >= FirstVolume * AverageTakeProfit * Symbol.PipSize)
{
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Buy && position.SymbolName == SymbolName && position.Label == ThiscBotLabel)
ClosePosition(position);
}
}
}
// Close all sell positions if all sell positions' target profit is met
if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == ThiscBotLabel) >= 2)
{
if (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == ThiscBotLabel).Average(x => x.NetProfit) >= FirstVolume * AverageTakeProfit * Symbol.PipSize)
{
foreach (var position in Positions)
{
if (position.TradeType == TradeType.Sell && position.SymbolName == SymbolName && position.Label == ThiscBotLabel)
ClosePosition(position);
}
}
}
i need to select first and last positions, then calculate if proift of this positions NetProfit > AverageTakeProfit, close first and last.
p.s. sorry my english
@netmstnet
PanagiotisCharalampous
03 Feb 2020, 14:29
Hi netmstnet,
You can try this condition
if (Positions.First().NetProfit > AverageTakeProfit)
Positions.First().Close();
Best Regards,
Panagiotis
@PanagiotisCharalampous
netmstnet
03 Feb 2020, 15:20
RE:
PanagiotisCharalampous said:
Hi netmstnet,
You can try this condition
if (Positions.First().NetProfit > AverageTakeProfit) Positions.First().Close();
Best Regards,
Panagiotis
You mean like this:
if ((Positions.First().NetProfit+ Positions.Last().NetProfit) > AverageTakeProfit)
Positions.First().Close();
Positions.Last().Close();
@netmstnet
PanagiotisCharalampous
03 Feb 2020, 14:02
Hi netmstnet,
You can use First() and Last() functions. See below an example
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous