This software is for educational purposes only. It does not constitute financial advice. Paper trading performance does not guarantee live trading results. Use at your own risk.
Three weeks ago I posted a post-mortem on my SPY 0DTE gamma-explosion bot after a -$309 day exposed five failure patterns. I was holding back the strategy parameters and teasing a paid release. I changed my mind — the full code is now open source, all parameters included, no paywalls.
This post covers what happened since May 29: a volatility regime shift, three new failure modes, two fixes, and why the +$1,287 day in the table below is fake.
Original post: https://www.reddit.com/r/alpacamarkets/comments/1tsw5ej/built_a_live_0dte_spy_options_bot_on_alpaca_heres/
Full code: github.com/milgar7969/alpaca-options-framework
What changed in the market
When I wrote the original post, SPY was around $758 and the 5-day daily ATR was roughly $5. Over the following two weeks:
This matters because ATR is baked into strike selection. Every morning the bot computes:
offset = ATR_MULT * baseline_atr # ATR_MULT = 0.60
call_strike = SPY + offset
put_strike = SPY - offset
At ATR=5, offset = $3.00 — strikes about $3 OTM, well within reach on a trending day.
At ATR=15, offset = $9.00 — strikes $9 OTM. SPY would need a 1.2% move just to reach the approach zone. On most days, it doesn't.
Failure Mode 6 — Strike calibration silently breaks under high ATR ✅ Fixed
June 12 and June 15 — two consecutive trading days — both had zero trades. Not zero winners. Zero entries. The bot ran all day, processed 390 bars, detected momentum signals, and never once entered.
From the June 12 log:
09:45 startup_atr=15.43 offset=9.26 call_target=762.50 put_target=744.00
10:30 [BAR] spy_close=753.14 atr5=0.312 APPROACH ZONE: NONE ([email protected] [email protected])
SPY spent the entire day between $751–$757. The call target was $762.50 — $9 away. No log errors. No warnings. The bot was technically working; the strike selection was just producing unreachable targets.
Fix: A hard cap on the strike offset:
MAX_STRIKE_OFFSET = 4.50
offset = min(ATR_MULT * baseline_atr, MAX_STRIKE_OFFSET)
The 5-day ATR is still used when it's low. The cap prevents elevated ATR from placing strikes beyond SPY's realized intraday range. June 16 was the first day with the cap live — 13 trades, the bot was active again.
Failure Mode 7 — Ghost position / watchdog restart cascade 🔲 Unresolved
This is the most damaging failure and still isn't fixed.
The bot has a watchdog: if silent for >20 seconds during market hours, it auto-restarts. Works fine for WebSocket drops. Under one specific EOD sequence, it produces a cascade:
Time stop fires at 3:25 PM — close_position() submitted, waiting for fill
MOC period is slow — fill response takes >20 seconds
Watchdog fires, kills the process, restarts
On startup, _recover_open_position() polls Alpaca REST for open positions
Finds positions the prior instance was mid-close on — reconstructs them as "recovered"
New instance holds those positions and hits the time stop again
Loop continues — positions liquidated at random end-of-session prices
June 3: Two cascade exits at 3:25–3:26 PM. $224 in losses from positions the prior instance had already closed.
June 4: The same cascade produced a +$1,831.11 time_stop exit (an untracked C755 got liquidated when C755 happened to be wide at 3:25 PM), plus -$234 and -$252 from two recovered puts.
Raw P&L that day: +$1,287. Clean strategy P&L (excluding the three cascade exits): -$58.
Calling this out explicitly because the table below looks much better without the asterisks. The "recovery" mechanism that's supposed to protect against restarts is the proximate cause of the cascades. Two root causes still under investigation: (1) why the time_stop path hangs >20 seconds; (2) why _recover_open_position() finds positions that were already closed.
Failure Mode 8 — Fixed SPY stop buffer causes 52% false stops ✅ Fixed
The bot has a SPY-level stop: if SPY bar-closes more than SPY_STOP_BUFFER dollars against the position direction, it exits regardless of option price. The original value was $0.10.
After tagging 58 spy_stop exits across the June sessions: 27 of 52 (52%) saw SPY reverse within 3 bars. The stop was cutting winners, not losers. $0.10 is inside normal bar-to-bar noise when atr5 is 0.35–0.45 — the regime after the volatility shift.
Fix: ATR-adaptive buffer using the intrabar ATR already tracked by the momentum engine:
SPY_STOP_ATR_MULT = 0.75 # buffer = 0.75 × atr5 at entry time
SPY_STOP_FLOOR = 0.10 # minimum buffer regardless of atr5
# at entry, store atr5 on the Position:
pos = Position(..., entry_spy_price=bar.close, entry_atr5=momentum_engine.state.atr5)
# on each bar close:
buf = max(config.SPY_STOP_FLOOR, config.SPY_STOP_ATR_MULT * pos.entry_atr5)
At atr5=0.20: buf = 0.15 — slightly tighter than before
At atr5=0.35: buf = 0.26 — gives the position room to breathe
At atr5=0.45: buf = 0.34 — high-velocity session, real reversals are larger moves
First day live (June 17): 2 spy_stops out of 6 trades vs. 7–11/day the prior week. Both that fired held 5 and 17 bars — actual reversals, not noise.
Full performance log
Days marked * have ghost-position cascade exits excluded from the clean column.
| Date | Trades | Raw P&L | Clean P&L | Notes |
|---|
| May 20 | 5 | +$64 | +$64 | |
| May 26 | 4 | -$309 | -$309 | Post-mortem session |
| May 27 | 10 | -$159 | -$159 | First day w/ fixes, trail miscalibrated |
| May 29 | 5 | +$70 | +$70 | First full session with ATR gate + trail |
| Jun 1 | 4 | -$124 | -$124 | |
| Jun 2 | 2 | -$117 | -$117 | |
| Jun 3 * | 10 | -$148 | +$76 | Ghost cascade: -$224 excluded |
| Jun 4 * | 11 | +$1,287 | -$58 | Ghost cascade: +$1,345 excluded |
| Jun 5 | 18 | +$178 | +$178 | |
| Jun 8 | 15 | -$324 | -$324 | High ATR, elevated spy_stop rate |
| Jun 9 | 15 | +$265 | +$265 | Strong bear leg |
| Jun 10 | 14 | -$79 | -$79 | |
| Jun 11 | 5 | -$1 | -$1 | |
| Jun 12 | 0 | $0 | $0 | ← strike calibration failure |
| Jun 15 | 0 | $0 | $0 | ← strike calibration failure |
| Jun 16 | 13 | -$19 | -$19 | First day with MAX_STRIKE_OFFSET cap |
| Jun 17 | 6 | +$82 | +$82 | First day with adaptive SPY stop |
Clean strategy total (May 20 – Jun 17): -$121
The raw total is +$1,007, almost entirely from the Jun 4 ghost position anomaly. -$121 is what the strategy actually produced.
What's still on the list
Three of the original five failure patterns remain unaddressed:
VWAP extension cap (|SPY - VWAP| ≤ $1.25)
Same-strike 60-minute session cooldown after a stop
Post-TP directional cooldown (10 bars)
One new unresolved item:
On open-sourcing
The original repo had None placeholders for all strategy parameters with a hint about a paid release. I've dropped that. The full working config is in the repo now — every threshold, multiplier, and stop level we're actually running.
The parameters alone aren't the edge. The edge (if there is one) is in understanding when the strategy fails and why — which is what these posts are for. A bot with the right numbers but no understanding of the ghost cascade bug or the regime sensitivity would still blow up.
Technical stack: Python 3.11, alpaca-py ≥ 0.43, asyncio. Three concurrent WebSocket streams (StockDataStream + OptionDataStream + TradingStream). Quote-driven exits via asyncio.create_task(_evaluate_exit()) — sub-50ms from quote arrival to order. SPY-level stop on bar close using atr5 stored at entry time. Strike offset capped at $4.50 regardless of 5-day ATR.
Full code: github.com/milgar7969/alpaca-options-framework
Still paper trading. Still logging everything. Ghost cascade is next.