
The CloseAtProfitMarket method sets a profit order for a position. The logic for triggering the profit order is executed in the terminal. Essentially, this can be considered a conditional order that is converted into an actual Market type order only when the specified conditions are met.
public void CloseAtProfitMarket(Position position, decimal priceActivation)
position – the position for which a profit order needs to be set;
priceActivation – the price at which a real order will be sent to the exchange upon being reached;
An example of use can be seen in the robot's code: https://github.com/AlexWan
In this example, an already opened position is passed to the method, where a profit order is set for the position:

1. Check whether there are any conditional orders set for closing the position.
2. For a Buy position, set a profit-market order above the market.
3. For a Sell position, set a profit-market order below the market.
Important Note 1
It is only possible to set a profit order after opening a position, that is, when its open volume is greater than zero. For these purposes, the PositionOpeningSuccesEvent is ideally suited. It signals to the robot that at least one trade has occurred for the opening order.
Important Note 2
Upon execution of this type of order, any stop order that was set for the position is canceled, if one had been placed.
If you have any difficulties or questions, please write to the support chat. Link