Skip to main content Relative Performance ThinkOrSwim - Stock Vs Benchmark Comparison Skip to main content Skip to content
Master the TTM Squeeze with our comprehensive 19-module course Start Learning →
TOS Indicators
  • Tools

    Categories

    • Indicators
    • Backtesters
    • Scans
    • Dashboards
    • thinkScript
    • Member Resources
    Browse Full Library

    Featured Tutorials

    Heiken Ashi Trend Indicator
    Heiken Ashi Trend Indicator
    Indicators

    Download our Custom Heiken Ashi indicator for ThinkOrSwim. Full ThinkScript code, formula...

    Learn more →
    Commodities Tracker
    Commodities Tracker
    Indicators

    For acceleration signals: trend-following strategies and buying pullbacks. For deceleration signals: short...

    Learn more →
    Build an Election Backtester in 10 Minutes
    Build an Election Backtester in 10 Minutes
    Backtesters

    Learn how to create a Post-Election Backtester in ThinkOrSwim to analyze market...

    Learn more →

    Popular Posts

    Unusual Volume
    Unusual Volume
    Scans

    Build 4 scans to easily find stocks with greater than...

    Learn more →
    Upcoming Earnings with High Short Interest
    Upcoming Earnings with High Short Interest
    Scans

    Build a scan to find stocks that are likely to...

    Learn more →
    Unusual Volume Pro Scans
    Unusual Volume Pro Scans
    Scans

    4 additional scans to find unusual volume overlapping with key...

    Learn more →
  • Courses
    Squeeze Course
    Squeeze Course
    19 Modules

    Scan, backtest, and trade the TTM Squeeze setup with precision.

    Unlock Course →
    Earnings Course
    Earnings Course
    3 Modules

    Master earnings plays with free indicators and proven strategies for ThinkOrSwim.

    Unlock Course →
    V-Shaped Reversals
    V-Shaped Reversals
    7 Modules

    Identify and trade powerful V-shaped reversal patterns with confidence and precision.

    Unlock Course →
    Fibonacci Trading
    Fibonacci Trading
    4 Modules

    Learn to trade Fibonacci retracements and extensions in ThinkOrSwim effectively.

    Unlock Course →
  • Products
    Futures Volatility Box Premium
    Futures Volatility Box

    Volatility models for 10 major futures markets, including micros & SPX.

    Explore Futures VB →
    Stock Volatility Box Premium
    Stock Volatility Box

    Dynamic support & resistance for 595+ stocks/ETFs, with a live scanner.

    Explore Stock VB →
    Opening Range Breakouts Premium
    Opening Range Breakouts

    Powerful live scanner & backtester for ORB strategies on 595+ stocks.

    Explore ORB Setups →
My Account
Back to Tutorials
Beginner 23 minutes ThinkOrSwim

Relative Performance

Build a flexible relative performance indicator for ThinkOrSwim that compares stocks against any benchmark using bars or specific dates for instant outperformance analysis.

Download Indicator
How to install in ThinkOrSwim →
Table of Contents
  • Relative Performance Analysis for Better Stock Selection
  • Smart Labeling System and Practical Applications

Find Outperformers vs Any Benchmark

Is Apple outperforming the NASDAQ? How does Tesla compare to the S&P 500? Is Microsoft beating its sector over the past 30 days?

Stop guessing and start measuring with this simple but powerful comparison tool:

  • Compare any stock vs any benchmark (indexes, sectors, individual stocks)
  • Choose between lookback bars (30 days) or specific date comparison
  • Instant visual feedback: green for outperform, yellow for underperform
  • Toggle between simple labels or detailed percentage breakdowns

Build it from scratch and understand exactly how relative performance analysis works.

Relative Performance Analysis for Better Stock Selection

Absolute returns tell only half the story. A stock up 15% sounds great until you discover the sector is up 25%. That 15% “winner” is actually underperforming by 10 percentage points.

Relative performance analysis reveals the complete picture by comparing individual stock returns against benchmarks like the S&P 500, sector ETFs, or peer stocks. This identifies true outperformers and helps avoid stocks that look good in isolation but are actually lagging their comparisons.

Professional portfolio managers use relative performance as a core selection criterion. Individual investors often skip this step, leading to suboptimal picks that underperform relevant benchmarks.

The Relative Performance indicator solves this with flexible comparison capabilities and instant visual feedback. No mental math required – just load any stock and immediately see if it’s winning or losing versus your chosen benchmark.

Start with the input configuration that gives users control:

input benchmarkType = {default bars, date};
input lookbackPeriod = 30;
input date = 20220217;
input benchmark = "SPY";
input detailedLabels = yes;

This creates a flexible system where users can compare performance either over a set number of lookback bars (like the past 30 trading days) or from a specific date. The benchmark can be any symbol – SPY for market comparison, QQQ for tech stocks, XLF for financials, or even individual stocks for peer analysis.

The core logic uses a switch statement to handle both comparison methods:

def benchmarkClose = close(symbol=benchmark);
def benchmarkPrevClose;
def currPrevClose;

switch(benchmarkType){
case bars:
    benchmarkPrevClose = close(symbol=benchmark)[lookbackPeriod];
    currPrevClose = close[lookbackPeriod];
case date:
    benchmarkPrevClose = if getYYYYMMDD() == date then close(symbol=benchmark) else benchmarkPrevClose[1];
    currPrevClose = if getYYYYMMDD() == date then close else currPrevClose[1];
}

For the bars method, it simply looks back the specified number of periods. For the date method, it finds the exact date specified and captures both the current stock and benchmark closing prices from that day, then carries those values forward through all subsequent bars.

Performance calculation uses the standard percentage change formula:

def benchmarkPerformance = (benchmarkClose - benchmarkPrevClose)/benchmarkPrevClose;
def currPerformance = (close - currPrevClose)/currPrevClose;

This calculates the percentage return for both the current stock and the benchmark over the same time period, making them directly comparable regardless of their absolute price levels.

Smart Labeling System and Practical Applications

The indicator provides two label options for different use cases:

# Simple label for quick assessment
AddLabel(yes, if currPerformance > benchmarkPerformance then "Outperform" else "Underperform", 
         if currPerformance > benchmarkPerformance then color.green else color.yellow);

# Detailed label with exact percentages         
AddLabel(detailedLabels, "Curr: " + AsPercent(currPerformance) + " | " + benchmark + ": " + AsPercent(benchmarkPerformance), 
         if currPerformance > benchmarkPerformance then color.green else color.yellow);

The simple label shows just “Outperform” or “Underperform” with color coding – perfect for quick scanning across multiple charts. The detailed label adds exact percentage returns for both the stock and benchmark, useful when you need specific numbers.

Color coding provides instant visual feedback: green indicates the stock is beating its benchmark, yellow means it’s lagging. This eliminates the mental math of comparing percentage returns.

Real-world applications demonstrate the indicator’s versatility:

Stock vs Market: Load TSLA with SPY as benchmark to see if Tesla is outperforming the broad market. Switch to QQQ benchmark for tech-specific comparison.

Sector Rotation: Compare XLK (technology) vs XLF (financials) to identify which sector has better momentum. Use this for sector ETF rotation strategies.

Peer Analysis: Set Lowe’s chart with Home Depot as benchmark to see which home improvement retailer is performing better over your chosen timeframe.

Asset Class Comparison: Compare GLD (gold) vs BTC-USD to see which alternative asset is outperforming over various time periods.

The flexibility between bars and date comparison serves different analytical needs:

Bars Method: Best for rolling performance comparisons. “How has this stock done vs its benchmark over the past X trading days?” Updates daily as new data comes in.

Date Method: Best for event-based analysis. “How has this stock performed since earnings?” or “What’s the performance since the Fed meeting?” Locked to specific starting points.

Professional traders often use 30-day relative performance for momentum screens, 90-day for intermediate trends, and 252-day (one year) for longer-term relative strength analysis. The indicator accommodates all these timeframes.

Common screening applications:

  • Momentum Screens: Find stocks outperforming SPY over the past 30 days
  • Sector Leaders: Identify which stocks are beating their sector ETFs
  • Relative Strength: Compare similar stocks to find the strongest performer
  • Market Timing: See if defensive stocks are outperforming growth during market stress

The indicator works on any timeframe – daily for swing trading analysis, weekly for longer-term trends, or even intraday for short-term relative momentum plays.

Remember that relative performance can diverge significantly from absolute performance. A stock down 5% might be outperforming if its benchmark is down 10%. Conversely, a stock up 8% might be underperforming if its benchmark is up 15%. This context is crucial for proper stock evaluation.

Combine this with other technical analysis for complete picture. Relative outperformance plus strong technical setup often provides higher-probability trade opportunities than either signal alone.

Relative Performance.ts
#TOS Indicators
#Home of the Volatility Box
#Indicator: Relative Performance
#Code written in 2022
#Full Tutorial: https://www.tosindicators.com/indicators/relative-performance

input benchmarkType = {default bars, date};
input lookbackPeriod = 30;
input date = 20220217;
input benchmark = "SPY";

// ... 23 more lines ...

Unlock This Code

Create a free account to access the full source code and download files.

Create Free Account Login
Bars method compares performance over a rolling window (like past 30 trading days) that updates daily. Date method compares from a fixed starting date, useful for event-based analysis like "performance since earnings" or "since Fed announcement." Choose bars for ongoing analysis, date for specific timeframe comparisons.
Yes, the benchmark input accepts any valid symbol. Use SPY for market comparison, sector ETFs like XLK (tech) or XLF (financials) for sector analysis, or individual stocks for peer comparison. Just type the symbol in the benchmark field and the indicator handles the rest.
Relative performance reveals whether a stock's gains or losses are actually impressive given market conditions. A stock up 5% might be underperforming if the market is up 12%. Conversely, a stock down 2% might be outperforming if the market is down 8%. Context matters for proper evaluation.
Green labels indicate the stock is outperforming its benchmark over the selected timeframe. Yellow labels mean the stock is underperforming. The colors make it instant visual feedback - you can quickly scan multiple charts to identify outperformers without reading numbers.
Day traders might use 5-10 bars for short-term relative momentum. Swing traders often use 20-30 bars to identify intermediate-term outperformers. Position traders may use 60-252 bars (3 months to 1 year) for longer-term relative strength analysis. Adjust the lookbackPeriod to match your trading horizon.
Absolutely. Compare sector ETFs against SPY to see which sectors are leading or lagging. For example, load XLK with SPY benchmark to see if technology is outperforming the broad market. Switch between different sector ETFs to identify rotation opportunities.
Set up multiple charts with the same benchmark and timeframe settings. Use the simple labels option to reduce chart clutter. You can quickly flip through different stock charts and instantly see which are outperforming (green) vs underperforming (yellow) without needing to read specific percentages.
Yes, as long as ThinkOrSwim provides data for both symbols. You can compare BTC-USD against SPY, EUR/USD against DXY, or ES futures against SPY. Just enter the correct symbol format for your chosen market as the benchmark. The percentage calculation works the same regardless of asset class.

Here are some resources that you may find useful:

  • How to import an indicator into ThinkOrSwim (video tutorial)
Featured Tools:
Stock Volatility Box

Stock Volatility Box

Spot reversal zones across 600 stocks & ETFs.

  • Hourly & daily models
  • Powerful Live Scanner
  • Built for day traders
Futures Volatility Box

Futures Volatility Box

Pinpoint reversal zones in 10 major futures markets.

  • 5 models (incl. Scalper)
  • ThinkOrSwim & TradingView
  • SPX traders
ORB Setups

ORB Setups

Find the best Opening Range Breakout setups.

  • Powerful real-time scanner
  • Instant backtests
  • 2+ years data

Get Free Access

Create a free account for downloads and new tutorial alerts.

Create Free Account

More Tutorials Like This

Market Pulse

Market Pulse

Beginner-Friendly • 40 mins
Commodities Tracker

Commodities Tracker

Beginner • 15 minutes
Dividend Yield Pro

Dividend Yield Pro

Intermediate • 28 minutes

Ready to Trade With an Edge?

Join 40,000+ traders using institutional-grade tools for ThinkOrSwim.

Get the Bundle
TOS Indicators

Premium thinkorswim indicators, scans, and trading tools to help you trade smarter.

ThinkOrSwim Tools

  • Indicators
  • Scans
  • Backtesters
  • Dashboards
  • thinkScript
  • Browse All

Courses

  • Squeeze Course
  • Earnings Course
  • V-Shaped Reversals
  • Fibonacci Trading

Products

  • Futures Volatility Box
  • Stock Volatility Box
  • ORB Setups
  • Shop All

Guides

  • TTM Squeeze
  • Automated Trading
  • Volatility Trading
  • Opening Range Breakouts
  • Trade Reports
  • Contact Us

© 2026 TOS Indicators. All rights reserved.

Privacy Policy Terms of Service Disclaimer

The information contained on this website is solely for educational purposes, and does not constitute investment advice. The risk of trading in securities markets can be substantial. You must review and agree to our Terms of Service prior to using this site.

U.S. Government Required Disclaimer - Commodity Futures Trading Commission. Futures and options trading has large potential rewards, but also large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. Don't trade with money you can't afford to lose. This website is neither a solicitation nor an offer to Buy/Sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this website. The past performance of any trading system or methodology is not necessarily indicative of future results.

Individual results may vary, and testimonials are not claimed to represent typical results. All testimonials are by real people, and may not reflect the typical purchaser's experience, and are not intended to represent or guarantee that anyone will achieve the same or similar results.

TOS Indicator's Traders and employees will NEVER manage or offer to manage a customer or individual's options, stocks, currencies, futures, or any financial markets or securities account. If someone claiming to represent or be associated with TOS Indicator solicits you for money or offers to manage your trading account, do not provide any personal information and contact us immediately.

CFTC RULE 4.41 - HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY, SIMULATED TRADING PROGRAMS IN GENERAL ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.