PROTECTED SOURCE SCRIPT
ROBUST iFVG [SurgeGuru]

The FVG/iFVG Robust Lifecycle indicator is a sophisticated market structure tool that moves beyond simple gap detection. It tracks the complete narrative of a Fair Value Gap—from its creation as a market imbalance to its resolution and the establishment of a new equilibrium zone. This dual-phase, institutional-grade approach provides a dynamic map of support and resistance, offering a profound edge in predicting price behavior.
Core Concept: The Two-Phase Lifecycle
The indicator is built on the principle that a Fair Value Gap has two distinct lives:
Phase 1: The Imbalance (FVG)
What it is: A rapid price move that leaves behind a "gap" or "void" with no trading activity.
Market Implication: Represents a moment of intense buying or selling pressure, creating an inefficient area price is statistically likely to return to.
Phase 2: The Equilibrium (iFVG)
What it is: A powerful support/resistance zone that forms the instant the original FVG is filled.
Market Implication: Represents the market's new consensus of "fair value" after the initial imbalance has been arbitraged away. This is often where institutional order flow resides for the next significant move.
Differentiators & "Robust" Features
Lifecycle Tracking: Unlike basic FVG tools that disappear once filled, this indicator captures the subsequent, often more important, iFVG phase.
Configurable Longevity: Offers two professional methods for managing iFVG lifespan (Full Cross or Number of Bars), preventing chart clutter while preserving relevant levels.
Advanced Alerting: Provides separate, configurable alerts for both FVG creation and iFVG formation, allowing traders to anticipate both the fill of an imbalance and the reaction at the new equilibrium.
Visual Hierarchy: Uses distinct, customizable colors and borders to instantly communicate the difference between an active imbalance (FVG) and an active decision zone (iFVG).
Code Architecture & How It Works
The script is a state management system built around two primary arrays that track the lifecycle of detected gaps.
1. Core Data Structures
The entire system is powered by parallel arrays that maintain the state of each detected zone:
FVG Arrays (Tracks Phase 1 - The Imbalance):
fvg_boxes[]: Stores the drawing object for each FVG.
fvg_top[] & fvg_bot[]: Store the price boundaries of the gap.
fvg_is_bull[]: Stores whether the FVG is bullish or bearish.
fvg_mitigated[]: The core state flag; becomes true when the FVG is filled, triggering the creation of an iFVG.
iFVG Arrays (Tracks Phase 2 - The Equilibrium):
ifvg_boxes[]: Stores the drawing object for each Inverse FVG.
ifvg_top[] & ifvg_bot[]: Inherits the price values from the parent FVG.
ifvg_is_bull[]: Is the inverse of the parent FVG's bias.
ifvg_original_fvg_index[]: Maintains a link back to the parent FVG for advanced management.
2. The Operational Workflow (Step-by-Step)
On every new bar, the script executes the following sequence:
STEP A: FVG Detection
The script checks for the 3-bar FVG pattern:
bullish_fvg = low > high[2] (Current low is above the high from two bars ago)
bearish_fvg = high < low[2] (Current high is below the low from two bars ago)
Upon detection, it creates a new box and pushes all its properties (price levels, bullish flag, etc.) into the FVG Arrays.
STEP B: FVG Management & Mitigation Check
The script iterates through all active FVGs in the fvg_boxes array.
For each FVG, it checks if the current price has "mitigated" (filled) the gap:
A Bullish FVG is mitigated if the current bar's low (body_low) crosses below the FVG's bottom boundary (bot_val).
A Bearish FVG is mitigated if the current bar's high (body_high) crosses above the FVG's top boundary (top_val).
If mitigation occurs, the script sets the FVG's fvg_mitigated flag to true.
STEP C: iFVG Creation (The Phase Transition)
The moment an FVG's fvg_mitigated flag is set to true, the script immediately creates a new iFVG.
It takes the exact same price levels from the parent FVG but inverts the bias (a mitigated Bullish FVG creates a Bearish iFVG, and vice versa).
It draws a new box with the user-defined iFVG color and border, and pushes all its properties into the iFVG Arrays.
STEP D: iFVG Lifecycle Management
The script iterates through all active iFVGs.
Depending on the user's setting, it manages the iFVG's lifespan:
Full Cross Mode: The iFVG remains active until price fully crosses through it again. Once crossed, the iFVG and its parent FVG are permanently deleted.
Number of Bars Mode: The iFVG remains visible for a fixed number of bars after its creation, then is automatically deactivated.
STEP E: Cleanup & Garbage Collection
The script constantly manages the visibility of boxes based on user toggles (show_normal_fvg, show_ifvg). If a feature is turned off, the boxes are not deleted but made transparent, allowing for fast performance and instant reactivation.
3. Alert System Architecture
The alert system is integrated into the state transitions:
FVG Alerts fire during STEP A (on creation).
iFVG Alerts fire during STEP C (on creation, which is the moment of FVG mitigation).
iFVG Mitigation Alerts fire during STEP D (when an iFVG is removed in Full Cross mode).
Conclusion
The FVG/iFVG Robust Lifecycle is not a mere indicator; it is a state-aware market analysis engine. By architecting a system that tracks the entire lifecycle of a price gap, it provides a dynamic, self-cleaning map of market imbalance and subsequent equilibrium. This offers a systematic framework for identifying high-probability support/resistance zones, making it an indispensable tool for discerning the underlying structure of price action.
Credits: TONO . this robust system was upgraded from his code.
Core Concept: The Two-Phase Lifecycle
The indicator is built on the principle that a Fair Value Gap has two distinct lives:
Phase 1: The Imbalance (FVG)
What it is: A rapid price move that leaves behind a "gap" or "void" with no trading activity.
Market Implication: Represents a moment of intense buying or selling pressure, creating an inefficient area price is statistically likely to return to.
Phase 2: The Equilibrium (iFVG)
What it is: A powerful support/resistance zone that forms the instant the original FVG is filled.
Market Implication: Represents the market's new consensus of "fair value" after the initial imbalance has been arbitraged away. This is often where institutional order flow resides for the next significant move.
Differentiators & "Robust" Features
Lifecycle Tracking: Unlike basic FVG tools that disappear once filled, this indicator captures the subsequent, often more important, iFVG phase.
Configurable Longevity: Offers two professional methods for managing iFVG lifespan (Full Cross or Number of Bars), preventing chart clutter while preserving relevant levels.
Advanced Alerting: Provides separate, configurable alerts for both FVG creation and iFVG formation, allowing traders to anticipate both the fill of an imbalance and the reaction at the new equilibrium.
Visual Hierarchy: Uses distinct, customizable colors and borders to instantly communicate the difference between an active imbalance (FVG) and an active decision zone (iFVG).
Code Architecture & How It Works
The script is a state management system built around two primary arrays that track the lifecycle of detected gaps.
1. Core Data Structures
The entire system is powered by parallel arrays that maintain the state of each detected zone:
FVG Arrays (Tracks Phase 1 - The Imbalance):
fvg_boxes[]: Stores the drawing object for each FVG.
fvg_top[] & fvg_bot[]: Store the price boundaries of the gap.
fvg_is_bull[]: Stores whether the FVG is bullish or bearish.
fvg_mitigated[]: The core state flag; becomes true when the FVG is filled, triggering the creation of an iFVG.
iFVG Arrays (Tracks Phase 2 - The Equilibrium):
ifvg_boxes[]: Stores the drawing object for each Inverse FVG.
ifvg_top[] & ifvg_bot[]: Inherits the price values from the parent FVG.
ifvg_is_bull[]: Is the inverse of the parent FVG's bias.
ifvg_original_fvg_index[]: Maintains a link back to the parent FVG for advanced management.
2. The Operational Workflow (Step-by-Step)
On every new bar, the script executes the following sequence:
STEP A: FVG Detection
The script checks for the 3-bar FVG pattern:
bullish_fvg = low > high[2] (Current low is above the high from two bars ago)
bearish_fvg = high < low[2] (Current high is below the low from two bars ago)
Upon detection, it creates a new box and pushes all its properties (price levels, bullish flag, etc.) into the FVG Arrays.
STEP B: FVG Management & Mitigation Check
The script iterates through all active FVGs in the fvg_boxes array.
For each FVG, it checks if the current price has "mitigated" (filled) the gap:
A Bullish FVG is mitigated if the current bar's low (body_low) crosses below the FVG's bottom boundary (bot_val).
A Bearish FVG is mitigated if the current bar's high (body_high) crosses above the FVG's top boundary (top_val).
If mitigation occurs, the script sets the FVG's fvg_mitigated flag to true.
STEP C: iFVG Creation (The Phase Transition)
The moment an FVG's fvg_mitigated flag is set to true, the script immediately creates a new iFVG.
It takes the exact same price levels from the parent FVG but inverts the bias (a mitigated Bullish FVG creates a Bearish iFVG, and vice versa).
It draws a new box with the user-defined iFVG color and border, and pushes all its properties into the iFVG Arrays.
STEP D: iFVG Lifecycle Management
The script iterates through all active iFVGs.
Depending on the user's setting, it manages the iFVG's lifespan:
Full Cross Mode: The iFVG remains active until price fully crosses through it again. Once crossed, the iFVG and its parent FVG are permanently deleted.
Number of Bars Mode: The iFVG remains visible for a fixed number of bars after its creation, then is automatically deactivated.
STEP E: Cleanup & Garbage Collection
The script constantly manages the visibility of boxes based on user toggles (show_normal_fvg, show_ifvg). If a feature is turned off, the boxes are not deleted but made transparent, allowing for fast performance and instant reactivation.
3. Alert System Architecture
The alert system is integrated into the state transitions:
FVG Alerts fire during STEP A (on creation).
iFVG Alerts fire during STEP C (on creation, which is the moment of FVG mitigation).
iFVG Mitigation Alerts fire during STEP D (when an iFVG is removed in Full Cross mode).
Conclusion
The FVG/iFVG Robust Lifecycle is not a mere indicator; it is a state-aware market analysis engine. By architecting a system that tracks the entire lifecycle of a price gap, it provides a dynamic, self-cleaning map of market imbalance and subsequent equilibrium. This offers a systematic framework for identifying high-probability support/resistance zones, making it an indispensable tool for discerning the underlying structure of price action.
Credits: TONO . this robust system was upgraded from his code.
受保護腳本
此腳本以閉源形式發佈。 不過,您可以自由且不受任何限制地使用它 — 在此處了解更多資訊。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
受保護腳本
此腳本以閉源形式發佈。 不過,您可以自由且不受任何限制地使用它 — 在此處了解更多資訊。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。