OPEN-SOURCE SCRIPT
FVG – (auto close + age) GR V1.0

FVG – Fair Value Gaps (auto close + age counter)
Short Description
Automatically detects Fair Value Gaps (FVGs) on the current timeframe, keeps them open until price fully fills the gap or a maximum bar age is reached, and shows how many candles have passed since each FVG was created.
Full Description
This indicator automatically finds and visualizes Fair Value Gaps (FVGs) using the classic 3-candle ICT logic on any timeframe.
It works on whatever timeframe you apply it to (M1, M5, H1, H4, etc.) and adapts to the current chart.
FVG detection logic
The script uses a 3-candle pattern:
Bullish FVG
Condition:
low[0] > high[2]
Gap zone:
Lower boundary: high[2]
Upper boundary: low[0]
Bearish FVG
Condition:
high[0] < low[2]
Gap zone:
Lower boundary: high[0]
Upper boundary: low[2]
Each detected FVG is drawn as a colored box (green for bullish, red for bearish in this version, but you can adjust colors in the inputs).
Auto-close rules
An FVG remains on the chart until one of the following happens:
Full fill / mitigation
A bullish FVG closes when any candle’s low goes down to or below the lower boundary of the gap.
A bearish FVG closes when any candle’s high goes up to or above the upper boundary of the gap.
Maximum bar age reached
Each FVG has a maximum lifetime measured in candles.
When the number of candles since its creation reaches the configured maximum (default: 200 bars), the FVG is automatically removed even if it has not been fully filled.
This keeps the chart cleaner and prevents very old gaps from cluttering the view.
Age counter (labels inside the boxes)
Inside every FVG box there is a small label that:
Shows how many bars have passed since the FVG was created.
Moves together with the right edge of the box and stays vertically centered in the gap.
This makes it easy to distinguish fresh gaps from older ones and prioritize which zones you want to pay attention to.
Inputs
FVG color – Main fill color for all FVG boxes.
Show bullish FVGs – Turn bullish gaps on/off.
Show bearish FVGs – Turn bearish gaps on/off.
Max bar age – Maximum number of candles an FVG is allowed to stay on the chart before it is removed.
Usage
Works on any symbol and any timeframe.
Can be combined with your own ICT / SMC concepts, order blocks, session ranges, market structure, etc.
You can also choose to only display bullish or only bearish FVGs depending on your directional bias.
Disclaimer
This script is for educational and informational purposes only and is not financial advice. Always do your own research and use proper risk management when trading.
Short Description
Automatically detects Fair Value Gaps (FVGs) on the current timeframe, keeps them open until price fully fills the gap or a maximum bar age is reached, and shows how many candles have passed since each FVG was created.
Full Description
This indicator automatically finds and visualizes Fair Value Gaps (FVGs) using the classic 3-candle ICT logic on any timeframe.
It works on whatever timeframe you apply it to (M1, M5, H1, H4, etc.) and adapts to the current chart.
FVG detection logic
The script uses a 3-candle pattern:
Bullish FVG
Condition:
low[0] > high[2]
Gap zone:
Lower boundary: high[2]
Upper boundary: low[0]
Bearish FVG
Condition:
high[0] < low[2]
Gap zone:
Lower boundary: high[0]
Upper boundary: low[2]
Each detected FVG is drawn as a colored box (green for bullish, red for bearish in this version, but you can adjust colors in the inputs).
Auto-close rules
An FVG remains on the chart until one of the following happens:
Full fill / mitigation
A bullish FVG closes when any candle’s low goes down to or below the lower boundary of the gap.
A bearish FVG closes when any candle’s high goes up to or above the upper boundary of the gap.
Maximum bar age reached
Each FVG has a maximum lifetime measured in candles.
When the number of candles since its creation reaches the configured maximum (default: 200 bars), the FVG is automatically removed even if it has not been fully filled.
This keeps the chart cleaner and prevents very old gaps from cluttering the view.
Age counter (labels inside the boxes)
Inside every FVG box there is a small label that:
Shows how many bars have passed since the FVG was created.
Moves together with the right edge of the box and stays vertically centered in the gap.
This makes it easy to distinguish fresh gaps from older ones and prioritize which zones you want to pay attention to.
Inputs
FVG color – Main fill color for all FVG boxes.
Show bullish FVGs – Turn bullish gaps on/off.
Show bearish FVGs – Turn bearish gaps on/off.
Max bar age – Maximum number of candles an FVG is allowed to stay on the chart before it is removed.
Usage
Works on any symbol and any timeframe.
Can be combined with your own ICT / SMC concepts, order blocks, session ranges, market structure, etc.
You can also choose to only display bullish or only bearish FVGs depending on your directional bias.
Disclaimer
This script is for educational and informational purposes only and is not financial advice. Always do your own research and use proper risk management when trading.
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.