OPEN-SOURCE SCRIPT

Trendshift [CHE]

381
Trendshift [CHE] — First-Shift Regime Turns with Premium/Discount Context

Summary

Trendshift [CHE] highlights the first confirmed directional structure shift in price and overlays a premium or discount context based on the most recent structural range. It identifies the major swing levels, detects a regime transition when price closes beyond these levels with optional ATR-based conviction, and marks only the first shift per direction to reduce repetition and noise. The indicator then establishes a premium or discount band around the break and tints the background when price operates in either region. This produces a clean regime-aware view that emphasizes only the earliest actionable turn while maintaining contextual bias information.

Motivation: Why this design?

Conventional swing-based structure tools often fire repeated signals after each minor break, especially in volatile environments. This leads to cluttered charts and little informational value. Trendshift [CHE] focuses on the core trading need: isolating the first confirmed change in directional structure and providing a premium or discount context after the break. By limiting signals to the initial flip and suppressing further markers until direction reverses again, the script reduces noise and highlights only the structural event that materially matters. The band logic further addresses the challenge of distinguishing contextual extremes and avoiding trades taken too late after a shift.

What’s different vs. standard approaches?

Baseline reference: Most structure indicators repeatedly plot every new break of a swing high or swing low.

Differences:

Only the first confirmed bullish or bearish shift is plotted until the opposite direction occurs.
ATR-filtered breakout validation to reduce false breaks during volatility spikes.
A reduced premium and discount band derived from the breakout candle and prior swing structure.
Tinted background for contextual positioning rather than explicit entry signals.

Practical effect:

Fewer but more meaningful shift markers.
Clear visual context of where price operates relative to the structural band.
Cleaner regime transitions and less chart clutter.

How it works (technical)

The indicator continuously evaluates major swing highs and lows using a symmetric window length. When a swing is confirmed, the script stores its price and bar index. A structure shift occurs when price closes beyond the most recent major swing in the opposite direction. Optional ATR filtering requires the breakout distance to exceed an ATR-scaled threshold.
Upon a confirmed shift, the script sets a regime state that remains active until a new shift or an optional timeout. It also establishes a structural band anchored between the breakout candle extremum and the prior opposite swing. The band informs the premium and discount boundaries, each representing a quarter subdivision.
Only the first shift event per direction generates a visual triangle marker. The band is validated by comparing its height to ATR to avoid extremely narrow structures. Background tinting activates whenever price resides within the premium or discount zones. Persistent variables maintain previous structural states and prevent re-triggering until direction reverses.

Parameter Guide

Swing length (default 5): Controls the number of bars used on each side of a swing. Smaller values are more reactive; larger values reduce noise.
Use ATR filter (default true): Requires breakout strength beyond the swing to exceed an ATR-scaled threshold. Disabling increases signal frequency.
ATR length (default 14): Controls volatility estimation for breakout filtering and band validation.
Break ATR multiplier (default 1.0): Higher values require stronger breakouts, reducing false shifts.
Enable framework (default true): Activates the premium and discount context logic.
Persist band on timeout (default true): Retains the current band after a regime timeout.
Min band size ATR mult (default 0.5): Rejects extremely small bands and prevents unrealistic tinting.
Regime timeout bars (default 500): Resets the regime after extended inactivity.
Invert colors (default false): Swaps premium and discount tint color assignments.
Show zone tint (default true): Toggles background shading.
Show shift markers (default true): Enables or disables the first-shift triangles.

Reading & Interpretation

A green or red tint signals that price is operating in the discount or premium region of the most recent structural band. These regions are derived from the breakout event and the prior swing. A green triangle below a bar indicates the first bullish structure shift after a bearish regime. A red triangle above a bar indicates the first bearish shift after a bullish regime. No further markers appear until direction reverses. When tint is active, price location within the band offers simple contextual bias without providing explicit entries.

Practical Workflows & Combinations

Trend following: Treat the first bullish marker as the earliest confirmation of a potential up-regime and the first bearish marker for a potential down-regime. Use price location relative to the premium and discount zones as context for continuation or mean-reversion setups.
Structure-based execution: Combine with simple swing highs and lows to refine entry points within discount after a bullish shift or within premium after a bearish shift.
Higher-timeframe overlays: Apply the indicator on higher timeframes to define macro structure, then trade on lower timeframes using the band as a contextual anchor.
Risk management: When price stays in premium during a bearish regime or in discount during a bullish regime, consider protective actions or position management adjustments.

Behavior, Constraints & Performance

The script uses only confirmed swing points and closed-bar conditions, so repainting from future bars does not occur except the inherent delay of pivot confirmation. No higher-timeframe security calls are used, avoiding HTF repaint paths.
Performance impact is minimal because the script uses no loops or arrays and relies on persistent variables. The maximum bars back setting is five-thousand, required for swing lookback. Known limitations include quiet behavior during long consolidations, occasional delayed recognition of shifts due to swing confirmation, and limited effectiveness during large market gaps where extremum logic may be distorted.

Sensible Defaults & Quick Tuning

Increase the swing length for smoother trend shifts and fewer signals.
Decrease the swing length for more sensitivity.
Raise the ATR breakout multiplier to reduce noise in volatile markets.
Lower the band size requirement to make premium and discount zones more active on slower markets.
Extend the regime timeout for slow-moving assets.

What this indicator is—and isn’t

This tool is a structural regime-shift detector with contextual premium and discount shading. It is not a complete trading system and does not include entries, exits, or risk models. It does not predict future price movement. It should be combined with broader structure analysis, liquidity considerations, and risk management practices.

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

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.