OPEN-SOURCE SCRIPT

Spot-Futures Spread

67
Spot-Futures Spread Indicator

A comprehensive indicator that automatically calculates and visualizes the percentage spread between spot and perpetual futures prices across multiple exchanges.

Key Features:

  • Automatic Exchange Detection - Automatically detects your current exchange and finds the corresponding spot/futures pair
  • Smart Fallback System - If the counterpart isn't available on your exchange, it automatically searches across 7+ major exchanges (Binance, Bybit, OKX, Gate.io, MEXC, KuCoin, HTX) and uses the first valid match
  • Multi-Exchange Support - Works with 14 exchanges including Binance, Bybit, OKX, MEXC, BitGet, Gate.io, KuCoin, and more
  • Clear Exchange Attribution - Shows exactly which exchanges are providing spot and futures data in the statistics table
  • Configurable Moving Average - Track the average spread with customizable period
  • Standard Deviation Bands - Identify unusual spread conditions with Bollinger-style bands
  • Built-in Alerts - Get notified when spread crosses bands or zero (parity)
  • Statistics Table - Real-time stats showing current spread, MA, std dev, and bands
  • Manual Override Options - Advanced users can manually specify exchanges and symbols


How It Works:

The indicator calculates the spread as: (Futures Price - Spot Price) / Spot Price × 100

  • Positive spread = Futures trading at a premium (contango)
  • Negative spread = Futures trading at a discount (backwardation)
  • Zero = Parity between spot and futures


Use Cases:

  1. Funding Rate Analysis - Correlates with perpetual funding rates
  2. Arbitrage Opportunities - Identify significant spot-futures divergences
  3. Market Sentiment - Premium/discount indicates bullish/bearish positioning
  4. Cross-Exchange Analysis - Compare spreads when spot and futures are on different exchanges


Smart Features:

  • Works whether you're viewing a spot or futures chart
  • Automatically handles exchange-specific perpetual contract naming (.P, PERP, SWAP, etc.)
  • Color-coded visualization (green for premium, red for discount)
  • Customizable colors and display options
  • Background shading based on spread direction


Perfect For:
Crypto traders monitoring funding rates, arbitrage traders, market makers, and anyone interested in spot-futures dynamics across multiple exchanges.

Getting Started:
Simply add the indicator to any spot or perpetual futures chart. It will automatically detect the exchange and find the corresponding pair. The statistics table shows which exchanges are being used for maximum transparency.

Note: The indicator automatically ignores invalid symbols, so you'll never see errors even if a specific pair doesn't exist on a particular exchange.[/I]

Kudos to AlekMel that made the "Spot - Fut Spread v2" indicator that I enhance the Automatic detection feature which was not working in some case.

Exención de responsabilidad

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.