OPEN-SOURCE SCRIPT
ICT Session FVGs [50% Mitigated]

This TradingView Pine Script (Version 5) is an overlay indicator designed for traders who use **Inner Circle Trader (ICT)** concepts. It automatically detects and highlights **Fair Value Gaps (FVGs)** that form during specific trading sessions (Killzones) and tracks them until price "mitigates" (fills) them to the 50% level.
Here is a breakdown of exactly how the script works under the hood:
### 1. User Inputs & Constraints
* **Session Toggles:** You can choose to highlight FVGs formed during the **Asia Killzone** (8:00 PM - 12:00 AM EST) and/or the **London Killzone** (2:00 AM - 5:00 AM EST).
* **Performance Lookback:** It only scans for and draws FVGs over the last X days (default is 5). Limiting historical data prevents the chart from lagging.
* **Visuals:** Allows customization of colors for Bullish (green) and Bearish (red) gaps.
### 2. Time Logic Filtering
The script hardcodes the timezone to `America/New_York` (EST). It checks every candle on the chart to see if it falls within the specified Asia or London time windows. If a candle is outside these windows (or outside the 5-day lookback limit), the script will ignore any FVGs that form.
### 3. FVG Detection (The 3-Bar Pattern)
When the active time zones are met, the script looks for the classic 3-candle FVG pattern using an array of custom data objects (`type FVG`):
* **Bullish FVG:** It triggers if the current candle's `low` is higher than the `high` of two candles ago. This leaves an empty gap where only buyers were present.
* **Bearish FVG:** It triggers if the current candle's `high` is lower than the `low` of two candles ago, leaving a gap where only sellers were present.
When a gap is found, the script calculates the exact top, bottom, and **midpoint (50% level)** of the gap, draws a colored box starting from the gap candle, and saves all this data into an array to be tracked.
### 4. Mitigation & 12 PM Cutoff Logic
This is the most dynamic part of the script. On every new candle, the script loops through all previously drawn, active FVGs to see what price is doing to them:
* **The 50% Mitigation Rule:** The script considers a gap "mitigated" (resolved) only when the price pierces the **50% midline** of the box.
* If a bullish gap's midline is hit by a candle's low, or a bearish gap's midline is hit by a candle's high, the gap is marked `mitigated = true`.
* The script then permanently locks the right side of the box to that specific candle, showing exactly where the gap was filled.
* **The Time Cutoff Rule:** If a gap has *not* been mitigated, the script will extend the box to the right so it stays visible on the chart. **However**, it stops extending unmitigated boxes at **12:00 PM (Noon) NY time**. It resumes extending them at 8:00 PM. This mimics the ICT concept of disregarding morning session unmitigated zones once the lunch hour hits.
Here is a breakdown of exactly how the script works under the hood:
### 1. User Inputs & Constraints
* **Session Toggles:** You can choose to highlight FVGs formed during the **Asia Killzone** (8:00 PM - 12:00 AM EST) and/or the **London Killzone** (2:00 AM - 5:00 AM EST).
* **Performance Lookback:** It only scans for and draws FVGs over the last X days (default is 5). Limiting historical data prevents the chart from lagging.
* **Visuals:** Allows customization of colors for Bullish (green) and Bearish (red) gaps.
### 2. Time Logic Filtering
The script hardcodes the timezone to `America/New_York` (EST). It checks every candle on the chart to see if it falls within the specified Asia or London time windows. If a candle is outside these windows (or outside the 5-day lookback limit), the script will ignore any FVGs that form.
### 3. FVG Detection (The 3-Bar Pattern)
When the active time zones are met, the script looks for the classic 3-candle FVG pattern using an array of custom data objects (`type FVG`):
* **Bullish FVG:** It triggers if the current candle's `low` is higher than the `high` of two candles ago. This leaves an empty gap where only buyers were present.
* **Bearish FVG:** It triggers if the current candle's `high` is lower than the `low` of two candles ago, leaving a gap where only sellers were present.
When a gap is found, the script calculates the exact top, bottom, and **midpoint (50% level)** of the gap, draws a colored box starting from the gap candle, and saves all this data into an array to be tracked.
### 4. Mitigation & 12 PM Cutoff Logic
This is the most dynamic part of the script. On every new candle, the script loops through all previously drawn, active FVGs to see what price is doing to them:
* **The 50% Mitigation Rule:** The script considers a gap "mitigated" (resolved) only when the price pierces the **50% midline** of the box.
* If a bullish gap's midline is hit by a candle's low, or a bearish gap's midline is hit by a candle's high, the gap is marked `mitigated = true`.
* The script then permanently locks the right side of the box to that specific candle, showing exactly where the gap was filled.
* **The Time Cutoff Rule:** If a gap has *not* been mitigated, the script will extend the box to the right so it stays visible on the chart. **However**, it stops extending unmitigated boxes at **12:00 PM (Noon) NY time**. It resumes extending them at 8:00 PM. This mimics the ICT concept of disregarding morning session unmitigated zones once the lunch hour hits.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.