OPEN-SOURCE SCRIPT
Gold Oil Ratio

Gold Oil Ratio: Macro Sentiment & Mean Reversion Overlay
This indicator provides a sophisticated look at the Gold-to-Oil Ratio, one of the oldest and most reliable macro-economic barometers. By tracking the relative value between "Safe Haven" Gold and "Industrial Growth" Oil, traders can gauge global economic sentiment and potential market turning points.
Key Features:
Macro Barometer: Instantly see if the market is in a "Risk-Off" (high ratio) or "Risk-On" (low ratio) phase.
Adaptive Volatility Bands: Uses a custom-built volatility envelope (Mean + Standard Deviation) that adjusts to historical price action, highlighting extreme overbought or oversold conditions in the ratio.
Dynamic Gradient Visualization: The candle colors change dynamically based on where the ratio sits relative to its historical bands—shifting from green (undervalued/low) to red (overvalued/high).
The "2020 Precision Fix": Includes a specialized logic to handle the extreme negative oil price anomaly of April 2020, ensuring your charts remain readable and the bands don't get distorted by the "black swan" spike.
Inversion Toggle: Switch between Gold/Oil and Oil/Gold focus with a single click in the settings.
How to use it:
Mean Reversion: When the ratio touches the Upper Band (Red), Gold is historically expensive compared to Oil—watch for a potential reversal or macro shift.
Risk Sentiment: Crossing above the Mean Line often signals increasing global uncertainty, while staying below suggests industrial expansion and stable growth.
Divergence: Use the gradient candles to spot when the ratio is losing momentum at extreme levels before the price action confirms it.
Note: This script pulls data from COMEX:GC1! and NYMEX:CL1! to ensure the most accurate futures-based ratio calculation.
This indicator provides a sophisticated look at the Gold-to-Oil Ratio, one of the oldest and most reliable macro-economic barometers. By tracking the relative value between "Safe Haven" Gold and "Industrial Growth" Oil, traders can gauge global economic sentiment and potential market turning points.
Key Features:
Macro Barometer: Instantly see if the market is in a "Risk-Off" (high ratio) or "Risk-On" (low ratio) phase.
Adaptive Volatility Bands: Uses a custom-built volatility envelope (Mean + Standard Deviation) that adjusts to historical price action, highlighting extreme overbought or oversold conditions in the ratio.
Dynamic Gradient Visualization: The candle colors change dynamically based on where the ratio sits relative to its historical bands—shifting from green (undervalued/low) to red (overvalued/high).
The "2020 Precision Fix": Includes a specialized logic to handle the extreme negative oil price anomaly of April 2020, ensuring your charts remain readable and the bands don't get distorted by the "black swan" spike.
Inversion Toggle: Switch between Gold/Oil and Oil/Gold focus with a single click in the settings.
How to use it:
Mean Reversion: When the ratio touches the Upper Band (Red), Gold is historically expensive compared to Oil—watch for a potential reversal or macro shift.
Risk Sentiment: Crossing above the Mean Line often signals increasing global uncertainty, while staying below suggests industrial expansion and stable growth.
Divergence: Use the gradient candles to spot when the ratio is losing momentum at extreme levels before the price action confirms it.
Note: This script pulls data from COMEX:GC1! and NYMEX:CL1! to ensure the most accurate futures-based ratio calculation.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.