OPEN-SOURCE SCRIPT
Gap Fill Engine [ES/NQ]

A session-open gap tool for index futures. It measures the RTH opening gap against recent daily range, classifies it by size, projects the prior RTH close as the fill target, and keeps a running tally of how often each gap class actually fills on your own chart.
What it does
At the RTH open the script compares the session's opening price to the prior session's closing price. If the gap clears a minimum tick filter, it is measured as a ratio of gap size to daily ATR and sorted into one of four classes — tiny, small, medium, or large — each with its own color.
The script then draws:
A shaded zone spanning the open and the prior close, colored by gap class
A dashed target line at the prior RTH close, the level that defines a fill
A label carrying the gap class and the live fill rate for that class on this chart
An on-chart table of counts and fill percentages by class, plus a separate breakdown of gaps that opened inside the prior session's range versus outside it
Every completed session updates the table, so the statistics are built from the symbol and timeframe you are actually looking at rather than from numbers hard-coded by me.
Why the inside/outside split matters
A gap that opens within the previous session's high–low range has price memory immediately behind it and tends to behave differently from one that opens beyond the prior range, where there is no recent trade to lean on. The script tracks the two populations separately so you can see the difference on your own data instead of assuming it.
Inputs
RTH session window and timezone
Minimum gap size in ticks, to skip noise
ATR length and the three ratio thresholds that separate the gap classes
Toggles for the zone, target line, labels, and statistics table
Table position and size
How I use it
Treat the target line as a reference level, not a signal. A tiny gap with a high historical fill rate on your chart is context for expecting a rotation back toward the prior close; a large gap beyond the prior range is context for expecting continuation and treating the fill as unlikely intraday. The table is there so you can check whether that intuition holds on the contract you trade before you act on it.
Built for ES and NQ, but the logic is symbol-agnostic and will run on anything with a defined session.
Notes
Fill statistics are descriptive of past bars on the loaded chart and carry no predictive guarantee. Results shift with the ATR length, thresholds, and history depth you load. This script is for chart analysis and education only, and is not financial advice or a recommendation to trade.
What it does
At the RTH open the script compares the session's opening price to the prior session's closing price. If the gap clears a minimum tick filter, it is measured as a ratio of gap size to daily ATR and sorted into one of four classes — tiny, small, medium, or large — each with its own color.
The script then draws:
A shaded zone spanning the open and the prior close, colored by gap class
A dashed target line at the prior RTH close, the level that defines a fill
A label carrying the gap class and the live fill rate for that class on this chart
An on-chart table of counts and fill percentages by class, plus a separate breakdown of gaps that opened inside the prior session's range versus outside it
Every completed session updates the table, so the statistics are built from the symbol and timeframe you are actually looking at rather than from numbers hard-coded by me.
Why the inside/outside split matters
A gap that opens within the previous session's high–low range has price memory immediately behind it and tends to behave differently from one that opens beyond the prior range, where there is no recent trade to lean on. The script tracks the two populations separately so you can see the difference on your own data instead of assuming it.
Inputs
RTH session window and timezone
Minimum gap size in ticks, to skip noise
ATR length and the three ratio thresholds that separate the gap classes
Toggles for the zone, target line, labels, and statistics table
Table position and size
How I use it
Treat the target line as a reference level, not a signal. A tiny gap with a high historical fill rate on your chart is context for expecting a rotation back toward the prior close; a large gap beyond the prior range is context for expecting continuation and treating the fill as unlikely intraday. The table is there so you can check whether that intuition holds on the contract you trade before you act on it.
Built for ES and NQ, but the logic is symbol-agnostic and will run on anything with a defined session.
Notes
Fill statistics are descriptive of past bars on the loaded chart and carry no predictive guarantee. Results shift with the ATR length, thresholds, and history depth you load. This script is for chart analysis and education only, and is not financial advice or a recommendation to trade.
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.