Actions · action block
Buy a percentage of cash
The buy % action invests a share of the bot's available cash: at market, at the close of the candle where the rule fired, or with a limit or stop order that waits for a better or a confirming price.
How the engine evaluates it
The requested amount is X% × available cash. Every buy then passes the risk guards: no buy while a position is open unless stacking is on, the optional per-trade dollar cap, the optional cap on the share of equity invested, and finally the cash you actually have. A buy worth less than one cent is skipped.
At market the fill price is the candle's close plus slippage, or the level of a wick-triggered P&L condition in the same rule. The dollars spent include the fee, so buy 100% uses all the cash. The average entry is updated by volume.
By default the action buys at market. limit X% instead places a buy limit at close × (1 − X/100), to buy a dip: it fills on the first candle whose low reaches it, at the lower of that candle's open and the limit, with no slippage. stop X% places a buy stop at close × (1 + X/100), to buy a breakout: it fills on the first candle whose high reaches it, at the higher of the open and the stop, plus slippage.
A limit or stop order is placed at the close of the candle where the rule fired and works on the next N candles (expires N, 12 by default); if none reaches its price, it lapses with no trade. Working orders are checked at the start of each candle, before that candle's rules, in rule order. Each rule has at most one working order, so the rule firing again while its order works places nothing. The size is worked out when the order fills, from the cash or position at that moment, and if there is nothing to trade the order is used up without a trade.
Every fill pays the fee set on the bot, a percent of the fill's value charged in dollars (0.1% for new bots; bots created before fees existed keep 0%). Market and stop fills also pay the bot's slippage, which moves the fill price against you; limit fills get none.
requested = cash × X / 100
spend = min(requested, max per trade, room under max invested, cash)
notional = spend / (1 + fee)
fee paid = spend − notional
BTC bought = notional / fill price
market fill = close × (1 + slippage)
Botscript syntax
In the Lab you pick this block from the Actions group and fill in its fields. In the code view the same action is written like this:
buy 50%
buy 100%
buy 100% limit 1%
buy 50% limit 2% expires 24
buy 100% stop 1.5%
Settings
| Setting | Values | Default | Notes |
|---|---|---|---|
| Percent of cash | 0 – 100% | 50% | Of the cash available when the buy fills, not the starting balance. |
| Order | market, limit, stop | market | Limit and stop orders wait for a price; see above. |
| Offset | 0.01 – 50% | 1% | Distance of the order price from the close of the candle where the rule fired. |
| Expires | 1 – 1,000 candles | 12 | How many candles a limit or stop order works for. |
How traders use it
- All-in systems:
buy 100%with one position at a time. - Scaling in:
buy 25%with stacking on, so each signal adds a quarter of the remaining cash. - Buy the dip below a signal:
buy 100% limit 1.5%only fills if price trades 1.5% lower within 12 candles. - Wait for confirmation:
buy 100% stop 1%only fills if price breaks 1% above the signal close.
Example bot
bot "Scale In"
guard stacking on
guard max_invested 75%
when rsi(14) < 30 and cooldown 12
then buy 25%
when rsi(14) > 65
then sell 100%
- Each oversold signal adds 25% of the remaining cash, at most once every 12 candles.
- The position never exceeds 75% of equity.
- Sells everything when RSI recovers.
Pitfalls
buy 50%twice is not 100%: the second buy takes 50% of what is left.- Without stacking, a buy while holding is skipped entirely. A limit or stop buy that reaches its price while you hold is used up without a trade.
- Limit orders only fill when price comes to them. In a strong rally a dip limit may never fill, which a backtest shows as a missed trade.
Buy %: frequently asked questions
Is the percentage of the starting balance?
No, of the cash available when the buy fills: at the close for a market order, or on the fill candle for a limit or stop order.
Why was my buy skipped?
Most often because the bot already holds a position and stacking is off, or a risk guard left no room. Buys under one cent are also skipped.
At what price does it fill?
At market, at the candle's close plus slippage, or at the trigger level when a wick-based P&L condition in the same rule fired. A limit fills at its price or a better open; a stop at its price or a worse open, plus slippage.
Are fees charged?
Yes, the fee set on the bot, as a percent of each fill. New bots start at 0.1% with 0.05% slippage; bots created before fees existed keep 0%. You can change both in the Lab.
What happens if a limit order never fills?
It lapses after its expiry candles and nothing is traded. The rule can place a new order the next time it fires.
Related blocks
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.