OPEN-SOURCE SCRIPT
Обновлено

FVG Confluence [AFD]

1 071
This Pine Script v6 overlay documents confirmed fair-value gaps (FVGs), optional order blocks (OBs), and overlap evidence from two selected higher timeframes. Its main output is a confluence band whose label identifies the two source timeframes and zone types when two same-direction zones overlap by a configurable amount.

This is a descriptive chart tool. It records what the source zones have done, how they overlap, and how price has interacted with them. It does not provide trade instructions, manage positions, or forecast an outcome.

────────── 1. Overview ──────────

The script has three related layers:

- Chart FVGs: three-candle fair-value gaps detected on the chart timeframe.
- Optional Order Blocks: the last opposite candle identified before a confirmed swing break.
- MTF Confluence: an overlap between source zones from Compare timeframe 1 and Compare timeframe 2.

By default, MTF confluence bands and labels showing their source timeframes and zone types are visible. Raw higher-timeframe source boxes are hidden by default and can be shown per timeframe with a choice of FVGs, Order Blocks, or both. Standalone chart FVG boxes and chart OB boxes are off by default; each appears when its respective Enable FVGs or Enable Order Blocks setting is turned on.

────────── 2. How FVGs are detected ──────────

A bullish chart FVG is recorded when the current confirmed bar's low is above the high from two bars earlier. A bearish FVG is the inverse. The Minimum gap filter removes gaps smaller than the selected ATR multiple or tick distance. The default filter is 0.05 ATR.

The same gap test is evaluated in each selected higher-timeframe context. Higher-timeframe events are admitted once per source origin time, which prevents the same source event from producing duplicate records on the chart.

────────── 3. FVG lifecycle ──────────

Each FVG keeps its original boundaries and tracks penetration using the selected Mitigation / fill rule:

- FRESH - price has not touched or entered the gap.
- TESTED - price has touched or entered the gap but has not reached its 50% midpoint.
- MITIGATED - price has reached the 50% midpoint but has not fully traversed the gap.
- FILLED - price has fully traversed the gap. Filled chart FVGs are removed unless Keep filled FVGs is enabled.

Wick mode uses the candle range for penetration and state changes. Close mode requires the candle close to reach the relevant boundary. The rule is applied consistently to chart FVGs, chart order blocks, and higher-timeframe FVG source zones. Higher-timeframe OB sources track penetration with the same FRESH → TESTED → MITIGATED lifecycle as chart OBs, so raw HTF OB labels show state and fill percentage. A higher-timeframe zone (FVG or OB) that is fully traversed becomes FILLED: it stays tracked internally, is hidden by default, can be revealed per timeframe with the Show 100% filled zones settings, and never feeds confluence.

A boundary touch counts as TESTED, while the fill percentage measures penetration through the original zone. A boundary-only test can therefore still display 0% Filled until price advances farther into the zone.

Shrink on partial fill changes only the displayed near edge of a chart FVG. The original boundaries and 50% midpoint remain available for fill measurement and lifecycle identity. Order Blocks have their own OB partial fill setting (off by default) that shrinks OB boxes the same way. Breaker blocks restart measurement from the near edge in the new direction.

The FVG Labels settings can show the percentage filled and, optionally, the FVG lifecycle state. Labels can be placed inside the box or to its right, with user-selected offset, size, and text color.

────────── 4. Order blocks ──────────

When enabled, the script confirms swing points using Swing strength and searches the configured OB candle lookback for the last opposite candle before a confirmed break. It records bullish and bearish blocks separately and limits the retained count per side.

OBs use the same Wick or Close interaction basis as FVGs. They can move from FRESH to TESTED and MITIGATED. If Show breakers is enabled, a block that is crossed changes direction and becomes a BREAKER with a new penetration measurement. If breakers are disabled, the crossed block is removed. When OB partial fill is enabled, OB boxes shrink their near edge inward as confirmed penetration advances, and breaker blocks restart measurement from the near edge in the new direction.

Chart OB detection, retention, and drawing are controlled together in the Order Blocks settings and are off by default.

────────── 5. MTF confluence ──────────

Confluence uses only the two selected comparison timeframes. The chart timeframe is not a confluence source. Both comparison timeframes must be strictly higher than the chart timeframe and must be different from each other. If either timeframe is invalid, or either source is disabled, the corresponding confluence path is not active.

The script compares source zones by:

1. Direction - bullish zones pair only with bullish zones, and bearish zones pair only with bearish zones.
2. Original geometry - qualification uses the original source boundaries, not a partially shrunk display edge.
3. Minimum overlap - the positive overlap must meet the configured threshold, measured as a multiple of the confirmed TF1 timeframe ATR and subject to a minimum tick. Using a fixed-timeframe ATR keeps band qualification stable when the chart timeframe changes.
4. Source details - a band retains both source origins, source timeframes, source types, and its own formation time.

The source HTF calculation uses shifted, completed higher-timeframe values and confirms pivot-based events before admission. This avoids using a developing higher-timeframe event, but it introduces confirmation delay. A source zone may therefore appear after the originating higher-timeframe movement rather than during it.

Raw HTF FVGs / OBs can be shown separately for inspection, with a per-timeframe choice of FVGs, Order Blocks, or both. The type selection is display-only; all raw zones still feed confluence. Each timeframe has its own raw partial fill setting (TF1 raw partial fill and TF2 raw partial fill) that shrinks the near edge of that timeframe's raw zone boxes (both FVGs and OBs) as penetration advances, and its own Show 100% filled zones setting (off by default) that keeps fully traversed raw zones visible. Raw HTF labels show state and fill percentage for all zone kinds. Confluence is FVG-only by default. If Include Order Blocks in confluence is enabled, same-direction FVG/OB, OB/FVG, and OB/OB overlaps can also qualify. Any band containing an OB is labeled STATIC because it does not have the pure FVG/FVG fill cycle.

────────── 6. Reading confluence bands ──────────

The band color describes overlap density, not a rating:

- One active overlap - the single-overlap color.
- Two active overlaps - the two-overlap color.
- Three or more active overlaps - the dense-overlap color.

Density counts active same-direction confluence records that share positive price overlap and are currently visible under the state and filled-band filters. Changing those visibility filters can therefore change a displayed band's density color. Density does not measure historical performance, reliability, or the future behavior of a level.

For pure FVG/FVG bands, Confluence partial fill can shrink the displayed band as confirmed penetration advances. Confluence fill % label reports penetration through the original overlap. The fill percentage is descriptive and is not a forecast.

Confluence labels can show:

- Source timeframes and source types.
- The number of overlapping active bands.
- Fill percentage for pure FVG/FVG bands on its own label line.
- FRESH, TESTED, PARTIAL, FILLED, or STATIC state, shown together with age on one horizontal metadata line.
- Age in chart bars or HH:MM:SS.
- Visits and breaks in the tooltip.

Fresh, Tested, Partial, and Filled visibility can be controlled independently. Filled confluence bands are hidden by default. Nearby labels are grouped onto a shared horizontal row and spaced by a configurable number of chart bars; this changes label placement only and does not change the bands.

────────── 7. Alerts ──────────

The script exposes two confirmed-bar alert conditions for chart-timeframe detections:

- FVG formed - a new confirmed chart-timeframe FVG.
- Order Block formed - a new confirmed chart-timeframe order block.

There are no built-in alerts for confluence formation, fills, mitigation, state changes, or position management. You can create TradingView alerts from the two available conditions.

────────── 8. Settings and defaults ──────────

FVG Drawings controls chart FVG detection, drawing, per-side retention, Wick or Close measurement, ATR or tick filtering, partial display shrink, filled-zone retention, lifecycle display, and bullish/bearish colors.

FVG Labels controls fill percentage, position, right-side offset, text size, and label color.

Order Blocks controls OB detection, drawing, per-side retention, swing strength, candle lookback, breaker behavior, partial fill, and colors.

MTF Confluence controls the MTF master enable, the two comparison timeframes, source inclusion, raw HTF visibility, and — independently per timeframe — raw zone types (FVGs, Order Blocks, or both), raw partial fill, filled-zone visibility, and source color. It also controls HTF retention, HTF lookback days, and raw labels. The default comparison pair is 30 minutes and 60 minutes.

Confluence Evidence controls partial fill, fill labels, OB-containing overlap inclusion, minimum overlap, maximum retained bands, source-detail labels, filled-band visibility, overlap colors, state and age display, label collision spacing, age format, and state filters.

Visuals controls the confluence label size.

────────── 9. How to use ──────────

1. Start on a time-based chart timeframe below both comparison timeframes. The default 30-minute and 60-minute pair is intended to be used from a lower chart timeframe such as 15 minutes.
2. Leave both comparison source checkboxes enabled when you want TF1 × TF2 confluence. Selecting the same comparison timeframe twice does not create a valid pair.
3. Use the default FVG-only mode when you want all bands to have the FVG lifecycle and fill measurement. Enable OB inclusion only when STATIC FVG/OB, OB/FVG, or OB/OB overlap evidence is useful to your analysis.
4. Use Wick or Close consistently with how you want penetration measured. Close mode ignores wick-only penetration for state and fill progression.
5. Turn on raw HTF zones, or enable chart FVGs/OBs in their own settings sections, only when you need to inspect those layers. They are intentionally hidden in the default chart view.
6. Use the state, age, fill, density, and source details to understand what produced a band and how price has interacted with it. Do not treat color density as a score.

────────── 10. What this script does not do ──────────

- It is not a strategy and does not provide backtests, win rates, performance statistics, or position sizing.
- It does not place orders, manage risk, or generate trade instructions.
- It does not use the chart timeframe as a confluence source.
- It does not create confluence from opposite-direction zones.
- It does not guarantee that every historical FVG or OB remains visible. Source retention, HTF lookback, state filters, filled-band visibility, and TradingView drawing limits can remove or hide records.
- It does not eliminate higher-timeframe confirmation delay. A valid setting can show no band when no recent confirmed source pair qualifies.
- It does not claim that every chart, symbol, session, or timeframe will produce the same number of zones. ATR, tick size, available history, market hours, and price behavior affect detection.

────────── 11. Limitations and developing values ──────────

Lifecycle mutations, HTF source admission, confluence identity, fill measurement, and state changes are gated on confirmed bars. Boxes and labels are redrawn on the last chart bar so their right edge, text, colors, and collision layout reflect the current view. This means the display can update while the underlying lifecycle remains confirmation-gated.

Changing the chart timeframe or either comparison timeframe clears the prior MTF context and rebuilds it from confirmed source history. The selected comparison timeframes must be higher than the new chart timeframe. If the new context has no retained qualifying source pair, the confluence view can be empty until confirmed source events are available. Band qualification uses the confirmed TF1 timeframe ATR, so the same source pairs qualify regardless of the chart timeframe. In the Wick basis, fill percentages and lifecycle states are chart-timeframe independent; in the Close basis, penetration follows chart-bar closes, so fill percentages and states can legitimately differ between chart timeframes.

The script is capped by TradingView drawing limits and by its own retention settings. Chart and higher-timeframe zone arrays prune older records according to their configured limits. The confluence maximum is a retained-record capacity: when a new qualifying pair arrives beyond the cap, the oldest record is removed first. A crowded chart can therefore show fewer drawings than the underlying detection logic considered. Higher-timeframe records are also limited by the HTF lookback-days and max-zones-per-HTF/type settings.

The implementation is confirmation-gated, but this description does not make an absolute non-repainting claim. Verify the current publication on TradingView with the intended symbols, timeframes, input changes, reload behavior, and Bar Replay before relying on its historical appearance.

────────── 12. Originality ──────────

FVGs, order blocks, pivots, ATR filters, and multi-timeframe analysis are established market-analysis concepts. The implementation focus here is showing which two source zones created each overlap and tracking its lifecycle: each confluence band preserves the source records that formed it, keeps immutable original overlap geometry, separates display-only partial fill from band identity, and exposes state, age, fill, visit, break, source, and overlap-density information instead of hiding them inside an unexplained composite value.

The source is open for inspection under the MPL 2.0 license. The calculations and visual labels are intended to be read as a record of price interaction, not as a promise about what happens next.

────────── 13. Disclaimer ──────────

For educational and informational purposes only. Not financial advice. Past chart behavior does not predict future results.
Информация о релизе
This version updates the existing FVG Confluence [AFD] script with confluence-lifecycle and label-presentation corrections. It does not change the script title, input names, input order, defaults, alert names, or MPL 2.0 license.

***What changed***

- ATR overlap qualification is now fixed when a confluence band is created. A band that qualified at formation no longer disappears only because the confirmed TF1 ATR changes later.
- A complete traversal of a pure FVG/FVG overlap now ends in FILLED rather than BROKEN. The existing Show 100% filled bands setting controls whether the retained record is displayed.
- Mixed FVG/OB overlap behavior is unchanged: a far-edge cross still ends the band as BROKEN.
- Chart-zone, raw higher-timeframe, and confluence labels now identify Bullish or Bearish direction.
- Chart-zone, raw higher-timeframe, and confluence labels now keep all visible text on one horizontal line, and all three surfaces are positioned by one shared layout instead of three independent ones. Confluence visits and break counts remain available in the tooltip.
- That layout is now a grid rather than a shared row. A label keeps its own zone price and its usual offset until a neighbour is genuinely in the way. Only then is it moved to the next horizontal column, and only once the columns beside it are taken is it lifted above them. Labels are no longer averaged onto a shared row price, so an uncrowded label sits on the zone it describes.
- The horizontal distance between columns is the width the longest visible label actually needs at the current zoom. It is no longer reduced to fit more labels onto one line, which is what previously allowed nearby labels to overlap.
- Vertical label spacing now also accounts for the visible candle price range, so compressed vertical zoom does not squeeze separate text rows into one another.
- When more labels sit near one price than can be placed legibly, the surplus labels now drop their text rather than print over a neighbour. The small anchor tag stays on its zone, its tooltip still opens where one is set, and the text returns on the next update once the crowding clears. Fewer readable labels is a deliberate trade against unreadable overlapping ones. Widen Label spacing (ATR) or Horizontal label spacing (bars) under Confluence, or use a smaller Label size, to change how many fit.
- With Keep filled FVGs off, fresh chart FVG boxes remain visible but no longer print a 0% Filled label. Partial percentages remain visible, and turning Keep filled FVGs on restores the complete fill scale.
- The default white FVG label-color setting now follows the chart foreground for dark/light contrast. Explicit non-white color selections remain unchanged.
- Invalid or duplicate comparison timeframes now produce one consolidated chart warning. Repeated setting changes do not stack warning labels.
- Every label coordinate now stays inside TradingView's 500-future-bar drawing limit, which prevents the out-of-range label coordinate that could appear during timeframe or viewport changes. That limit now caps how many columns are available rather than squeezing the spacing between them. Retained confluence boxes use time anchors when redrawn, avoiding the corresponding historical bar-index limit.
- HTF lookback is now a rolling window from the latest available chart bar; source zones outside it are not admitted or retained.
- Order-block breaks are deduplicated by pivot origin rather than price alone, so a later distinct pivot at the same price remains eligible. A partially shrunk block also restores its original bounds when it flips to a breaker and restarts from 0% fill.

Confluence band states

The states named above, measured as coverage of the band's original overlap:

- FRESH - 0% covered.
- TESTED - more than 0% and less than 50% covered.
- PARTIAL - 50% or more, less than 100% covered. The Show PARTIAL bands filter governs its visibility.
- FILLED - 100% covered. The record is retained and is hidden unless Show 100% filled bands is on.
- STATIC - mixed FVG/OB evidence, which has no FVG fill cycle to measure.
- BROKEN - price crossed the far edge of the original overlap without completing the pure-FVG traversal described above. The record is not retained.

Alerts

- The FVG formed and Order Block formed conditions report chart-timeframe detections only. Each one requires its own detection layer to be on, and Enable FVGs and Enable Order Blocks are both off by default. An alert created on default settings will therefore never trigger. Turn on the matching layer first.
- There are still no built-in alerts for confluence formation, fills, mitigation, state changes, or position management.

Timing and interpretation

- Lifecycle mutations and new chart events are processed only after a chart bar closes.
- Higher-timeframe events use completed source-bar values. This avoids using a forming higher-timeframe event, but it also means an event appears only after source-timeframe confirmation.
- Box right edges, label text, and label placement refresh on the chart's last bar. Which column a label occupies, and whether it currently shows text, therefore depend on what else is visible and on the zoom level. These are presentation updates only; they do not replace stored source origins or original band bounds.
- Wick and Close modes retain their prior behavior. Close mode remains dependent on the selected chart timeframe because it evaluates confirmed chart-bar closes.
- Sensitivity defaults are unchanged. The 0.05 ATR gap and overlap thresholds are permissive; raise them to suppress smaller gaps and narrower overlaps.

This is a lifecycle and presentation correction, not a new signal or forecasting feature. No absolute non-repainting claim is made.
Информация о релизе
Updated main image.
Информация о релизе
This version updates the existing FVG Confluence [AFD] script with confluence-lifecycle and label-presentation corrections. It does not change the script title, input names, input order, defaults, alert names, or MPL 2.0 license.

What changed

- ATR overlap qualification is now fixed when a confluence band is created. A band that qualified at formation no longer disappears only because the confirmed TF1 ATR changes later.
- A complete traversal of a pure FVG/FVG overlap now ends in FILLED rather than BROKEN. The existing Show 100% filled bands setting controls whether the retained record is displayed.
- Mixed FVG/OB overlap behavior is unchanged: a far-edge cross still ends the band as BROKEN.
- Chart-zone, raw higher-timeframe, and confluence labels now identify Bullish or Bearish direction.
- Chart-zone, raw higher-timeframe, and confluence labels now keep all visible text on one horizontal line, and all three surfaces are positioned by one shared layout instead of three independent ones. Confluence visits and break counts remain available in the tooltip.
- That layout is now a grid rather than a shared row. A label keeps its own zone price and its usual offset until a neighbour is genuinely in the way. Only then is it moved to the next horizontal column, and only once the columns beside it are taken is it lifted above them. Labels are no longer averaged onto a shared row price, so an uncrowded label sits on the zone it describes.
- The horizontal distance between columns is the width the longest visible label actually needs at the current zoom. It is no longer reduced to fit more labels onto one line, which is what previously allowed nearby labels to overlap.
- Vertical label spacing now also accounts for the visible candle price range, so compressed vertical zoom does not squeeze separate text rows into one another.
- When more labels sit near one price than can be placed legibly, the surplus labels now drop their text rather than print over a neighbour. The small anchor tag stays on its zone, its tooltip still opens where one is set, and the text returns on the next update once the crowding clears. Fewer readable labels is a deliberate trade against unreadable overlapping ones. Widen Label spacing (ATR) or Horizontal label spacing (bars) under Confluence, or use a smaller Label size, to change how many fit.
- With Keep filled FVGs off, fresh chart FVG boxes remain visible but no longer print a 0% Filled label. Partial percentages remain visible, and turning Keep filled FVGs on restores the complete fill scale.
- The default white FVG label-color setting now follows the chart foreground for dark/light contrast. Explicit non-white color selections remain unchanged.
- Invalid or duplicate comparison timeframes now produce one consolidated chart warning. Repeated setting changes do not stack warning labels.
- Every label coordinate now stays inside TradingView's 500-future-bar drawing limit, which prevents the out-of-range label coordinate that could appear during timeframe or viewport changes. That limit now caps how many columns are available rather than squeezing the spacing between them. Retained confluence boxes use time anchors when redrawn, avoiding the corresponding historical bar-index limit.
- HTF lookback is now a rolling window from the latest available chart bar; source zones outside it are not admitted or retained.
- Order-block breaks are deduplicated by pivot origin rather than price alone, so a later distinct pivot at the same price remains eligible. A partially shrunk block also restores its original bounds when it flips to a breaker and restarts from 0% fill.

Confluence band states

The states named above, measured as coverage of the band's original overlap:

- FRESH - 0% covered.
- TESTED - more than 0% and less than 50% covered.
- PARTIAL - 50% or more, less than 100% covered. The Show PARTIAL bands filter governs its visibility.
- FILLED - 100% covered. The record is retained and is hidden unless Show 100% filled bands is on.
- STATIC - mixed FVG/OB evidence, which has no FVG fill cycle to measure.
- BROKEN - price crossed the far edge of the original overlap without completing the pure-FVG traversal described above. The record is not retained.

Alerts

- The FVG formed and Order Block formed conditions report chart-timeframe detections only. Each one requires its own detection layer to be on, and Enable FVGs and Enable Order Blocks are both off by default. An alert created on default settings will therefore never trigger. Turn on the matching layer first.
- There are still no built-in alerts for confluence formation, fills, mitigation, state changes, or position management.

Timing and interpretation

- Lifecycle mutations and new chart events are processed only after a chart bar closes.
- Higher-timeframe events use completed source-bar values. This avoids using a forming higher-timeframe event, but it also means an event appears only after source-timeframe confirmation.
- Box right edges, label text, and label placement refresh on the chart's last bar. Which column a label occupies, and whether it currently shows text, therefore depend on what else is visible and on the zoom level. These are presentation updates only; they do not replace stored source origins or original band bounds.
- Wick and Close modes retain their prior behavior. Close mode remains dependent on the selected chart timeframe because it evaluates confirmed chart-bar closes.
- Sensitivity defaults are unchanged. The 0.05 ATR gap and overlap thresholds are permissive; raise them to suppress smaller gaps and narrower overlaps.
Информация о релизе
Main chart update

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

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