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!
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.