PROTECTED SOURCE SCRIPT

FVG & IFVG Box Detector

132

The "FVG & IFVG Box Detector" is a custom Pine Script v6 indicator for TradingView that identifies and highlights Fair Value Gaps (FVGs) and their subsequent mitigation as Imbalance Fair Value Gaps (IFVGs) on a price chart. Tailored for use on a 5-minute timeframe (though it must be manually set by the user due to script limitations), this indicator provides a visual representation of market imbalances using colored boxes, which automatically disappear when the gaps are filled by price action. The script is designed to be clean and minimalistic, omitting text labels or annotations as per your preference.Key FeaturesFVG Detection:A Bullish FVG is detected when the low of the current candle is higher than the high of the candle two bars ago, indicating a potential upward imbalance, visualized with a green-bordered box filled with a semi-transparent green background.
A Bearish FVG is detected when the high of the current candle is lower than the low of the candle two bars ago, indicating a potential downward imbalance, visualized with a red-bordered box filled with a semi-transparent red background.
A minimum gap size filter (default 0%) can be adjusted to exclude small gaps, ensuring only significant imbalances are highlighted.

IFVG Transition:When a Bearish FVG is filled (price closes below its lower boundary), the red box disappears, and a blue-bordered box with a semi-transparent blue background briefly appears to mark the Bullish IFVG, indicating the zone may now act as support. This box then vanishes.
When a Bullish FVG is filled (price closes above its upper boundary), the green box disappears, and an orange-bordered box with a semi-transparent orange background briefly appears to mark the Bearish IFVG, indicating the zone may now act as resistance. This box then vanishes.
The disappearance of boxes reflects the resolution of the imbalance, keeping the chart uncluttered.

Customization:Users can toggle the display of Bullish FVGs, Bearish FVGs, Bullish IFVGs, and Bearish IFVGs via input settings.
The extendBars parameter (default 50) controls how far to the right the boxes extend, allowing adjustment of their visibility duration.
Colors for Bullish FVG, Bearish FVG, Bullish IFVG, and Bearish IFVG can be customized using TradingView’s color picker, with defaults set to semi-transparent green, red, blue, and orange, respectively.

Performance:The script includes a cleanup mechanism to limit the number of active boxes to 50 per type, preventing performance issues by deleting the oldest boxes when the limit is exceeded.
It uses static variable assignments to ensure compatibility with Pine Script v6’s strict type requirements for drawing functions.

FunctionalityThe indicator scans each bar on the 5-minute chart to detect FVGs based on the defined conditions.
Upon detection, it creates a box extending from the starting bar (two bars ago) to the current bar plus the extendBars value, using the high and low prices to define the box’s vertical range.
When price action fills an FVG, the original box is deleted, and a brief IFVG box is created at the same price levels, which also disappears, signaling the imbalance has been neutralized.
No text or labels are displayed, ensuring a clean visual experience focused solely on the boxes.

Intended UseTraders: This tool is ideal for traders using FVG and IFVG concepts (common in Smart Money or ICT trading strategies) to identify potential support and resistance zones. The blue boxes (Bullish IFVGs) may indicate areas to buy or expect a bounce, while orange boxes (Bearish IFVGs) may indicate areas to sell or expect a pullback.
Chart Analysis: By observing when and where boxes appear and disappear, traders can track market structure shifts without cluttering the chart with annotations.

LimitationsThe script must be applied to a 5-minute chart manually, as the timeframe argument is not supported due to the use of drawing functions.
The brief appearance of IFVG boxes means historical levels must be tracked manually (e.g., via screenshots) or by adjusting the script to retain them if desired.
The minimum gap size filter might need tuning depending on the instrument (e.g., Gold) to capture relevant gaps.

Current Status (as of 08:53 AM EDT, October 23, 2025)The script is fully functional on your 5-minute chart, with the latest version (v5) resolving the timeframe error by removing the invalid argument. Boxes should now appear and disappear as intended, with green for Bullish FVGs, red for Bearish FVGs, blue for Bullish IFVGs, and orange for Bearish IFVGs.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.