OPEN-SOURCE SCRIPT
Mis à jour [GYTS-CE] Kinetic Trend Envelope (adaptive trailing stop)

Kinetic Trend Envelope (Community Edition)
🌸 Part of GoemonYae Trading System (GYTS) 🌸
🌸 --------- INTRODUCTION --------- 🌸
💮 What is the Kinetic Trend Envelope?
The Kinetic Trend Envelope (KTE) is an adaptive directional trailing stop in the lineage of SuperTrend, rebuilt around the premise that volatility is kinetic energy. It measures per-bar motion with five academically grounded volatility estimators, then widens the envelope as energy rises and contracts it as motion settles.
In an uptrend, the lower band ratchets higher and never retreats; in a downtrend, the upper band ratchets lower. The direction changes when the active stop is breached, after which the opposite side becomes the new trailing stop.
💮 Why Use This Indicator?
Conventional trailing stops typically combine a price anchor with one symmetric ATR-derived width. The KTE extends that model with:
↑ The KTE on a trending instrument. The thick line is the active trailing stop; the thin line shows the opposing side of the envelope. Both expand and contract with market energy.
↑ KTE beside TradingView's built-in SuperTrend, both using ATR with a 10-bar lookback. KTE's asymmetric profile changes how each side responds to directional volatility while the monotonic active band avoids premature loosening.
🌸 --------- HOW IT WORKS --------- 🌸
💮 Core Concept
The bands share a smoothed price estimator as their anchor, but use separate volatility profiles:
The selected direction-switch method changes only the breach test. It does not change the smoothed estimator anchoring the envelope, so a wick-sensitive trigger cannot drag the bands around with the wick.
💮 The Five Volatility Estimators
Each estimator reads a different part of the OHLC bar:
↑ ATR and Yang-Zhang at Adaptation Speed 2. The long profile memory (low speed) smooths away most of the difference, so the two envelopes nearly overlap.
↑ ATR and Yang-Zhang at Adaptation Speed 8. The short profile memory (high speed) exposes their different volatility readings, producing visibly distinct envelope widths.
💮 Asymmetric Volatility Profiling and Adaptation Speed
The KTE stores volatility from bullish and bearish candles separately. Bullish samples determine the upper width; bearish samples determine the lower width. This allows the two sides to respond differently when upward and downward motion carry different energy.
Adaptation Speed controls the memory of this profile, not the speed of the price estimator and not the distance of the stop by itself. Its 1–10 scale maps logarithmically to an internal window:
This is why two instances matched during a calm period can separate during a shock, especially when they also use different Volatility Factor values. Compare Adaptation Speed with the same factor first; matching lines in one regime does not make two configurations equivalent elsewhere.
The profiles are also direction-conditioned: bullish samples are replaced by later bullish candles and bearish samples by later bearish candles. A recent high-volatility sample can therefore persist through a run of opposite-colour candles, producing deliberate step-like plateaux in the relevant band.
↑ Asymmetric profiling in action: the upper and lower widths respond independently to bullish- and bearish-candle volatility.
💮 Direction Switch Methods
The breach source sets the balance between responsiveness and false flips:
↑ The three switch methods share the same band geometry but change direction at different times.
🌸 --------- KEY FEATURES --------- 🌸
💮 Eight Estimator Filters
The configurable price anchor includes:
💮 Visual Layering
The display separates function from context:
🌸 --------- USAGE GUIDE --------- 🌸
💮 Getting Started
Start with the defaults, observe several calm and volatile regimes, and change one dimension at a time:
💮 Choosing a Volatility Estimator
↑ Three estimators compared on one instrument, each reading a different combination of OHLC information.
💮 Tuning Width and Responsiveness
These controls solve different problems:
↑ A tight factor follows price more closely and flips more often; a loose factor tolerates larger pullbacks.
💮 Trading Applications
💮 Integration with GYTS Suite
The visible bands and estimator can be selected as sources by compatible Pine scripts. Two packed streams are also exposed:
Beyond that primary role, the signed trailing-stop stream can also serve as a trend signal, since its sign flips with direction: it can be read through sign and magnitude as an entry/exit signal, including by Flux Composer. The KTE can also be paired with Market Regime Detector so flips are acted on only when the broader regime supports trend-following behaviour.
🌸 --------- LIMITATIONS --------- 🌸
🌸 --------- CREDITS --------- 🌸
💮 Academic Sources
💮 Inspiration
💮 Libraries Used
🌸 Part of GoemonYae Trading System (GYTS) 🌸
🌸 --------- INTRODUCTION --------- 🌸
💮 What is the Kinetic Trend Envelope?
The Kinetic Trend Envelope (KTE) is an adaptive directional trailing stop in the lineage of SuperTrend, rebuilt around the premise that volatility is kinetic energy. It measures per-bar motion with five academically grounded volatility estimators, then widens the envelope as energy rises and contracts it as motion settles.
In an uptrend, the lower band ratchets higher and never retreats; in a downtrend, the upper band ratchets lower. The direction changes when the active stop is breached, after which the opposite side becomes the new trailing stop.
💮 Why Use This Indicator?
Conventional trailing stops typically combine a price anchor with one symmetric ATR-derived width. The KTE extends that model with:
- Asymmetric volatility profiling — Bullish- and bearish-candle volatility shape the upper and lower bands independently.
- Three direction-switch methods — High/low, close, or a smoothed estimator controls flip sensitivity without moving the band anchor.
- Five volatility estimators — ATR plus Parkinson, Garman-Klass, Rogers-Satchell, and Yang-Zhang covers different treatments of gaps, drift, and intrabar range.
🌸 --------- HOW IT WORKS --------- 🌸
💮 Core Concept
The bands share a smoothed price estimator as their anchor, but use separate volatility profiles:
- Upper band = estimator + (factor × bullish-candle volatility)
- Lower band = estimator − (factor × bearish-candle volatility)
The selected direction-switch method changes only the breach test. It does not change the smoothed estimator anchoring the envelope, so a wick-sensitive trigger cannot drag the bands around with the wick.
💮 The Five Volatility Estimators
Each estimator reads a different part of the OHLC bar:
- ATR (Wilder, 1978) — Familiar baseline that handles gaps through true range.
- Parkinson (1980) — Uses high-low range; efficient under continuous, low-drift conditions.
- Garman-Klass (1980) — Adds open-close information; favours continuous sessions without material gaps.
- Rogers-Satchell (1991) — Drift-independent and well suited to trending, continuously traded instruments.
- Yang-Zhang (2000) — Combines overnight gaps, open-close movement, and Rogers-Satchell; the gap-aware default.
💮 Asymmetric Volatility Profiling and Adaptation Speed
The KTE stores volatility from bullish and bearish candles separately. Bullish samples determine the upper width; bearish samples determine the lower width. This allows the two sides to respond differently when upward and downward motion carry different energy.
Adaptation Speed controls the memory of this profile, not the speed of the price estimator and not the distance of the stop by itself. Its 1–10 scale maps logarithmically to an internal window:
- Speed 3 — approximately 878 bars: stable and slow to re-weight
- Default 3.5 — approximately 570 bars: general-purpose smoothing
- Speed 8 — approximately 11 bars: highly responsive to recent volatility
- Speed 10 — approximately 2 bars: extremely reactive and noisy
This is why two instances matched during a calm period can separate during a shock, especially when they also use different Volatility Factor values. Compare Adaptation Speed with the same factor first; matching lines in one regime does not make two configurations equivalent elsewhere.
The profiles are also direction-conditioned: bullish samples are replaced by later bullish candles and bearish samples by later bearish candles. A recent high-volatility sample can therefore persist through a run of opposite-colour candles, producing deliberate step-like plateaux in the relevant band.
💮 Direction Switch Methods
The breach source sets the balance between responsiveness and false flips:
- On high/low — Uses the current bar's wick and can switch on the breach bar. Fastest and most sensitive to noise.
- On close — Uses the previous confirmed close; the switch appears on the following bar.
- On estimator — Uses the previous smoothed estimator; the most conservative default, also switching on the following bar.
🌸 --------- KEY FEATURES --------- 🌸
💮 Eight Estimator Filters
The configurable price anchor includes:
- Ultimate Smoother, 2- or 3-pole — Low-noise, near-zero-lag passband response; the 2-pole version is the default.
- Super Smoother, 2- or 3-pole — Ehlers low-pass filters for progressively stronger smoothing.
- BiQuad — Second-order low-pass filter with an adjustable Q-factor.
- ADXvma — Adapts to trend strength and tends to flatten in ranges.
- MAMA — Cycle-adaptive MESA moving average.
- A2RMA — Adaptive recursive moving average with adjustable gamma.
💮 Visual Layering
The display separates function from context:
- Active band — Thick directional trailing-stop line
- Opposing band — Thin reference for the inactive side
- Channel fill — Visual separation between the estimator and each band
- Estimator — Optional smoothed anchor
🌸 --------- USAGE GUIDE --------- 🌸
💮 Getting Started
Start with the defaults, observe several calm and volatile regimes, and change one dimension at a time:
- Tune Volatility Factor for the preferred stop distance.
- Tune Adaptation Speed for how quickly width should respond to regime changes.
- Choose the direction-switch method for the preferred confirmation level.
- Change the volatility estimator only when its assumptions better fit the instrument.
💮 Choosing a Volatility Estimator
- Gapped equities — Yang-Zhang accounts for overnight movement.
- Trending 24/7 markets — Rogers-Satchell is drift-independent without a separate gap component.
- Continuous, range-led markets — Parkinson or Garman-Klass offers efficient range-based measurement under their assumptions.
- Familiar baseline — ATR provides conventional true-range behaviour.
💮 Tuning Width and Responsiveness
These controls solve different problems:
- Volatility Factor — Sets the distance per unit of measured volatility.
- Adaptation Speed — Sets the memory of the bullish/bearish profile; faster can widen the stop sooner during shocks.
- Volatility Lookback — Sets how quickly the underlying per-bar volatility estimate changes.
- Estimator Lookback — Sets the smoothness of the price anchor.
- Frequent flips on minor pullbacks — Increase Volatility Factor or use a more conservative switch method (e.g. "on estimator").
- Excessive give-back — Decrease Volatility Factor or use a more responsive switch method (e.g. "on high/low").
- Width reacts too slowly to regime changes — Increase Adaptation Speed or reduce Volatility Lookback.
- Bands become erratic during shocks — Reduce Adaptation Speed or increase Volatility Lookback.
💮 Trading Applications
- Discretionary trailing stop — Move a protective stop with the active band as it tightens.
- Trend confirmation — Accept long signals only during a bullish KTE state, and short signals only while bearish.
- Exit timing — Treat a direction change as an exit when the trade thesis is trend-following.
💮 Integration with GYTS Suite
The visible bands and estimator can be selected as sources by compatible Pine scripts. Two packed streams are also exposed:
- 🔗 STREAM KTE 🪜 Trailing Stoploss — Positive lower-band value in a bullish state; negative upper-band value in a bearish state.
- 🔗 STREAM KTE 🪜 Mechanism — Encodes the switch method and scale-invariant estimator relationship for compatible consumers.
Beyond that primary role, the signed trailing-stop stream can also serve as a trend signal, since its sign flips with direction: it can be read through sign and magnitude as an entry/exit signal, including by Flux Composer. The KTE can also be paired with Market Regime Detector so flips are acted on only when the broader regime supports trend-following behaviour.
🌸 --------- LIMITATIONS --------- 🌸
- Trailing-stop latency — Every trailing stop gives back some of the move between the trend extreme and the eventual breach.
- Whipsaws in ranges — Low-energy chop can produce repeated flips; a regime filter may help when ranging conditions dominate.
- Fast adaptation can widen the stop — Higher Adaptation Speed means faster volatility response, not guaranteed proximity to price.
- Direction-conditioned memory — A bullish or bearish outlier remains in its own profile until enough matching-direction samples replace it, which can create plateaux after shocks.
- Warm-up and sample size — Long profile windows need sufficient chart history; strongly one-sided markets may leave one side with few recent samples.
🌸 --------- CREDITS --------- 🌸
💮 Academic Sources
- Wilder, J. W. (1978). New Concepts in Technical Trading Systems. Trend Research.
- Parkinson, M. (1980). The Extreme Value Method for Estimating the Variance of the Rate of Return. Journal of Business, 53(1), 61–65. DOI
- Garman, M. B., & Klass, M. J. (1980). On the Estimation of Security Price Volatilities from Historical Data. Journal of Business, 53(1), 67–78. DOI
- Rogers, L. C. G., & Satchell, S. E. (1991). Estimating Variance from High, Low and Closing Prices. Annals of Applied Probability, 1(4), 504–512. DOI
- Yang, D., & Zhang, Q. (2000). Drift-Independent Volatility Estimation Based on High, Low, Open, and Close Prices. Journal of Business, 73(3), 477–491. DOI
- Ehlers, J. F. (2024). The Ultimate Smoother. Technical Analysis of Stocks & Commodities, 2024-04. TASC
- Ehlers, J. F. (2004). Cybernetic Analysis for Stocks and Futures. Wiley. Covers SuperSmoother, MAMA and more.
💮 Inspiration
- Thanks to Trendoscope for inspiring us with the Supertrend - Ladder ATR (2021). It derives long-side stop distance from bearish-candle ATR and short-side distance from bullish-candle ATR, which is one of the mechanisms that we tried to develop further with the KTE.
💮 Libraries Used
- FiltersToolkit — Ultimate Smoother, Super Smoother, BiQuad, ADXvma, MAMA, and A2RMA
- VolatilityToolkit — Parkinson, Garman-Klass, Rogers-Satchell, and Yang-Zhang estimators
- MathTransform — Logarithmic scaling for Adaptation Speed
- ColourUtilities — Palette management and light/dark-mode colour adjustment
Notes de version
v1.0.1Minor
- Documented the cosmetic one-bar colour offset in "on high/low" switch mode
- Refreshed description and tooltips
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.
🌸 --- GoemonYae Trading System (GYTS) --- 🌸
・ Website: goemonyae.com
・ Docs: goemonyae.com/docs
・ Get Pro Access: goemonyae.com/get-access
・ Discord (🦊YaeBot): discord.gg/ef6Tu4kha3
・ Website: goemonyae.com
・ Docs: goemonyae.com/docs
・ Get Pro Access: goemonyae.com/get-access
・ Discord (🦊YaeBot): discord.gg/ef6Tu4kha3
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.
🌸 --- GoemonYae Trading System (GYTS) --- 🌸
・ Website: goemonyae.com
・ Docs: goemonyae.com/docs
・ Get Pro Access: goemonyae.com/get-access
・ Discord (🦊YaeBot): discord.gg/ef6Tu4kha3
・ Website: goemonyae.com
・ Docs: goemonyae.com/docs
・ Get Pro Access: goemonyae.com/get-access
・ Discord (🦊YaeBot): discord.gg/ef6Tu4kha3
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.