OPEN-SOURCE SCRIPT
מעודכן ETF-CFD Ratio Bridge

This indicator helps traders visualize the relationship between ETFs and their corresponding CFD/Spot instruments. It allows you to trade on one chart while monitoring the equivalent price levels of the other instrument without mental math or switching screens.
Features
1. Ratio Table
A customizable table displayed on the chart (default: Top Right) that shows:
- Pair: The ETF and CFD pair being monitored.
- Ratio: The calculated price ratio (ETF / CFD).
- Prices: Real-time prices for both instruments.
2. Companion Price Label
A dynamic label that moves with the current price candle.
- Displays the equivalent price of the paired instrument.
- Example: If you are viewing SPY, the label shows the equivalent US500 price next to the candle.
3. Left Virtual Scale
A custom vertical axis drawn on the left side of the chart.
- Shows price levels for the companion instrument corresponding to the current visible chart range.
- Allows you to read "CFD prices" directly on an "ETF chart" (and vice versa) via the Y-axis.
4. Historical Levels lines
Visualizes recent market structure converted to the companion price.
- HH(x): Highest High of the last X bars (default: 20).
- LL(x): Lowest Low of the last X bars.
- Dashed lines extend to the right with labels showing the converted price at those key levels.
5. Closed Market Handling
Ensures the indicator remains useful even when the ETF market is closed (e.g., after hours) while the Futures/CFD market is open.
- Automatic Detection: The script detects if the ETF market is closed based on the timestamp.
- Fixed Ratio: Automatically switches to a user-defined "Fixed Ratio" when the ETF is closed.
- Continuous Updates: Prevents values from freezing, calculating a synthetic "Shadow Price" for the closed asset so you can continue to see projected levels based on the live CFD market.
Technical Explanation (The Math)
The indicator functions by calculating a dynamic ratio between the two instruments and using it to convert price levels.
Formulas
1. Calculate Ratio:
Ratio = Price(ETF) / Price(CFD)
2. Conversion:
- ETF Chart → CFD Price:
Equivalent CFD Price = Current ETF Price / Ratio
- CFD Chart → ETF Price:
Equivalent ETF Price = Current CFD Price × Ratio
Example (SPY vs US500)
- Scenario: You are trading on the SPY chart.
- Current Prices:
- SPY (ETF) = $500
- US500 (CFD) = $5000
- Step 1: Calculate Ratio
- 500 / 5000 = 0.10
- Step 2: Calculate Equivalent Price
- If SPY moves to $505, what is the US500 equivalent?
- 505 / 0.10 = 5050
- The indicator will display "US500: 5050" on the label and scale.
Supported Pairs
SPY (AMEX) = US500
GLD (AMEX) = XAUUSD
SLV (AMEX) = XAGUSD
IWM (AMEX) = US2000
QQQ (NASDAQ) = NAS100
IBIT (NASDAQ) = BTCUSD
Settings
- Symbols: Customize the ticker symbols for each pair if your broker uses different names.
- Fixed Ratio (Closed): Manually adjust the fallback ratio used when the ETF market is closed (default values provided).
- Visuals:
- Toggle Table, Labels, Scale, and Historical Lines on/off.
- Customize colors, text sizes, and positions.
- Right Offset (Bars from Current): Adjusts how far back (from the current live bar) the Left Virtual Scale is drawn. Increasing this moves the scale further to the left.
- Historical Levels:
- Lookback Length: Number of bars to check for High/Low calculations (Default: 20).
הערות שחרור
This indicator helps traders visualize the relationship between ETFs and their corresponding CFD/Spot instruments. It allows you to trade on one chart while monitoring the equivalent price levels of the other instrument without mental math or switching screens.
Features
1. Ratio Table
A customizable table displayed on the chart (default: Top Right) that shows:
- Pair: The ETF and CFD pair being monitored.
- Ratio: The calculated price ratio (ETF / CFD).
- Prices: Real-time prices for both instruments.
- Status: Shows Open or Closed. Highlighted in Orange (default) when using Fixed Ratio.
2. Companion Price Label
A dynamic label that moves with the current price candle.
- Displays the equivalent price of the paired instrument.
- Visual Change: Background turns Orange (default) when Market is Closed to indicate Fixed Ratio usage.
- Example: If you are viewing SPY, the label shows the equivalent US500 price next to the candle.
3. Left Virtual Scale
A custom vertical axis drawn on the left side of the chart.
- Shows price levels for the companion instrument corresponding to the current visible chart range.
- Allows you to read "CFD prices" directly on an "ETF chart" (and vice versa) via the Y-axis.
4. Historical Levels lines
Visualizes recent market structure converted to the companion price.
- HH(x): Highest High of the last X bars (default: 20).
- LL(x): Lowest Low of the last X bars.
- Dashed lines extend to the right with labels showing the converted price at those key levels.
5. Closed Market Handling
Ensures the indicator remains useful even when the ETF market is closed (e.g., after hours) while the Futures/CFD market is open.
- Automatic Detection: The script detects if the ETF market is closed based on the timestamp.
- Fixed Ratio: Automatically switches to a user-defined "Fixed Ratio" when the ETF is closed.
- Visual Cues: Table and Label change color to indicate "Closed" status so you know the Fixed Ratio is active.
- Continuous Updates: Prevents values from freezing, calculating a synthetic "Shadow Price" for the closed asset so you can continue to see projected levels based on the live CFD market.
Technical Explanation (The Math)
The indicator functions by calculating a dynamic ratio between the two instruments and using it to convert price levels.
Formulas
1. Calculate Ratio:
Ratio = Price(ETF) / Price(CFD)
2. Conversion:
- ETF Chart → CFD Price:
Equivalent CFD Price = Current ETF Price / Ratio
- CFD Chart → ETF Price:
Equivalent ETF Price = Current CFD Price × Ratio
Example (SPY vs US500)
- Scenario: You are trading on the SPY chart.
- Current Prices:
- SPY (ETF) = $500
- US500 (CFD) = $5000
- Step 1: Calculate Ratio
- 500 / 5000 = 0.10
- Step 2: Calculate Equivalent Price
- If SPY moves to $505, what is the US500 equivalent?
- 505 / 0.10 = 5050
- The indicator will display "US500: 5050" on the label and scale.
Supported Pairs
SPY (AMEX) = US500
GLD (AMEX) = XAUUSD
SLV (AMEX) = XAGUSD
IWM (AMEX) = US2000
QQQ (NASDAQ) = NAS100
IBIT (NASDAQ) = BTCUSD
Settings
- Symbols: Customize the ticker symbols for each pair if your broker uses different names.
- Fixed Ratio (Closed): Manually adjust the fallback ratio used when the ETF market is closed (default values provided).
- Visuals:
- Toggle Table, Labels, Scale, and Historical Lines on/off.
- Customize colors, text sizes, and positions.
- Closed Colors: Set specific colors for the Table status and Companion Label for when the market is closed.
- Right Offset (Bars from Current): Adjusts how far back (from the current live bar) the Left Virtual Scale is drawn. Increasing this moves the scale further to the left.
- Historical Levels:
- Lookback Length: Number of bars to check for High/Low calculations (Default: 20).
הערות שחרור
Bug Fix:Improved Market Status Detection Fixed an issue where minor data lags caused the indicator to incorrectly trigger 'Market Closed' (Fixed Ratio) mode while the live market was still open. Improved the detection logic by adding a 1-bar tolerance threshold, ensuring a more stable and accurate 'Open/Closed' status synchronization.הערות שחרור
Update: Pre-Market & Post-Market Session SupportThis update introduces full pre-market and post-market session awareness to the ETF-CFD Ratio Bridge indicator.
What's New:
Live Extended Session Prices The indicator now fetches extended session prices for all ETF pairs using TradingView's ticker.modify(session=session.extended). During pre-market (04:00–09:30 ET) and post-market (16:00–20:00 ET), the ratio and displayed prices are calculated from the live extended ETF price — not the stale regular-session close.
Four-State Session Status The Status column in the Ratio Table now shows four distinct states:
- Open — Regular session, live ratio
- Pre-Mkt — Pre-market, live extended price
- Post-Mkt — Post-market, live extended price
- Closed — All sessions closed, fixed fallback ratio
Session detection is based on real-time wall-clock (timenow) in the America/New_York timezone, so it works correctly on any chart — including ETF charts where no new candles form during off-hours.
Companion Label Positioning On ETF charts with Extended Trading Hours enabled, the companion label now anchors to the extended session price level during Pre/Post market — not the stale regular-session close price.
Contextual Table Warnings Two new warning rows appear at the bottom of the Ratio Table when specific conditions are detected:
When viewing a Daily or higher timeframe (Pre/Post detection unavailable)
When an ETF chart has "Extended Trading Hours" disabled in chart settings — with a direct instruction on how to enable it
Required Setup for ETF Charts To get live pre-market/post-market prices on the ETF chart side, enable Extended Trading Hours in the chart settings: Click the Chart Settings → Session → Extended Trading Hours
CFD charts (XAUUSD, US500, etc.) always work without additional settings.
הערות שחרור
Table Position Control — The Ratio Table can now be placed in any of 9 positions on the chart (Top/Middle/Bottom × Left/Center/Right) via the indicator settings, with directional emoji indicators for quick visual reference. A new Hide option also allows removing the table without disabling the indicator entirely.הערות שחרור
Bugfix: "Extended Trading Hours" warning was silently broken on ETF charts due to TradingView classifying ETFs as type "fund" instead of "stock". Now fixed.הערות שחרור
Pair-Aware Visibility : The indicator is now completely invisible on unsupported chart symbols. All visual elements (Ratio Table, Companion Label, Left Virtual Scale, Historical HH/LL Levels) are suppressed when the current chart does not match any of the 6 configured ETF/CFD pairs. No UI clutter on unrelated charts.הערות שחרור
Chart update fixed.סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.