OPEN-SOURCE SCRIPT

Mitigation Velocity Order Block Ranker [PhenLabs]

8 329
📊 Mitigation Velocity Order Block Ranker [PhenLabs]

Version: PineScript™ v6

snapshot

📌 Description

Most order block tools dump every candle that qualifies onto your chart and leave you to guess which ones actually matter. That works fine in clean trends and falls apart in ranges, where five or ten blocks are active at once and only one or two will ever produce a meaningful reaction. The Mitigation Velocity Order Block Ranker replaces that guesswork with an objective score.

Every active block is graded in real time on three independent dimensions: how quickly it gets tested after creation, how aggressive the volume was when it formed, and whether it sits in the right half of the higher-timeframe range. The result is a single composite score per block and a top-N ranking that updates with every bar — so the strongest zones stand out visually and the marginal ones fade into the background.

This is built for traders who already understand order block theory and want a way to filter for quality without flipping between timeframes or eyeballing volume. Use it as a confidence layer, a trigger filter, or a way to prioritize which zones deserve an alert.

🚀 Points of Innovation

  • Composite scoring engine that grades every block on velocity, volume, and HTF context instead of treating all OBs as equal
  • Time-to-first-touch velocity metric — freshness is measured against a configurable bar horizon, so stale zones decay naturally
  • Volume depth scoring uses the formation candle’s relative volume against a rolling SMA baseline, not raw volume
  • HTF premium/discount alignment automatically rewards bullish OBs in discount and bearish OBs in premium
  • Dynamic top-N ranking table with side, levels, and live score for every tracked block
  • Rank-driven color fading visually separates the strongest zones from the rest at a glance


🔧 Core Components

  • Velocity Score: Measures bars elapsed between OB creation and its first mitigation touch, normalized against a user-defined horizon. Untouched blocks decay as they age, so freshness is rewarded.
  • Volume Score: Compares the formation candle’s volume to its rolling SMA baseline and maps the ratio to a 0-to-1 range, clamped at 3x baseline so a single spike can’t dominate.
  • HTF Alignment Score: Pulls the high and low of the selected HTF lookback range and rewards bullish blocks below the midpoint, bearish blocks above it, scaled by how deep into the array the block sits.


🔥 Key Features

  • Real-Time Composite Ranking: Every active block gets a fresh score on every bar, with ranks reassigned dynamically as conditions change.
  • Configurable Metric Weights: Tune velocity, volume, and HTF weights independently to match your trading style or backtest results.
  • Top-N Ranking Table: See your strongest zones at a glance with side, top, bottom, and live score in a clean on-chart table.
  • Rank-Faded Zone Colors: The #1 zone shows vivid; lower-ranked zones fade progressively, making chart hierarchy instantly readable.
  • Top-Block Mitigation Alerts: Get notified the moment a top-ranked OB is tested — no noise from low-quality zone touches.
  • Wick or Body Mitigation Toggle: Choose whether wicks count as a touch or only the candle body, depending on your style.
  • Configurable HTF Reference: Set any higher timeframe and lookback range for the premium/discount array.


🎨 Visualization

  • Ranking Table: Top-right by default (position is configurable), shows rank number, side, top price, bottom price, and current score for each tracked block.
  • Zone Boxes: Every active OB is drawn as a colored box from its formation bar forward. The #1 zone is fully vivid; rank 2, 3, 4… fade progressively toward transparency.
  • Rank Labels: Top-N blocks display a label at the right edge showing “#rank score” so you can map any box back to its row in the table without counting.
  • Border Weight: Top-N zones get a heavier border to draw the eye; lower-ranked zones use a lighter border.
  • Listed images displaying all necessary components


📖 Usage Guidelines

Order Block Detection

  • Swing Pivot Length — Default: 5 — Range: 2-50 — Controls how many bars must confirm a swing before an OB is created. Higher values produce fewer, more significant zones; lower values catch more structure but generate more noise.
  • Max Active Blocks — Default: 20 — Range: 5-50 — Hard cap on tracked unmitigated blocks. Oldest blocks are dropped first when the cap is exceeded.
  • Use Wick Mitigation — Default: false — A wick touch counts as a mitigation when enabled; only the candle body counts when disabled. Wick mitigation is stricter and produces faster invalidations.


Scoring Weights

  • Velocity Weight — Default: 0.40 — Range: 0-1 — How much the time-to-first-touch metric contributes to the composite score.
  • Volume Weight — Default: 0.35 — Range: 0-1 — How much the formation-candle relative volume contributes to the composite score.
  • HTF Alignment Weight — Default: 0.25 — Range: 0-1 — How much the HTF premium/discount bonus contributes to the composite score.
  • Velocity Horizon (bars) — Default: 50 — Range: 5-500 — Bar window used to normalize the velocity score. Shorter horizons make the velocity metric stricter; longer horizons are more forgiving.
  • Volume Lookback — Default: 20 — Range: 5-200 — SMA length used as the relative volume baseline for the volume score.


Higher Timeframe Alignment

  • HTF Timeframe — Default: D (Daily) — Higher timeframe used to compute the premium/discount array. Common picks: 4H, D, W.
  • HTF Range Lookback — Default: 20 — Range: 5-200 — Number of HTF bars used to construct the premium/discount range.


Ranking Table

  • Show Ranking Table — Default: true — Toggles the on-chart table.
  • Top N Blocks — Default: 5 — Range: 1-15 — Number of top-ranked blocks displayed in the table and emphasized with vivid coloring on the chart.
  • Table Position — Default: top_right — Choose where the table renders on the chart.
  • Table Text Size — Default: small — Font size for table cells.


Visual Settings

  • Bullish Base Color — Default: teal — Base color for bullish zones. Top-ranked zones use this color at full opacity; lower ranks fade toward transparency.
  • Bearish Base Color — Default: red — Base color for bearish zones, with the same rank-fading behavior.
  • Show Rank Labels on Zones — Default: true — Toggles the rank/score labels at the right edge of top-N zones.
  • Extend Zones to Right — Default: true — Extends boxes 10 bars past the current candle for easier visual targeting.


✅ Best Use Cases

  • Smart Money and ICT traders looking to filter their order block list down to the highest-conviction zones
  • Swing and position traders who want HTF premium/discount logic baked into their LTF entry zones
  • Scalpers needing to prioritize which of several active blocks to actually trade in a range-bound session
  • Discretionary traders who want a quantitative confidence layer on top of their existing order block process
  • Markets with reliable volume data — futures, indices, crypto majors, large-cap equities


⚠️ Limitations

  • Volume score depends on reliable volume data — spot forex and thinly traded instruments will produce noisy results
  • The HTF alignment metric assumes the current HTF range is meaningful; in extended trends, premium/discount logic can lag
  • Scores are relative within the active block set — a “high” score in a quiet market is not directly comparable to a “high” score in a volatile one
  • Order block detection uses confirmed pivots, which means OBs are drawn with a swing-length bar delay
  • Like all order block tools, this is a context indicator — it does not generate standalone buy or sell signals


💡 What Makes This Unique

Existing order block indicators either show every block equally or filter on a single dimension like volume. This script is the first to combine velocity, volume, and HTF context into a single composite score and rank every active block against the others in real time. The output is a clean hierarchy of zones you can act on with confidence — strongest first, weakest faded out — instead of a chart cluttered with equally-weighted boxes.

🔬 How It Works

1. Detect and Track
The script scans for confirmed swing highs and lows using your pivot length. For each one, it walks back to find the last opposing-color candle, marks that as the order block, and stores its top, bottom, formation volume, and creation bar. Active blocks are tracked in a managed array up to your configured max.

2. Score Every Bar
On every new bar, each unmitigated block is re-scored on three independent metrics — velocity (how fresh), volume (how aggressive at formation), and HTF alignment (whether it sits in the right half of the higher-timeframe range). The three sub-scores are normalized to 0–1 and combined using your configured weights into a single composite score.

3. Rank, Render, Alert
All active blocks are sorted by composite score descending. The top-N get vivid coloring, rank labels, and rows in the on-chart table. Lower-ranked blocks fade progressively. When price returns to a top-ranked zone and mitigates it, an alert fires so you never miss a test on a zone you actually care about.

💡 Note:
This indicator is a context and prioritization tool, not a signal generator. Use the scores and rankings to qualify zones you would already be watching, not as standalone entry triggers. Backtest the weight combinations on your instrument and timeframe before committing them to live trading — the right mix of velocity, volume, and HTF weighting depends heavily on the market you trade.

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.