OPEN-SOURCE SCRIPT
已更新

Gap Zones

619
This TradingView indicator automatically detects daily price gaps and plots them clearly on any timeframe (intraday or daily).
It helps visualize where unfilled gaps are sitting, track whether they’ve been filled, and control how far the zone extends.

Key Features
1. Daily Gap Detection
• Works even when you’re on intraday charts (uses daily OHLC data).
• Marks both gap up (potential support zones) and gap down (potential resistance zones).
2. Shaded Gap Zones
• Each gap is highlighted as a band (greenish for up, reddish for down).
• Option to turn shading off if you just want horizontal lines.
3. Hide When Filled
• Once price closes or touches the far side of the gap, it disappears (configurable: Touch vs Close).
4. Lookback Window
• Gaps only show if they occurred within the past X trading days (default: 30).
• Prevents your chart from being cluttered with ancient gaps.
5. Multiple Gaps Tracked
• Can track up to 5 recent gaps simultaneously.
• Oldest gaps “roll off” as new ones form.
6. Finite Right-Edge Guides
• Optional horizontal guide lines extend to the right, but only for a fixed number of bars (default: 50).
• Cleaner than infinite extensions.
7. Gap-Day Marker
• Optional vertical line drawn on the bar where the gap first occurred.



⚙️ Inputs & Settings

When you apply the indicator, you’ll see these options:
• Lookback (trading days): How far back to scan for gaps (default 30).
• Max gaps to show (1..5): How many simultaneous gap zones to display.
• Min gap size (% of prior close): Filter out tiny gaps (default 0.25%).
• Hide gaps once filled: Removes a gap from the chart once filled.
• Fill rule uses CLOSE (off = Touch):
• Touch = filled when price trades through the level intraday.
• Close = filled only when a candle close crosses it.
• Show shading: Toggle zone fills on/off.
• Show vertical marker on gap day: Toggle gap-day marker line.
• Show finite right-edge lines: Toggle horizontal lines extending right.
• Right line length (bars): How far those lines extend (default 50 bars).



🟢 How to Use It
1. Apply on Any Chart
• Works best on daily or intraday (5m, 15m, 1h).
• Gaps are always calculated from daily data, so intraday charts will show higher-timeframe gaps correctly.
2. Interpret Colors
• Green shading = Gap Up (often acts as support).
• Red shading = Gap Down (often acts as resistance).
3. Watch for Fills
• When price re-enters the gap zone, the indicator checks if it’s “filled” (based on your Touch/Close setting).
• If “Hide When Filled” is on, the zone vanishes.
4. Trade Context
• Many traders use gaps as targets (expecting a fill) or levels of support/resistance.
• Combined with your bull put/bear call spread strategies, it helps confirm strong levels.
版本注释
🔍 Purpose

This script automatically detects price gaps on a chart (daily or intraday) and visually marks those gaps as zones that extend to the right — allowing you to track potential support/resistance levels until they are filled.



⚙️ How It Works

1. Gap Detection
• The function f_gap() checks for gaps between the previous candle’s high/low and the current candle’s open.
• Two detection modes:
• Daily: Uses daily candles via request.security() regardless of chart timeframe.
• Intraday Bars: Detects gaps between individual intraday bars.
• When a gap exceeds your chosen minimum percentage (minGapPct), it flags it as a valid event (ev = true).



2. Gap Zone Creation
When a gap is detected:
• Two horizontal lines are drawn at the gap high and gap low using line.new().
• These lines are extended infinitely to the right (extend.right).
• A shaded zone (linefill.new()) is filled between them:
• Green (lime) for gap-ups
• Red for gap-downs

This creates a clear visual band showing the unfilled gap area.



3. Gap Fill Detection
• On every confirmed bar (barstate.isconfirmed), the script runs f_filled() to check if price has entered or closed inside the gap.
• The test respects your setting:
• Close-based fill: (fillUsesClose = true) — price must close inside the gap.
• Touch-based fill: (fillUsesClose = false) — any wick penetration fills it.

Once a fill occurs:
• The zone and its lines are hidden by setting their colors to na and extend.none.



4. Persistent Tracking
• All detected gaps (and their lines, directions, etc.) are stored in arrays.
• This lets multiple unfilled gaps remain visible and independent of each other — each one is managed until it’s filled.



5. Visual Summary
• A label appears above the last bar summarizing:
• Active mode (Daily or Intraday)
• Minimum gap size threshold (%)



🧠 Practical Uses
• Quickly identify unfilled gaps — often used as targets, support, or resistance zones.
• Switch between daily and intraday gap modes depending on your analysis timeframe.
• Helps visualize gap fill probabilities and trend continuation setups for swing or intraday strategies.



🧩 Your Key Parameters

Setting Function
Gap Mode Daily or Intraday gap detection
Min gap size Minimum % move to qualify as a gap
Gap fill rule uses close Determines whether fill requires close inside or just a touch
Show Summary Label Displays or hides the top-right info label
版本注释
Automatically detects bullish and bearish price gaps and highlights them as shaded zones that extend to the right of the chart. Zones stay perfectly aligned with price when zooming and are hidden once filled.

Ideal for tracking unfilled gaps as potential support or resistance levels across both daily and intraday timeframes.
版本注释
pdate – Gap Zones (wick-fill, custom colors, hide filled)

What’s new
• Wick-based gap fills
• A gap is now considered filled as soon as the price wick touches the far edge of the gap.
• Gap up → filled when low ≤ lower edge.
• Gap down → filled when high ≥ upper edge.
• Custom colors & transparency
• New inputs:
• Gap Up Color
• Gap Down Color
• Gap Fill Transparency
• Lets you style bullish / bearish gaps and adjust how strong the zones appear on the chart.
• Hide filled gaps (optional)
• New toggle: Hide Gaps Once Filled.
• When ON, lines and fills are deleted as soon as the gap is filled.
• When OFF, gaps stop extending and are faded out (colors set to na).
• Daily + Intraday modes preserved
• Gap Mode still supports both:
• "Daily" → gaps between daily candles (using higher-timeframe data).
• "Intraday Bars" → gaps between consecutive intraday bars.

Stability / bug fixes
• Fixed all line.new() and label.new() syntax issues by keeping function calls on a single line.
• Added a safety guard so the script doesn’t try to read from empty arrays on the first bar (if count > 0).
• Cleaned up the gap detection logic so there are no ta.change() warnings.


🧭 How to Use
1. Add the script to your chart
Works on any symbol or timeframe. Choose between Daily or Intraday Bars mode in the settings.
2. Set your gap criteria
• Adjust Min Gap Size (% of prior close) — e.g. 0.25% filters out smaller gaps.
• Choose Daily for day-to-day gaps or Intraday Bars for gaps between consecutive candles.
3. Customize the visuals
• Pick your Gap Up Color and Gap Down Color.
• Fine-tune transparency with Gap Fill Transparency.
• Lines automatically extend to the right until the gap is filled.
4. Gap fill logic
• A gap is marked filled as soon as the wick touches the far edge (no close required).
• For up gaps → filled when low ≤ lower edge.
• For down gaps → filled when high ≥ upper edge.
5. Hide or retain filled gaps
• Toggle Hide Gaps Once Filled:
• ON → gaps are removed once filled (clean chart).
• OFF → filled gaps remain, faded out for reference.
6. At-a-glance summary
• Enable Show Summary Label to display current mode and min gap threshold in the top-left corner.
版本注释
Gap Zones - Update

免责声明

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.