Feature
Fees, slippage and order types
Every simulated fill pays the trading fee and slippage set on the bot, and any action can wait for a price with a limit or stop order instead of trading at the close. Costs look small per trade, but they add up over many trades, and a backtest without them looks better than reality.
Fees and slippage
Each bot has two execution settings: a fee and a slippage, each from 0% to 5% per fill. New bots start at a 0.1% fee and 0.05% slippage. Bots created before these settings existed keep 0% for both, so their past results don't change; set them yourself to include costs.
The fee is a percent of each fill's value, charged in dollars. On a buy, the dollars the action spends include the fee, so buy 100% uses all the cash. On a sale, the fee comes out of the proceeds.
Slippage stands for the price moving against you between the signal and the fill. Buys fill at price × (1 + slippage) and sells at price × (1 − slippage). It applies to market and stop fills only; a limit order never fills at a worse price than its own.
- Market buys and sells, including close-triggered exits: fee and slippage.
- Stop orders, a stop loss on the wick (
pnl down … on wick) and a trailing stop on the wick: fee and slippage. - Limit orders and a take profit on the wick (
pnl up … on wick): fee only.
How costs are calculated
- Buy:
notional = spend / (1 + fee),fee paid = spend − notional,BTC bought = notional / fill price. - Sell:
notional = BTC sold × fill price,fee paid = notional × fee,cash received = notional − fee paid. - Each recorded fill shows the fill price after slippage, the BTC amount, the cash that actually moved and the fee paid.
- Buy and hold, the benchmark every run is compared with, pays the same costs once:
start cash / (1 + fee) / (first close × (1 + slippage)) × last close. - A round trip is a win only if its proceeds after fees beat its cost including fees.
Worked example: one round trip
A bot with a 0.1% fee and 0.05% slippage starts with $10,000. Its buy rule fires at a close of $60,000 with buy 100%, and its sell rule later fires at a close of $63,000 with sell 100%.
- Buy fill: $60,000 × 1.0005 = $60,030.00.
- The $10,000 spent splits into $9,990.01 of BTC (10,000 / 1.001) and a $9.99 fee, buying 9,990.01 / 60,030 = 0.16641696 BTC.
- Sell fill: $63,000 × 0.9995 = $62,968.50.
- The sale is worth 0.16641696 × $62,968.50 = $10,479.03. The fee is $10.48, so the bot receives $10,468.55.
- Result: +4.69%, against +5.00% for the same trade without costs. Costs took $31.45: $20.47 in fees and $10.98 in slippage.
- Buy and hold over the same two closes ends at $10,000 / 1.001 / $60,030 × $63,000 = $10,484.27 (+4.84%), paying the buy fee and slippage once.
Limit and stop orders
Any buy or sell action can wait for a price instead of trading at the close. Add limit X% or stop X% to the action, and optionally expires N for how many candles the order works: 12 by default, up to 1,000. X is the distance from the close of the candle where the rule fired, from 0.01% to 50%.
bot "Patient Entries"
when pnl down 4% on wick
then sell 100%
when price crosses above sma(50)
then buy 100% stop 0.5%
when rsi(14) < 30
then buy 100% limit 1% expires 6
- Buy limit at
close × (1 − X/100), to buy a dip. It fills when a candle's low reaches it, at the lower of that candle's open and the limit. - Buy stop at
close × (1 + X/100), to buy a breakout. It fills when a candle's high reaches it, at the higher of the open and the stop, plus slippage. - Sell limit at
close × (1 + X/100), to take profit higher. It fills when a candle's high reaches it, at the higher of the open and the limit. - Sell stop at
close × (1 − X/100), to get out lower. It fills when a candle's low reaches it, at the lower of the open and the stop, less slippage.
How working orders behave
- An order is placed at the close of the candle where its rule fired and works from the next candle on. If none of its candles reaches the price, it lapses without a trade.
- Working orders are checked at the start of each candle, before that candle's rules run, in rule order.
- Each rule has at most one working order. While it works, the rule firing again places nothing.
- The size is worked out when the order fills, from the cash or position at that moment, and the risk guards apply then. If there is nothing to buy or sell, the order is used up without a trade.
- A fill counts as a trade on its candle, for the cooldown and every other block that looks at trades.
Worked example: limit and stop fills
The same bot, with $10,000 in cash, a 0.1% fee and 0.05% slippage, and a signal at a close of $60,000:
buy 100% limit 1%places a buy limit at $59,400. If the next candle opens at $59,800 and trades down to $59,250, the order fills at $59,400 with no slippage: $9,990.01 of BTC (0.16818199 BTC) and a $9.99 fee. Had that candle opened at $59,100, below the limit, it would have filled at the open, $59,100.buy 100% stop 2%places a buy stop at $61,200. A candle that opens at $60,100 and reaches $61,500 fills it at $61,200 plus slippage: $61,230.60.- Later, after a close of $63,000,
sell 100% stop 3%places a sell stop at $61,110. A candle that opens above it and trades below it fills the order at $61,110 less slippage: $61,079.45.
Fees, slippage and order types: frequently asked questions
What fee should I use?
The fee your exchange charges you for the order type you would use. The 0.1% default matches a common standard spot rate; lower it if you pay less.
Why do my older bots show 0% fees?
Bots created before fees and slippage existed keep 0% so their past results stay reproducible. Set the fee and slippage on the bot to include costs.
Does buy and hold pay fees too?
Yes, once: the benchmark pays one buy fee and slippage at the first close and is valued at the last close.
Is slippage applied to limit orders?
No. Limit fills, including a take profit on the wick, get no slippage. Market and stop fills do.
Why didn't my limit order fill?
Price never reached it before the order expired. A dip limit misses trades in strong rallies; that is a real cost of limit orders, and the backtest shows it.
Can a limit order fill at a better price than its limit?
Yes, when a candle opens beyond it. A buy limit fills at the open if the candle opens below the limit, and a sell limit at the open if the candle opens above it.
Related
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.