OPEN-SOURCE SCRIPT
Capital Rotational Event (CRE)

Capital Rotational Event (CRE) – Inter-Asset Rotation Detector
This open-source, non-overlay indicator identifies potential **capital rotation events** between two user-selected assets by combining:
1. Relative Strength (RS) — measures how one asset is performing compared to another
2. Momentum of that RS line — detects acceleration or deceleration in the relative outperformance
The goal is to highlight periods when capital appears to be rotating **into** or **out of** the second asset (e.g., from stocks → gold, equities → bonds, risk-on → risk-off, etc.).
Core Concept
In macro-driven or rotational markets, money often flows between asset classes or correlated instruments. When one asset starts consistently outperforming another (and the outperformance is accelerating), it can signal a shift in investor preference, risk appetite, or sector leadership.
This script uses a smoothed relative strength ratio + its momentum to create a simple, objective filter for these rotational shifts.
How It Works
1. Fetches closing prices of two symbols:
- Asset #1 (lead/default: SPY) – the reference/benchmark
- Asset #2 (rotate into/default: GLD) – the asset being evaluated
2. Calculates Relative Strength line:
RS = SMA( (close₂ / close₁) × 100 , length )
→ Values > 50 = Asset 2 outperforming Asset 1
→ Values < 50 = Asset 1 outperforming Asset 2
3. Computes momentum of the RS line:
Mom(RS) = SMA( change(RS) , momentum length )
4. Generates CRE signal:
- Bullish CRE (+1): RS > its own SMA **and** RS momentum > 0
→ Asset 2 is outperforming **and** the outperformance is accelerating
- Bearish CRE (-1): RS < its own SMA **and** RS momentum < 0
→ Asset 2 is underperforming **and** the underperformance is accelerating
- Neutral (0): otherwise
Visual Output
- Blue line: Relative Strength (Asset 2 vs Asset 1, scaled around 100)
- Gray hline at 50: Neutral level
- Orange line: Momentum of RS (oscillates around zero)
- Green upward triangles (bottom): Bullish Capital Rotation Event
- Red downward triangles (top): Bearish Capital Rotation Event
- Background coloring: light green (bullish rotation), light red (bearish rotation)
Why this combination?
- Raw RS ratio shows **who is stronger**, but can be slow-moving or noisy.
- Adding momentum of RS filters for **dynamic shifts** — catching the moments when rotation is actually gaining steam rather than just drifting.
- The dual-condition logic (RS above/below average + positive/negative momentum) reduces false signals and focuses on meaningful acceleration in relative performance.
Typical Use Cases
- Macro rotation: SPY vs GLD (risk-on vs safe-haven), SPY vs TLT (equities vs bonds), QQQ vs XLF (tech vs financials)
- Sector rotation: XLE vs XLU (energy vs utilities), XLK vs XLV (tech vs healthcare)
- Currency pairs or crypto: BTCUSD vs ETHUSD, USD vs gold, etc.
- Timeframes: Daily/weekly for macro swings, 4h/1h for shorter tactical rotations
How to Use
1. Apply to any chart (timeframe of your choice).
2. Set Asset #1 (benchmark) and Asset #2 (target) via inputs.
3. Adjust RS Length (default 14) and Momentum Length (default 9) to match your timeframe.
4. Watch for triangle signals + background color change as early clues of rotation.
5. Combine with price action on the actual assets — CRE is a relative bias tool, not a direct buy/sell signal.
6. Best in trending or regime-shifting markets; less useful in strong correlated moves.
Inputs
- Asset #1 (lead): default SPY
- Asset #2 (rotate into): default GLD
- RS Length: smoothing period for relative strength (default 14)
- Momentum Length: smoothing period for RS change (default 9)
Publishing Notes
- Publish with a clean chart (only this indicator active).
- Recommended example setup: daily or 4h chart with SPY + GLD (or your preferred pair).
- No other overlays/indicators needed for basic interpretation.
This script is fully open-source for learning and transparency. It is an educational tool — not a guaranteed predictor of market direction. Trading and investing involve significant risk of loss.
Feedback welcome — happy rotating!
This open-source, non-overlay indicator identifies potential **capital rotation events** between two user-selected assets by combining:
1. Relative Strength (RS) — measures how one asset is performing compared to another
2. Momentum of that RS line — detects acceleration or deceleration in the relative outperformance
The goal is to highlight periods when capital appears to be rotating **into** or **out of** the second asset (e.g., from stocks → gold, equities → bonds, risk-on → risk-off, etc.).
Core Concept
In macro-driven or rotational markets, money often flows between asset classes or correlated instruments. When one asset starts consistently outperforming another (and the outperformance is accelerating), it can signal a shift in investor preference, risk appetite, or sector leadership.
This script uses a smoothed relative strength ratio + its momentum to create a simple, objective filter for these rotational shifts.
How It Works
1. Fetches closing prices of two symbols:
- Asset #1 (lead/default: SPY) – the reference/benchmark
- Asset #2 (rotate into/default: GLD) – the asset being evaluated
2. Calculates Relative Strength line:
RS = SMA( (close₂ / close₁) × 100 , length )
→ Values > 50 = Asset 2 outperforming Asset 1
→ Values < 50 = Asset 1 outperforming Asset 2
3. Computes momentum of the RS line:
Mom(RS) = SMA( change(RS) , momentum length )
4. Generates CRE signal:
- Bullish CRE (+1): RS > its own SMA **and** RS momentum > 0
→ Asset 2 is outperforming **and** the outperformance is accelerating
- Bearish CRE (-1): RS < its own SMA **and** RS momentum < 0
→ Asset 2 is underperforming **and** the underperformance is accelerating
- Neutral (0): otherwise
Visual Output
- Blue line: Relative Strength (Asset 2 vs Asset 1, scaled around 100)
- Gray hline at 50: Neutral level
- Orange line: Momentum of RS (oscillates around zero)
- Green upward triangles (bottom): Bullish Capital Rotation Event
- Red downward triangles (top): Bearish Capital Rotation Event
- Background coloring: light green (bullish rotation), light red (bearish rotation)
Why this combination?
- Raw RS ratio shows **who is stronger**, but can be slow-moving or noisy.
- Adding momentum of RS filters for **dynamic shifts** — catching the moments when rotation is actually gaining steam rather than just drifting.
- The dual-condition logic (RS above/below average + positive/negative momentum) reduces false signals and focuses on meaningful acceleration in relative performance.
Typical Use Cases
- Macro rotation: SPY vs GLD (risk-on vs safe-haven), SPY vs TLT (equities vs bonds), QQQ vs XLF (tech vs financials)
- Sector rotation: XLE vs XLU (energy vs utilities), XLK vs XLV (tech vs healthcare)
- Currency pairs or crypto: BTCUSD vs ETHUSD, USD vs gold, etc.
- Timeframes: Daily/weekly for macro swings, 4h/1h for shorter tactical rotations
How to Use
1. Apply to any chart (timeframe of your choice).
2. Set Asset #1 (benchmark) and Asset #2 (target) via inputs.
3. Adjust RS Length (default 14) and Momentum Length (default 9) to match your timeframe.
4. Watch for triangle signals + background color change as early clues of rotation.
5. Combine with price action on the actual assets — CRE is a relative bias tool, not a direct buy/sell signal.
6. Best in trending or regime-shifting markets; less useful in strong correlated moves.
Inputs
- Asset #1 (lead): default SPY
- Asset #2 (rotate into): default GLD
- RS Length: smoothing period for relative strength (default 14)
- Momentum Length: smoothing period for RS change (default 9)
Publishing Notes
- Publish with a clean chart (only this indicator active).
- Recommended example setup: daily or 4h chart with SPY + GLD (or your preferred pair).
- No other overlays/indicators needed for basic interpretation.
This script is fully open-source for learning and transparency. It is an educational tool — not a guaranteed predictor of market direction. Trading and investing involve significant risk of loss.
Feedback welcome — happy rotating!
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.