OPEN-SOURCE SCRIPT
Güncellendi

Fixed Range Control Box [AGPro Series]

1 733
Fixed Range Control Box [AGPro Series]

🔹 Overview

Fixed Range Control Box isolates a single high-conviction price range on your chart and classifies who is in control inside it. The tool draws one clean hero box around the most recent structural range, places a volume-weighted Control Line inside it, and tracks state transitions in real time: Inside, Upper, Lower, or Failed. When price structurally breaks the box, the range freezes, locking the reference so you can study the aftermath without visual drift.

Four range-definition modes are available — Pivot, Lookback, Compression, and Manual-Date — so the tool adapts to discretionary range traders, systematic rotation traders, and anyone who wants a fixed reference zone for backtesting or journaling.

🔸 Unique Edge

Most range tools on TradingView draw many boxes and leave the user to guess which one matters. Fixed Range Control Box is built around a different philosophy: one range, one story, one decision. The hero box is the visual focus; historical ranges fade into the background; the Control Line tells you which side of the range is winning the statistical argument.

Three design choices separate this from standard range-box scripts:

- Volume-weighted Control Line. Rather than dropping a midpoint line, the Control Line is computed from the volume-weighted typical price across the life of the range, with an edge-fallback to midpoint if the line drifts too close to either boundary. This produces a structurally meaningful reference instead of a geometric one.
- Retrospective fill on range rebuild. When a new range is committed, the script walks back through the range window and retroactively computes touch count, hold quality, and the Control Line. You see a fully-formed box with accurate statistics the moment it appears, not an empty box that slowly populates.
- Freeze-on-failure. When price closes beyond the range and the state transitions to Failed, the box locks at the break bar. No more drifting endpoints on broken structures — the reference stays where the story ended.

🔷 Methodology

The script cycles through four stages on every bar:

1. Range detection. Depending on the selected mode, the script looks for a qualifying range: confirmed swing pivots (Pivot), rolling highest/lowest (Lookback), short-ATR over long-ATR compression (Compression), or a user-defined date window (Manual). Gating rules — minimum lifespan, minimum width percentage, and a failed-state cooldown — prevent rapid re-triggers on noisy conditions.
2. Commit and retrospective fill. Once a range qualifies, the script snapshots the old range into history, installs the new one, and walks back through the window to compute the Control Line, touch count, and hold quality in a single pass. No warm-up period.
3. State machine. Each confirmed bar feeds the state machine. Strict logic requires bar closes on one side of the Control Line for the configured number of bars before switching to Upper or Lower; a close beyond either range boundary transitions to Failed.
4. Rendering. On the last bar, the hero box, Control Line, origin marker, and state badge are rebuilt from scratch. Historical ranges persist as muted boxes up to a configurable cap.

🔶 Signals & Alerts

Three alert conditions cover the full range lifecycle:

- New Control Box. Fires once per bar close when a new range is committed.
- Line Reclaimed (Bull or Bear). Fires when state transitions into Upper or Lower control, confirming directional bias inside the range.
- Control Failed. Fires once when price closes beyond the range and the box is frozen.

All alerts use alert() calls with once-per-bar-close frequency.

🔹 Key Inputs

- Range Mode — Auto-Pivot, Auto-Lookback, Auto-Compression, or Manual-Date.
- Pivot Length / Lookback Bars / Compression Window — window controls for each detection mode.
- Min Range Lifespan / Min Range Width % — structural filters to suppress micro-ranges.
- Failed Cooldown — bars to wait after a broken range before searching for a new one.
- Strict Control Logic + Reclaim Confirmation — governs how the Control Line state machine transitions.
- Visual controls — fade old boxes, max boxes kept, show state badge, show range origin, future projection bars, panel and label font sizes.

🔸 How to Use

1. Start on your primary timeframe and select the Range Mode that matches your style: Pivot for discretionary swing structures, Lookback for mechanical windows, Compression for auto-locking onto consolidations, Manual-Date for backtesting a specific episode.
2. Tune Min Range Width % and Min Range Lifespan so only structurally meaningful ranges appear.
3. Read the panel top-down: Mode confirms what you are tracking, Control tells you which side of the Control Line is winning, Range Age and Touches describe maturity and confluence, Hold Quality summarizes how cleanly price has respected the range, and State shows the live classification.
4. Use alerts to monitor the range lifecycle without staring at the chart.

🔻 Limitations & Transparency

- This is an analytical tool, not a strategy. It does not generate buy or sell recommendations and does not compute entries, stops, or targets.
- Past range behavior does not forecast future range behavior. Structural breaks can occur at any time.
- In very thin or illiquid markets, the volume-weighted Control Line can drift toward a boundary; the edge-fallback defaults to midpoint to protect against degenerate cases.
- Auto-Compression mode requires sufficient ATR history; expect a warm-up period on very recent symbols.
- The script is overlay-only and does not access other timeframes.

🔶 Risk Disclosure

Nothing in this script constitutes financial advice. Trading involves substantial risk of loss and is not suitable for every investor. Always do your own research and manage risk appropriately.
Sürüm Notları
UPDATE NOTES - V1.1

This update focuses on source cleanup, centered range ownership, panel standardization, and publication readability.

The core purpose of the script remains unchanged.
This release improves how the fixed range, volume-weighted control line, control state, historical boxes, and panel are presented 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
------------------------

* Cleaned the source header and footer.
The script now follows the current AGPro public-free source format without an extra header or footer block.

* Preserved the Fixed Range Control Box engine.
Range modes, pivot/lookback/compression/manual range logic, volume-weighted control line, strict/loose reclaim logic, failed-range freezing, touch count, hold quality, historical boxes, and alerts remain intact.

* Added a centered control-box badge.
The active range can now display a separate centered badge such as BULL CONTROL / BOX, BEAR CONTROL / BOX, NEUTRAL / CONTROL BOX, or FAILED / CONTROL BOX.

* Added standard panel controls.
Panel show/hide, panel location, panel theme, and panel font-size controls now follow the current AGPro format.

* Expanded label and panel font-size controls.
Font-size controls now include Tiny, Small, Normal, Large, and Huge.


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

* Active control boxes now read as owned zones instead of generic rectangles.

* Centered badges clarify who controls the active range at first glance.

* Historical boxes remain muted so the active control box stays dominant.

* Panel layout now follows the single merged blue header standard.


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

* Added Elite Dark, Slate, and Clean Light panel themes.

* Expanded panel locations to include top, middle, and bottom center positions.

* Added live panel repositioning with table.set_position.

* Panel header now follows the AGPro render order: table.clear -> table.merge_cells -> header.

* Show Panel now deletes the panel cleanly when disabled.


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

This update does not change the core analytical logic of the script.

Outputs should still be read as fixed range context, control-line behavior, hold quality, and control state mapping.

The goal is to improve clarity and usability, not to introduce predictive behavior.


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

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, timeframe differences, pivot sensitivity, and volume quality may affect how ranges and control states 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.
Sürüm Notları
🔧 UPDATE NOTES - v1.3

This update focuses on label contrast and readability.

The core purpose of the script remains unchanged. It still isolates a single
high-conviction range, classifies control through a volume-weighted control
line, and reports range age, touches, hold quality and state through a clean
panel and a centered control-box badge.

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
------------------------

• Meaningful, dynamic Hold Quality
Hold Quality previously measured whether closes stayed inside the range, which
is true by construction while a range is active, so it sat at ~100% and never
moved. It now measures conviction: the share of range bars that closed on the
side currently in control (above the control line for Upper control, below it
for Lower, and the dominant side while Inside/Neutral). The reading now varies
from roughly 50% (contested, weak control) to high values (decisive one-sided
control), and the panel cell colors accordingly.

• Contrast-aware label and panel text
The centered control-box badge, the right-side state tag and the colored panel
cells now choose their text color from the background luminance. Previously the
text was always light, which read poorly on the brighter state colors (bearish
pink and neutral amber). Every state now reads crisply.


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

• Higher-contrast centered badge, state tag and panel control cell across all
states (Bull, Bear, Neutral, Failed).

• No change to box geometry, control line, origin marker or historical box
fading.


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

• Panel readability improved on every theme without changing its layout:
Mode, Control, Range Age, Touches, Hold Quality, State.


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

This update does not change any range detection, control-line or reclaim logic.
The Hold Quality metric was redefined to measure control conviction instead of
a near-constant in-range check, and on-chart and panel text-color handling was
adjusted for contrast. All other outputs are interpreted as before.


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

The script remains a rule-based analytical tool. Market conditions such as
volatility, liquidity and timeframe differences may affect how ranges and
control states 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.

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.