SellAtMarketToPosition

SellAtMarketToPosition
public void SellAtMarketToPosition(Position position, decimal volume)

Unlike the previous one, the SellAtMarketToPosition method modifies a position by adding a market sell order to the list of opening orders. It accepts the following parameters:

1. position – the position that needs to be modified;

2. volume – the volume for the new market order;

This method is well suited for increasing the volume of a short position. Let's outline the following task: in a trend strategy, we want to build up the position in two parts. If the price has deviated from the moving average by a set percentage, we sell the first part; if it continues to fall and crosses the boundary of double the deviation from the current value of the SMA, we sell the second part.

Let's do this:

1. If the price has dropped below the level of one deviation, we sell the first part on the market.

2. Calculate the second level for the deviation.

3. If the price has fallen below the second level and the robot has not yet acquired the required volume (conditionally 100 lots), we enter the body of the conditional construct.

4. We call the method SellAtMarketToPosition with the aim of selling the remaining part.

And so, in the journal, we see two market opening orders in the position.

public void SellAtMarketToPosition(Position position, decimal volume, string signalType)

The second version of the method performs the same actions and accepts an additional parameter, signalType.

If you have any difficulties or questions, please write to the support chat. Link