bracket_backtest
Backtest long and short trading strategies on Binance with ATR-based bracket exits, intrabar execution, and realistic fee and slippage costs.
Instructions
Backtest scalp/day/swing strategies (long AND short) on Binance 1m-1d klines.
Unlike backtest_strategy (Yahoo, 1h/1d, long-only), this simulates real execution: ATR-bracket exits (stop / take-profit / time-stop) checked intrabar against high/low, conservative stop-first fills, and per-side fee + slippage so the round-trip cost hurdle is explicit.
Args: symbol: Binance pair, e.g. BTCUSDT, ETHUSDT, SOLUSDT strategy: squeeze_breakout (Bollinger squeeze → band-break entry) | ema_momentum (EMA 9/21 cross gated by EMA200 side) interval: 1m | 3m | 5m | 15m | 30m | 1h | 4h | 1d (candle size) days: History window, 1-730. Suggested: 5m→14, 15m→30, 1h→90-365, 4h→365-730, 1d→730. (Capped at 30k candles total.) direction: both | long | short rr: Reward:risk ratio for the take-profit bracket (default 1.5) atr_mult: Stop distance in ATR(14) multiples (default 1.0) max_hold_bars: Time-stop — force exit after this many bars (default 60) fee_pct: Fee % per side (default 0.05 = Binance USDT-M futures taker; use 0.02 for maker, 0.1 for spot taker) slippage_pct: Slippage % per side (default 0.02) initial_capital: Starting capital in USD (default $10,000) include_trade_log: Include every trade with direction/exit_reason (default False) regime_filter: Gate signals by higher-timeframe trend — longs only in anchor uptrend, shorts only in downtrend, flat in chop regime_anchor: Symbol whose trend gates trades (default BTCUSDT — the market leader; "self" = the traded pair itself) regime_interval: Anchor timeframe for the regime read (default 4h)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rr | No | ||
| days | No | ||
| symbol | Yes | ||
| fee_pct | No | ||
| atr_mult | No | ||
| interval | No | 1h | |
| strategy | No | squeeze_breakout | |
| direction | No | both | |
| slippage_pct | No | ||
| max_hold_bars | No | ||
| regime_anchor | No | BTCUSDT | |
| regime_filter | No | ||
| initial_capital | No | ||
| regime_interval | No | 4h | |
| include_trade_log | No |