ib_0dte_ema_vix
Select and optionally place 0DTE credit spreads by applying EMA9/21 cross and VIX/VXN volatility gates, ranking candidates, and executing a dry run or live combo order.
Instructions
Find (and optionally place) the best 0DTE credit spread via the EMA + VIX/VXN strategy.
Reads closed 12-min IB bars + the live vol index, applies the vol gate, then auto-selects bull_put or bear_call from the EMA9/EMA21 cross before ranking spreads. NDX/QQQ are gated on VXN (Nasdaq-100 vol); all other symbols on VIX. Returns success=False with a reason when a gate blocks the trade (VIX-SKIP / no-cross / EMA-Dn-no-RR / missing-bars).
Default is a bare EMA cross runnable any time of day; enable the optional confirmation gates per call. Default is a dry run — pass execute=True to place a live combo order with the automatic OCA exit bracket. Requires TWS or IB Gateway running locally.
Args: symbol: Underlying (e.g. NDX, SPX, RUT, QQQ, SPY) budget: Max capital at risk in dollars (default 50000) port: IB port (7496 for live, 7497 for paper) vix_threshold: Skip if vol index >= this. Default is per-index: VXN 30 for NDX/QQQ, VIX 20 otherwise. target_delta: Short-leg delta target (default 0.11 bear call / 0.07 bull put) rr_gate: Require red→red (today's two most recently closed bars both red) to confirm a Bear Call time_gate: Require today's bars from 9:30 through 10:30 ET (run at 10:30 ET+) and anchor the EMA-cross lookback to the last bar closing by 10:30 ET bar_minutes: Bar size in minutes for the EMAs and gates (default 12) max_width: Cap the strike width in points (default 150; 0 = no cap) gex: Compute the dealer gamma-exposure profile top: Number of candidates to return (default 5) account: IBKR account for execution (required with execute when >1 managed account) execute: Place the chosen spread as a live combo order (default False = dry run) pick: 1-based rank of the candidate to execute (default 1 = best) limit_frac: Walk between the marketable combo credit (0) and mid (1.0) at execution
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gex | No | ||
| top | No | ||
| pick | No | ||
| port | No | ||
| budget | No | ||
| symbol | Yes | ||
| account | No | ||
| execute | No | ||
| rr_gate | No | ||
| max_width | No | ||
| time_gate | No | ||
| limit_frac | No | ||
| bar_minutes | No | ||
| target_delta | No | ||
| vix_threshold | No |