Position
interface cAlgo.API
DesktopCLICloud
Taking or opening a position means buying or selling a trading pair.
Definition
public interface Position
Namespace: cAlgo.API · Group: Positions
Examples
Example 1
foreach (var position in Positions)
{
Print("Position {0} {1} {2}: entry {3}, net profit {4}", position.Id, position.SymbolName, position.TradeType, position.EntryPrice, position.NetProfit);
}
for position in api.Positions:
api.Print(f"Position {position.Id} {position.SymbolName} {position.TradeType}: entry {position.EntryPrice}, net profit {position.NetProfit}")
Example 2
var result = ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.QuantityToVolumeInUnits(0.01), "myLabel", 20, 40);
if (result.IsSuccessful)
{
var position = result.Position;
position.ModifyStopLossPips(10);
position.Close();
}
else
{
Print("Order failed: {0}", result.Error);
}
result = api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, api.Symbol.QuantityToVolumeInUnits(0.01), "myLabel", 20, 40)
if result.IsSuccessful:
position = result.Position
position.ModifyStopLossPips(10)
position.Close()
else:
api.Print(f"Order failed: {result.Error}")
Example 3
protected override void OnStart()
{
Positions.Opened += OnPositionsOpened;
Positions.Closed += OnPositionsClosed;
}
private void OnPositionsOpened(PositionOpenedEventArgs args)
{
Print("Position {0} opened at {1}", args.Position.Id, args.Position.EntryPrice);
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
Print("Position {0} closed ({1}), net profit {2}", args.Position.Id, args.Reason, args.Position.NetProfit);
}
def on_start(self):
api.Positions.Opened += self.on_positions_opened
api.Positions.Closed += self.on_positions_closed
def on_positions_opened(self, args):
api.Print(f"Position {args.Position.Id} opened at {args.Position.EntryPrice}")
def on_positions_closed(self, args):
api.Print(f"Position {args.Position.Id} closed ({args.Reason}), net profit {args.Position.NetProfit}")
Methods
| Name | Description |
|---|---|
CloseDesktopCLICloudTradeResult | Shortcut for the Robot.ClosePosition method. |
ModifyStopLossBreakEvenDesktopCLICloudTradeResult | Shortcut for the Robot.ModifyPosition method to change the StopLoss Break-Even. |
ModifyStopLossPipsDesktopCLICloudTradeResult | Shortcut for the Robot.ModifyPosition method to change the Stop Loss pips |
ModifyStopLossPriceDesktopCLICloudTradeResult | Shortcut for Robot.ModifyPosition method to change the Stop Loss. |
ModifyTakeProfit 2 overloadsDesktopCLICloudTradeResult | Shortcut for the Robot.ModifyPosition method to change the Take Profit protection |
ModifyTakeProfitPipsDesktopCLICloudTradeResult | Shortcut for the Robot.ModifyPosition method to change the Take Profit pips |
ModifyTakeProfitPriceDesktopCLICloudTradeResult | Shortcut for Robot.ModifyPosition method to change the Take Profit. |
ModifyTrailingStopDesktopCLICloudTradeResult | Shortcut for the Robot.ModifyPosition method to change the Trailing Stop. |
ModifyVolumeDesktopCLICloudTradeResult | Shortcut for the Robot.ModifyPosition method to change the VolumeInUnits. |
Reverse 2 overloadsDesktopCLICloudTradeResult | Shortcut for the Robot.ReversePosition method to change the direction of the trade. |
Properties
| Name | Description |
|---|---|
AbsoluteTakeProfitProtectionsDesktopCLICloudAbsoluteTakeProfitProtections | The take profit protections of the position. Null if position has no take profit. |
ChannelDesktopCLICloudstring | Gets the channel via which the position was placed in a string format. |
CommentDesktopCLICloudstring | Comment can be used as a note for the order. |
CommissionsDesktopCLIClouddouble | Commission Amount of the request to trade one way (Buy/Sell) associated with this position. |
CurrentPriceDesktopCLIClouddouble | Gets the position current market price. If Position's TradeType is Buy it returns Symbol current Bid price. If position's TradeType is Sell it returns Symbol current Ask price. |
DealsDesktopCLICloudIReadonlyList<Deal> | Gets the position deals. |
EntryPriceDesktopCLIClouddouble | Entry price of the position. |
EntryTimeDesktopCLICloudDateTime | Entry time of trade associated with the position. The Timezone used is set in the cBot attribute. |
GrossProfitDesktopCLIClouddouble | Gross profit accrued by the order associated with the position. |
HasTrailingStopDesktopCLICloudbool | When HasTrailingStop set to true, the server updates the Stop Loss every time the position moves in your favor. |
IdDesktopCLICloudint | The position's unique identifier. |
LabelDesktopCLICloudstring | Label can be used to represent the order. |
LastUpdateTimeDesktopCLICloudDateTime? | Gets the time when a position was last updated. The timezone used is set in the algorithm class attribute. |
MarginDesktopCLIClouddouble | The amount of used margin by the position. |
NetProfitDesktopCLIClouddouble | The Net profit of the position. |
PipsDesktopCLIClouddouble | Represents the winning or loosing pips of the position. |
QuantityDesktopCLIClouddouble | Quantity of lots traded by the position. |
StopLossDesktopCLIClouddouble? | The Stop Loss level of the position. |
StopLossBreakEvenDesktopCLICloudStopLossBreakEven | The stop loss break even of the position. |
StopLossTriggerMethodDesktopCLICloudStopTriggerMethod? | Trigger method for the position's Stop Loss. |
SwapDesktopCLIClouddouble | Swap is the overnight interest rate if any, accrued on the position. |
SymbolDesktopCLICloudSymbol | Gets the position symbol. |
SymbolNameDesktopCLICloudstring | Gets the symbol name. |
TakeProfitDesktopCLIClouddouble? | The take profit level of the position. |
TradeTypeDesktopCLICloudTradeType | Trade type (Buy/Sell) of the position. |
VolumeInUnitsDesktopCLIClouddouble | The amount traded by the position. |
Deprecated members (3)
string SymbolCode {get;}— Use SymbolName insteadlong Volume {get;}— Use VolumeInUnits insteaddecimal Profit {get;}— Use GrossProfit instead