OPEN-SOURCE SCRIPT

Trendshift [CHE] Strategy

221
Trendshift Strategy [CHE] — First-Shift Structural Regime Trading

Profitfactor 2,603

Summary

Trendshift Strategy [CHE] implements a structural regime-shift trading model built around the earliest confirmed change in directional structure. It identifies major swing highs and lows, validates breakouts through optional ATR-based conviction, and reacts only to the first confirmed shift in each direction. After a regime reversal, the strategy constructs a premium and discount band between the breakout candle and the previous opposite swing. This band is used as contextual bias and may optionally inform stop placement and position sizing.
The strategy focuses on clear, interpretable structural events rather than continuous signal generation. By limiting entries to the first valid shift, it reduces false recycles and allows the structural state to stabilize before a new trade occurs. All signals operate on closed-bar logic, and the strategy avoids higher-timeframe calls to stabilize execution behavior.

Motivation: Why this design?

Many structure-based systems repeatedly trigger as price fluctuates around prior highs and lows. This often leads to multiple flips during volatile or choppy conditions. Trendshift Strategy [CHE] addresses this problem by restricting execution to the first confirmed structural event in each direction. ATR-based filters help differentiate genuine structural breaks from noise, while the contextual band ensures that the breakout is meaningful in relation to recent volatility.
The design aims to represent a minimalistic structural trading framework focused on regime turns rather than continuous trend signaling. This reduces chart noise and clarifies where the market transitions from one regime to another.

What’s different vs. standard approaches?

Baseline reference

Typical swing-based structure indicators report every break above or below recent swing points.

Architecture differences

First-shift-only regime logic that blocks repeated signals until direction reverses
ATR-filtered validation to avoid weak or momentum-less breaks
Premium and discount bands derived from breakout structure
Optional band-driven stop placement
Optional band-dependent position-sizing factor
Regime timeout system to neutralize structure after extended inactivity
Persistent-state architecture to prevent re-triggering

Practical effect

Only the earliest actionable structure change is traded
Fewer but higher-quality signals
Premium/discount tint assists contextual evaluation
Stops and sizing can be aligned with structural context rather than arbitrary volatility measures
Improved chart interpretability due to reduced marker frequency

How it works (technical)

The algorithm evaluates symmetric swing points using a fixed bar window. When a swing forms, its value and bar index are stored as persistent state. A structural shift occurs when price closes beyond the most recent major swing on the opposite side. If ATR filtering is enabled, the breakout must exceed a volatility-scaled distance to prevent micro-breaks from firing.
Once a valid shift is confirmed, the regime is updated to bullish or bearish. The script records the breakout level, the opposite swing, and derives a band between them. This band is checked for minimum size relative to ATR to avoid unrealistic contexts.
The first shift in a new direction generates both the strategy entry and a visual marker. Additional shifts in the same direction are suppressed until a reversal occurs. If a timeout is enabled, the regime resets after a specified number of bars without structural change, optionally clearing the band.
Stop placement, if enabled, uses either the opposite or same band edge depending on configuration. Position size is computed from account percentage and may optionally scale with the price-span-to-ATR relationship.

Parameter Guide

Market Structure

Swing length (default 5): Controls swing sensitivity. Lower values increase responsiveness.
Use ATR filter (default true): Requires breakouts to show momentum relative to ATR. Reduces false shifts.
ATR length (default 14): Volatility estimation for breakout and band validation.
Break ATR multiplier (default 1.0): Required breakout strength relative to ATR.

Premium/Discount Framework

Enable framework (default true): Activates premium/discount evaluation.
Persist band on timeout (default true): Keeps structural band after timeout.
Min band ATR mult (default 0.5): Rejects narrow bands.
Regime timeout bars (default 500): Neutralizes regime after inactivity.
Invert colors (default false): Color scheme toggle.

Visuals

Show zone tint (default true): Background shade in premium or discount region.
Show shift markers (default true): Display first-shift markers.

Execution and Risk

Risk per trade percent (default 1.0): Determines position size as account percentage.
Use band for size (default false): Scales size relative to band width behavior.
Flat on opposite shift (default true): Forces reversal behavior.
Use stop at band (default false): Stop anchored to band edges.
Stop band side: Chooses which band edge is used for stop generation.

Reading & Interpretation

A green background indicates discount conditions within the structural band; red indicates premium conditions. A green triangle below price marks the first bullish structural shift after a bearish regime. A red triangle above price marks the first bearish structural shift after a bullish regime.
When stops are active, the opposite band edge typically defines the protective level. Band width relative to ATR indicates how significant a structural change is: wider bands imply stronger volatility structure, while narrow bands may be suppressed by the minimum-size filter.

Practical Workflows & Combinations

Trend following: Use first-shift entries as initial regime confirmation. Add higher-timeframe trend filters for additional context.
Swing trading: Combine with simple liquidity or fair-value-gap concepts to refine entries.
Bias mapping: Use higher timeframes for structural regime and lower timeframes for execution within the premium/discount context.
Exit management: When using stops, consider ATR-scaling or multi-stage profit targets. When not using stops, reversals become the primary exit.

Behavior, Constraints & Performance

The strategy uses only confirmed swings and closed-bar logic, avoiding intrabar repaint. Pivot-based swings inherently appear after the pivot window completes, which is standard behavior. No higher-timeframe calls are used, preventing HTF-related repaint issues.
Persistent variables track regime and structural levels, minimizing recomputation. The maximum bars back setting is five-thousand. The design avoids loops and arrays, keeping performance stable.
Known limitations include limited signal density during consolidations, delayed swing confirmation, and sensitivity to extreme gaps that stretch band logic. ATR filtering mitigates some of these effects but does not eliminate them entirely.

Sensible Defaults & Quick Tuning

Fewer but stronger entries: Increase swing length or ATR breakout multiplier.
More responsive entries: Reduce swing length to capture earlier shifts.
More active band behavior: Lower the minimum band ATR threshold.
Stricter stop logic: Use the opposite band edge for stop placement.
Volatile markets: Increase ATR length slightly to stabilize behavior.

What this indicator is—and isn’t

Trendshift Strategy [CHE] is a structural-regime trading engine that evaluates major directional shifts. It is not a complete trading system and does not include take-profit logic or prediction features. It does not attempt to forecast future price movement and should be used alongside broader market structure, volatility context, and disciplined risk management.

Disclaimer

The content provided, including all code and materials, is strictly for educational and informational purposes only. It is not intended as, and should not be interpreted as, financial advice, a recommendation to buy or sell any financial instrument, or an offer of any financial product or service. All strategies, tools, and examples discussed are provided for illustrative purposes to demonstrate coding techniques and the functionality of Pine Script within a trading context.

Any results from strategies or tools provided are hypothetical, and past performance is not indicative of future results. Trading and investing involve high risk, including the potential loss of principal, and may not be suitable for all individuals. Before making any trading decisions, please consult with a qualified financial professional to understand the risks involved.

By using this script, you acknowledge and agree that any trading decisions are made solely at your discretion and risk.

Do not use this indicator on Heikin-Ashi, Renko, Kagi, Point-and-Figure, or Range charts, as these chart types can produce unrealistic results for signal markers and alerts.

Best regards and happy trading

Chervolino

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.