OPEN-SOURCE SCRIPT
已更新

Key Levels Pro [AGPro Series]

5 469
Key Levels Pro [AGPro Series]

🔑 Overview

Key Levels Pro is a comprehensive, non-repainting level tracker that consolidates every institutionally significant price reference into one clean overlay. Previous day, week, and month highs/lows (PDH, PDL, PWH, PWL, PMH, PML) are plotted alongside Asian, London, and New York session highs and lows. Every level is actively monitored — touch count, break count, and respect rate update in real time, giving you a live quality score for each price zone.

Most level scripts stop at drawing lines. Key Levels Pro goes further: lines automatically thicken on repeated touches, switch to dashed style when broken, and fade to muted color to signal invalidation. Zone rectangles extend back to the formation bar of each level, making historical respect visible at a glance. An ATR-aware label collision system keeps the chart readable on every timeframe, and same-price levels are intelligently deduplicated so you never see four overlapping labels at the same price.

───────────────────────────────────────────────────────

📐 Unique Edge

Unlike generic pivot or S/R scripts, Key Levels Pro tracks the behavioral quality of each level — not just its existence. A level that has been tested five times without breaking carries a different weight than a fresh, untested one. Key Levels Pro surfaces that difference automatically through line width, style, and panel data.

What makes it distinct:

🔹 Complete previous-period coverage (PDH/PDL, PWH/PWL, PMH/PML) in one overlay, without redundant current-period duplicates.
🔹 Live session tracking for Asian, London, and New York simultaneously, with automatic hiding on Daily and higher timeframes.
🔹 Per-level touch count, break count, and respect rate computed from actual historical price interaction.
🔹 Dynamic line thickening on repeated touches (width 1 → 2 → 3).
🔹 Auto-broken state with dashed style + muted color — no distracting flags or banners.
🔹 Historical zone boxes extending back to the formation bar of each level.
🔹 ATR-aware label collision resolution that stacks overlapping labels vertically.
🔹 Price-based deduplication: when two levels share the same price, the higher-priority one wins (Monthly > Weekly > Daily > Session).
🔹 ATR-normalized proximity to the nearest level above and below the current price.

───────────────────────────────────────────────────────

🔬 Methodology

Previous-period levels are pulled from the daily, weekly, and monthly timeframes using request.security() with lookahead enabled for the completed-period values. This approach is standard, transparent, and non-repainting — historical data does not change.

Session levels are tracked bar by bar using customizable session time inputs. Each session resets at its start time and tracks the running high and low until the session closes. The Asian, London, and New York sessions can each be configured independently.

Touch detection uses an ATR-based tolerance band (default 10% of ATR). When price closes within that tolerance of a level, the touch counter increments. A break is registered when price closes on the opposite side of a level compared to the prior bar. Respect rate is calculated as touches / (touches + breaks) × 100.

Line width scales with touch count: 1 touch = width 1, 2–4 touches = width 2, 5+ touches = width 3. Broken levels switch to dashed style and a muted color.

The label collision system operates in three stages: first, all enabled levels are collected into a sorted array; second, same-price levels are deduplicated based on priority (Monthly highest, Session lowest); third, an upward sweep enforces minimum vertical spacing using a blend of ATR and chart-range heuristics, ensuring labels never overlap regardless of market volatility.

───────────────────────────────────────────────────────

📊 Signals & States

This script is a visualization and data tool — it does not generate buy or sell signals.

Level states are communicated visually:

🔹 Active (solid line, full color): level has not been broken.
🔹 Touched (thicker line, 2–3px): level has been tested one or more times.
🔹 Broken (dashed line, muted slate color): level has been decisively closed through.

Info panel states:

🔹 Session: active market session (Asian / London / New York / Off-Hours / N/A on Daily+).
🔹 Near Above / Near Below: price of the closest active level on each side of the current close.
🔹 Dist Above / Below ATR: distance expressed as a multiple of ATR(14).
🔹 Touch and respect rate data for PDH, PDL, PWH, PWL.

───────────────────────────────────────────────────────

⚙️ Key Inputs

Level Groups: Toggle previous day, week, month, and session levels independently.
Session Times: Fully customizable start/end times for Asian, London, and New York sessions in exchange timezone.
Zone Style: Enable/disable S/R zones and adjust zone transparency.
Lines & Labels: Set line extension length, toggle labels, choose label density (All / Reduced / Minimal), set font size, and enable or disable same-price deduplication.
Info Panel: Toggle panel, set location (six positions), and choose theme (Dark / Light).
ATR Settings: Set ATR period and touch tolerance as an ATR multiple (0.02 to 0.50).

───────────────────────────────────────────────────────

📖 How to Use

1. Add the script to a chart — all major levels appear immediately.
2. Adjust session times if trading non-crypto markets.
3. Watch line thickness: thicker = more tested = stronger historical reaction zone.
4. Dashed + muted color = broken. Treat broken levels as potential new S/R from the opposite side (role reversal).
5. Use the panel's Near Above and Near Below fields to gauge proximity before entry or exit decisions.
6. Use "Reduced" density (default) for cleaner charts, or switch to "All" when you need session context.
7. Works on all asset classes: crypto, forex, equities, indices, commodities.

Recommended timeframes: 15m–4H for session levels; 1H–1D for previous-period levels.

───────────────────────────────────────────────────────

⚠️ Limitations & Transparency

🔹 Session tracking is session-relative and resets each new session.
🔹 Touch tolerance is an ATR-based heuristic and may need adjustment on extremely low-volatility instruments.
🔹 All data is historical. Touch count and respect rate describe past price behavior, not future outcomes.
🔹 This script is not a trading strategy, does not issue trade signals, and cannot predict market direction.
🔹 On exotic or illiquid instruments with large gaps, formation-bar zone boxes may appear truncated if the level formed outside the chart's visible range.

───────────────────────────────────────────────────────

🛡️ Risk Disclosure

This script is provided for informational and educational purposes only. It does not constitute financial advice, investment advice, or a recommendation to buy or sell any financial instrument. All trading involves risk. Past level behavior does not guarantee future results. Always use proper risk management and test any approach in a demo environment before committing real capital.
發行說明
UPDATE NOTES - v2.0

This update focuses on decision clarity, statistical honesty, and performance.

The core purpose of the script remains unchanged.
This release improves how the existing level logic is measured, presented, organized, and interpreted on the chart.

This script continues to function as an analytical and visualization tool.
It does not attempt to predict price direction or provide guaranteed outcomes.


------------------------
What Changed
------------------------

* Per-tier Level Hold engine
The single aggregated hold statistic was split into three independent, cumulative trackers: Daily, Weekly, and Monthly. Each tier now reports its own hold rate and its own sample size, so the panel shows how previous-day, previous-week, and previous-month levels have actually behaved on this chart and timeframe - separately.

* Honest, event-based touch counting
Touches now register once per visit: a touch is counted only when price newly enters the ATR tolerance band around a level, not on every bar spent inside it. Hold-tracking episodes open the same way. This removes the sample inflation of the previous version and makes both touch counts and hold sample sizes meaningful.

* Reaction Score (0 - 100) for the nearest level
The nearest visible level is now scored from four transparent components: tier weight (Monthly > Weekly > Daily > Session), that tier's historical hold rate (applied only when the sample reaches n >= 8, otherwise a neutral contribution so an unproven level is never overstated), freshness (unbroken vs already broken this period), and confluence (another visible level within 0.6 ATR).

* Focus Level decision card on the chart
When price comes within one ATR of the nearest level, a compact card appears on that level showing its name and price, its Reaction Score, and its tier hold rate with sample size. The card sits above or below the level on the side away from the candles.

* Clear next-action line
The panel now ends with a single action state that is always consistent with the score and distance: testing, approaching, broken - retest watch, or wait.

* Alerts added
Three alert conditions are now available: Key Level Test, Key Level Break, and High Quality Level Test (a test of a level with a high Reaction Score and a sufficient hold sample). Alerts are attention markers, not trade instructions.

* Fully non-repaint hold statistics
Hold-tracking episodes both open and resolve on confirmed bars only, with the level, ATR, and tolerance frozen at registration. The statistic never changes after the fact.


------------------------
Visual Improvements
------------------------

* Rebuilt the drawing lifecycle: the previous set of lines, zones, and labels is deleted before each refresh, so objects no longer accumulate during live updates and the chart stays clean and fast.

* Restructured the info panel around decisions: Session, nearest levels with ATR distance on a single row each, Focus Level, Reaction Score, the three-tier Level Hold proof block, and the action line.

* Replaced rows that were frequently empty early in a period (per-level respect percentages) with the cumulative per-tier hold statistics, which always carry data.

* Score and hold values are color-coded only when the sample size is sufficient (n >= 8); below that threshold they stay neutral instead of implying confidence.


------------------------
Interface & Usability
------------------------

* Level visibility is now fully consistent: the drawn levels, the panel proximity readout, and the focus engine all use exactly the same set of levels (group toggles plus density setting).

* Distance-to-level readouts were merged into the Near Above / Near Below rows for a tighter information flow.

* Added a "Show Focus Level Card" toggle so the decision card can be turned off for minimal charts.

* Removed unused internal code paths for a leaner, faster script.


------------------------
Behavior Notes
------------------------

This update does not change the core level-mapping logic of the script.

Touch counts and hold statistics will read differently than in the previous version because counting is now event-based; the new numbers are smaller and more truthful, not weaker.

Users should interpret outputs the same way as before, but with improved statistical context and a clearer visual structure.


------------------------
Limitations Reminder
------------------------

The script remains a rule-based analytical tool.

Hold statistics are measured on the current chart and timeframe only; different symbols and timeframes will produce different results.

Market conditions such as volatility, liquidity, and timeframe differences may affect how levels and statistics appear.

Outputs should always be interpreted within broader market context.


------------------------
Risk Reminder
------------------------

This script is for educational and analytical purposes only.

It does not provide financial advice or guaranteed trading outcomes.

Users remain responsible for their own decisions.

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。