OPEN-SOURCE SCRIPT

Prior Level Reaction & Retest Profiler

303
Short description
An evidence-based profiler for first touches, reactions, breakouts, and confirmed retests at previous-day and previous-week highs and lows, with ATR-normalized outcomes and volatility-regime statistics.

Overview
Previous-day and previous-week highs and lows are widely used as support, resistance, breakout references, and liquidity levels. However, drawing these levels does not answer the practical question: how has this symbol historically behaved after first reaching them?
Prior Level Reaction & Retest Profiler converts each first interaction with PDH, PDL, PWH, and PWL into a measurable event. It records whether price moved away from the level, continued through it, produced a false-break reaction, remained unresolved, or formed a confirmed breakout retest. All distances are normalized with the previous completed daily ATR so observations remain comparable across changing volatility conditions.
This is a descriptive research and decision-support tool. It does not issue automatic buy or sell signals, and historical frequencies are not presented as predictions.

What the indicator measures

For every enabled level, the script selects one first-touch observation during that level's valid daily or weekly period. At the moment of contact, it freezes both the level and the previous completed daily ATR.
For a prior high:
Movement below the level is measured as reaction excursion.
Movement above the level is measured as breakout excursion.
For a prior low, those directions are reversed.
The event is then classified as:
Reaction: The configured reaction threshold is reached first.
Breakout: The configured breakout threshold is reached first.
False-break reaction: Price closes through the level but reaches the reaction threshold before the breakout threshold.
Ambiguous: Both thresholds are reached on the same evaluation bar, so their order cannot be determined from OHLC data.
Unresolved: Neither threshold is reached before the evaluation horizon ends or the source level expires.
Reaction and breakout percentages use directionally resolved observations as their denominator. The dashboard also displays the total sample, ambiguous observations, unresolved observations, and average maximum excursions in daily ATR units.

Why evaluation begins after the touch bar
Historical OHLC bars do not reveal whether the high or low occurred first. Counting the touch bar could therefore invent a sequence that is not present in the data. This script begins outcome evaluation on the following bar and explicitly preserves same-bar dual-threshold outcomes as ambiguous rather than guessing.

Breakout retest engine
When completed history favors breakout over reaction for a level, the optional retest engine follows a confirmed close through that level using a transparent state sequence:
Retest pending: A breakout close occurred and the engine is waiting for price to return.
Retest in progress: Price entered the ATR-normalized retest zone but has not yet confirmed.
Retest confirmed: Price touched the zone and produced a confirmed close back in the breakout direction. Users can optionally require a directional confirmation candle.
Target reached or invalidated: After confirmation, the script records whether the configured ATR target was traded before a confirmed close beyond the invalidation boundary.
Only confirmed chart bars change retest states. A confirmation by itself is not counted as a successful retest. Retest success is calculated only from completed post-confirmation target and invalidation outcomes.

Volatility-conditioned evidence
Retests are not assumed to behave identically in every volatility environment. When regime conditioning is enabled, the script stores the volatility regime present when the breakout setup begins and maintains separate target/invalidation histories for:
Low volatility: Previous daily ATR is at or below 0.80 of its 100-day average.
Normal volatility: The ratio is between 0.80 and 1.20.
High volatility: Previous daily ATR is at or above 1.20 of its 100-day average.
The live decision gate uses only the matching regime's completed retests. It does not borrow confidence from unrelated volatility conditions.

Evidence gate
The simple dashboard prevents attractive headline statistics from being mistaken for a tradable edge.
Observe only: The matching volatility regime has fewer completed retests than the configured minimum.
Stand aside: The sample is sufficient, but target-before-invalidation success is below the configured requirement.
Retest pending / in progress: The evidence gate passes, but confirmation is not complete.
Retest confirmed: The evidence gate passes and the required retest close is confirmed.
Target reached / invalidated: The live confirmed setup has completed.
For example, a level can have a high general breakout rate while its low-volatility retests have a poor success rate. In that situation, the dashboard shows Stand Aside rather than promoting the broader breakout statistic.

Display modes
Simple mode is the default. It shows only the current level segments and a plain-language decision card containing:
Setup
Active level
What to do now
Required confirmation
Invalidation condition
Supporting sample and regime evidence
Only the latest confirmed retest marker is displayed by default. Historical markers can be enabled for auditing.
Evidence mode shows the complete PDH, PDL, PWH, and PWL matrix with sample count, reaction rate, breakout rate, false-break rate, ambiguous and unresolved shares, and average excursions.

Main settings

Daily ATR length
Reaction and breakout thresholds in ATR units
Evaluation horizon in chart bars
Previous-day and previous-week level toggles
Retest-zone width and retest window
Optional directional confirmation candle
Minimum completed retest sample
Minimum acceptable retest success rate
Volatility-regime conditioning
Simple or Evidence display mode
Static and dynamic alerts
Changing chart timeframe changes the real duration represented by the bar-based evaluation and retest windows. Statistics should therefore be compared only when symbol, timeframe, and settings are consistent.

Alerts
Named alerts are available for:
First level touch
Reaction or breakout outcome
False-break reaction
Ambiguous outcome
Breakout close with retest pending
Retest confirmation
Retest failure or expiry
Confirmed-retest target reached
Confirmed-retest invalidation
Dynamic messages can be used by enabling the dynamic-alert setting and creating an alert with Any alert() function call.

Repainting and data behavior
Previous-day, previous-week, daily ATR, and ATR-average values are requested with a one-period offset. Only completed higher-timeframe values are used; no future data is accessed.
Retest state changes require confirmed chart bars. Once a historical event or retest outcome is finalized, its classification does not change. Active events can update as new bars close.

Limitations
Designed primarily for intraday charts.
OHLC data does not reveal intrabar high/low order; ambiguous cases are retained explicitly.
Gap openings can cross a level without trading every intervening price.
Available chart history and data-feed differences affect samples.
Regime-filtered samples can be considerably smaller than overall samples.
The reference target uses traded price, while post-confirmation invalidation requires a confirmed close.
Spread, slippage, commissions, liquidity, position sizing, and execution constraints are not modeled.
Historical behavior does not guarantee future results.
This indicator is not financial advice.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.