OPEN-SOURCE SCRIPT

MAD Supertrend ~ C H I P A

311
MAD Supertrend ~ C H I P A is a custom trend-following system that replaces the standard deviation core of a classic Supertrend with Median Absolute Deviation (MAD) — a robust volatility measure that ignores outlier wicks instead of inflating on them. The result is a trail that holds steady through shakeout spikes where stdev-based bands blow out and go blind.
It uses:
A user-selectable source and MAD length
A choice of MAD estimator — true Median-of-deviations for maximum robustness, or Mean for a slightly smoother read
Independent upper and lower MAD multipliers for asymmetric band control
A selectable centerline engine: raw Source for zero lag, Single Median, or a Double Median smoother that kills staircase artefacts without adding meaningful delay
A PSAR-style exit acceleration module — each new closing extreme in the trend tightens the exit trail by a configurable step, down to a user-defined floor
Supertrend ratchet logic with persistent trend state and clean flip detection
The exit acceleration is the key behavioural difference from a standard Supertrend: fresh trends begin at full band width, giving early moves room to survive shakeouts, while mature trends that keep printing new extremes are trailed progressively tighter — so extended runs are exited far closer to their peak. The trail only ever tightens mid-trend and fully resets on each flip.
Alerts fire on confirmed trend flips in both directions.
Note: MAD Supertrend is provided "as is" without formal robustness or optimization testing. Past performance is not indicative of future results; use in live trading only after sufficient back-testing and validation.

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.