Trend Quality [AGPro Series]Trend Quality
Trend Quality fuses three independent regime dimensions — ADX directional strength, Kaufman Efficiency Ratio, and ATR-normalized EMA slope — into a single 0–100 composite Trend Quality Score. A hysteresis + confirmation + cooldown gate turns that score into a stable TREND / CHOP regime, enhanced with HTF confirmation, lifecycle phases, score velocity, breakout grading, directional dominance, and a full adaptive on-chart quality window. The goal is simple: replace noisy "is this a trend?" guessing with a transparent, multi-dimensional, low-lag quality reading you can read in one glance.
🎯 OVERVIEW
Most trend filters fail at the same thing — they tell you a trend exists, but not whether that trend is clean, accelerating, fading, or already exhausted. Trend Quality answers the harder question. Every bar is scored on three independent dimensions that each measure a different physical property of price movement:
• ADX — directional strength (how strongly one side dominates)
• Kaufman Efficiency Ratio (ER) — path efficiency (how little wasted motion)
• ATR-normalized EMA slope — normalized trend velocity (how fast, relative to volatility)
These three signals are combined into one 0–100 Trend Quality Score. A hysteresis band + confirmation bars + cooldown filter convert that score into a stable TREND / CHOP regime — no single-bar flipping, no false recovery wicks. On top of the core regime, the indicator layers Score Velocity, Lifecycle phases (Emerging → Confirmed → Exhausting), Breakout Quality grading (A / B / C), directional dominance, and a visual Quality Window that tracks the active trend zone and projects it forward.
💎 UNIQUE EDGE
What separates Trend Quality from a standard ADX filter, an EMA slope indicator, or a generic regime meter:
• Tri-factor fusion (not a single metric) — ADX alone misses path quality; ER alone misses direction; slope alone misses choppy-but-strong moves. Weighted fusion (45% ADX, 35% ER, 20% Slope) neutralizes each component's blind spot.
• Stable regime, not a flickering line — the TREND / CHOP state passes through a 3-layer filter: hysteresis band around the threshold, N confirmation bars, and a cooldown window after every transition. The result is a regime reading that holds through pullbacks without flipping.
• Score Velocity Engine — a second-derivative layer that watches how fast the score itself is changing. Surges flag momentum ignition; collapses flag quality breakdown before price confirms it. A bearish divergence detector fires when price makes new highs while quality is fading.
• Lifecycle phases — inside every TREND regime, the script distinguishes Emerging (young, fresh, accelerating), Confirmed (mature, stable, above buffer), and Exhausting (score rolling over from a peak). This lets you see whether you are entering early, running mid-trend, or catching the end.
• Breakout Quality Badge (A / B / C) — every CHOP → TREND transition receives a graded badge based on composite score plus velocity bonus. Grade A breakouts are rare and have an optional dedicated alert.
• HTF confirmation with Auto-HTF mapping — the same engine runs on a higher timeframe. When LTF is trending but HTF is not, the regime is marked BLOCKED (not forced to CHOP) so you retain full transparency about why the regime is gated.
• Adaptive Quality Window — a live rectangular zone that tracks the full trend's high/low from its start bar, projects forward, shows ceiling/floor projection labels, and preserves historical windows with directional color coding (green for up-trends, pink for down-trends, amber for HTF-blocked trends).
🧪 METHODOLOGY
Core composite score (every bar, LTF):
Score = 100 × (0.45 × ADX_norm + 0.35 × ER_norm + 0.20 × Slope_norm)
• ADX_norm = min(ADX / 50, 1)
• ER_norm = |close − close | / (SMA(|Δclose|, N) × N)
• Slope_norm = min(|EMA − EMA | / ATR × 10, 1)
Regime gating:
• Hysteresis: +3 above threshold to enter TREND, −3 below to enter CHOP
• Confirmation: N consecutive bars above/below the hysteresis band
• Cooldown: N bars after every regime flip where no new flip is allowed
MTF confirmation (optional, default ON):
The same core function is called via request.security on the HTF (Auto: 30m→4H, 4H→Daily, Daily→Weekly, Weekly→Monthly in Strict mode). When LTF=TREND but HTF=CHOP, the regime is tagged BLOCKED — a transparent third state that is neither forced-CHOP nor accepted-TREND.
Lifecycle logic:
• Emerging: TREND is young (bars since start ≤ Emerging Bars) OR score slope ≥ 0 and score below buffer
• Confirmed: score ≥ threshold + Confirmed Buffer AND HTF passes (optional)
• Exhausting: score slope < 0 AND pullback from peak ≥ Exhaustion Pullback
Score velocity:
velocity = score − score (default 5-bar look-back)
Breakout quality grading:
bqScore = score + velocity_bonus (bonus: +15 if vel>15, +7 if vel>5, else 0)
A ≥ 82, B ≥ 67, C < 67
🔔 SIGNALS & ALERTS
The script exposes 12 alert conditions — all moderator-safe, educational, non-solicitating:
• CHOP → TREND / TREND → CHOP regime flips with LTF+HTF context
• Strong Trend composite conviction threshold
• HTF Blocked / HTF Unblocked third-state transparency events
• Emerging / Confirmed / Exhausting Trend lifecycle phase changes
• Velocity Surge / Velocity Collapse second-derivative extremes
• Grade-A Breakout rare high-conviction breakouts
• Bearish Divergence price up, quality down warning
On-chart visual events (also filterable via inputs):
• Breakout Quality badge (A / B / C) at every CHOP → TREND
• Bearish divergence ⚠ marker at trend peaks where quality fades
• State tag near backbone: EMERGING / CONFIRMED / EXHAUSTING / HTF BLOCKED
• Quality Window label: ACTIVE + phase
• Projection labels on the right edge: QUALITY CEILING / TREND FLOOR
All badge and warning labels are gated with an 8-bar cooldown so the chart stays clean even on repeated intra-swing triggers.
⚙️ KEY INPUTS
Core engine:
• ADX Length (14) — directional strength look-back
• Efficiency Length (20) — ER path-efficiency window
• Slope EMA Length (50) — trend backbone reference
• ATR Length (14) — volatility normalization
• TREND Threshold (55) — composite score level to enter TREND
• Confirmation Bars (1) — bars of persistence before flipping
• Strong Trend Offset (15) — extra score above threshold for STRONG tag
MTF:
• HTF Confirmation (ON) — enable/disable HTF gate
• Auto HTF (ON, Strict) — smart HTF mapping per chart TF
• Manual HTF (240) — override timeframe
Stability:
• Change Cooldown Bars (2) — lock-out window after any regime flip
Lifecycle:
• Emerging Phase Bars (4) — max trend age to stay Emerging
• Confirmed Buffer (8.0) — score must clear threshold+buffer
• Exhaustion Pullback (4.0) — peak-to-current drop to flag Exhausting
Visual Overlay:
• Backbone + Glow + Zone + State Candles + Quality Window + Historical Windows + Projection Box + Guides + Midline (all toggleable)
Panel, Theme, Layout, Help rows, Alerts, Score Velocity Engine, Breakout Quality Badge, Divergence Detector — every layer has its own input group and can be shown/hidden independently.
📘 HOW TO USE
Read-in-one-glance panel (standard AGPro format):
• Blue header row: script title
• Line 2: REGIME / LIFECYCLE · Score N/100 · Velocity state
• Line 3: LTF regime · Direction · Directional Dominance
• Line 4: HTF regime · MTF PASS/BLOCKED · Active Window state · Streak
Quick playbook:
1. CHOP on LTF → wait. No setup, no commitment.
2. CHOP → TREND transition with Grade A badge + HTF PASS → highest-conviction regime start.
3. CONFIRMED phase with DOM HIGH and rising score → the middle of the trend, usually the cleanest section.
4. Velocity COLLAPSE or EXHAUSTING phase with bearish divergence ⚠ → quality is deteriorating; reduce exposure or tighten stops.
5. HTF BLOCKED amber window → LTF trend exists but higher timeframe disagrees; treat as lower-conviction and be aware of mean-reversion risk.
The indicator does NOT issue buy/sell signals, does NOT define entry/exit prices, and is NOT a strategy. It is a regime-quality reading — a context layer you pair with your own trade management.
⚠️ LIMITATIONS & TRANSPARENCY
• Trend-quality indicators are inherently trend-following. In low-volatility ranges the score can stay above threshold on minor moves; in very fast markets the score can lag by 1–3 bars while the filters stabilize.
• HTF confirmation introduces a natural HTF delay. This is intentional (it removes noise) but means the HTF gate may lift several LTF bars after price has already moved.
• All composite signals rely on look-backs (ADX 14, ER 20, Slope EMA 50, ATR 14). On very short intraday timeframes with low bar counts these need calibration.
• Lifecycle phases are structural readings, not predictions. EXHAUSTING means the score is rolling over — not that price must reverse.
• Past performance of any visual regime does not imply future performance. Charts showing clean historical windows are illustrative of the indicator's logic, not trading results.
• No repainting on historical bars. The HTF call uses lookahead_off and barmerge.gaps_off. Score and regime values on closed bars are final.
🛡️ RISK DISCLOSURE
This script is published as an educational and analytical tool. It does not provide financial advice, does not generate trade signals of any kind, and must not be used as a standalone decision system. Markets involve substantial risk of loss. Past behavior of any market regime, indicator output, or historical visual window is no guarantee of future results. Always combine any indicator with independent risk management, position sizing, a tested plan, and — where appropriate — the guidance of a licensed professional. You are solely responsible for any trading decisions you make.
Pine Script® Indikator






















