Official blocks: Sell conditions (during purchase)
Guide to the Sell conditions block, where the bot may sell a contract early, plus Sell at market price, Sell is available and Sell profit/loss.
3. Sell conditions is the third root block. It is where you tell the bot when to close a contract early, before it ends by itself. In the Bot Builder menu the root block and Sell at market price sit under "Sell conditions (optional)". The two helper blocks, Sell is available and Sell profit/loss, sit in the Analysis group, under "Contract". This box is optional. If you leave it empty, every contract simply runs until its end time.
The bot runs this box only while a contract is open: after the Purchase block has bought it, and until it ends. It runs on every update of the open contract, which is about once per tick (a tick is one price update from the market). Then, when the contract is over, the bot goes on to the Restart trading conditions box.
A word used here: the market price of an open contract is the price Deriv would pay you for it right now if you sold it. It moves with the market, so it can be more or less than your stake. Not every contract can be sold early. Deriv decides, contract by contract and moment by moment, and the Sell is available block tells you the answer.
3. Sell conditions
- Kind: Official (Deriv)
- Type id:
during_purchase - Shape: Root block (a big box with no notch above or below; other blocks go inside it)
- Where it goes: On its own on the workspace. Only one copy is allowed. It is optional. A fresh Bot Builder has one, with an if block that checks "Sell is available".
- What it does: Holds the rules for selling an open contract early. Put an if block in it with your rule, and a Sell at market price block inside the if.
- Inputs:
- One slot for a stack of blocks. In practice you use if blocks, comparisons, the two helper blocks below, variables, and the Sell at market price block.
- How it works: While a contract is open, the bot runs this box each time the contract updates. If a Sell at market price block runs, the bot asks Deriv to sell, and when the sale is done the bot moves on to Restart trading conditions. If no sell happens, the contract goes on until it ends by itself. Any "Tick analysis" block you have runs just before this box on every new tick.
- Example: Sell early when selling now would give a profit of at least 0.5.
┌─ 3. Sell conditions ───────────────────────────┐
│ if < Sell is available > then │
│ if < ( Sell profit/loss ) ≥ ( 0.5 ) > then │
│ Sell at market price │
└────────────────────────────────────────────────┘- Good to know:
- The box is optional. Some bots never sell early.
- It only does something for contracts that can be sold. Deriv decides which ones can.
- BRINOVS adds more blocks made for this box (see the BRINOVS part of this guide).
- A sell rule limits a loss only if the contract can still be sold when the rule fires. It does not guarantee a result.
Sell at market price
- Kind: Official (Deriv)
- Type id:
sell_at_market - Shape: Action block (it has a notch on top and a notch below)
- Where it goes: Inside 3. Sell conditions, usually inside an if block. Outside that box it switches itself off. You can use it more than once.
- What it does: Sells your open contract right now at the current market price. You get whatever Deriv pays at that moment.
- Inputs:
- None. It has no boxes to fill.
- How it works: The bot first checks that a contract is open, not already sold, not expired, and that Deriv allows a sale. If any of these is not true, nothing is sold and the journal shows "Resale of this contract is not offered." If all are true, the bot sends the sell order and writes the sold-for amount in the journal. If Deriv says the contract is too close to its end to sell, the bot does not stop; it lets the contract finish. Selling the same contract twice is not possible.
- Example: Sell as soon as a sale is possible.
┌─ 3. Sell conditions ─────────────────────┐
│ if < Sell is available > then │
│ Sell at market price │
└──────────────────────────────────────────┘- Good to know:
- The price is the market price at that moment. It can be below your stake.
- Put a Sell is available check in front of it. This keeps the journal free of "not offered" lines.
- If a sell fails for another reason, what happens depends on the "Restart buy/sell on error" tick box in 1. Trade parameters.
Sell is available (Can contract be sold?)
- Kind: Official (Deriv)
- Type id:
check_sell - Shape: True/false block
- Where it goes: Anywhere a true/false answer is wanted inside 3. Sell conditions, most often in an if. Outside that box it switches itself off. It can be used as often as you like.
- What it does: Tells you whether your open contract can be sold right now at the market price.
- Inputs:
- None. On the block it reads "Sell is available".
- Gives back: True when a sale is possible now. Otherwise it gives nothing (an empty answer), which an if block treats as false.
- How it works: The block checks the latest update of the open contract. It is true only when the contract is open, not already sold, not expired, and Deriv marks it as sellable at this moment.
- Example: Do something only when selling is possible.
┌─ 3. Sell conditions ─────────────────────┐
│ if < Sell is available > then │
│ Sell at market price │
└──────────────────────────────────────────┘- Good to know:
- The answer can change from one tick to the next, so the bot asks again each time the box runs.
- It says nothing about whether a sale would be a good idea. For that, look at Sell profit/loss.
Sell profit/loss (Profit/loss from selling)
- Kind: Official (Deriv)
- Type id:
sell_price - Shape: Value block (gives a number)
- Where it goes: Anywhere a number is wanted inside 3. Sell conditions. Outside that box it switches itself off. It can be used as often as you like.
- What it does: Gives the profit or loss you would have if you sold the open contract right now.
- Inputs:
- None. On the block it reads "Sell profit/loss".
- Gives back: A number, in your account currency. A positive number is a profit. A negative number is a loss.
- How it works: The bot takes the price Deriv would pay now (the bid price) and subtracts what you paid for the contract (the buy price). The answer is rounded to the decimals of your currency.
- Example: Sell early only when the sale would give at least 0.5 profit.
┌─ 3. Sell conditions ───────────────────────────┐
│ if < Sell is available > then │
│ if < ( Sell profit/loss ) ≥ ( 0.5 ) > then │
│ Sell at market price │
└────────────────────────────────────────────────┘- Good to know:
- It is a number for this moment only. A moment later it can be different.
- Check Sell is available first, as the example does.