OPEN-SOURCE SCRIPT
EURUSD | Yield Curve Flip Strategy (2s10s State Flips)

Strategy Core (Concept)
The strategy trades EURUSD exclusively when the US yield curve regime (2Y/10Y) flips into a new, clearly bullish or bearish regime. The core assumption is that re-pricing in the US yield curve (rather than individual data points) is a robust driver of USD strength or weakness and can act as a structural trigger for trend changes.
⸻
Data Basis
• Uses US 2Y Yield (TVC:US02Y) and US 10Y Yield (TVC:US10Y).
• The 2s10s curve is calculated as:
curveUS = US10Y – US2Y
• Regime assessment is based on the N-day change (default: 5 days), calculated on true rates bars (not intraday noise).
⸻
Regime Detection (Correct Bond Logic)
First, the strategy checks whether the curve has significantly steepened or flattened over the lookback period:
• Steepener if Δ(2s10s) > thrCurve (default: +0.10 percentage points = 10 bp)
• Flattener if Δ(2s10s) < −thrCurve
Next, a leg confirmation determines the specific type of steepener/flattener (default thrLeg = 5 bp):
Bull Steepener
• Curve steepens because yields fall, with the 2Y falling more (risk-off / rate-cut pricing)
Bear Steepener
• Curve steepens because yields rise, with the 10Y rising more (reflation / term-premium move)
Bull Flattener
• Curve flattens because yields fall, with the 10Y falling more (growth shock / long-end rally)
Bear Flattener
• Curve flattens because yields rise, with the 2Y rising more (hawkish repricing / front-end up)
Important: By default, a Bear Steepener is not treated as a bearish signal, unless allowBearSteepForShort is enabled.
⸻
State Machine (Memory + Flip Triggers)
The strategy maintains a persistent state variable curveState:
• +1 = bullish
• −1 = bearish
• 0 = neutral
The state is updated only on a new rates bar (daily rates when tfRates = "D"), avoiding intraday noise.
A trade is generated only on a true regime flip:
• flipToBull: new state turns bullish and the previous state was bearish (or neutral, if allowed)
• flipToBear: new state turns bearish and the previous state was bullish (or neutral, if allowed)
The option enterFromNeutral controls whether the first clear regime emerging from neutral is traded.
The option onlyOnNewRatesBar ensures signals occur only when a new rates bar is printed, providing clean timing.
⸻
Trading Rules (Entry / Exit)
There are no stops, targets, or trailing mechanisms. The strategy is a pure regime-switching / reversal system:
• On flipToBull
• Close short (“S”)
• Open long (“L”)
• On flipToBear
• Close long (“L”)
• Open short (“S”)
Positions are therefore held until the next regime flip.
⸻
Parameter Interpretation
• N: Smoothing / inertia. Smaller = faster but noisier; larger = more stable but later.
• thrCurve: Minimum curve move required to define a regime.
• thrLeg: Minimum move of the confirming leg (2Y or 10Y) to reduce misclassification.
• allowBearSteepForShort: Makes the system more aggressive (more bearish signals), but represents a different macro case.
• enterFromNeutral: Increases trade frequency by trading the first regime impulse.
⸻
What You See on the Chart
• Background shading:
• Green for bullish state
• Red for bearish state
• The curve and Δ-curve are plotted but hidden (display=none), mainly for debugging and analysis.
The strategy trades EURUSD exclusively when the US yield curve regime (2Y/10Y) flips into a new, clearly bullish or bearish regime. The core assumption is that re-pricing in the US yield curve (rather than individual data points) is a robust driver of USD strength or weakness and can act as a structural trigger for trend changes.
⸻
Data Basis
• Uses US 2Y Yield (TVC:US02Y) and US 10Y Yield (TVC:US10Y).
• The 2s10s curve is calculated as:
curveUS = US10Y – US2Y
• Regime assessment is based on the N-day change (default: 5 days), calculated on true rates bars (not intraday noise).
⸻
Regime Detection (Correct Bond Logic)
First, the strategy checks whether the curve has significantly steepened or flattened over the lookback period:
• Steepener if Δ(2s10s) > thrCurve (default: +0.10 percentage points = 10 bp)
• Flattener if Δ(2s10s) < −thrCurve
Next, a leg confirmation determines the specific type of steepener/flattener (default thrLeg = 5 bp):
Bull Steepener
• Curve steepens because yields fall, with the 2Y falling more (risk-off / rate-cut pricing)
Bear Steepener
• Curve steepens because yields rise, with the 10Y rising more (reflation / term-premium move)
Bull Flattener
• Curve flattens because yields fall, with the 10Y falling more (growth shock / long-end rally)
Bear Flattener
• Curve flattens because yields rise, with the 2Y rising more (hawkish repricing / front-end up)
Important: By default, a Bear Steepener is not treated as a bearish signal, unless allowBearSteepForShort is enabled.
⸻
State Machine (Memory + Flip Triggers)
The strategy maintains a persistent state variable curveState:
• +1 = bullish
• −1 = bearish
• 0 = neutral
The state is updated only on a new rates bar (daily rates when tfRates = "D"), avoiding intraday noise.
A trade is generated only on a true regime flip:
• flipToBull: new state turns bullish and the previous state was bearish (or neutral, if allowed)
• flipToBear: new state turns bearish and the previous state was bullish (or neutral, if allowed)
The option enterFromNeutral controls whether the first clear regime emerging from neutral is traded.
The option onlyOnNewRatesBar ensures signals occur only when a new rates bar is printed, providing clean timing.
⸻
Trading Rules (Entry / Exit)
There are no stops, targets, or trailing mechanisms. The strategy is a pure regime-switching / reversal system:
• On flipToBull
• Close short (“S”)
• Open long (“L”)
• On flipToBear
• Close long (“L”)
• Open short (“S”)
Positions are therefore held until the next regime flip.
⸻
Parameter Interpretation
• N: Smoothing / inertia. Smaller = faster but noisier; larger = more stable but later.
• thrCurve: Minimum curve move required to define a regime.
• thrLeg: Minimum move of the confirming leg (2Y or 10Y) to reduce misclassification.
• allowBearSteepForShort: Makes the system more aggressive (more bearish signals), but represents a different macro case.
• enterFromNeutral: Increases trade frequency by trading the first regime impulse.
⸻
What You See on the Chart
• Background shading:
• Green for bullish state
• Red for bearish state
• The curve and Δ-curve are plotted but hidden (display=none), mainly for debugging and analysis.
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.