OPEN-SOURCE SCRIPT
XAU Macro Regime + Mispricing Oscillator

This indicator is designed to measure the true macro environment behind gold (XAUUSD) and identify when price is aligned with macro flows or mispriced relative to them.
It combines a macro composite index, a mispricing spread oscillator, and automatic divergence detection into one tool.
1. Macro Composite Index (Regime Filter)
The top layer of the indicator constructs a macro regime score derived from:
A basket of gold FX pairs (XAUJPY, XAUAUD, XAUCHF, XAUNZD, XAUSGD)
The inverted DXY (to represent USD pressure on gold)
US30 (to capture global risk appetite and macro sentiment)
Each component is normalized and weighted, then combined into a composite macro index.
A smoothed baseline (SMA) is subtracted from this composite to form the Regime Line.
Interpretation
Regime > 0 (Green background):
Macro environment is supportive for gold.
XAUUSD is more likely to rise, consolidate, or mean revert upward.
Regime < 0 (Red background):
Macro environment is hostile for gold.
XAUUSD is more likely to fall, struggle, or mean revert downward.
This creates a macro trend filter that tells you when it is safer to prefer longs, shorts, or stay out.
2. Mispricing Spread Oscillator (Spread MACD)
The second layer measures the difference between XAUUSD and the macro composite index:
Spread = (Macro Composite) – (Normalized XAUUSD)
This spread is then smoothed into a signal line, and a histogram is plotted from their difference (MACD-style).
Interpretation
Spread > 0:
Gold is undervalued relative to macro conditions.
Macro strength > price strength.
Spread < 0:
Gold is overvalued relative to macro conditions.
Price strength > macro strength.
Spread crossing above signal:
Macro momentum turning bullish relative to price.
Spread crossing below signal:
Macro momentum turning bearish relative to price.
Green histogram: acceleration upward
Red histogram: acceleration downward
This oscillator captures mispricing, momentum shifts, and macro-pressure reversals.
3. Automatic Divergence Detection
The indicator automatically detects:
-Bullish Divergence-
XAUUSD makes a lower low
Spread makes a higher low
→ Price is weaker than macro reality → potential bullish reversal or mispricing reversion.
-Bearish Divergence-
XAUUSD makes a higher high
Spread makes a lower high
→ Price is stronger than macro reality → potential bearish reversal or exhaustion.
Labels (“Bull div” / “Bear div”) appear directly on the oscillator for clarity.
4. What The Indicator Seeks To Do
This indicator aims to answer the question:
“Is gold moving with the true macro pressure behind it, or diverging from it?”
Most gold indicators only watch XAUUSD price.
This one watches:
-gold cross-currency flows
-USD strength
-global risk sentiment
-gold’s relative position vs macro
-mispricing momentum
-divergence between price and macro reality
This creates a unique tool that:
-Detects when gold is overextended
-Detects when gold is undervalued
-Reveals hidden macro strength or weakness
-Highlights turning points and exhaustion
-Shows when a pullback is likely to end
-Shows when a rally is likely to fail
-Gives regime-aware trade direction (long vs short bias)
-Adds divergence labels for precision entries
It combines a macro composite index, a mispricing spread oscillator, and automatic divergence detection into one tool.
1. Macro Composite Index (Regime Filter)
The top layer of the indicator constructs a macro regime score derived from:
A basket of gold FX pairs (XAUJPY, XAUAUD, XAUCHF, XAUNZD, XAUSGD)
The inverted DXY (to represent USD pressure on gold)
US30 (to capture global risk appetite and macro sentiment)
Each component is normalized and weighted, then combined into a composite macro index.
A smoothed baseline (SMA) is subtracted from this composite to form the Regime Line.
Interpretation
Regime > 0 (Green background):
Macro environment is supportive for gold.
XAUUSD is more likely to rise, consolidate, or mean revert upward.
Regime < 0 (Red background):
Macro environment is hostile for gold.
XAUUSD is more likely to fall, struggle, or mean revert downward.
This creates a macro trend filter that tells you when it is safer to prefer longs, shorts, or stay out.
2. Mispricing Spread Oscillator (Spread MACD)
The second layer measures the difference between XAUUSD and the macro composite index:
Spread = (Macro Composite) – (Normalized XAUUSD)
This spread is then smoothed into a signal line, and a histogram is plotted from their difference (MACD-style).
Interpretation
Spread > 0:
Gold is undervalued relative to macro conditions.
Macro strength > price strength.
Spread < 0:
Gold is overvalued relative to macro conditions.
Price strength > macro strength.
Spread crossing above signal:
Macro momentum turning bullish relative to price.
Spread crossing below signal:
Macro momentum turning bearish relative to price.
Green histogram: acceleration upward
Red histogram: acceleration downward
This oscillator captures mispricing, momentum shifts, and macro-pressure reversals.
3. Automatic Divergence Detection
The indicator automatically detects:
-Bullish Divergence-
XAUUSD makes a lower low
Spread makes a higher low
→ Price is weaker than macro reality → potential bullish reversal or mispricing reversion.
-Bearish Divergence-
XAUUSD makes a higher high
Spread makes a lower high
→ Price is stronger than macro reality → potential bearish reversal or exhaustion.
Labels (“Bull div” / “Bear div”) appear directly on the oscillator for clarity.
4. What The Indicator Seeks To Do
This indicator aims to answer the question:
“Is gold moving with the true macro pressure behind it, or diverging from it?”
Most gold indicators only watch XAUUSD price.
This one watches:
-gold cross-currency flows
-USD strength
-global risk sentiment
-gold’s relative position vs macro
-mispricing momentum
-divergence between price and macro reality
This creates a unique tool that:
-Detects when gold is overextended
-Detects when gold is undervalued
-Reveals hidden macro strength or weakness
-Highlights turning points and exhaustion
-Shows when a pullback is likely to end
-Shows when a rally is likely to fail
-Gives regime-aware trade direction (long vs short bias)
-Adds divergence labels for precision entries
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.