Skip to content

Plugin.Positions

property · Plugin · cAlgo.API

DesktopCLICloud

The list of all open positions of the account.

Environment behaviour

CLI — not supported. Plugins cannot run in the CLI: ctrader-cli runs cBots only.

Cloud — not supported. Plugins cannot run in the cloud: it runs cBots only.

Definition

public Positions Positions {get;}
api.Positions: Positions

Returns Positions

Examples

Example 1

foreach (var position in Positions)
{
    if (position.StopLoss == null)
        ModifyPosition(position, 10, 20, ProtectionType.Relative);
}
for position in api.Positions:
    if position.StopLoss is None:
        api.ModifyPosition(position, 10, 20, ProtectionType.Relative)

Example 2

var position = Positions.Find("myLabel", "EURUSD", TradeType.Sell);
if (position != null)
    Print("Found position {0} with net profit {1}", position.Id, position.NetProfit);
position = api.Positions.Find("myLabel", "EURUSD", TradeType.Sell)
if position is not None:
    api.Print(f"Found position {position.Id} with net profit {position.NetProfit}")