OPEN-SOURCE SCRIPT
Daily Levels + Score

# Daily Levels + Score (DHL×2)
---
## WHAT IT DOES
Most support/resistance scripts draw every level they find and leave you to guess which ones matter. DHL×2 finds the daily highs and lows that cluster together, draws them on your intraday chart, and then **grades each level with a statistical effectiveness score** based on how price actually reacted to it — evaluated strictly out-of-sample, so a level never "confirms itself". It also maps the current premium/discount context of the range with a time-at-price profile (POC / VAH / VAL).
## HOW IT WORKS
**1. Level detection — density clustering (KDE).**
Daily highs and lows over the lookback window are grouped with a kernel density estimate (triangular kernel, bandwidth = tolerance). Levels are the peaks of that density, so the result does not depend on the order in which candles are scanned, unlike the usual greedy grouping. Each touch is weighted by recency, and the final level is the weighted average of its touches. Tolerance adapts to volatility: Parkinson (default, converges faster after regime changes) or ATR.
**2. No self-confirmation bias.**
The touches that *form* a cluster do not count as tests. A cluster is "born" once it gathers the minimum number of touches; everything after that candle is out-of-sample evaluation. This is the key difference from scripts that count the same touches twice — once to build the level and again to "prove" it works.
**3. Effectiveness score.**
From its birth onward, every approach to the level is classified as respected or broken (consecutive candles in the zone count as one event). Three score modes:
- **Wilson 95%** — lower bound of the confidence interval; small samples are pushed toward 0 instead of showing a misleading "100% (2/2)".
- **Bayes (shrinkage)** — empirical Bayes: each level's score is pulled toward the base rate of all levels on the chart, with a configurable prior strength.
- **Raw %** — no correction, for comparison.
On top of that:
- **Time decay** — a respect from 30 days ago weighs less than yesterday's (configurable half-life).
- **Liquidity-consumption penalty** — consecutive respected tests progressively weaken the score, mimicking how resting orders get consumed at a real level.
- **Bounce magnitude (MFE)** — the average favorable excursion after each respect, expressed in daily-volatility multiples (σ), shown next to the score.
**4. Confluence.**
Round numbers (●, step configurable: e.g. 100 for NQ, 25 for ES) and proximity to the range equilibrium (◆) add a score bonus.
**5. Premium / Discount + time-at-price profile.**
The selected range (previous day, last N days, or full lookback) is split with fib lines (0 / 25 / 50 / 75 / 100) and an equilibrium line. A TPO-style **time-at-price profile** (no volume needed) is built from chart-resolution bars inside the range and plots the **POC, VAH and VAL**. When the POC sits meaningfully away from the geometric equilibrium (threshold as % of the range), the status label flags the imbalance with its direction: **POC>EQ** (p-shaped, value built in premium) or **POC<EQ** (b-shaped, value built in discount).
**6. Ranking table.**
Every level — including the EQ — is ranked in a table with its type, role (S / R / S+R / broken), respected/total tests, score, average bounce in σ, and distance to price. Sort by score or by proximity.
## HOW TO READ IT
- Line color intensity follows the score (configurable gradient); distant levels fade out so the chart stays clean near price.
- Labels show price, score and the average bounce (e.g. `23150 62% ~1.4σ`), plus ● / ◆ confluence marks.
- Status label: PREMIUM/DISCOUNT %, range direction, and the POC≠EQ flag when the profile is out of balance.
- A level with a high score, several out-of-sample respects and a decent σ bounce is a meaningful reaction zone; a level marked ✕ has been traded through and is better read as a target/liquidity draw than as support or resistance.
## SETTINGS WORTH KNOWING
- **Score mode + gradient:** with Wilson use floor 10 / ceiling 55; with Bayes ~40/70; with Raw % ~40/90.
- **Round number step:** 100 for NQ/MNQ, 25 for ES/MES.
- **POC≠EQ threshold:** default 10% of the range; raise it if the flag fires too often on your instrument.
- Designed for intraday charts (1m–30m) reading daily levels; works on any symbol with daily data.
## ORIGINALITY
What sets this apart from typical S/R scripts: order-independent KDE clustering, strict out-of-sample scoring (no self-confirmation), Wilson/empirical-Bayes correction for small samples, time decay and liquidity-consumption penalty, Parkinson volatility, bounce magnitude in σ, and a volume-free time-at-price profile with a directional POC-vs-EQ imbalance flag.
## DISCLAIMER
For educational purposes only. The score measures how the level behaved in the past; it is not a prediction and not financial advice. Always manage your risk.
---
## WHAT IT DOES
Most support/resistance scripts draw every level they find and leave you to guess which ones matter. DHL×2 finds the daily highs and lows that cluster together, draws them on your intraday chart, and then **grades each level with a statistical effectiveness score** based on how price actually reacted to it — evaluated strictly out-of-sample, so a level never "confirms itself". It also maps the current premium/discount context of the range with a time-at-price profile (POC / VAH / VAL).
## HOW IT WORKS
**1. Level detection — density clustering (KDE).**
Daily highs and lows over the lookback window are grouped with a kernel density estimate (triangular kernel, bandwidth = tolerance). Levels are the peaks of that density, so the result does not depend on the order in which candles are scanned, unlike the usual greedy grouping. Each touch is weighted by recency, and the final level is the weighted average of its touches. Tolerance adapts to volatility: Parkinson (default, converges faster after regime changes) or ATR.
**2. No self-confirmation bias.**
The touches that *form* a cluster do not count as tests. A cluster is "born" once it gathers the minimum number of touches; everything after that candle is out-of-sample evaluation. This is the key difference from scripts that count the same touches twice — once to build the level and again to "prove" it works.
**3. Effectiveness score.**
From its birth onward, every approach to the level is classified as respected or broken (consecutive candles in the zone count as one event). Three score modes:
- **Wilson 95%** — lower bound of the confidence interval; small samples are pushed toward 0 instead of showing a misleading "100% (2/2)".
- **Bayes (shrinkage)** — empirical Bayes: each level's score is pulled toward the base rate of all levels on the chart, with a configurable prior strength.
- **Raw %** — no correction, for comparison.
On top of that:
- **Time decay** — a respect from 30 days ago weighs less than yesterday's (configurable half-life).
- **Liquidity-consumption penalty** — consecutive respected tests progressively weaken the score, mimicking how resting orders get consumed at a real level.
- **Bounce magnitude (MFE)** — the average favorable excursion after each respect, expressed in daily-volatility multiples (σ), shown next to the score.
**4. Confluence.**
Round numbers (●, step configurable: e.g. 100 for NQ, 25 for ES) and proximity to the range equilibrium (◆) add a score bonus.
**5. Premium / Discount + time-at-price profile.**
The selected range (previous day, last N days, or full lookback) is split with fib lines (0 / 25 / 50 / 75 / 100) and an equilibrium line. A TPO-style **time-at-price profile** (no volume needed) is built from chart-resolution bars inside the range and plots the **POC, VAH and VAL**. When the POC sits meaningfully away from the geometric equilibrium (threshold as % of the range), the status label flags the imbalance with its direction: **POC>EQ** (p-shaped, value built in premium) or **POC<EQ** (b-shaped, value built in discount).
**6. Ranking table.**
Every level — including the EQ — is ranked in a table with its type, role (S / R / S+R / broken), respected/total tests, score, average bounce in σ, and distance to price. Sort by score or by proximity.
## HOW TO READ IT
- Line color intensity follows the score (configurable gradient); distant levels fade out so the chart stays clean near price.
- Labels show price, score and the average bounce (e.g. `23150 62% ~1.4σ`), plus ● / ◆ confluence marks.
- Status label: PREMIUM/DISCOUNT %, range direction, and the POC≠EQ flag when the profile is out of balance.
- A level with a high score, several out-of-sample respects and a decent σ bounce is a meaningful reaction zone; a level marked ✕ has been traded through and is better read as a target/liquidity draw than as support or resistance.
## SETTINGS WORTH KNOWING
- **Score mode + gradient:** with Wilson use floor 10 / ceiling 55; with Bayes ~40/70; with Raw % ~40/90.
- **Round number step:** 100 for NQ/MNQ, 25 for ES/MES.
- **POC≠EQ threshold:** default 10% of the range; raise it if the flag fires too often on your instrument.
- Designed for intraday charts (1m–30m) reading daily levels; works on any symbol with daily data.
## ORIGINALITY
What sets this apart from typical S/R scripts: order-independent KDE clustering, strict out-of-sample scoring (no self-confirmation), Wilson/empirical-Bayes correction for small samples, time decay and liquidity-consumption penalty, Parkinson volatility, bounce magnitude in σ, and a volume-free time-at-price profile with a directional POC-vs-EQ imbalance flag.
## DISCLAIMER
For educational purposes only. The score measures how the level behaved in the past; it is not a prediction and not financial advice. Always manage your risk.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.