OPEN-SOURCE SCRIPT

Dual Iron Butterfly Analyzer

67
Overview
This indicator backtests and analyzes a 0DTE (zero days to expiration) dual iron butterfly options strategy on SPX. It measures how often price stays within profitable ranges from a fixed daily entry time to settlement, calculating expected P/L based on your butterfly structure.

The strategy enters at 16:00 CET (10:00 ET) and settles at RTH close (22:00 CET / 16:00 ET), giving approximately 6 hours of exposure per trade.

Strategy Structure
The dual iron butterfly consists of two overlapping flies centered around the entry price:

Fly A (Bearish-Biased)
Center strike at Entry Price minus Offset (default: -20 points)
Wings extend ±40 points from center

Fly B (Bullish-Biased)
Center strike at Entry Price plus Offset (default: +20 points)
Wings extend ±40 points from center

This creates three profit zones:
  • Max Profit Zone: Price settles between the two center strikes (within ±20 points of entry)
  • Both Win Zone: Price settles where both flies remain profitable (within ±40 points)
  • Breakeven Zone: Combined structure breaks even at ±60 points from entry


How It Works
The indicator captures the entry price at 16:00 CET each trading day and records the settlement price at the following day's first bar. It then calculates:

Deviation Analysis
Absolute percentage and point deviation from entry to settlement, sorted into customizable buckets to show the probability distribution.

P/L Calculation
For each fly, the P/L formula is: Credit minus the minimum of (deviation from center) or (wing width). The combined P/L sums both flies. With default settings (29 points credit per fly, $100 multiplier), max profit per day is $3,200 and max loss is $2,200.

Drawdown Tracking
The indicator tracks cumulative P/L over the lookback period, calculating peak equity, maximum drawdown, and current drawdown to assess strategy risk.

What Makes This Different
Unlike standard deviation indicators, this tool is purpose-built for options traders analyzing dual iron butterfly viability. It provides:
  • Options-specific P/L calculations based on actual butterfly payoff structure
  • Visual probability distribution with key thresholds marked (breakeven, both-win, max-profit zones)
  • Rolling lookback window that respects your chosen sample size
  • Drawdown metrics essential for position sizing and risk management


Features
  • Distribution Table — Shows deviation buckets with cumulative probability
  • Zone Highlighting — Color-coded rows for max profit, both-win, and breakeven thresholds
  • P/L Summary — Total P/L, average per session, win rate, best/worst days
  • Drawdown Section — Max drawdown in dollars and percentage, peak equity, current drawdown
  • Optional Labels — Entry and settlement markers on the chart
  • Configurable Structure — Adjust offset, wing width, and credit to match your actual trades


Settings Guide

Iron Butterfly Structure
  • [code]Center Offset[/code] — Distance from entry price to each fly's center strike (default: 20 points). Larger offset = wider max profit zone but lower probability.
  • [code]Wing Width[/code] — Distance from center to outer wings (default: 40 points). Determines max loss per fly and breakeven distance.
  • [code]Net Credit per Fly[/code] — Premium received per iron butterfly in SPX points (default: 29). Adjust based on current market conditions and your actual fills.
  • [code]Lookback[/code] — Rolling window of trading days to analyze (default: 252 = 1 year). Use 504 for 2 years of data.


Distribution Settings
  • [code]Bucket Size[/code] — Percentage increment for distribution buckets (default: 0.10%). Smaller = more granular view.
  • [code]Number of Buckets[/code] — How many rows to display (default: 20).


Display
  • [code]Table Position[/code] — Corner placement for the statistics table.
  • [code]Show Entry/Settle Labels[/code] — Toggle chart labels marking entry and settlement prices.


How to Use
  • Apply to SPX (SPCFD) on an intraday timeframe (1 hour recommended)
  • Set the butterfly parameters to match your intended trade structure
  • Review the Cumul % column to see probability of staying within each deviation level
  • The highlighted BREAKEVEN row shows your probability of profit
  • Use the P/L Summary to evaluate expected returns over your lookback period
  • Monitor the Drawdown section to understand worst-case scenarios for position sizing


Interpreting the Table
  • Purple row (MAX PROFIT) — Deviation where both flies achieve maximum profit
  • Green row (BOTH WIN) — Deviation where both flies remain profitable
  • Yellow row (BREAKEVEN) — Combined structure breakeven point
  • Green percentages (≥80%) — High probability levels
  • Orange percentages (60-79%) — Medium probability levels
  • Red percentages (<60%) — Lower probability levels


Chart Requirements
  • Symbol: SPX (use SPCFD for extended hours data)
  • Timeframe: Intraday (1h recommended, 30m or lower also works)
  • The chart must include 16:00 CET bars for entry detection


Alerts
  • Deviation Exceeds Breakevens — Triggered when settlement exceeds the combined breakeven range
  • Max Profit Zone Hit — Triggered when settlement falls within the max profit zone


Limitations
  • Historical analysis only — Past deviation patterns may not predict future behavior
  • Fixed entry time — Does not account for intraday entry timing optimization
  • Credit assumption — Actual premiums vary with VIX, time to expiry, and market conditions
  • No transaction costs — Does not include commissions, fees, or slippage
  • Single contract — Assumes 1 contract per trade with no scaling or compounding


Disclaimer
This indicator is for educational and research purposes only. It does not constitute financial advice.
  • Past performance does not guarantee future results
  • Options trading involves significant risk of loss
  • The P/L calculations are theoretical based on your input parameters
  • Always paper trade and validate with real market data before risking capital
  • Conduct your own research and consult a financial advisor if needed

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.