OPEN-SOURCE SCRIPT
XAUUSD/SPX Slope with Bollinger Bands %B

The XAUUSD/SPX Slope with Bollinger Bands %B Indicator plots the slope of the XAUUSD (Gold) to SPX (S&P 500) ratio (blue line) using linear regression (default 20 bars) to show Gold’s relative performance against stocks. Bollinger Bands %B (length: 20, StdDev: 2.0) is calculated on the chart’s current symbol (e.g., GLD, BTCUSD) and plotted in yellow, indicating the symbol’s price position within its bands (0 to 1 range). The slope’s zero is aligned with the %B middle band (0.5) for easy comparison. A positive slope (above 0.5) suggests Gold outperforming SPX, while %B above 1 indicates overbought conditions and below 0 indicates oversold for the chart’s symbol. Overbought (1), middle (0.5), and oversold (0) lines, with optional background fills (green for overbought, blue for middle, red for oversold, unchecked by default), aid interpretation. Adjust the slope scale factor for visibility.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.