OPEN-SOURCE SCRIPT
Coinbase Premium(/binance)

Script Overview
This indicator is designed to measure the price gap (premium) between Coinbase (BTC/USD) and Binance (BTC/USDT). Since Coinbase is often viewed as a proxy for institutional demand in the US, this "premium" helps traders identify whether buying pressure is coming from US-based institutions or global retail markets.
Key Components & Logic
1. Data Integration (Multi-Exchange)
The script uses the request.security() function, which is the standard in Pine Script v5 for fetching data from different symbols or exchanges:
Binance BTCUSDT: Represents the global retail market price.
Coinbase BTCUSD: Represents the US institutional market price.
Bitfinex USTUSD: Used as a "Stablecoin Peg" adjustment to ensure the comparison between USD and USDT is mathematically accurate.
2. Calculation Logic
Price Normalization: It multiplies the Binance BTC price by the USDT/USD exchange rate (binance_btc * usdt_peg). This ensures we are comparing "apples to apples" (USD vs. USD).
Premium Calculation: * USD Difference: Simply subtracts the adjusted Binance price from the Coinbase price.
Percentage (%) Premium: Calculates the percentage gap. Following your original code's logic, it uses the 2-bar delay ([2]) to smooth out minor data lag or specific historical points.
3. Visual Elements (UI)
The script is optimized for Dark Mode users with a "White" theme:
Histogram (Percent): Displays the percentage premium. A value above 0 indicates Coinbase is more expensive than Binance (Bullish signal for US demand).
Columns (USD): Shows the raw dollar difference with slight transparency (60%) to keep the chart clean.
Zero Line: A solid white line at the 0 level to clearly distinguish between a "Premium" (positive) and a "Discount" (negative).
This indicator is designed to measure the price gap (premium) between Coinbase (BTC/USD) and Binance (BTC/USDT). Since Coinbase is often viewed as a proxy for institutional demand in the US, this "premium" helps traders identify whether buying pressure is coming from US-based institutions or global retail markets.
Key Components & Logic
1. Data Integration (Multi-Exchange)
The script uses the request.security() function, which is the standard in Pine Script v5 for fetching data from different symbols or exchanges:
Binance BTCUSDT: Represents the global retail market price.
Coinbase BTCUSD: Represents the US institutional market price.
Bitfinex USTUSD: Used as a "Stablecoin Peg" adjustment to ensure the comparison between USD and USDT is mathematically accurate.
2. Calculation Logic
Price Normalization: It multiplies the Binance BTC price by the USDT/USD exchange rate (binance_btc * usdt_peg). This ensures we are comparing "apples to apples" (USD vs. USD).
Premium Calculation: * USD Difference: Simply subtracts the adjusted Binance price from the Coinbase price.
Percentage (%) Premium: Calculates the percentage gap. Following your original code's logic, it uses the 2-bar delay ([2]) to smooth out minor data lag or specific historical points.
3. Visual Elements (UI)
The script is optimized for Dark Mode users with a "White" theme:
Histogram (Percent): Displays the percentage premium. A value above 0 indicates Coinbase is more expensive than Binance (Bullish signal for US demand).
Columns (USD): Shows the raw dollar difference with slight transparency (60%) to keep the chart clean.
Zero Line: A solid white line at the 0 level to clearly distinguish between a "Premium" (positive) and a "Discount" (negative).
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.