1. Dynamic Delta FVG Strategy Description
Detects classic 3-candle Fair Value Gaps (FVGs), splits each gap zone into two portions by an estimated buy/sell volume ratio reconstructed from lower-timeframe data (optimally 1 second), and aggregates market sentiment from every open gap into a live dashboard.
1.1 Indicator Concept
This indicator is built on the classic Fair Value Gap (FVG) concept: a 3-candle pattern where the current candle and the candle 2 bars ago leave a price "gap" (the middle candle is entirely skipped in the comparison) where no trading actually occurred - this zone is considered "not yet fairly filled" and tends to pull price back to it later.
What sets this indicator apart: whenever an FVG forms, it also estimates the buy/sell volume split that occurred WITHIN the specific candle that caused the gap (the middle "displacement" candle), by pulling lower-timeframe candle data (default: 1 second) and accumulating volume by each small candle's direction. That ratio is then used to split the FVG zone into two differently-colored boxes in proportion - whichever side dominated the delta gets the larger visual share of the zone, giving an at-a-glance read of who actually controlled the displacement that created the gap.
- Market sentiment dashboard: averages the buy/sell ratio across EVERY currently-open (not yet mitigated) gap into a single "Buyer Strength / Seller Strength / Net Sentiment" summary.
- Two mitigation modes: "Touch" (price only needs to reach the gap's near edge) or "Full Fill" (price must pierce all the way to the far edge) - lets the user choose how strict "invalidated" means.
- Dual filter: filters by the displacement candle's volume (vs. its 20-bar average) AND by the gap's minimum size in ATR terms - removing insignificant/tiny gaps.
1.2 Indicator Features
- Delta-Split FVG Zone: each gap is drawn as two stacked boxes - a "buyer" box (buyColorInput) and a "seller" box (sellColorInput), the dividing line between them shifts according to the measured B/S% ratio, not a fixed midpoint.
- Delta Label: a "B:xx% S:xx%" text placed at the zone's midpoint, background colored to match whichever side dominated (green if buyers won, red if sellers won).
- Mitigation-Driven Lifecycle: a gap's right edge auto-extends every bar while active (runs on every tick, reacting almost instantly), disappearing or fading (depending on "Show Mitigated Gaps") the moment it's mitigated under the selected mode.
- Overlap filter: when ON, any newly formed gap automatically deletes EVERY unmitigated older gap whose price range overlaps it - no strength comparison, the new gap always wins.
- Live dashboard: a 2-column table showing open bullish/bearish gap counts, average buyer/seller strength %, and a "Net Sentiment" row classifying the spread as Aggressive Buying/Selling/Neutral.
- Max gap cap: once "Max Active Gaps" is exceeded, the OLDEST gap in the array is FIFO-retired.
1.3 How to Use the Indicator
- Read the larger colored portion of each gap as the controlling side: if the "buy" box takes up most of the zone, the candle that created the gap had more buying volume behind it - a bullish tilt to weigh when price revisits that zone.
- Pick "Mitigation Mode" to match your trading style: "Touch" reacts sooner (a gap invalidates the instant price merely reaches the near edge), "Full Fill" waits for stronger confirmation (price must fill the entire zone).
- Watch the Dashboard for overall sentiment: "Aggressive Buying/Selling" appears when the average spread between the two sides exceeds 5 percentage points - use it as general context, not a direct entry signal for any one specific gap.
- Tune "Min ATR Magnitude" to filter gaps by size: raise it to keep only gaps that are genuinely significant relative to average volatility; lower it to catch small gaps too.
- Consider "Delta Timeframe" carefully: 1 second gives the highest accuracy but requires a paid TradingView plan for second-based data; without it, the indicator automatically falls back to a rough candle-direction estimate (see the Note below).
- Enable "Filter Overlapping" on lower timeframes to avoid multiple overlapping gaps cluttering the chart - only the newest gap per price zone is kept.
1.4 How the Indicator Works
Inputs & Roles
- volMultInput ("Min Volume Threshold", Float, default: 0.0): the displacement (middle) candle's volume must be ≥ its own 20-bar average × this multiplier. Default 0 = always true (the filter is OFF by default).
- atrMultInput ("Min ATR Magnitude", Float, default: 0.2): the gap's size must be ≥ the current ATR(14) × this multiplier. Example: ATR=0.0050, atrMultInput=0.2 → the gap must be ≥ 0.0010 wide to qualify.
- mitModeInput ("Mitigation Mode", options: Touch/Full Fill, default: "Touch"): "Touch" = invalidated the moment price reaches the gap's NEAR edge; "Full Fill" = must pierce all the way to the FAR edge to count as invalidated.
- filterOverlapInput ("Filter Overlapping", Boolean, default: true): when ON, a new gap deletes every unmitigated older gap whose price range overlaps it - no strength comparison, the new gap always survives.
- deltaTfInput ("Delta Timeframe", default: "1S"): the lower timeframe used to reconstruct the buy/sell volume ratio inside the displacement candle.
- maxGapsInput ("Max Active Gaps", Integer, default: 20): caps the storage array's size; once exceeded, the FRONT element (oldest by creation order) is FIFO-retired.
- buyColorInput / sellColorInput (Color, default: 60%-transparent green/red): colors for each gap's two box halves.
- showMitigatedInput ("Show Mitigated Gaps", Boolean, default: false): keeps a mitigated gap as a very faded box instead of deleting it outright, and separately deletes its delta label.
- showDashInput ("Show Dashboard", Boolean, default: true) / dashPosInput / dashSizeInput: toggle, position, and text size for the summary dashboard.
Main Logic Blocks
🧮 Flow 1: Estimating Volume Delta (every bar, real time)
- get_delta_details() runs on EVERY bar (not waiting for a confirmed close): pulls open/close/volume data for every deltaTfInput-timeframe candle inside the current bar. For each small candle: closes up → its full volume goes to buyVol; closes down → goes to sellVol; flat → split 50/50.
- If lower-timeframe data isn't available (fallback): uses the current bar's own direction with a hardcoded 100 value (bullish → buyVol=100; bearish → sellVol=100; flat → 50/50 each) - since only the FINAL percentage matters, the absolute magnitude of 100 doesn't matter, only the correct ratio does.
- Returns buyPct/sellPct = % of the total (defaults to 50/50 if the total is 0).
🎯 Flow 2: FVG Detection (confirmed bars only)
- isBullFVG = low > high[2]: the current bar's low sits above the high from 2 bars ago - a bullish gap. isBearFVG = high < low[2]: symmetric, a bearish gap. Both completely SKIP the middle (displacement) candle in the comparison.
- volFilter: the MIDDLE candle's (bar[1]'s) volume ≥ its own 20-bar average × volMultInput. sizeFilterBull/Bear: the gap's width ≥ the current ATR × atrMultInput.
- If both pass: top/bottom are assigned based on gap direction (bull: top=current low, bottom=high[2]; bear: top=low[2], bottom=current high).
🖊️ Flow 3: Drawing the Delta-Split Gap
- Reads buyPct[1]/sellPct[1] - SPECIFICALLY the delta ratio measured at the MIDDLE candle (the displacement candle, index 1), not the confirmation bar - since the middle candle is the one that actually "caused" the gap.
- splitLevel = bottom + rangeHeight × (sellPct/100): the dividing line between the buy and sell boxes. A higher sellPct → splitLevel shifts UP → the sell box gets a larger share of the area (and vice versa) - box area is directly proportional to the measured delta %.
- If filterOverlapInput is ON: deletes every unmitigated older gap whose price range overlaps the new one - no strength comparison.
- Draws two boxes (buy box from top→splitLevel, sell box from splitLevel→bottom) spanning bar_index[2] (the true origin candle) to the current bar_index, plus a delta text label at the midpoint, colored by whichever side dominated. Pushes into the activeGaps array. If the array exceeds maxGapsInput → deletes the FRONT element (oldest).
- Example: a bullish FVG, top=1.2650 (current low), bottom=1.2620 (high[2]) → rangeHeight=0.0030. bPct[1]=65%, sPct[1]=35% → splitLevel=1.2620+0.0030×0.35=1.2620+0.00105=1.26305. The buy box spans 1.26305 to 1.2650 (65% of the zone's height), the sell box spans 1.2620 to 1.26305 (35%) - the buy portion clearly dominates, correctly reflecting the 65% bPct.
🗑️ Flow 4: Mitigation Check (every tick)
- For a bullish gap: "Touch" mode → mitigated when low < gap.top (near edge); "Full Fill" mode → when low < gap.bottom (far edge). A bearish gap is symmetric, using high instead of low.
- If mitigated: sets isMitigated := true. If showMitigatedInput is OFF → both boxes and the label are deleted outright, removed from the array. If ON → kept in the array, both boxes switch to a very faded color (90%/95% transparent, using chart.fg_color), the label object is DELETED entirely (not just cleared) - the box's right edge simply stops being updated going forward (an implicit freeze at wherever it last extended to, not an explicit "freeze" call).
- If NOT yet mitigated: extends both boxes' right edges + the label to the current bar_index (the label always sits exactly AT the box's right edge, not floating ahead like on some other indicators). Accumulates into the dashboard totals: totalActive, sumAllBuyPct/sellPct (using gap.buyPct/gap.sellPct - the FROZEN value from when the gap first formed, not a live-recomputed delta), and counts openBull/openBear.
📊 Flow 5: Computing Dashboard Metrics
- avgBuyAll = sumAllBuyPct / totalActive (defaults to 50% if no gap is open), avgSellAll the same way. netMarketDelta = avgBuyAll - avgSellAll.
🖥️ Flow 6: Drawing the Dashboard (last bar only)
- A 2-column × 9-row table, only drawn when barstate.islast and showDashInput is on: header "Active Imbalances" → open bullish/bearish gap counts → Buyer Strength/Seller Strength % → a "Net Sentiment" row classifying netMarketDelta > 5 → "Aggressive Buying", < -5 → "Aggressive Selling", otherwise → "Neutral / Balanced".
Outputs & Usage Roles
- Delta-split FVG box: a support/resistance zone with a visual "delta weight" - each color's share of the area is proportional to the buy/sell strength measured when the gap formed.
- Delta text label: the exact B/S% figures for that specific gap, with a background color flagging which side dominated.
- Dashboard: a market-wide sentiment overview based on EVERY currently-open gap, meant as general context rather than a signal for any single gap.


