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.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.