BTC Pulse

Replaying 1,646 recorded Bitcoin markets before changing a trading bot's exits

Replaying 1,646 recorded 5-minute Bitcoin markets showed a trading bot's exits, not its signal, were the problem. The fix, the hindsight trap and the limits.

By 4 min read

In short

In flat 5-minute Bitcoin markets the late entry signal matched settlement in 83.6% of recorded snapshots, but an adverse-move exit armed after 2 seconds on a 3-tick move closed correct trades on noise. On 1,301 recorded flat markets, an in-sample simulation with no fees went from 34% to 51% winning trades with wider exits. The regime label used hindsight, so the live gate uses a 20-minute Bollinger-width proxy instead.

BTC Pulse is a terminal trading bot I built for Polymarket's short "Bitcoin up or down" markets. Each 5-minute market asks whether BTC will finish above a target price, and shares trade between 0 and 1 dollar until it settles. The bot watches BTC's spot price and the order book, decides when to enter and exit, and records every snapshot to SQLite, so a change can be replayed against real sessions before it trades.

In early June the recordings showed something odd. In flat markets, when BTC sat 5 or more basis points from the target late in the window, the side it was on matched the final result in 83.6% of snapshots. The entry signal was strong. Yet one losing trade had entered NO correctly and been thrown out 19 seconds later by the bot's own exit rule, in a market that NO went on to win. The bot was paying for good calls and then cashing them in early, at a loss.

What one trade looked like

Here's that trade from the recorded snapshots. The bot buys NO at 0.65 with BTC 10 basis points under the target. Nineteen seconds later BTC ticks up to 1.1 basis points above it, a tiny move. The NO price drops a few cents, the signal briefly flips, and the rule called exit_adverse_confirmation fires: it was armed after just 2 seconds of holding and needed only a 3-tick (3 cent) move against the position. The bot sells at 0.59 for a loss of $4.62. BTC finishes 20.8 basis points under the target, NO settles at 1, and the position would have made about $26.

A recorded NO trade: entry at 0.65, a 1.1 bps blip 19 seconds later triggers the adverse exit at 0.59, and BTC settles 20.8 bps below target, so NO would have won.

Across 1,646 recordings

One trade is an anecdote, so I swept the whole recorded set: 1,646 five-minute markets from 20 May to 3 June, each labelled by how far BTC moved in its window. 86% were flat (under 20 basis points), 14% moderate (20 to 50) and 1% volatile.

Then I replayed the strategy grid per regime. On 1,301 flat markets, with the same 738 entries and $25 per trade, the old exits closed 34% of trades as winners for a simulated +$97, and wider exits closed 51% for a simulated +$1,380. The biggest levers were the adverse-move threshold (3 ticks to 10) and the minimum hold (2 seconds to 30). In a flat 5-minute market, the first 30 seconds are mostly noise.

Simulated results on 1,301 recorded flat markets, same 738 entries, $25 per trade: old exits 34% wins and +$97, new exits 51% wins and +$1,380. In-sample backtest, no fees.

What I got wrong along the way

  1. Settings chosen for a market that had changed. An earlier analysis on 23 and 24 May had found only about 40% of markets flat. The full set was 86% flat, so the market had changed under the bot's settings.
  2. A first sweep that left out two production rules. It didn't model the adverse-move threshold or the minimum hold, the two biggest levers, so it underestimated the damage. The numbers above are from the sweep with both modelled.
  3. A label that used the future. "Flat" was measured over the whole 5-minute window, which the bot only knows once the market is over, so a live gate can't use it. I tested proxies the bot can compute at decision time against it: three times the range of the first 60 seconds matched 82% of flat markets, and a rolling average of the last six markets' range matched 84% overall. The gate I shipped uses the width of a 20-minute Bollinger band on BTC, which the spot feed already computed. Below 0.20% the market counts as flat, and in that state YES entries are blocked, because brief spikes above the target kept reverting before settlement. The 0.20% figure is a first estimate, set between the typical flat and moderate widths seen in the data.
  4. A relaxed entry gate for moderate markets. The sweep suggested it, but it was too permissive in trending markets, and the June commit reverted it.
  5. A commit with 14 failing tests. They came from mocks without the new Bollinger field, an unregistered config key and a trace id missing from the gate metadata. A follow-up on 15 June fixed them, and the terminal suite went back to 224 passing.

What shipped, and what the numbers can't say

The change landed in one commit on 3 June: the flat-regime YES blocker, a 10 basis point counter-trend block, wider 5-minute exits (adverse move 3 to 10 ticks, minimum hold 2 to 30 seconds, trail start 8 to 16, hard stop 6 to 10) and a fix to a dynamic stop that could stretch to 27 ticks. The hourly bot got a fail-closed fix alongside: if the Binance feed it settles against is down, it no longer falls back to another price source, and trading stops.

The replay backtest calls the same build_signal and exit evaluator the live bot uses, so a recorded session goes through the production decision path. Tests such as test_replay_frames_changes_backtest_results_when_strategy_thresholds_change pin that.

Still, the numbers above come from a backtest, not trading results. They're in-sample: the settings were chosen on the same markets they're scored on. The sweep fills entries at the ask and exits at the bid or at the exact stop level, and it doesn't subtract fees. So these numbers justify trying the change on new sessions. They don't predict a profit.

Further reading

  • Backtesting
  • Python
  • Data analysis
  • Trading systems
  • SQLite
  • Testing

More writing