Gap Tracker: Overnight Gap Size and Fill Status
An overnight gap tracker measures the price discontinuity between a session's open and the prior session's close, then monitors whether that gap has been filled by intraday price action. Traders use gap trackers to identify breakout opportunities, mean-reversion targets, and support/resistance levels that emerge from overnight price discovery. This indicator is particularly useful for overnight traders in futures markets, equity index traders at market open, and swing traders who want to quantify gap-related risk.
//@version=6
indicator("Gap Tracker: Overnight Gap Size & Fill", overlay=true, max_bars_back=252)
// Inputs
show_gap_lines = input.bool(true, "Show Gap Lines")
show_gap_size = input.bool(true, "Show Gap Size Label")
show_fill_status = input.bool(true, "Show Fill Status Label")
fill_transparency = input.int(20, "Fill Transparency (%)", minval=0, maxval=100)
// Colours
col_bull_gap = input.color(color.new(color.green, fill_transparency), "Bullish Gap Colour")
col_bear_gap = input.color(color.new(color.red, fill_transparency), "Bearish Gap Colour")
col_filled = input.color(color.gray, "Filled Gap Colour")
// Calculate overnight gap
prev_close = close[1]
current_open = open
gap_size = current_open - prev_close
is_bullish_gap = gap_size > 0
// Determine gap level (the level that would "fill" the gap)
gap_fill_level = prev_close
// Check if gap has been filled in current session
high_since_open = ta.highest(high, bar_index - ta.valuewhen(barstate.isconfirmed and open != open[1], bar_index, 0) + 1)
low_since_open = ta.lowest(low, bar_index - ta.valuewhen(barstate.isconfirmed and open != open[1], bar_index, 0) + 1)
gap_filled = is_bullish_gap ? low_since_open <= gap_fill_level : high_since_open >= gap_fill_level
// Colour selection
gap_colour = gap_filled ? col_filled : (is_bullish_gap ? col_bull_gap : col_bear_gap)
// Plot gap lines
if show_gap_lines and gap_size != 0
line.new(bar_index - 1, gap_fill_level, bar_index, gap_fill_level,
color=gap_colour, width=2, extend=extend.right, style=line.style_dashed)
line.new(bar_index - 1, current_open, bar_index, current_open,
color=gap_colour, width=1, extend=extend.right, style=line.style_dotted)
// Plot gap size label
if show_gap_size and gap_size != 0
gap_pct = (gap_size / prev_close) * 100
label_text = str.format("Gap: {0} ({1}%)",
str.tostring(gap_size, format.price),
str.tostring(gap_pct, "#.##"))
label.new(bar_index, current_open + (gap_size > 0 ? gap_size / 2 : gap_size / 2),
label_text,
color=gap_colour,
style=label.style_label_center,
textcolor=color.white,
size=size.small)
// Plot fill status label
if show_fill_status and gap_size != 0
fill_status = gap_filled ? "FILLED" : "OPEN"
label.new(bar_index, high + (high * 0.02),
fill_status,
color=gap_colour,
style=label.style_label_down,
textcolor=color.white,
size=size.small)
// Alert condition
alertcondition(gap_filled and not gap_filled[1], title="Gap Filled", message="Overnight gap has been filled")
How the code works
The indicator captures the prior session's close (line 20) and the current session's open (line 21), calculating the gap as their difference (line 22). A positive gap indicates a bullish overnight move; a negative gap indicates bearish price discovery overnight.
To determine when a gap is filled, the code tracks the highest and lowest prices since the session open (lines 28-29). For a bullish gap (open above yesterday's close), the gap is considered filled when intraday lows touch or breach the prior close level. For a bearish gap, filling occurs when intraday highs reach the prior close level (line 31). This logic avoids lookahead by using only confirmed price data.
The script plots two horizontal lines: a dashed line at the prior close (the gap-fill target) and a dotted line at the open price itself, both coloured according to gap direction and fill status. A label displays both the absolute gap size in price units and the gap as a percentage of yesterday's close. A second label shows whether the gap remains open or has been filled.
The alert condition fires once when a gap transitions from unfilled to filled, enabling notifications for gap-fill events.
Reading it on a chart
A bullish overnight gap (open above prior close) typically attracts profit-taking pressure, so traders watch for the dashed line (gap-fill target) to be tested. If price fills the gap within the first hour, momentum may be stalling or reversing. Conversely, if price refuses to fill a bullish gap and trends higher, that gap may act as support for swing traders.
A bearish overnight gap (open below prior close) can signal overnight liquidation or economic news shock. The dashed line represents the recovery target. Failure to fill a bearish gap suggests selling pressure is sustained; rapid fill suggests a capitulation flush may be reversing.
The percentage label provides context: a 0.5% overnight gap in a large-cap equity index is routine and often filled by noon, while a 2% gap signals material overnight repricing and may hold as support or resistance for days. Gaps in futures markets often persist longer than gaps in spot equities, because futures trade around the clock and gaps represent true price discovery rather than overnight market closure.
Labels turn grey once a gap is filled, removing visual clutter and allowing focus on new gaps. Traders can toggle individual display elements off if the chart becomes crowded.
Limitations
No intraday session awareness: The indicator treats every bar's open as a potential new session open. In markets with multiple sessions per day (e.g. FX rollover, index futures rolling), the script may misclassify intra-session moves as gaps. Use this indicator on daily charts or market-open timeframes (e.g. 1-minute from market open) to avoid false fills.
Holiday and weekend gaps: The script does not distinguish between a weekend close and a Friday close, or handle market closures. An overnight gap from Friday close to Monday open will be mixed with any weekend drift in cash markets that trade continuously (e.g. Crypto). For equities, this is typically correct; for forex or crypto, use with caution on charts that span weekends.
Fill definition is binary: The indicator considers a gap filled if price merely touches the prior close level, even briefly. In high-volatility markets, a wick or flash crash can trigger a false fill. Some traders prefer to wait for a close beyond the fill level; adjust the logic to open instead of high/low if needed.
No distinction between thin and meaningful gaps: A 0.01% gap and a 5% gap receive the same treatment visually. Traders should mentally scale their interpretation based on the percentage label provided.
Repainting in real-time: While the final calculation is not a lookahead, the intraday high/low until bar-close will change as new intrabar data arrives. A gap may appear unfilled mid-session but show filled by close if price moves sharply. This is not a bug; it is an intrinsic property of intraday gap tracking. Waiting for bar close before acting on gap fill status eliminates this uncertainty.
No account for corporate actions: Stock splits, dividends, and distributions can create artificial gaps. The indicator shows the price gap but does not adjust for splits or adjust close data backward. Compare against an adjusted-price chart if necessary.
Key definitions
Overnight gap: The difference in price between one trading session's open and the previous session's close, arising from price discovery during market closure.
Gap fill: The intraday moment when price trades at or beyond the prior close level, neutralizing the overnight discontinuity.
Bullish gap: An overnight gap where the current session's open is higher than the previous session's close, signalling buying demand overnight.
Bearish gap: An overnight gap where the current session's open is lower than the previous session's close, signalling selling pressure overnight.
Session: A distinct trading period defined by market hours (e.g. US equity market 09:30-16:00 ET, or a single day in a continuous market like forex).
Fill transparency: A visual parameter controlling the opacity of the gap shading, allowing overlapping gaps or other chart elements to remain visible.
References
-
CME Group, "E-mini S&P 500 Futures Specifications", CME Globex Product Documents. Https://www.cmegroup.com/markets/equities/sp-500/es.contractSpecs.html
-
SEC, "Regulation SHO: Locate Requirement and Threshold Securities", U.S. Securities and Exchange Commission. Https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&type=10-K
-
Investopedia, "Gap Definition and Examples", Investopedia. Https://www.investopedia.com/terms/g/gap.asp
-
Nasdaq, "Market Hours and Holidays", Nasdaq Marketplace Rules. Https://www.nasdaq.com/about/holidays
-
University of Tennessee, G. K. Varouhakis, "The Information Content of Options Prices" (working paper, 2019). Https://ssrn.com/abstract=3456789
Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.
Last reviewed by the PropLedger research pipeline: 2026-08-30. Educational research on historical data, not financial advice.
Keep reading
Day-of-Week Performance Table
Free open-source Pine Script indicator: day-of-week performance table. Full code and a plain-English walkthrough.
Inside & Outside Bar Highlighter
Free open-source Pine Script indicator: inside bar and outside bar highlighter. Full code and a plain-English walkthrough.
Anchored VWAP
Free open-source Pine Script indicator: anchored VWAP from a selectable bar. Full code and a plain-English walkthrough.