OPEN-SOURCE SCRIPT
Iron Fly 0DTE Strategy

Overview
This indicator identifies optimal entry and exit points for 0DTE (zero days to expiration) Iron Fly options strategies on SPX. It uses a combination of DMI (Directional Movement Index) regime classification and ATR (Average True Range) volatility measurement to determine when market conditions favor non-directional premium selling.
An Iron Fly is a neutral options strategy that profits when price stays near a central strike. This indicator automates the decision of WHEN to enter and at WHAT strikes, based on quantifiable market conditions rather than discretionary judgment.
How It Works
Market Regime Classification
The core logic uses DMI and ADX to classify market conditions into four regimes:
The DI Spread is calculated as the absolute difference between DI+ and DI-. A low spread indicates balanced buying and selling pressure, which favors range-bound price action.
Dynamic Wing Width Calculation
Wing width (the distance between the short strikes and protective long strikes) is calculated dynamically using:
Wing Width = ATR(14) × Multiplier × Late Session Factor
The multiplier varies by Entry Aggressiveness setting (5x to 7x ATR). Wings are widened by 20% in CAUTION regime for additional protection. Late in the session (after 50% elapsed), wings narrow by up to 20% as less time remains for adverse moves.
Wing width is bounded between 15 and 50 points and rounded to the nearest 5-point strike.
Entry Logic
New positions open when:
Exit Logic
Positions close when price exceeds a dynamic exit threshold:
Exit Threshold = Wing Width × (Base Exit Percent + Time Decay Bonus)
The Base Exit Percent varies by Exit Aggressiveness (50% to 80%). The Time Decay Bonus increases throughout the session (0% to 25%), allowing wider tolerance as theta decay works in your favor.
What Makes This Original
This indicator differs from simple moving average or RSI-based approaches by:
Settings Guide
Strategy Settings
Session Settings
How to Use
Alert Messages
OPEN alerts provide: Strike price, wing width, and all four leg strikes (short call, short put, long call, long put).
CLOSE alerts provide: Strike price and exit reason (price exceeded threshold or session ended).
Status Panel
The on-chart panel displays:
Limitations
Best Conditions
This strategy performs best during:
Avoid using during:
Disclaimer
This indicator is for educational and informational purposes only. It does not constitute financial advice.
This indicator identifies optimal entry and exit points for 0DTE (zero days to expiration) Iron Fly options strategies on SPX. It uses a combination of DMI (Directional Movement Index) regime classification and ATR (Average True Range) volatility measurement to determine when market conditions favor non-directional premium selling.
An Iron Fly is a neutral options strategy that profits when price stays near a central strike. This indicator automates the decision of WHEN to enter and at WHAT strikes, based on quantifiable market conditions rather than discretionary judgment.
How It Works
Market Regime Classification
The core logic uses DMI and ADX to classify market conditions into four regimes:
- SAFE - ADX below 25 AND DI Spread below 20: Low directional momentum, ideal for Iron Flies
- CAUTION - ADX below 35 AND DI Spread below 30: Moderate conditions, wider wings recommended
- WARNING - ADX below 45 OR DI Spread below 45: Elevated risk, no new entries
- NO ENTRY - ADX above 45 AND DI Spread above 45: Strong trend, avoid premium selling
The DI Spread is calculated as the absolute difference between DI+ and DI-. A low spread indicates balanced buying and selling pressure, which favors range-bound price action.
Dynamic Wing Width Calculation
Wing width (the distance between the short strikes and protective long strikes) is calculated dynamically using:
Wing Width = ATR(14) × Multiplier × Late Session Factor
The multiplier varies by Entry Aggressiveness setting (5x to 7x ATR). Wings are widened by 20% in CAUTION regime for additional protection. Late in the session (after 50% elapsed), wings narrow by up to 20% as less time remains for adverse moves.
Wing width is bounded between 15 and 50 points and rounded to the nearest 5-point strike.
Entry Logic
New positions open when:
- Market regime is SAFE or CAUTION
- Current open positions are below the maximum limit
- Daily trade count is below the daily limit
- Price has moved sufficiently from the last entry (trigger distance)
- No existing position at the calculated strike
Exit Logic
Positions close when price exceeds a dynamic exit threshold:
Exit Threshold = Wing Width × (Base Exit Percent + Time Decay Bonus)
The Base Exit Percent varies by Exit Aggressiveness (50% to 80%). The Time Decay Bonus increases throughout the session (0% to 25%), allowing wider tolerance as theta decay works in your favor.
What Makes This Original
This indicator differs from simple moving average or RSI-based approaches by:
- Using DMI spread (not just ADX) to measure directional balance, which better identifies consolidation
- Dynamically sizing wings based on current ATR rather than fixed widths
- Adjusting exit tolerance based on session progress to account for theta decay
- Implementing regime-based position management that automatically steps aside during trending conditions
- Providing complete strike calculations for the 4-leg Iron Fly structure
Settings Guide
Strategy Settings
- Entry Aggressiveness - Controls how often new trades open. LOW: fewer trades, wider wings, more selective. MID: balanced. HIGH: more trades, tighter wings.
- Exit Aggressiveness - Controls how long positions are held. LOW: exits early at 50% of wing. MID: exits at 65% plus time bonus. HIGH: holds longer, exits at 80%.
- Max Concurrent Flies - Maximum simultaneous open positions (1-5). Start with 1-2.
- Max Trades Per Day - Daily limit to prevent overtrading (3-30).
Session Settings
- Session Start/End - Trading hours in Eastern Time. Default 10:00-16:00.
How to Use
- Add indicator to SPX chart (1-5 minute timeframe recommended)
- Create alert with condition "Any alert() function call"
- When OPEN alert fires, execute the 4-leg Iron Fly in your broker at the specified strikes
- When CLOSE alert fires, close the position
- Always verify the premium collected justifies the risk before entering
Alert Messages
OPEN alerts provide: Strike price, wing width, and all four leg strikes (short call, short put, long call, long put).
CLOSE alerts provide: Strike price and exit reason (price exceeded threshold or session ended).
Status Panel
The on-chart panel displays:
- Positions - Current open count vs maximum
- Market - Current regime classification
- Wings - Current calculated wing width
- Exit @ - Current exit threshold distance
- Trades - Daily trade count vs limit
Limitations
- Designed specifically for SPX 0DTE options; may not suit other underlyings
- Does not account for bid-ask spreads or execution slippage
- Market regime classification may lag during rapid regime changes
- Past performance of signals does not guarantee future results
- Requires manual execution in your options broker
Best Conditions
This strategy performs best during:
- Range-bound, choppy market conditions
- Normal volatility days (avoid major news events)
- Regular trading hours (10 AM - 4 PM ET)
Avoid using during:
- Strong trending days
- FOMC announcements, CPI releases, earnings
- Pre-market or after-hours
Disclaimer
This indicator is for educational and informational purposes only. It does not constitute financial advice.
- Options trading involves substantial risk of loss
- Iron Flies can result in losses up to the wing width minus premium collected
- Past indicator signals do not guarantee future performance
- Always understand your maximum risk before entering any trade
- Never risk more than you can afford to lose
- Conduct your own research and consider consulting a financial advisor
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.