OPEN-SOURCE SCRIPT

Illiquidity 1m gaps

274
// WHAT IT DOES
// Detects illiquid stocks by counting how often consecutive 1-minute bars
// fail to touch each other. On liquid names trades print continuously, so
// each bar's open is essentially equal to the previous bar's close. On
// illiquid names there are minutes with zero trades, and when a trade
// finally happens it can land at a meaningfully different price - leaving
// a visible gap between bars. Many such gaps in a session is a direct
// signal of thin liquidity.
//
// The indicator runs the 1-min gap analysis even when applied to higher
// timeframes (e.g. daily). Each daily candle is annotated with the total
// number of 1-min gaps that occurred during that session, broken into
// gap-ups and gap-downs. When the count exceeds the threshold, the
// display turns red.
//
// HOW IT WORKS
// 1. Fetches 1-minute data via request.security_lower_tf(), regardless
// of the chart's current timeframe.
// 2. For each 1-min bar, compares open to the prior close.
// 3. A gap is registered when |open - prevClose| / prevClose * 100
// exceeds the configured threshold.
// 4. Session-boundary jumps (overnight, lunch break) are excluded by
// checking the time delta between consecutive bars - only bars less
// than 5 minutes apart in real time are considered.
// 5. Gaps are summed across all 1-min bars within the current chart bar.
//
// INPUTS
// - Min gap size pct: Minimum price jump (% of price) that counts as a
// gap. Default 0.10%. Increase for cheap stocks (<Rs.100 use 0.20%),
// decrease for high-priced names (>Rs.3000 use 0.05%).
// - Gaps per chart bar to flag illiquid: Threshold above which the bar
// is marked red. Suggested starting values by category:
// Nifty 50 / large caps : 10
// Mid caps : 20 (default)
// Small caps : 35
// Microcaps / SME : 60+
// - Show on chart (table): Toggle the corner table.
// - Show in status line: Toggle the three numbers in TradingView's
// status line (Total / Up / Down).
// - Table position: 9-way position picker (top/middle/bottom x
// left/center/right).
// - Text size: Tiny / Small / Normal / Large.
//
// DISPLAY
// - Table shows: "<total>g <up>u <down>d" e.g. "14g 8u 6d".
// - Status line shows the same three numbers as separate plot values.
// - Background of the readout flips red when total >= threshold.
//
// LIMITATIONS
// - TradingView caches a limited amount of lower-timeframe history. On
// a daily chart pulling 1-min data, typically only the most recent
// 10-40 trading days will populate accurately. Older bars may show
// zero gaps because the 1-min data is unavailable, not because the
// stock was liquid.
// - Free/Basic plans have stricter intrabar limits than paid plans.
// - Works best on equity instruments with regular sessions. For 24/7
// markets (crypto), the session-boundary filter is unused.
//
// USE CASE
// Screen out illiquid stocks before adding them to a watchlist or sizing
// into a position. Apply this indicator to your daily chart, glance at
// the corner readout, and skip any name flagged red - the spread and
// slippage on those will eat your edge.
//
// CALIBRATION
// Apply to three reference tickers on your daily chart:
// - A known liquid name (RELIANCE) - should read ~0-5 gaps.
// - A midcap you actually trade - note the typical count.
// - A microcap or SME - should read 50+.
// Set your threshold to roughly 2x the typical count of your tradeable
// midcap.
// =============================================================================

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.