Gap Scanner Table

TradingView Lab Tool

What is the Gap Scanner?

The Gap Scanner is your primary tool for "Gapping" strategies. It filters your watchlist to show which stocks have moved the most overnight relative to their previous close. This allows you to identify morning breakouts or "Gap and Crap" reversals before the market even opens.

  • Automatic Calculation: Instantly calculates the % gap from Yesterday's Close to Today's Open.
  • Color-Coded Data: Positive gaps are highlighted in green, while "Gap Downs" are highlighted in red.
  • Pre-Market Ready: Works during the pre-market session so you can build your plan before 9:30 AM.

🚀 Setup Instructions

1
Copy the Script: Click the "Copy Script" button in the black box below.
2
Open Pine Editor: In TradingView, click the "Pine Editor" tab at the bottom of your chart.
3
Install: Paste the code, click "Save," and then "Add to Chart."
Pro Tip: To see gaps accurately, ensure your TradingView chart is set to "Regular Trading Hours" (RTH) rather than Extended Hours (EXT) in the bottom right corner of the chart.
//@version=5
indicator("DTL Lab - Gap Scanner Table", overlay=true)

// --- POSITION SETTINGS ---
table_pos = input.string("top_right", "Table Position", options=["top_right", "bottom_right", "top_left", "bottom_left"])

pos_val = table_pos == "top_right" ? position.top_right : 
          table_pos == "bottom_right" ? position.bottom_right : 
          table_pos == "top_left" ? position.top_left : position.bottom_left

// --- Ticker Inputs ---
t1 = input.symbol("AAPL", "Ticker 1"), t2 = input.symbol("TSLA", "Ticker 2")
t3 = input.symbol("NVDA", "Ticker 3"), t4 = input.symbol("AMD", "Ticker 4")
t5 = input.symbol("META", "Ticker 5"), t6 = input.symbol("MSFT", "Ticker 6")

// --- Gap Logic Function ---
calculateGap(sym) =>
    prevClose = request.security(sym, "D", close[1], lookahead=barmerge.lookahead_on)
    currOpen  = request.security(sym, "D", open, lookahead=barmerge.lookahead_on)
    gapPct    = ((currOpen - prevClose) / prevClose) * 100
    gapPct

// --- Execution ---
g1 = calculateGap(t1), g2 = calculateGap(t2)
g3 = calculateGap(t3), g4 = calculateGap(t4)
g5 = calculateGap(t5), g6 = calculateGap(t6)

// --- UI Table ---
var tbl = table.new(pos_val, 2, 7, frame_color=color.gray, frame_width=1)
if barstate.islast
    table.cell(tbl, 0, 0, "Symbol", bgcolor=color.new(#6f42c1, 80), text_color=color.white)
    table.cell(tbl, 1, 0, "Gap %", bgcolor=color.new(#6f42c1, 80), text_color=color.white)
    
    // Rows
    table.cell(tbl, 0, 1, t1, text_color=color.white)
    table.cell(tbl, 1, 1, str.tostring(g1, "#.##") + "%", bgcolor = g1 >= 0 ? color.new(color.green, 40) : color.new(color.red, 40), text_color=color.white)
    
    table.cell(tbl, 0, 2, t2, text_color=color.white)
    table.cell(tbl, 1, 2, str.tostring(g2, "#.##") + "%", bgcolor = g2 >= 0 ? color.new(color.green, 40) : color.new(color.red, 40), text_color=color.white)
    
    table.cell(tbl, 0, 3, t3, text_color=color.white)
    table.cell(tbl, 1, 3, str.tostring(g3, "#.##") + "%", bgcolor = g3 >= 0 ? color.new(color.green, 40) : color.new(color.red, 40), text_color=color.white)
    
    table.cell(tbl, 0, 4, t4, text_color=color.white)
    table.cell(tbl, 1, 4, str.tostring(g4, "#.##") + "%", bgcolor = g4 >= 0 ? color.new(color.green, 40) : color.new(color.red, 40), text_color=color.white)
    
    table.cell(tbl, 0, 5, t5, text_color=color.white)
    table.cell(tbl, 1, 5, str.tostring(g5, "#.##") + "%", bgcolor = g5 >= 0 ? color.new(color.green, 40) : color.new(color.red, 40), text_color=color.white)
    
    table.cell(tbl, 0, 6, t6, text_color=color.white)
    table.cell(tbl, 1, 6, str.tostring(g6, "#.##") + "%", bgcolor = g6 >= 0 ? color.new(color.green, 40) : color.new(color.red, 40), text_color=color.white)
Common Issues:
Gap shows 0%: This often happens if the market hasn't opened yet and there is no "Today's Open" data yet. It will populate once the first print of the day hits.
Delayed Data: If you are on a free TradingView plan, your "Gap" might reflect the data from 15 minutes ago.
⚠️ Disclaimer: Gap trading involves extreme volatility and risk. This tool is for educational purposes. Real-time data is highly recommended for accurate morning gap analysis.