
The overloads of the SellAtStop method are designed for the deferred opening of short positions through conditional orders. After calling the method, an object of the class PositionOpenerToStopLimit is created within the tab, which contains data on the conditional order. We will refer to this object as a conditional position, because the real position will only be created upon the fulfillment of conditions.
Let's consider the principle of operation of conditional orders. Essentially, it's a regular order, but it is sent to the exchange only if certain conditions are met. Take a hypothetical instrument, the current price of which is 100 units. We want to sell one lot when the price reaches 80 units. It's not possible to do this with the current price, but one can set a condition in the program that when the price reaches 80, it should send an order to the exchange to sell one lot.
public void SellAtStop(decimal volume, decimal priceLimit, decimal priceRedLine, StopActivateType activateType, int expiresBars, string signalType, PositionOpenerToStopLifeTimeType lifeTimeType)
The method does not return anything and takes the following parameters:
1. volume – the volume for the opening order;
2. priceLimit – the price for the order;
3. priceRedLine – the price at which the order will be sent to the exchange when reached;
4. activateType – the type of activation, must use the value less than or equal to;
5. expiresBars – the lifetime of the order, measured by the number of candles (bars);
6. signalType – a string containing the name of the signal for opening a position;
7. lifeTimeType – enables/disables the calculation of the lifetime for the order;
Let's modify the example. The robot opens a short after the price deviates downwards by a certain percentage from the current value of the SMA. The algorithm's calculation triggers after the close of each candle, but while we wait for its closure, the price may fall much lower than the necessary boundary. To solve this problem, we use the SellAtStop method. If the price deviates by the required magnitude, the program will automatically open a short position.

1. Modify the CrossDown method. It will inform us whether the price is below the moving average.
2. Add the GetBorderDownPrice method, which will calculate and return the price considering the deviation.
And then we change the event handler for the completion of the candle.

1. We define the signal to open a position.
2. As a condition, we use the price at which the tab will open a short position upon being reached.
3. We calculate the price at which the order will be sent at the moment the condition is triggered, taking into account slippage.
4. We command the tab to open a short position when the limit value is reached.
As a parameter for expiresBars, we set the value to 1. This means that the conditional position will exist over the course of one candle, after which it will be canceled. Our algorithm will recreatively establish a conditional position after the completion of each candle, as long as the instrument's price remains below the moving average.
If necessary, a different approach can be used. Let's create a conditional position with an unlimited lifespan.

1. We add two additional checks: the tab must not have active conditional positions and active ordinary positions.
2. As the last parameter for the method SellAtStop, we pass the value NoLifeTime.
Thus, the conditional position will not be canceled until a real position has been created.
The SellAtStop method has several overloads. All of them differ only in the sets of parameters they accept. The functionality is provided by the version with the most parameters, and the others call it, passing literals as some of the parameters of the method.
public void SellAtStop(decimal volume, decimal priceLimit, decimal priceRedLine, StopActivateType activateType, int expiresBars, string signalType)
The method overload that does not require the lifeTimeType parameter by default uses the value CandlesCount to calculate the lifetime for the conditional position.
public void SellAtStop(decimal volume, decimal priceLimit, decimal priceRedLine, StopActivateType activateType, int expiresBars)
The method version that does not require the signalType and lifeTimeType parameters by default uses an empty string for the signal and the value CandlesCount to calculate the lifetime for the conditional position.
public void SellAtStop(decimal volume, decimal priceLimit, decimal priceRedLine, StopActivateType activateType, string signalType)
Does not require parameters expiresBars and signalType. By default, it uses one and the value CandlesCount to calculate the lifetime for the conditional position.
public void SellAtStop(decimal volume, decimal priceLimit, decimal priceRedLine, StopActivateType activateType)
Does not require parameters expiresBars, signalType, and lifeTimeType. By default, it uses one, an empty string for the signal, and the value CandlesCount to calculate the lifetime for the conditional position, respectively.
If you have any difficulties or questions, please write to the support chat. Link