OPEN-SOURCE SCRIPT

Dynamic Spot vs Perp Spread

### **Description for TradingView Publication**

---

**Dynamic Spot vs Perp Spread**
(For USDT-Spot and USDT.P-Perp)
Summary of Usefulness:
This indicator is a valuable tool for traders who want to monitor and capitalize on the relationship between spot and perpetual futures (perp) prices. When the spot price exceeds the perp price, it's often a leading signal that the perp price will follow, creating potential trading opportunities. While this behavior doesn't happen every time, divergences between spot and perp prices can frequently signal significant market movements.

What it Does:
This indicator calculates and displays the price spread (percentage difference) between the spot price and perpetual futures (perp) price of a cryptocurrency asset. It dynamically adjusts to the instrument being viewed, ensuring that spot dominance (spot price higher) is plotted above the zero line and perp dominance (perp price higher) is plotted below the zero line. Additionally, the indicator accounts for symbols with multipliers (e.g., `1000SHIBUSDT.P`) to ensure accurate calculations.

Key features include:
- Automatic symbol detection and adjustment for Spot/Perp pairs.
- Dynamic handling of price multipliers for assets with prefixes like `1000`.
- Visualization of spread with a histogram and optional smoothing using an EMA (Exponential Moving Average).
- Configurable alerts for significant spread changes and spread flips.
- No repainting: the indicator uses the `barmerge.lookahead_off` setting to ensure stable, non-repainting values.

---

### **How to Use**

1. **Add the Indicator:**
- Search for "Dynamic Spot vs Perp Spread" in the TradingView Indicators library and add it to your chart.

2. **Understand the Visualization:**
- A positive spread (green histogram) indicates that the spot price is higher than the perp price (spot dominance).
- A negative spread (red histogram) indicates that the perp price is higher than the spot price (perp dominance).

3. **Customize Settings:**
- **EMA Length:** Use the input field to smooth the spread data over a chosen number of periods.
- **Alert Threshold:** Set a threshold to receive alerts when the spread exceeds a specific percentage.

4. **Receive Alerts:**
- Enable alerts for spread flips (when dominance shifts between spot and perp) or when the spread exceeds the defined threshold.

5. **Use Case Examples:**
- **Spot vs. Perp Arbitrage:** Traders can monitor significant deviations between spot and perp prices to identify potential arbitrage opportunities.
- **Market Sentiment Analysis:** Persistent spot dominance may indicate stronger buying interest in the spot market, while perp dominance may suggest futures market speculation.

---

### **Repainting Behavior**

This indicator **does not repaint** because it uses `barmerge.lookahead_off` for all calculations, ensuring that data from the comparison symbol (spot or perp) is locked to the currently completed candle. This means the values plotted and alerts triggered are reliable and do not change retrospectively.

Repainting occurs when an indicator uses future-looking or incomplete data for calculations. By design, this indicator avoids such practices, making it suitable for live trading and analysis.

---
multitimeframesentimentTrend Analysis

Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Хотите использовать этот скрипт на графике?


Мои профили:

Отказ от ответственности