OPEN-SOURCE SCRIPT

Pullback Value Recovery [PhenLabs]

3 585
📊 Pullback Value Recovery [PhenLabs]

Version: Pine Script™ v6

📌 Description

Pullback Value Recovery identifies a specific continuation sequence: a fresh breakout impulse, an established pullback, and a confirmed recovery. Instead of calling every dip a buying opportunity or every bounce a short, it waits for price to recover two separately measured price averages and clear the previous candle.

The two averages follow different groups of bars. One contains closes advancing with the original impulse; the other contains closes retracing against it. Here, “value” means these conditional HLC3 averages, not fair value, institutional positioning, or actual buying and selling pressure.

A qualifying recovery prints one directional marker and a fixed reference-close, structural-stop, 1R and 2R map. If the recovery is too extended or its stop is too wide, the episode is consumed without a signal, and the dashboard explains the rejection.

🚀 Points of Innovation
  • Two role-conditioned means: advance and retracement bars are accumulated separately after a confirmed seed, rather than blended into one whole-leg VWAP.
  • Preparation before recovery: a pullback must establish sufficient adverse bars and depth before a later candle can confirm recovery.
  • Prior-band testing: the recovery candle is tested against averages known before it formed. It cannot move its own confirmation threshold.
  • Whole-episode volume fallback: missing volume switches both averages to complete equal-bar histories, rather than mixing volume weights with arbitrary unit weights.
  • Explicit skip semantics: the first prepared structural recovery either produces a plan or is rejected. The same setup cannot issue repeated “second chance” signals.


🔧 Core Components
  • Impulse seed: a confirmed close breaks the prior rolling range, its directional body meets the ATR threshold, and it closes in the candle's outer quarter.
  • Advance mean: uses HLC3 from bars whose close-to-close movement agrees with the seed direction. The seed itself belongs to this group.
  • Retracement mean: uses HLC3 from bars whose close-to-close movement opposes the seed. Unchanged closes are excluded from both groups.
  • Local pullback: adverse-bar count and the pullback extreme reset after a close beyond the earlier running directional extreme. The cohort means remain anchored to the seed.
  • Recovery gate: after preparation, a long closes beyond the prior upper cohort mean plus a buffer AND above the previous candle high. A short closes below the prior lower mean minus a buffer AND below the previous candle low.
  • Risk map: the signal close is the reference price. The stop sits beyond the signal-inclusive pullback extreme; 1R and 2R are arithmetic references from that distance.


🔥 Key Features
  • Separate, clearly named bullish and bearish confirmed-recovery alerts.
  • Numeric event and state plots for Pine Screener workflows.
  • No external symbol requests, lower-timeframe requests, imported libraries, or footprint dependency.
  • Visible weighting mode, waiting state, rejection reason, and ignored-seed count.
  • One active setup or observed plan at a time, with capped historical maps.
  • Confirmed-bar state changes and fixed reference levels.


🎨 Visualization
  • Blue-violet line: advance-cohort mean.
  • Amber line: retracement-cohort mean. The means may cross; neither color represents buy/sell delta.
  • Faint ribbon: the interval between the cohort means while a setup is developing.
  • Teal / coral triangles: accepted long / short recovery events.
  • Dashed lines: reference close and structural stop. Dotted lines: 1R and 2R.
  • Short shaded map: analytical risk/reward regions. A resolved map stops growing; its prices remain fixed.
  • Retained status: REF | SL means stop threshold breached; REF | 2R means 2R reached/exceeded; ? is same-bar ambiguity; EXP is unresolved expiry; DATA is unknown. Hover the reference label for details. These are observations, not realized trading results.
  • Dashboard: detailed state information without covering the chart in labels. Table Size offers Compact, Normal, and Large.


📖 Usage Guidelines

Setup
  • Breakout lookback: default 20, range 5–100. Shorter windows admit more local breaks; longer windows require a broader range break.
  • Impulse body / ATR: default 0.65, range 0.20–2.00. Uses ATR(14) from BEFORE the seed and a directional body, not absolute candle size.
  • Retracement bars: default 2, range 1–6. Counts adverse closes within the local pullback; they need not be consecutive.
  • Setup expiry bars: default 48, range 10–150. Seed age is zero; age 48 expires before recovery, leaving default opportunities at ages 1–47.
  • Mean weighting: Auto uses reported chart volume; Equal bars ignores volume intentionally. Auto falls back for the entire episode if an included bar has missing or nonpositive volume.


Recovery filters
  • Maximum chase / ATR: default 1.00, range 0.10–3.00. Distance beyond the tested prior outer cohort mean.
  • Maximum stop distance / ATR: default 2.50, range 0.25–6.00. Rejects oversized reference-close-to-stop distance.
  • Plan observation bars: default 30, range 5–100. Observes only bars AFTER the signal. Threshold events on the final observation bar take priority over expiry.


Chart presentation
  • Show risk / reward maps: on by default. Hiding drawings does not disable plan observation or its busy state.
  • Initial map length: default 12, range 4–30. An unresolved map grows to the current bar only after that initial length.
  • Retained maps: default 6, range 1–12, including the active map. Older drawing objects are removed first; plotted recovery markers remain.
  • Show seed markers: off by default to keep the chart clean.
  • Show dashboard: on by default.
  • Table Size: Compact by default; Normal and Large are available. Map-dependent and dashboard-dependent controls are grayed out when inactive.


Fixed rules
  • Minimum pullback depth: 0.35 of frozen seed ATR.
  • Recovery buffer: 0.05 ATR beyond the prior outer cohort mean.
  • Origin invalidation and structural-stop padding: 0.10 ATR.
  • Cooldown: the next 8 bars after an accepted or rejected recovery attempt.
  • Only a fresh qualifying breakout burst can seed. Impulses while busy are ignored, never queued.


✅ Best Use Cases
  • Structuring a discretionary pullback-continuation review on standard candles.
  • Separating an unprepared pullback, an armed recovery, and an overextended entry.
  • Keeping reference risk visible without a dense multi-indicator layout.
  • Scanning event/state plots, then inspecting the underlying chart and data mode.


⚠️ Limitations
  • This is a pattern detector and analytical map, not a strategy backtest. No profitability, win rate, or accuracy is established.
  • The signal close is a reference, not proof of an executable fill. Gaps may breach a threshold without trading at its exact price.
  • If stop and 2R are both observed in the same candle, the result is marked ambiguous. OHLC does not establish which happened first.
  • 1R is informational. There is no automatic partial exit, stop-to-breakeven, trailing stop, or position sizing.
  • One active episode or plan intentionally blocks other opportunities. The dashboard reports fresh seeds ignored while busy.
  • Reported volume can be tick volume or venue-specific volume. These groups do not identify buyers, sellers, absorption, or order flow.
  • On a fallback transition, the switch bar cannot signal. The indicator does not manufacture a delayed catch-up event.
  • Parameters, loaded-history initialization, revised data, and nonstandard chart types can change the result. Use standard candles for acceptance testing.
  • Signals are evaluated on confirmed bars using information available through that close. Recorded events and fixed plan prices remain unchanged under unchanged inputs, data, and initialization; active means and observation endpoints continue to develop by design.
  • No setup is a valid state. Consult the dashboard before loosening filters; more signals are not evidence of a stronger edge.


💡 What Makes This Different
  • The distinction is the advance-versus-retracement partition and the causal recovery sequence, not a renamed moving average or a decorative score.
  • The two means are role-conditioned across the entire episode, while local pullback readiness resets. This avoids carrying an old pullback stop into every later shallow dip.


⚙️ Under the Hood
  • Conditional anchored accumulators: each cohort keeps sum(HLC3), bar count, sum(HLC3 × volume), and sum(volume). The selected mean is the corresponding ratio. Only bars assigned to that cohort contribute.
  • Typed episode and plan objects: Pine user-defined types keep the anchor, direction, extrema, preparation latch, and drawing handles together. A bounded UDT array deletes the oldest maps first.
  • Causal state ordering: the bar's starting phase decides its processing branch. Origin invalidation and expiry precede recovery, and accepted plans are not observed until the next bar.
  • Prepared latch: enough retracement count/depth plus a close not beyond the buffered band arms a later recovery. This does not require a full traversal from below BOTH means, and the rail crossing need not coincide with the prior-candle break.
  • Data mode: core calculations need only chart OHLC and optional reported volume. Missing volume has an equal-bar fallback; missing required price data invalidates preparation or makes an active plan unknown. No premium data call is embedded.
  • Screener & alerts: “PVR Event (+1 long, -1 short)” is +1 or -1 only on an accepted event bar and 0 otherwise. “PVR Armed Direction” exposes +1/-1 for prepared setups. “PVR Phase” is 0 idle, 1 setup, 2 plan. Alerts are “PVR: Long recovery confirmed” and “PVR: Short recovery confirmed”; use Once Per Bar Close. Pine Screener availability and history limits remain subject to TradingView's plan/product rules.


🔬 How It Works
  1. A fresh directional breakout starts an episode and freezes its ATR benchmark.
  2. Advancing and retracing closes feed separate seed-anchored price averages.
  3. The local pullback establishes adverse-bar count, sufficient depth, and a prepared close relative to the cohort band.
  4. A later close recovers the prior band and clears the previous candle boundary.
  5. Chase and stop-distance filters either accept that first structural recovery or consume it as a skipped setup.
  6. An accepted event fixes the analytical map. Subsequent bars resolve it by stop threshold, 2R threshold, ambiguity, data invalidity, or time expiry.


💡 Note:
Start with default settings, inspect both directions, verify symbol-scale attachment, and compare replay/reload behavior before relying on alerts. This tool is an analytical aid, 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.