ClosePosition SymbolName
ClosePosition SymbolName
18 Nov 2020, 00:19
Hi,
I need help with the code below so that it only closes the position with the indicated SymbolName for example "USDJPY"
I'm using the code below and it closes all positions.
if ()
{
foreach (var position in Positions)
ClosePositionAsync(position);
}
Thx for help!
//mgpublic
Replies
mgpublic
18 Nov 2020, 01:08
RE: RE:
mparama said:
mgpublic said:
Hi,
I need help with the code below so that it only closes the position with the indicated SymbolName for example "USDJPY"
I'm using the code below and it closes all positions.
if ()
{
foreach (var position in Positions)
ClosePositionAsync(position);
}Thx for help!
//mgpublic
You should use:
var posBuy = Positions.FindAll(Label, SymbolName, TradeType.Buy);
var posSell = Positions.FindAll(Label, SymbolName, TradeType.Sell);
if ()
{
foreach (var position in posBuy)
ClosePositionAsync(position);
}
Thx for reply and help.
How do I code so that it finds and closes the position with SymbolName "USDJPY" either if its posBuy or posSell. In the example above its only posBuy.
@mgpublic
nguyendan81985
21 Jan 2021, 11:08
RE: RE: RE:
mgpublic said:
Thx for reply and help.
How do I code so that it finds and closes the position with SymbolName "USDJPY" either if its posBuy or posSell. In the example above its only posBuy.
hi
you can try as below:
foreach (var position in Positions)
{
if (position.SymbolName == Symbol.Name)
{
ClosePosition(position);
}
}
@nguyendan81985
mparama
18 Nov 2020, 00:40
RE:
mgpublic said:
You should use:
var posBuy = Positions.FindAll(Label, SymbolName, TradeType.Buy);
var posSell = Positions.FindAll(Label, SymbolName, TradeType.Sell);
if ()
{
foreach (var position in posBuy)
ClosePositionAsync(position);
}
@mparama