OPEN-SOURCE SCRIPT
Updated

AG Pro Fair Value Gap Engine [AGPro Series]

1 404
AG Pro Fair Value Gap Engine [AGPro Series]

OVERVIEW / WHAT IT DOES

AG Pro Fair Value Gap Engine is a rules-based overlay built to detect 3-bar fair value gap structures and organize them as a living imbalance map on the chart.

The script identifies bullish fair value gaps when the current low is above the high from two bars earlier, and bearish fair value gaps when the current high is below the low from two bars earlier. Once detected, each zone is stored, rendered, tracked through time, and updated as price interacts with it.

Instead of stopping at basic FVG detection, this script continues to follow the structure after creation. It monitors whether the gap remains active, whether price returns into it, whether mitigation occurs, how old the structure has become, and how strong or weak that mitigation event appears relative to the gap itself.

The result is not just a visual list of imbalances. It is an FVG lifecycle model designed to help traders distinguish between fresh gaps, aging gaps, mitigated gaps, and higher-quality mitigation events.

UNIQUE EDGE

Many fair value gap tools simply highlight every detected gap and leave the user to interpret the rest.

This script is built around a different idea:
not all FVGs deserve the same attention, and not every mitigation event carries the same informational value.

AG Pro Fair Value Gap Engine separates itself by combining detection, aging, prioritization, mitigation tracking, and scoring in a single structured workflow. Gaps are not treated as static rectangles. They are treated as evolving chart objects with a lifecycle.

Within the AG Pro Series, this script is also distinct from breakout-quality, reclaim, rotation, pressure, or acceptance-style overlays. Those models focus on trend behavior, reclaim behavior, structural confirmation, momentum pressure, or price acceptance around a reference. This one is centered on imbalance structure itself: where the 3-bar gap formed, how long it stayed relevant, whether price returned, and how credible that mitigation looked once interaction happened.

In practical terms, the script is designed to answer questions such as:
Which FVGs are still active?
Which ones are becoming stale?
Which mitigation events happened with better quality?
Which visible zones are worth keeping in focus, and which are just legacy context?

That is the core difference. This is not a generic FVG highlighter. It is an imbalance-ranking and mitigation-quality engine.

METHODOLOGY

1) Detection Logic

The script scans for standard 3-bar fair value gap structures.

Bullish FVG:
current low > high from two bars back

Bearish FVG:
current high < low from two bars back

A minimum size filter relative to ATR is applied so that very small gaps can be ignored when desired.

2) Structure Tracking

After detection, each FVG is stored and tracked over time. The script keeps the zone on the chart, extends active zones forward when enabled, and updates their visual state as the market evolves.

This allows the chart to preserve the structural memory of imbalance zones instead of treating every new gap as an isolated event.

3) Aging and Visual Decay

Older gaps gradually lose visual priority through fade logic. This helps newer or more relevant structures stay readable while old zones move into the background.

Optional controls can also suppress distant legacy zones when they become both old and far from current price.

4) Mitigation Logic

The script monitors how deeply price returns into each gap. When the user-defined mitigation threshold is reached, the FVG is marked as mitigated.

Mitigated zones can remain visible as context or be hidden for a cleaner chart, depending on preference.

5) Quality Scoring

Mitigation is not treated as a simple yes/no event. The script evaluates mitigation quality using a weighted model that includes:

- Gap size relative to ATR
- Speed of return into the zone
- Relative volume during the mitigation event
- Return strength after contact with the gap

This produces a normalized score intended to help separate weaker fills from stronger, better-formed mitigation behavior.

6) Focus and Prioritization

To reduce chart noise, the script includes focused labeling, active-zone prioritization, top-zone filtering, and legacy suppression logic.

This means the visual output can be tuned away from “show everything” and toward “show what matters most.”

SIGNALS & ALERTS

This script provides alert conditions for:
- Newly detected bullish fair value gaps
- Newly detected bearish fair value gaps
- Bullish fair value gaps reaching mitigation
- Bearish fair value gaps reaching mitigation

These alerts are event-based and rules-based. They are not forecasts, predictions, or trade instructions.

The labels and panel are designed to summarize state, not to replace the user’s broader market process.

KEY INPUTS

Core Settings
- Minimum FVG Size (ATR)
- Mitigation Threshold (%)
- Maximum Tracked FVG Count
- Age Fade Length
- Extend Active FVG Boxes

Scoring Engine
- Speed Score Reference
- Volume Score SMA Length
- Volume Score Max Ratio
- Size Score Max ATR

Visual Settings
- Show FVG Labels
- Focused Label Mode
- Focused Label Minimum Score
- Active / Mitigated Label Age Limits
- Highlight Score Threshold
- Theme Preset
- Show Mitigated Zones
- Show Mitigated Zone Labels
- Label Horizontal Offset
- Hide Distant Legacy FVGs
- Legacy Hide Age
- Legacy Hide Distance
- Show Only Top Active Zones
- Top Active Zones Count
- Label Stack Spacing

Panel Settings
- Show Panel
- Panel Position
- Panel Font Size

These controls allow the same logic to be used in a more information-dense mode or in a much cleaner presentation mode, depending on the charting style of the user.

LIMITATIONS & TRANSPARENCY

This script detects and organizes 3-bar imbalance structures. It does not claim to identify every meaningful liquidity event, order-flow shift, or broader smart money context factor on its own.

A fair value gap can remain open for a long time, fail quickly, or be revisited multiple times. A high score does not guarantee a directional outcome. A low score does not automatically invalidate the zone as context.

The mitigation score is a structured ranking model, not an objective truth about future price behavior. It is designed to help compare events inside the framework of this script.

Because chart structure, volatility, timeframe, and instrument behavior vary, users should expect different FVG densities and different score distributions across markets.

This tool is best used as a market-organization layer for imbalance analysis, not as a standalone execution system.

RISK DISCLOSURE

AG Pro Fair Value Gap Engine is an analytical charting tool for educational and informational use.

It does not provide financial advice, does not promise outcomes, and should not be interpreted as a standalone buy or sell system. Fair value gaps, mitigation events, and score readings should be evaluated together with market structure, volatility, timeframe context, liquidity conditions, and the user’s own risk framework.

Trading involves risk. Past chart behavior does not guarantee future results.
Release Notes
Update Notes — V1.1

This update focuses on panel standardization and interface refinement.

What changed:
- Rebuilt the dashboard header into the new AG Pro standard layout.
- Applied the single merged top row structure for a cleaner and more consistent presentation.
- Updated the first panel row to the standard blue header style.
- Simplified the header content so the top row now shows only the script name.
- Kept the panel default font size aligned with the current AG Pro small-size standard.
- Kept label sizing aligned with the current AG Pro normal-size standard.
- Improved panel consistency so the script now matches the latest AG Pro visual framework more closely.

Notes:
- This update is primarily visual and structural.
- Core Fair Value Gap detection logic was not redesigned in this step.
- Existing workflow remains centered on chart-based FVG visualization and monitoring.
- No outcome, profit, or performance claim is implied by this update.

Risk Disclosure:
This script is a chart analysis tool. It does not predict future price movement and does not provide financial advice. Any use of this script should be combined with independent analysis and risk management.
Release Notes
Update Notes - V1.2.1

This follow-up update focuses on visual cleanup after the main V1.2 release. The script identity remains the same, but the label layer has been refined so active fair value gaps read more naturally on the chart.

What changed

- Restored stronger active-zone label visibility so important live FVG structures are not underrepresented on the chart.
- Simplified label wording back toward a cleaner FVG-first presentation instead of repeating zone-state language too aggressively.
- Reduced the default label drift by pinning labels to the right edge of each zone.
- Re-anchored label placement around the zone midpoint so labels sit closer to their actual structure.
- Lowered the default vertical offset so labels feel more connected to the box they describe.
- Increased the visible label budget so active zones can stay readable across 1H, 4H, and 1D layouts without collapsing into a sparse presentation.

Why this update was made

- The previous visual pass became too selective and pushed labels too far away from their zones.
- This revision is meant to restore a more premium and more natural chart balance.
- The goal is stronger readability without turning the script into a cluttered label-heavy overlay.

What remains unchanged

- The script is still the same Fair Value Gap Engine update, not a renamed or repositioned concept.
- Core FVG detection, mitigation logic, scoring, and panel behavior remain intact.
- The script still stays in the FVG lane rather than drifting into order block, supply-demand, or generic support-resistance framing.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.