Opening Range & Key Levels [AFD]Opening Range & Key Levels is an open-source Pine Script version 6
indicator for studying how price behaves around configurable opening ranges
and reference levels. It tracks up to five opening-range windows, optional key
levels, optional volume-weighted average price (VWAP) and volume-weighted
moving average (VWMA) context, and an optional dashboard.
The script is descriptive. It reports confirmed break/retest events and state
changes; it does not provide trade instructions, performance claims, or
probability estimates. Break/retest events use confirmed chart bars. The
developing range updates while its window is open, including the live forming
bar, and locks on the first confirmed bar at or after the configured window
end. The script uses current chart data only and contains no request.security()
calls.
Quick start
Default — Starts with the 60-minute Opening Range (OR) #4 selected, plus the default day/session levels.
Minimal — Starts with the 60-minute OR only; the preset suppresses key-level rows.
Full — Forces all five OR slots on. Key-level and VWAP visibility remains controlled by those inputs.
Custom — Uses the individual OR, key-level, VWAP, and other inputs for a custom layout.
The OR slot checkboxes remain usable with the Default and Minimal presets.
Switch to Custom when you want a preset-independent configuration.
Opening-range lifecycle
FORMING — The high and low update while the window is open, including the live forming bar, from the exchange-session open until the configured window ends.
LOCKED — The range freezes on the first confirmed bar at or after its window ends. Extension levels use the frozen range width.
BROKE UP or BROKE DOWN — A confirmed close must cross the OR high or low. A wick alone does not establish a break. Each direction is tracked once per session.
RETEST — Price entering the selected tolerance band is TESTING. HELD means a confirmed close returns beyond the broken level in the breakout direction. FAILED means a confirmed close returns inside the range.
EXTENSION — Optional 0.5x, 1.0x, 1.5x, and 2.0x measured-move projections are drawn from the locked longest enabled opening range. The 1.0x reached state is touch-based rather than close-based.
After a failed retest, the opposite breakout direction can be evaluated later
in the same session. The range engine records what happened; it does not turn
the state into a recommendation.
Theory labels and Auction Market Theory (AMT) context
A duration of exactly 15 minutes receives the Toby label, regardless of which OR slot contains it.
A duration of exactly 60 minutes receives the AMT Initial Balance (IB) label, regardless of which OR slot contains it.
The 60-minute row can add day-type context when the range is locked and valid: TREND up, TREND down, NEUTRAL DAY, or NORMAL DAY.
The AMT hover text explains the first hour as the Initial Balance. Inside the IB is described as Balance/Rotation, while one-side or both-side extensions provide the related day-type context.
Key levels
The script provides 17 standard key-level references plus an optional gap-fill
level. The abbreviations are grouped by the context they describe. Overnight
High (ONH) and Overnight Low (ONL) track the overnight session. Prior-day
references are Prior Day Open (PDO), Prior Day High (PDH), Prior Day Low (PDL),
and Prior Day Close (PDC). Current Session Open (OPEN) marks the current
session's open. Pre-Market High (PMH) and Pre-Market Low (PML) track the
pre-market extremes.
Prior Week High (PWH) and Prior Week Low (PWL), together with Current Week High
(CWH) and Current Week Low (CWL), provide weekly references. Prior Month High
(PMoH) and Prior Month Low (PMoL), together with Current Month High (CMoH) and
Current Month Low (CMoL), provide monthly references. GAP is the Price Gap /
Gap Fill level.
The GAP level appears only when the opening gap meets the configured minimum
percentage. It can be shown as a line or zone, with fill tracking.
Key levels support individual enable, color, style, width, label, and price
controls. Static key levels use the same confirmed-close break and average
true range (ATR)-based retest tolerance concepts as the opening ranges.
Current week/month extremes and GAP have their own data-state handling.
ONH, ONL, PMH, and PML need extended-hours (ETH) data. If overnight data is
unavailable, those levels are hidden. The dashboard specifically reports
missing ONH/ONL data when that condition is detected. Weekly and monthly
references are calendar-period trackers built from chart data; they are not
imported with request.security().
Dashboard
The dashboard is off by default. When enabled, its normal layout reads from
top to bottom as OR rows, BIAS (the range-position read), and broken key-level
rows.
OR rows separate BREAK, RETEST, TREND, and price/details cells so each status can use the correct color.
In Directional mode, a break up or TREND up is green, a break down or TREND down is red, RETEST HELD is green, RETEST FAILED is red, and RETEST TESTING is yellow.
Individual key-level rows show TREND as N/A because trend classification applies to the 60-minute AMT context, not to a single key level.
The BIAS row compares the current close with the longest enabled OR. Above OR is an imbalance above the range, below OR is an imbalance below the range, and INSIDE OR means Balance/Rotation.
The BIAS row can also include the opening-gap read, GAP fill information when GAP is enabled, and the intraday VWAP when it is enabled.
Neutral mode changes status text to neutral white or gray tones instead of directional colors.
Default visual settings
OR #4 is selected by default and is set to 60 minutes. OR #1, OR #2, OR #3, and the seconds OR are off by default.
All opening-range extensions are off by default.
The mid line, OR break/retest event labels, right-edge status tag, and dashboard are off by default.
Range boxes, OR/extension tags, and prices in OR tags are on by default.
Key-level break/retest event labels are off by default. The dashboard's broken key-level rows are a separate display option.
Breakout and retest controls
Retest tolerance supports Daily ATR, Intraday ATR, and Fixed Ticks. The default mode is Daily ATR with a 0.1 multiplier; Daily ATR uses a fixed 14-session RMA. Intraday ATR uses the configurable ATR length, defaulting to 14 bars.
The optional killzone filter suppresses breakout and retest processing inside a user-defined exchange-time window.
The optional OR width filter suppresses OR events when a locked range is outside configured multiples of daily ATR and marks it WIDTH FILTERED.
The optional volume confirmation compares breakout volume with a configurable multiple of the 20-bar average and can drive its own alert.
VWAP and VWMA
Intraday VWAP resets at the exchange-session open.
Overnight VWAP resets at the prior session close.
Continuous VWMA does not reset and uses a configurable length, defaulting to 20.
All three are optional and off by default.
Alerts
The script provides six Opening Range (OR) alert conditions and four key-level
(KL) alert conditions. All break and retest conditions describe confirmed
crossings or confirmed retest outcomes.
OR Break Up
OR Break Down
OR Retest Held
OR Retest Failed
OR Extension 1.0x Reached
OR Break Volume-Confirmed
KL Break Up
KL Break Down
KL Retest Held
KL Retest Failed
Dynamic alert text can include the symbol, OR duration, event, and price. To
receive dynamic messages, create an alert on this indicator and select Any
alert() function call. The fixed-text alert conditions remain available in
PulseWire's alert dialog.
How to use
Add Opening Range & Key Levels to a standard time-based chart and allow enough history for the selected session and reference levels.
Start with the Default preset, or switch to Minimal, Full, or Custom.
Choose the OR windows and key levels that match the session you are studying.
Select the retest tolerance that fits the instrument and timeframe.
Enable the dashboard, extensions, event labels, VWAPs, or key-level events only when those additional views are useful.
Create alerts from the indicator's fixed conditions or select Any alert() function call for dynamic alert text.
Limitations and disclosures
The script is single-timeframe. It does not import higher-timeframe values with request.security(). A 60-minute OR can still be built from smaller chart bars; the chart timeframe must be appropriate for the selected window.
The seconds OR slot requires a seconds chart, such as 30S or lower for a 30-second window. Larger timeframes show a timeframe warning instead of producing a false precision.
ONH, ONL, PMH, and PML depend on an extended-hours data feed. Twenty-four-hour markets without an exchange-session boundary may not provide the intended overnight segmentation.
The current-day close is not plotted during the session because it does not exist yet.
Drawing history and object counts are bounded by Pine limits. The source declares maximum budgets of 200 lines, 100 labels, and 50 boxes.
This is an informational chart tool. It does not provide entries, exits, stops, targets, or performance guarantees.
Originality and license
The script combines configurable multi-window opening ranges, confirmed-close
break/retest tracking for both opening ranges and key levels, AMT Initial
Balance context, and a dashboard with separate break, retest, trend, and bias
readouts in one single-timeframe indicator. The source is open and available
for inspection under the Mozilla Public License 2.0.
Indicator


