Build a custom ThinkScript that compares current option prices to historical values and displays percentage changes for smarter options trading decisions
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:
Designed for options traders who want objective data about premium expansion and contraction cycles.
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.
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:
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.
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.
Follow this detailed tutorial to create a custom ThinkScript that displays percentage changes in option prices compared to historical periods.
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.
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.
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%.
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.
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
Apply the script to an options chain and verify the calculations:
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.
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.
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);
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.
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.
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.
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.
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.
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;
# Basic relative value calculation
def signal = ((close/close[lookbackPeriod]));
# Option to Stock Price Ratio (uncomment to use)
#plot condition = if signal = 0.5 then color.green
else if condition = minVolume;
def filteredCondition = if volumeFilter
then (close – close[lookbackPeriod])/close[lookbackPeriod]
else Double.NaN;
# Multi-timeframe analysis
def change1Day = if close[1] != 0 then (close – close[1])/close[1] else 0;
def change5Day = if close[5] != 0 then (close – close[5])/close[5] else 0;
def change10Day = if close[10] != 0 then (close – close[10])/close[10] else 0;
# Toggle between different timeframes by changing the condition variable
# condition = change1Day; # 1-day analysis
# condition = change5Day; # 5-day analysis
# condition = change10Day; # 10-day analysisWant the .ts file and the one-click import? Both come with a free account.
Here are some resources that you may find useful:
Join 40,000+ traders using institutional-grade tools for ThinkOrSwim.
Get the Bundle