PROTECTED SOURCE SCRIPT

Ratio Spread (Hybrid)

121
Ratio Spread (Hybrid)

Ratio Spread (Hybrid) plots a daily OHLC “spread candle” built from the price ratio of two instruments:

Spread (Ratio) = A / B
A = Numerator (top leg)
B = Denominator (bottom leg)

It’s designed to be used on a Daily chart. Internally, it scans a lower intraday timeframe to reconstruct a more accurate daily High / Low / Close for the ratio than a simple daily A/B calculation.

What it does
- Builds a synthetic daily candle for the ratio A/B (Open, High, Low, Close).
- Uses intraday data to find the day’s true ratio extremes and last ratio close using only bars where both symbols line up by timestamp.
- Colors the bar green when Close >= Open and red when Close < Open.

How the Hybrid calculation works
1) Runs only on Daily charts
The script performs its intraday syncing/aggregation only when the chart timeframe is Daily.

2) Pulls intraday OHLC for both legs
It requests lower-timeframe OHLC for A and B using the selected Intraday TF.

3) Syncs intraday bars by time
It matches A and B intraday bars using their timestamps and only calculates ratios on matched bars. This helps avoid distortions from missing bars, different liquidity, or slight feed differences.

4) Builds the daily ratio candle from matched intraday bars
For each matched intraday bar it computes:
- Ratio Open = Open(A) / Open(B)
- Ratio Close = Close(A) / Close(B)
- Raw Ratio High = High(A) / High(B)
- Raw Ratio Low = Low(A) / Low(B)

Then it sanitizes each intraday ratio bar so High/Low always contains Open/Close:
- Intraday ratio High = max(ratio open, ratio close, raw ratio high)
- Intraday ratio Low = min(ratio open, ratio close, raw ratio low)

Across the day it aggregates:
- Daily High = highest intraday ratio High
- Daily Low = lowest intraday ratio Low
- Daily Close = ratio close of the last matched intraday bar

Daily Open options (the Hybrid part)
- Force Daily Open ON (recommended)
Daily Open = Official Daily Open(A) / Official Daily Open(B)
Intraday data is still used for High/Low/Close.

- Force Daily Open OFF
Daily Open = ratio open from the first matched intraday bar of the day.

Fail-safe
After aggregation, the script ensures the final daily High/Low includes the chosen Open and the final Close, so the candle range always covers them.

Recommended settings and best practices
- Use on a Daily chart (required for the calculation to run).
- Recommended Intraday TF: 15 minutes. Best balance between accuracy and performance.
- Recommended instruments: use legs from the same exchange/region/session when possible to improve timestamp alignment and reduce gaps.
Examples:
- Two US futures (e.g., CME/CBOT products)
- Two US stocks (both US-listed equities)
- Two instruments on the same exchange with similar trading hours

Notes
- If B is zero or either symbol has missing data, the ratio can be unavailable.
- If the two legs have different sessions/holidays, fewer bars will match, which can affect the computed daily OHLC.

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.