Close positions by Position.Id

Created at 08 Jan 2020, 21:18
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!
DelFonseca's avatar

DelFonseca

Joined 25.06.2017

Close positions by Position.Id
08 Jan 2020, 21:18


Good night,

How can i close positions by Position.Id ? Positions ID its a string (PID00000000).
My code below

Thank you

[Parameter("POS.ID #1", Group = "Close Pos.ID", DefaultValue = "")]
public string PosID1 { get; set; }

[Parameter("POS.ID #2", Group = "Close Pos.ID", DefaultValue = "")]
public string PosID2 { get; set; }

netBalancePosID = 0.0;
foreach (var position in Positions)
{
   if (position.Id == PosID1 && position.Id == PosID2)
   {
     netBalancePosID += position.NetProfit;
   }
   _netBalancePosID = Math.Round(netBalancePosID, 2);
   _PermissionToCloseByPosID = (_netBalancePosID >= EquityProfitClosePosID) ? true : false;
}

@DelFonseca
Replies

PanagiotisCharalampous
09 Jan 2020, 08:37

Hi DelTrader,

See below

            if (Positions.Count(x => x.Id == PosID1) > 0)
            {
                Positions.First(x => x.Id == PosID1).Close();
            }

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

DelFonseca
20 Jan 2020, 22:54

RE:

PanagiotisCharalampous said:

Hi DelTrader,

See below

            if (Positions.Count(x => x.Id == PosID1) > 0)
            {
                Positions.First(x => x.Id == PosID1).Close();
            }

Best Regards,

Panagiotis 

Join us on Telegram

 

Thank you so much Sir.


@DelFonseca