Blocks
Trading blocks are executed by the platform: they call the exchange, compute indicators and send notifications. A block’s inputs are set in the properties panel — as a value or a variable; its result goes to a variable for the following blocks.
Fetch candles
Section titled “Fetch candles”getKlines — loads candles (klines) for a symbol.
| Input | Description |
|---|---|
| Exchange | the exchange to take candles from |
| Symbol | the instrument, e.g. BTC/USD_LEVERAGE |
| Interval | candle timeframe |
| Number of candles | how many latest candles to load |
| Wait for close | wait for the current candle to close before loading |
Result — a list of Candles: each has open time, open, high, low,
close and volume. The latest candle is klines[-1].
Compute indicator
Section titled “Compute indicator”computeIndicator — computes a technical indicator over candles.
| Input | Description |
|---|---|
| Indicator | rsi, macd, bollinger_bands, ks, sma, ema, stochastic, atr, cci, williams_r, roc, mfi, obv, super_trend |
| Candles | the candle list from Fetch candles |
Result — a list of values per candle. Fields depend on the indicator:
| Indicator | Fields | Defaults |
|---|---|---|
| RSI | value | period 14 |
| MACD | value, MACD line | 12 / 26 / 9 |
| Bollinger Bands | upper band, middle line, lower band | period 20 |
| KS | trend direction (up / down / no signal) | — |
| SMA | value, direction (price above / below the average) | period 20 |
| EMA | value, direction (price above / below the average) | period 20 |
| Stochastic | %K line, %D line, direction (≤ 20 up, ≥ 80 down) | period 14 |
| ATR | value (no direction) | period 14 |
| CCI | value, direction (≤ −100 up, ≥ 100 down) | period 20 |
| Williams %R | value, direction (≤ −80 up, ≥ −20 down) | period 14 |
| ROC | value (fraction: 0.1 = +10%), direction by sign | period 9 |
| MFI | value, direction (≤ 20 up, ≥ 80 down) | period 14 |
| OBV | value, direction (rise / fall vs previous candle) | — |
| SuperTrend | value, direction (price above / below the line) | period 14, multiplier 2.5 |
Condition / expression
Section titled “Condition / expression”evaluateExpression — evaluates any FEEL expression and stores the result
in a variable. Useful when a condition is computed once and used in several
places. See Conditions for the syntax.
Place order
Section titled “Place order”createOrder — opens an order on the exchange.
| Input | Required | Description |
|---|---|---|
| Exchange, Symbol | yes | where and what to trade |
| Quantity | yes | order size |
| Leverage | yes | leverage |
| Side | yes | buy or sell |
| Price | no | limit price; without it — a market order |
| Stop loss / Stop loss distance | no | stop as a level or a distance from the price |
| Take profit / Take profit distance | no | take as a level or a distance from the price |
| Notification type | no | telegram — report the accepted order |
Result — the Order ID (orderUid): use it to close or update the
order and to check its status.
Before sending, the order is checked against the risk limits. An order that breaks a limit is not sent to the exchange and the process goes on — Order status returns Rejected for it.
Order status
Section titled “Order status”getOrderStatus — returns the order status by orderUid: Not opened,
Open, Closed, Canceled, Rejected, Expired. Usually
followed by a gateway that decides what to do next.
Besides the status the block returns the result of the trade. Until the trade is closed these fields are empty (the entry price appears once the order is filled):
| Variable | What it is |
|---|---|
entryPrice |
Entry price — the price the position was opened at |
closePrice |
Close price |
pnl |
PnL of the trade before the fee: negative is a loss |
fee |
Fee paid for the trade |
closeReason |
Close reason: stopLoss, takeProfit, manual or strategy |
The numbers arrive as strings, so a condition reads them with number(...),
after checking the status: status = "closed" and number(pnl) < 0 — “the
trade closed with a loss”. This is how you build “pause after a loss” or
“raise the size after a winning trade”; the same variables can go into the text
of a notification: {{pnl}}. If you rename the
block’s result (say, to statusB), the other variables take its name as a
prefix: statusBPnl, statusBFee. This way two blocks in one diagram do not
overwrite each other.
In demo and live the result comes from the run’s trade journal, which is reconciled with the exchange once a minute. Until the journal has settled a closed trade, the block still answers Open (and asks the journal to refresh right away), so a “closed with a loss” condition does not miss the trade. If the position is gone from the exchange but the journal could not find it, the status is Closed and the result fields are empty. In a backtest it comes from the simulation; Play has no trades, so the fields are empty.
Keep in mind:
- In demo and live the close reason is derived from the close price and the order’s stop and take profit levels (including those set by the Update trade block). A close at or beyond the stop counts as a stop loss, even if you closed the position by hand on the exchange.
- The fee in a backtest is an estimate: both sides of the trade are taken at the entry price, the way the backtest balance is charged. On an exchange the fee is the actual one.
- Backtest trades closed before these fields existed have no fee or reason.
Update trade
Section titled “Update trade”updateOrder — changes the stop loss and take profit of an open trade by
orderUid. The new stop is checked against risk limits too: you cannot
remove the stop when a stop loss is required, or move it beyond the allowed
risk.
Close order
Section titled “Close order”closeOrder — closes the position opened by orderUid, or cancels an order
that has not been filled yet. Positions can be closed even while new orders
are halted by a risk limit.
Send notification
Section titled “Send notification”sendNotification — sends your text to the chosen channel. See
Notifications.