OPEN-SOURCE SCRIPT

Codi's Perp-Spot Basis

# Perp-Spot Basis Indicator

This indicator calculates the percentage basis between perpetual futures and spot prices for crypto assets. It is inspired by the original concept from **Krugermacro**, with the added improvement of **automatic detection of the asset pairs** based on the current chart symbol. This enhancement makes it faster and easier to apply across different assets without manual configuration.

## How It Works
The indicator compares the perpetual futures price (e.g., `BTCUSDT.P`) to the spot price (e.g., `BTCUSDT`) on Binance. The difference is expressed as a percentage: (Perp - Spot) / Spot * 100


The results are displayed in a color-coded graph:
- **Blue (Positive Basis):** Perpetual futures are trading at a premium, indicating **bullish sentiment** among derivatives traders.
- **Red (Negative Basis):** Perpetual futures are trading at a discount, indicating **bearish sentiment** among derivatives traders.

This percentage basis is a core component in understanding funding rates and derivatives market dynamics. It serves as a faster proxy for funding rates, which typically lag behind real-time price movements.

---

## How to Use It
### General Concept
- **Red (Negative Basis):** Ideal to execute **longs** when derivatives traders are overly bearish.
- **Blue (Positive Basis):** Ideal to execute **shorts** when derivatives traders are overly bullish.

### Pullback Sniping
1. During an **uptrend**:
- If the basis turns **red** temporarily, it can signal an opportunity to **buy the dip**.
2. During a **downtrend**:
- If the basis turns **blue** temporarily, it can signal an opportunity to **sell the rip**.
3. Wait for the basis to **pop back** (higher in uptrend, lower in downtrend) to time entries more effectively—this often coincides with **stop runs** or **liquidations**.

### Intraday Execution
- **When price is falling**:
- If the basis is **red**, the move is derivatives-led (**normal**).
- If the basis is **blue**, spot traders are leading, and perps are offside—wait for **price dumps** before longing.
- **When price is rising**:
- If the basis is **blue**, the move is derivatives-led (**normal**).
- If the basis is **red**, spot traders are leading, and perps are offside—wait for **price pops** before shorting.

### Larger Time Frames
- **Consistently Blue Basis:** Indicates a **bull market** as derivatives traders are bullish over the long term.
- **Consistently Red Basis:** Indicates a **bear market** as derivatives traders are bearish over the long term.

---

## Improvements Over the Original
This version of the Perp-Spot Basis indicator **automatically detects the Binance perpetual futures and spot pairs** based on the current chart symbol. For example:
- If you are viewing `ETHUSDT`, it automatically references `ETHUSDT.P` for the perpetual futures pair and `ETHUSDT` for the spot pair in BINANCE.
sentimentstatisticsTrend Analysis

สคริปต์โอเพนซอร์ซ

ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถเข้าใจและตรวจสอบได้ ต้องขอบคุณผู้เขียน! ที่ให้คุณใช้ได้ฟรี แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?

คำจำกัดสิทธิ์ความรับผิดชอบ