- Build a Custom Option Chain Relative Value Analysis System
- The Problem with Traditional Options Analysis
- Understanding Relative Value in Options Trading
- Step-by-Step Coding Tutorial: Building the Relative Value Scanner
- Real-World Application Examples
- Integration with Portfolio Management
- Common Implementation Mistakes and Solutions
- Advanced Strategy Applications
- Automation and Scanning Workflows
Build a Custom Options Relative Value Scanner
Track which options have become expensive or cheap compared to recent trading periods. This custom ThinkScript scanner reveals percentage changes in option premiums across different timeframes.
What you’ll learn to build:
- Compare current option prices to any historical period
- Identify options with extreme percentage changes
- Calculate option-to-stock price ratios for context
- Filter for liquid options to avoid false signals
Designed for options traders who want objective data about premium expansion and contraction cycles.
Build a Custom Option Chain Relative Value Analysis System
Options traders often buy premium at the worst times—purchasing calls after volatility spikes or selling puts when IV has already collapsed. Instead of guessing whether premium is fair, you can build a custom scanner that shows exact percentage changes compared to any historical period.
This tutorial shows you how to create a ThinkScript that transforms option chain analysis by revealing which strikes have become cheap or expensive relative to recent trading periods.
The Problem with Traditional Options Analysis
Standard options analysis focuses on Greeks, implied volatility percentiles, and theoretical pricing models. While these tools provide valuable insights, they miss a crucial element: historical context for individual strike prices.
Common Analysis Gaps:
- IV percentile shows overall volatility but not strike-specific changes
- Greeks provide sensitivity measures but not value comparisons
- Volume and open interest show popularity but not pricing efficiency
- Bid-ask spreads indicate liquidity but not historical value shifts
These traditional metrics leave traders asking: “Is this $2.50 call expensive compared to last week?” The relative value scanner answers this question with precise percentage calculations.
Understanding Relative Value in Options Trading
Relative value analysis compares current option prices to their historical levels, revealing opportunities that traditional analysis misses. When the market sells off, put premiums often spike 100-300% while call premiums collapse by similar amounts. Understanding these shifts creates significant trading advantages.
Key Relative Value Concepts:
Premium Expansion: During market stress, option premiums inflate beyond their historical norms. Put options become expensive as fear peaks, while call options crash as optimism fades.
Premium Contraction: As markets stabilize, inflated premiums return to normal levels. This creates opportunities to sell expensive options and buy cheap ones.
Strike-Specific Changes: Different strikes experience different premium changes. Out-of-the-money puts might increase 200% while near-the-money puts increase only 75%.
Time Decay Interaction: Premium changes compound with time decay effects. Understanding both components helps optimize entry and exit timing.
Step-by-Step Coding Tutorial: Building the Relative Value Scanner
Follow this detailed tutorial to create a custom ThinkScript that displays percentage changes in option prices compared to historical periods.
Step 1: Setting Up the Basic Script Structure
Create a new Custom Quote Formula in ThinkOrSwim and start with the essential input variables:
input lookbackPeriod = 5;
input showPriceRatio = no;
def signal = ((close/close[lookbackPeriod]));
The lookbackPeriod determines how many days back to compare prices. Start with 5 days to compare current prices to last week’s levels. The signal variable calculates the price ratio between current and historical periods.
Step 2: Creating the Percentage Change Calculation
Convert the price ratio into a meaningful percentage change:
def condition = (close - close[lookbackPeriod])/close[lookbackPeriod];
AddLabel(condition, Round(condition*100,0)+"%", if condition >= 0.5
then color.green else if condition <= -0.5
then color.red else color.white);
This calculation shows the exact percentage change from the historical period. Positive values indicate the option has become more expensive, while negative values show it has become cheaper.
Step 3: Adding Conditional Color Coding
Visual indicators help quickly identify significant changes:
def condition = (close - close[lookbackPeriod])/close[lookbackPeriod];
AddLabel(condition, Round(condition*100,0)+"%",
if condition >= 0.5 then color.green
else if condition <= -0.5 then color.red
else color.white);
Green labels indicate options that increased 50% or more (expensive). Red labels show options that decreased 50% or more (cheap). White labels show moderate changes under 50%.
Step 4: Implementing the Option-to-Stock Ratio Feature
Add a second condition to show how expensive the option is relative to the underlying stock price:
# Commented out - Option to Stock Price Ratio
#plot condition = if signal = 0.5 then color.green
else if condition <= -0.5 then color.red
else color.white);
When uncommented, the first condition checks if the option costs less than 4% of the stock price, following the IBD rule for reasonable option pricing.
Step 5: Customizing the Lookback Period
Different trading scenarios require different comparison periods:
1-Day Lookback: Change to input lookbackPeriod = 1; for overnight analysis
2-Day Lookback: Use input lookbackPeriod = 2; for recent volatility changes
Weekly Analysis: Keep input lookbackPeriod = 5; for week-over-week comparison
Step 6: Testing the Scanner on Live Data
Apply the script to an options chain and verify the calculations:
- Open an options chain in ThinkOrSwim
- Add a Custom Quote Formula column
- Paste your script code
- Set the column name to "Pricing" or "RelValue"
- Apply to see percentage changes across all strikes
Step 7: Interpreting the Results
The scanner displays percentage changes that reveal trading opportunities:
Large Positive Changes (+100% to +300%): Options have become expensive, potentially good for selling premium strategies like cash-secured puts or covered calls.
Large Negative Changes (-50% to -75%): Options have become cheap, potentially good for buying strategies like long calls or protective puts.
Moderate Changes (-25% to +25%): Normal price fluctuations that may not warrant specific action.
Step 8: Adding Volume and Liquidity Filters
Enhance the script to filter out illiquid options:
input lookbackPeriod = 5;
input minVolume = 10;
def condition = if volume >= minVolume
then (close - close[lookbackPeriod])/close[lookbackPeriod]
else Double.NaN;
AddLabel(!IsNaN(condition), Round(condition*100,0)+"%",
if condition >= 0.5 then color.green
else if condition <= -0.5 then color.red
else color.white);
This version only shows data for options with adequate trading volume, preventing analysis of illiquid strikes that may show misleading percentage changes.
Step 9: Creating Multiple Timeframe Analysis
Build versions for different analysis periods:
# Version 1: Short-term (1-day)
def condition1d = (close - close[1])/close[1];
# Version 2: Medium-term (5-day)
def condition5d = (close - close[5])/close[5];
# Version 3: Long-term (10-day)
def condition10d = (close - close[10])/close[10];
# Display based on timeframe preference
def condition = condition5d; # Change to 1d or 10d as needed
AddLabel(condition, Round(condition*100,0)+"%",
if condition >= 0.5 then color.green
else if condition <= -0.5 then color.red
else color.white);
Step 10: Advanced Implementation and Optimization
Final version with error handling and optimization:
input lookbackPeriod = 5;
input showPriceRatio = no;
input minVolume = 5;
def validData = !IsNaN(close) and !IsNaN(close[lookbackPeriod]) and close[lookbackPeriod] != 0;
def volumeFilter = volume >= minVolume;
def condition = if validData and volumeFilter
then (close - close[lookbackPeriod])/close[lookbackPeriod]
else Double.NaN;
# Option to Stock Price Ratio (when enabled)
def stockRatio = if showPriceRatio and validData
then close / GetUnderlyingPrice()
else Double.NaN;
AddLabel(!IsNaN(condition), Round(condition*100,0)+"%",
if condition >= 0.75 then color.green
else if condition <= -0.5 then color.red
else color.white);
This final version includes error handling for missing data, volume filtering for liquidity, and optional stock ratio analysis.
Real-World Application Examples
Market Selloff Scenario: During a 3-day market decline, SPY puts might show +150% increases while calls show -60% decreases. The scanner immediately identifies this volatility expansion, suggesting opportunities to sell expensive puts and buy cheap calls for recovery plays.
Earnings Volatility Crush: After earnings announcements, options often experience rapid premium contraction. A stock reporting in-line results might see options decrease 40-70% overnight, creating buying opportunities for future catalysts.
Sector Rotation Events: When investors rotate from growth to value stocks, tech calls might show sustained decreases while financial calls show increases. The scanner helps identify these sector-specific opportunities.
Fed Announcement Impact: Central bank announcements create predictable volatility patterns. Rate decision days often see puts spike 100%+ beforehand, then crash 75%+ afterward as uncertainty resolves.
Integration with Portfolio Management
Position Sizing Guidance: Use percentage changes to determine position sizes. When puts show extreme increases (+200%), consider smaller position sizes due to elevated risk. When options show moderate changes (<50%), standard position sizing applies.
Risk Management Applications: Monitor existing positions using the scanner. If puts you sold continue showing increases, prepare for potential assignment. If calls you bought show sustained decreases, consider reducing exposure.
Profit-Taking Strategies: Use the scanner to time exits. If you sold puts showing +150% increases and they now show only +25% increases, consider buying them back to lock in profits from volatility contraction.
Common Implementation Mistakes and Solutions
Ignoring Liquidity Filters: Analyzing illiquid options creates false signals. Always filter for minimum volume and reasonable bid-ask spreads.
Wrong Lookback Periods: Using 10-day lookbacks for day trading or 1-day lookbacks for swing trading provides irrelevant context. Match your analysis period to your trading timeframe.
Overreacting to Extreme Changes: A put showing +300% might seem like a great selling opportunity, but if the underlying is in free fall, assignment risk may be unacceptable.
Neglecting Fundamental Context: Technical relative value analysis must consider fundamental factors. Earnings dates, Fed meetings, and sector events affect option pricing beyond pure technical patterns.
Advanced Strategy Applications
Volatility Arbitrage: Identify options showing unusual relative value changes compared to similar strikes. Sometimes 30-day calls decrease 40% while 45-day calls decrease only 20%, creating calendar spread opportunities.
Cross-Strike Analysis: Compare percentage changes across different strikes on the same underlying. Often, out-of-the-money options show more extreme changes than at-the-money options, revealing skew opportunities.
Sector Relative Analysis: Apply the scanner across multiple stocks in the same sector. When airline stocks sell off, compare which airline puts increased most—this identifies relative value within the sector.
ETF vs. Individual Stock Analysis: Compare sector ETF option changes to individual stock changes. Sometimes individual stocks show more extreme moves than their ETFs, creating dispersion trading opportunities.
Automation and Scanning Workflows
Daily Scanning Routine: Each morning, run the scanner on your watchlist with a 1-day lookback to identify overnight changes. Focus on options showing >75% changes for immediate opportunities.
Weekly Planning Process: Every weekend, use a 5-day lookback to identify options that changed significantly during the week. This helps plan strategies for the following week.
Catalyst-Driven Analysis: Before known events (earnings, Fed meetings, etc.), run the scanner with appropriate lookbacks to understand pre-event positioning and post-event opportunities.
The Option Chain Relative Value Scanner transforms options analysis from subjective guesswork into objective, data-driven decision making. By understanding which options have become cheap or expensive relative to their recent history, you gain a significant edge in timing entries and exits across all options strategies.
# Option Chain Relative Value Scanner
# TOS Indicators – Custom Quote Formula for Options Analysis
# Tutorial: tosindicators.com/indicators/option-relative-value
input lookbackPeriod = 5;
input showPriceRatio = no;
// ... 31 more lines ...Here are some resources that you may find useful: