OPEN-SOURCE SCRIPT
BTC CME Gap – detector & single signals

# BTC CME Gap — Detector & Single Signals (Pine v5)
**What it does**
This indicator finds the **weekend gap** on **CME Bitcoin futures** and turns it into a clean, tradable object:
* Draws a **gap zone** (Friday close ↔ Monday open) as a right-extending box.
* Fires **one-time signals** per gap:
* **ENTER** – first touch of the gap zone by price.
* **FILL** – gap is considered filled when price tags **Friday’s close**.
It works on any BTC chart (spot or futures). The gap itself is calculated from **CME\:BTC1!** daily data.
---
## How it works
1. Pulls **daily** `open`/`close` from `CME:BTC1!` (`request.security`, no lookahead).
2. On **Monday**, compares Monday **open** with previous **Friday close**:
* If different → a **gap** exists.
3. Defines the zone:
* `gapTop = max(MonOpen, FriClose)`
* `gapBot = min(MonOpen, FriClose)`
4. Renders a box + boundary lines, **extending right** until price action resolves it.
5. Signals:
* **ENTER**: the first bar that **enters** the gap zone.
* **FILL**: first bar that **touches Friday close** (gap completion).
6. Each new Monday gap **replaces** the previous box and signals.
---
## Inputs
* **CME symbol** (default `CME:BTC1!`)
* **Gap timeframe** (default `D`)
* **Colors** for the box and edges
---
## Plot & Signals
* **Box** = visual gap zone (transparent fill, outlined).
* **ENTER** = triangle up below bar.
* **FILL** = triangle down above bar.
* Optional label prints **Top / Bottom / Fill** levels.
---
## Notes on behavior
* Uses `barmerge.lookahead_off` and daily aggregation, so the gap definition **does not repaint** once Monday’s daily bar is confirmed.
* Signals are **single-shot** per gap (no clutter).
* Works on any chart timeframe; the gap logic always references **CME daily**.
---
## Practical use
* Track obvious **“magnets”** for mean-reversion, stop-runs, or liquidity grabs.
* Combine with your higher-timeframe bias (e.g., **1D trend filter**) and execution on **4H/1H**.
* Typical outcomes: quick Monday fill, staged fill after partial rejection, or delayed fill during later consolidation.
---
## Customization ideas
* Add `alertcondition(enterSignal, …)` / `alertcondition(fillSignal, …)` for automation.
* Gate trades with trend filters (EMA/SMA, Kernel regression, ADX) or session tools (VWAP/POC).
* Persist multiple historical gap boxes if you want to track **unfilled** gaps.
---
**Credits**: Built for BTC CME weekend gaps; minimal, publication-ready visualization with single-event signals to keep charts clean.
**What it does**
This indicator finds the **weekend gap** on **CME Bitcoin futures** and turns it into a clean, tradable object:
* Draws a **gap zone** (Friday close ↔ Monday open) as a right-extending box.
* Fires **one-time signals** per gap:
* **ENTER** – first touch of the gap zone by price.
* **FILL** – gap is considered filled when price tags **Friday’s close**.
It works on any BTC chart (spot or futures). The gap itself is calculated from **CME\:BTC1!** daily data.
---
## How it works
1. Pulls **daily** `open`/`close` from `CME:BTC1!` (`request.security`, no lookahead).
2. On **Monday**, compares Monday **open** with previous **Friday close**:
* If different → a **gap** exists.
3. Defines the zone:
* `gapTop = max(MonOpen, FriClose)`
* `gapBot = min(MonOpen, FriClose)`
4. Renders a box + boundary lines, **extending right** until price action resolves it.
5. Signals:
* **ENTER**: the first bar that **enters** the gap zone.
* **FILL**: first bar that **touches Friday close** (gap completion).
6. Each new Monday gap **replaces** the previous box and signals.
---
## Inputs
* **CME symbol** (default `CME:BTC1!`)
* **Gap timeframe** (default `D`)
* **Colors** for the box and edges
---
## Plot & Signals
* **Box** = visual gap zone (transparent fill, outlined).
* **ENTER** = triangle up below bar.
* **FILL** = triangle down above bar.
* Optional label prints **Top / Bottom / Fill** levels.
---
## Notes on behavior
* Uses `barmerge.lookahead_off` and daily aggregation, so the gap definition **does not repaint** once Monday’s daily bar is confirmed.
* Signals are **single-shot** per gap (no clutter).
* Works on any chart timeframe; the gap logic always references **CME daily**.
---
## Practical use
* Track obvious **“magnets”** for mean-reversion, stop-runs, or liquidity grabs.
* Combine with your higher-timeframe bias (e.g., **1D trend filter**) and execution on **4H/1H**.
* Typical outcomes: quick Monday fill, staged fill after partial rejection, or delayed fill during later consolidation.
---
## Customization ideas
* Add `alertcondition(enterSignal, …)` / `alertcondition(fillSignal, …)` for automation.
* Gate trades with trend filters (EMA/SMA, Kernel regression, ADX) or session tools (VWAP/POC).
* Persist multiple historical gap boxes if you want to track **unfilled** gaps.
---
**Credits**: Built for BTC CME weekend gaps; minimal, publication-ready visualization with single-event signals to keep charts clean.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.