INVITE-ONLY SCRIPT

Trend Filter

19
Trend Filter

Summary
Trend Filter is a multi-factor trend-confidence indicator that produces a simple, actionable output: Direction (Up / Down / Ranging) and a normalized Confidence %. It is intended as a decision-support overlay to help traders quickly identify whether a market is trending or rangebound, and how strong that directional bias is.

What it shows

A single line in the on-chart table: Direction (Up / Down / Ranging).
A Confidence % (0–100) that combines multiple normalized market signals into a single score.
Optional notification row when a manually-selected reference timeframe does not match the chart timeframe.
Alert conditions when direction changes to Up, Down, or Ranging.

How the indicator works (concise, non-proprietary explanation)

Trend Filter computes a weighted confidence score from several complementary components, each normalized to a 0–100 scale and combined into a single confidence value. The components and their roles are:

EMA structure & spread (trend breadth)
-Uses three EMAs (fast / mid / slow) computed at lengths that scale with the selected/reference timeframe. The EMA spread (fast vs slow) quantifies directional separation.

HH/HL structure and streaks (price structure)
-Counts higher highs/higher lows (and the reverse) across a scaled lookback to measure whether price structure is predominantly bullish, bearish or mixed.

EMA slope (momentum of trend)
-A robust slope approximation (smoothed) measures whether the short EMA is rising/falling relative to its own smoothed history.

ADX / DMI (trend strength)
-Uses a standard ADX-style component to capture directional persistence and dampen the confidence score when the ADX is weak.

ATR (volatility context)
-ATR expressed as a percentage of price helps detect abnormal volatility regimes which affect the validity of trend signals.

Volume context
-Simple volume vs a short SMA gives a participation signal that increases confidence when moves occur with higher volume.

Each component is capped to avoid outsized influence. Components are scaled by a set of weights (configurable in code) and then combined. The final confidence is lightly smoothed before being used to determine direction and to feed alert conditions.

Important implementation & safety design choices (why it’s not a simple mashup)

Adaptive timeframe scaling: EMA lengths and lookbacks are proportionally scaled based on the chosen reference timeframe (Auto or manual). This preserves relative indicator behavior across 1-minute → Daily timeframes without manual retuning of each parameter.

HH/HL structure plus streaks: Instead of relying solely on moving averages or ADX, the script explicitly measures price structure (HH/HL counts and streaks) and blends that with slope/ADX. This reduces false trending signals on noisy price action.

Normalized, weighted combination with caps: Each component is normalized (0–100) and combined by predefined weights; cap thresholds prevent extreme component values from dominating the result. This is a design intended to produce interpretable confidence % rather than opaque binary outputs.

History and loop safety: The code enforces a cap and protects loop lengths against available historical bars to avoid runtime errors and to ensure the script remains stable on short data series.

Practical guardrails: The script includes notification behavior to highlight manual timeframe mismatches and avoids dynamic indexing patterns that can cause unreliable results on small bar histories.

These design decisions — adaptive scaling, structural HH/HL scoring, capped normalization and explicit safety limits — are the elements that distinguish Trend Filter from simple, single-indicator overlays (EMA-only, ADX-only, etc.) and form the basis for why closed-source protection is reasonable for commercial/invite-only publication.

User controls & recommended usage

Reference Timeframe: Auto (uses chart TF) or choose a manual reference TF (1min → D). When manual TF is selected, the table shows a mismatch warning if the chart TF differs.

Table placement & colors: Positioning and appearance of the on-chart table are configurable.

Confidence thresholds: The indicator uses internal thresholds to mark high/medium/low confidence. Users can interpret the Confidence % relative to those ranges.

Alerts: Built-in alerts fire only on direction changes (to Up, Down, or Ranging). Use alerts as a signal to review the chart rather than an instruction to trade automatically.

How traders typically use it

Add Trend Filter as an overlay to your chart.

Confirm that the recommended reference timeframe is appropriate (Auto will adjust automatically).

Use Direction and Confidence % together: high Confidence + Up (or Down) suggests staying with trend; Ranging suggests avoiding trend-following entries.

Combine this filter with your entry/exit rules (price structure, support/resistance, or your preferred signal generator).

Disclaimers & limitations

This is a decision-support indicator, not an automated execution strategy. It does not place orders and does not provide P/L or backtesting statistics.

Confidence % is an aggregated measure — treat it as context, not a guarantee.

Results vary across symbols and timeframes; use appropriate position sizing and risk controls.

The code intentionally includes history and loop safeguards; on very short histories the indicator may display conservative results.

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.