INVITE-ONLY SCRIPT

Close vs SuperTrend % Diff

20
On Every Bar: SuperTrend and percent_diff are recalculated; the line plot updates with coloring.
On Visible Bars Only: High/low extremes and sums/counts accumulate via VC checks.
On Last Bar: Table refreshes with current stats, reflecting the visible view.
User Interaction: Zooming/panning triggers VC.barIsVisible() to recompute aggregates dynamically—no full history scan needed.
Edge Cases:

Empty visible range: High/low default to na; averages guarded against zero counts.
Division by zero in percent_diff: Unlikely, as st is ATR-based and rarely zero, but Pine handles na gracefully.
Performance: Efficient for long histories (e.g., daily charts over years) since stats are view-localized.



This indicator is useful for trend traders: Watch for percent_diff crossing zero for signals, and use the table to gauge visible volatility (e.g., if avg high > avg low in magnitude, bullish bias). Customize SuperTrend params (3,10) for different assets/timeframes. To extend, you could add alerts on threshold crosses or integrate dir for trend filters.

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.