OPEN-SOURCE SCRIPT
Aggiornato RPFXBYDAN - 3-Phase Gap Retest

This indicator identifies a three-phase price cycle — consolidation, liquidity sweep, and directional expansion — and highlights price imbalance zones created during the expansion phase. Entry signals are generated when price retests these imbalance zones from the correct side. Optional VWAP and trend filters help align signals with broader market bias. Designed for futures and index markets on intraday timeframes.
Note di rilascio
3-Phase Gap Retest Entry [RawPipsFX] v6Overview
This indicator identifies high-probability entry signals by detecting a specific three-phase sequence in price behavior: a consolidation range, followed by a liquidity sweep beyond that range, followed by a structural break back in the opposite direction that creates a price imbalance gap zone. Entries are triggered when price retests that gap zone from the correct side. The indicator is built for intraday futures trading, primarily on 1-minute and 15-minute timeframes on instruments like NQ and ES.
The Core Concept: Three-Phase Market Cycle
Markets frequently move through a repeating three-phase pattern before a directional move:
Phase 1 — Consolidation: Price compresses into a tight range for a configurable number of bars. The indicator measures this using a rolling highest/lowest calculation compared against a multiple of the Average True Range (ATR). When the range width falls below the ATR threshold, a consolidation zone is detected and drawn on the chart with a blue box.
Phase 2 — Liquidity Sweep: Price breaks aggressively beyond one side of the consolidation zone (exceeding it by a configurable ATR multiple), then recovers back inside on the same bar. This is identified by checking that the candle's body-to-wick ratio meets a minimum threshold — confirming the spike was rejected, not accepted. An optional volume filter can require that the spike bar's volume exceeds a moving average, adding further confirmation. The sweep is labeled "S" on the chart.
Phase 3 — Structural Break and Gap Zone: After the sweep, the indicator waits for price to close back through the consolidation range in the direction opposite the sweep. This close confirms the reversal and is labeled "Break" on the chart. Once the structural break is confirmed, the indicator scans for a price imbalance gap — a three-bar pattern where the current bar's low is entirely above the high of the bar two bars prior (for bullish gaps), or the current bar's high is entirely below the low two bars prior (for bearish gaps). This gap represents an area where price moved so quickly that no trading occurred between those two price levels, leaving an unfilled imbalance. This zone is drawn on the chart in green (bull) or red (bear).
Why These Components Are Combined
Each component serves a specific, non-redundant role in a sequential detection pipeline:
ATR provides adaptive, volatility-normalized thresholds throughout — the consolidation range width, the sweep depth, the structural break level, and the minimum gap size all scale with current market volatility rather than using fixed price values. This makes the indicator self-adjusting across different instruments and volatility regimes.
Volume confirmation (optional) adds an independent layer of conviction on the sweep candle, filtering out low-participation spikes that are less likely to represent meaningful liquidity events.
VWAP with standard deviation bands serves as a session-based trend and bias filter. When the VWAP filter is enabled, long signals are only permitted above VWAP and short signals only below VWAP. A second layer of the filter checks that the gap zone itself sits on the correct side of VWAP — not just that the close at retest time was above or below. This prevents bearish gap zones sitting above VWAP from firing short signals (and vice versa), which would represent counter-trend entries.
HTF EMA trend filter (optional) provides a higher-timeframe directional bias using three EMAs on a configurable timeframe. Signals in the direction of the higher-timeframe trend carry higher conviction.
Sequential State Machine
The detection engine operates as a strict five-state sequential gate. States advance only forward — a signal cannot fire without each prior phase being confirmed in order:
State 0: Idle — scanning for consolidation
State 1: Consolidation confirmed — scanning for sweep
State 2: Sweep confirmed — waiting for structural break
State 3: Break confirmed — scanning for price gap zone
State 4: Gap zone found — waiting for retest entry
If any phase times out (configurable bar limits for each transition), the machine resets to State 0. This prevents signals from firing based on stale setups.
While in State 4, if a wider gap zone forms in the same direction before the retest occurs, the zone is automatically upgraded to the newer, wider imbalance. This ensures the entry always uses the freshest and most significant level.
Entry Modes
Two signal modes are available via the "Signal on Gap Break" toggle:
Retest Mode (default): The signal fires when price first touches the gap zone from the correct side — low touches into the zone from above for longs, high touches into the zone from below for shorts — while the closing price holds at or within the zone. This signals that the zone is acting as support or resistance.
Break Mode: The signal fires only after price has first entered the zone AND then closes back out through the zone boundary in the expansion direction — confirming the zone held and rejected price. This is a more conservative filter.
Stop Loss and Take Profit
When SL/TP display is enabled, the indicator draws three lines on each signal:
Stop Loss is placed beyond the extreme of the sweep candle (the lowest low for bull setups, highest high for bear setups), plus an ATR buffer.
Entry is configurable as the top, midpoint, or bottom of the gap zone.
Take Profit is calculated as a fixed Risk/Reward multiple from the entry to the stop.
How to Use
Add to a 1-minute or 15-minute chart on NQ, ES, or similar liquid futures.
Start with all filters OFF (VWAP filter OFF, Trend filter OFF, Displacement OFF) to observe raw signal behavior.
Enable the VWAP filter to restrict signals to the correct side of the day's volume-weighted average price.
Enable the trend filter for an additional higher-timeframe directional bias if desired.
Use the "Gap Zone Created" alerts to be notified when a setup forms, before the entry signal fires.
Use the "Cycle Gap Entry" alerts for actual entry notification.
Recommended starting settings for 1-minute NQ: Accumulation Min Bars: 10, ATR Mult: 2.0, Sweep ATR x: 0.5, Structure Break: Midpoint, Min Gap Size: 0.05, Bars to find Gap: 20, Bars to retest: 40.
Developed by RawPipsFX. For educational purposes. Past signal frequency is not indicative of future performance.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.