Isolated Scroll Container

1. Multitimeframe Fair Value Gap – FVG Strategy Description

On a chosen timeframe, the indicator watches for the classic three-candle "gap" — the current candle starts completely above (or below) the range of the candle two bars earlier — and keeps it only if the current candle's body is big enough compared with the average body. Each surviving gap is drawn as a grey box with a dashed midline and two half-boxes showing how the candle closed, stays on the chart until price fills it, and can be listed in a side table. A smoothed trend line, pulled by every new gap, runs on top.

1.1 Indicator Concept

The indicator answers four simple questions: "Where did price move so fast that it left an untraded hole behind? Was that move big enough to matter? Has price come back to fill the hole yet? And what is the overall pull of these holes on the trend?" The hole is called a Fair Value Gap (FVG) — also called an imbalance: a price area where, within three consecutive candles, buyers or sellers dominated so completely that the two outer candles do not even overlap.

  • An FVG is a gap between candle 1 and candle 3. Take three candles in a row. If the low of the newest candle is above the high of the candle two bars earlier, the area between those two prices was skipped by the market in one violent push up — a Bullish FVG (buy-side imbalance). If the high of the newest candle is below the low of the candle two bars earlier, it is a Bearish FVG (sell-side imbalance). The middle candle is the one that did the "jumping".
  • The belief: markets tend to come back and "rebalance" such holes, so an unfilled gap is a magnet and a possible reaction zone — support for a bullish gap sitting below price, resistance for a bearish gap sitting above it.
  • Only strong gaps count. The newest candle's body must be at least as big as the average candle body seen so far (times a sensitivity factor). Small, noisy gaps are thrown away. (The code calls this body a "wick", but it is the open-to-close distance.)
  • Any timeframe, drawn on any chart. Gaps can be computed on a timeframe different from the one you are looking at (for example 1-hour gaps on a 15-minute chart). Higher-timeframe gaps are bigger and usually treated as more important.
  • Reading the candle: who closed it? Inside each box, two half-boxes show where the newest candle closed within its own high–low range. A close near the high = buyers had the last word; near the low = sellers. No real volume is used.
  • A gap dies when price fills it ("mitigation"). By default as soon as price reaches the gap's midpoint; optionally only when price crosses the whole gap.
  • The FVG trend line. A smoothed line that follows price, with a gentle tilt toward a level that is pulled toward the current price every time a new gap appears; it is coloured by whether that level just rose or fell.

In short: an automatic imbalance finder with a quality filter (body size), zone bookkeeping (alive / filled), a quick "who closed the candle" read and a trend gauge. It is pattern-based, not volume-based, and — unlike many zone indicators — it has no alerts.

1.2 Indicator Features

  • Display:
    • The FVG box: a grey box (85% transparent) covering exactly the gap — from the high of the older candle to the low of the newest one (bullish), or from the high of the newest candle to the low of the older one (bearish). It starts at the older candle and ends 10 chart bars (default) after the newest candle's extreme. It does not stretch to the present, so an old, still-valid gap appears as a short box far to the left. Bullish and bearish boxes look identical: tell them apart by position relative to price.
    • The midline: a white dashed line across the box at the half-way price of the gap.
    • Two half-boxes (buy / sell split): the upper half of the gap holds a green-aqua bar whose length is "buy %" of the box width; the lower half holds a red bar whose length is "sell %". They add up to 100%. Both are 50% transparent by default.
    • The FVG table (optional, off by default): a column on the right-hand margin (about 50–100 bars after the last candle) that repeats every live gap at its price level with its date and time inside. A copy is red if the current close is below the gap, otherwise green-aqua. A thin grey frame spans the whole price history behind it.
    • The FVG trend line (on by default): a smooth line, lime while the underlying level is rising and red while it is falling, with a soft gradient fill (70% transparent) toward a short average.
  • Alert: The indicator has NO alertcondition() calls. To be notified you must create alerts by hand in TradingView or add the code yourself.

1.3 How to Use the Indicator

  • Treat every box as a "magnet and reaction zone". A grey box below price is a bullish gap — look for price to dip back in and bounce (longs). A box above price is a bearish gap — look for price to rally back in and reject (shorts). It is still on the chart only because price has not filled it yet.
  • Trade the return, not the creation. The box appears the moment the gap is complete, when price is already running away. The classic plan is to wait for the pullback into the zone and look for confirmation there. The indicator gives no entry signal on its own.
  • Use the midline as the "half-filled" mark. By default a gap is removed when price touches the midline, so the midline is the line past which the zone counts as used. A reaction that starts at the box edge or before the midline is the cleaner case.
  • Raise Sensativity to keep only impulsive gaps. Example: at 1.0 the newest candle's body must be at least the average body; at 2.0 it must be at least twice the average — fewer, stronger gaps. At 0 every gap qualifies, including noise.
  • Read the buy / sell split as a tie-breaker. A bullish gap with a long aqua bar means the candle that created it closed near its high — a strong, committed push. A short aqua bar means it faded before the close.
  • Pick the timeframe on purpose. Leave Timeframe empty to use the chart's own. Choose a higher one (e.g. 60 on a 15-minute chart) to see bigger imbalances while you trade the smaller chart. Avoid a timeframe lower than the chart.
  • Remember that consecutive gaps are drawn once. In a strong trend several candles in a row can each leave a gap; only the first of the series is drawn (see Flow 2). A missing box inside a run is not a bug.
  • Use the FVG table when the chart gets crowded. Scroll slightly to the right to see it; it lists every live gap with its date so you can find the nearest zone above and below the price.
  • Use the trend line as a slow bias, not a signal. It mostly follows price, so lime / red tells you whether the most recent gap level was pulled up or down. It is smoother and slower than price by design, and distorted at the very start of the chart (see the notes).

1.4 How the Indicator Works

Inputs & their role

  • tf ("Timeframe", timeframe picker, group "FVG Timeframe", default empty = the chart's timeframe): the timeframe on which candles are read to find gaps. Example: on an M15 chart, empty → M15 candles; "60" → H1 candles, so a "three-candle gap" means three hourly candles. It has no tooltip of its own; the explanation sits on the next input.
  • BodySens ("Sensativity" — spelled this way in Settings —, decimal, default 1.0, step 0.1, min 0, same row as Timeframe): the body-size filter. The newest candle's body must be at least average body × this number. Before/after: 0 → no filter, all gaps drawn; 1.0 → body at least average; 2.0 → at least double the average (fewer, stronger gaps). Example: average body 2.5 points, newest body 4 → passes at 1.0 (needs 2.5), fails at 2.0 (needs 5.0).
  • mit ("Mitigated on mid", tick box, group "FVG Mitigation", default on): on = a gap is deleted as soon as price reaches its midpoint; off = only when price crosses the whole gap to its far edge. Example: bullish gap 2644–2647, midpoint 2645.5. A candle with a low of 2645.4 deletes it when "on"; with "off" it survives until a low of 2644 or lower.
  • showActive ("Show FVG table", tick box, group "FVG Table", default off): turns the right-margin table on or off. Display only — the logic is unaffected.
  • TableLeft ("Table Left", integer 0–30, default 5) and TableRight ("Right", integer 10–50, default 10): where the table starts and ends, in steps of 10 bars to the right of the current candle. Defaults → from 50 to 100 bars ahead. Example: Left 5 / Right 10 = a 50-bar-wide column; Left 0 / Right 20 = starts at the last candle, 200 bars wide. Only matters when the table is on.
  • extendLength ("Extend Boxes", integer, group "FVG Style", default 10, no limits): how many chart bars the box is extended past the newest candle's extreme. Example: on M15, 10 bars = 2.5 hours after the newest candle's high (bullish) or low (bearish). Purely cosmetic: the gap stays alive until price fills it, however old.
  • UpCol / DnCol / Col (three colour swatches on one row, no titles): UpCol default green-aqua (#00ffbb, 50% transparent) paints the buy bars and the "green" table copies; DnCol default red (#ff1100, 50%) paints the sell bars and the "red" table copies; Col default grey (85% transparent) paints the FVG box itself. Colours only.
  • showTrend ("Show FVG Trend", tick box, group "Trend", default on): shows or hides the trend line and its fill. Off = nothing of the trend is drawn (the calculation still runs).
  • rp ("Passband Ripple (dB)", decimal, default 10.0, min 0.1, step 0.1) and fc ("Cutoff Frequency (0 to 0.5)", decimal, default 0.1, min 0.001, max 0.5, step 0.01): the two knobs of the smoothing filter. fc is the speed: 0.1 is roughly "one cycle per 10 bars", so smaller = slower and smoother, larger = faster. rp shapes the filter (the notes explain a surprise about its direction).
  • TUpCol (default lime) and TDnCol (default red), one row, group "Trend": colour of the trend while it is rising / falling.

Hard-coded constants (NOT inputs)

  • Data requests: the numbers come from request.security with lookahead_on and no one-candle shift.
  • Time search: four scans of up to 5000 chart bars back (for i = 0 to 4999) to find when each key price happened.
  • Average body: a running average of every candle body seen so far on the chosen timeframe (kept in a list that only grows).
  • Trend settings: the filter input mixes price and the gap level in thirds (see Flow 7), a 10-bar EMA (ta.ema(Trend, 10)) for the fill, 70% fill transparency, and a starting gap level of 0.0.
  • Drawing details: white dashed midline, date format yyyy-MM-dd HH:mm in the chart's timezone, text colour = chart text colour.
  • Limits: max_boxes_count = 500, max_bars_back = 5000; the line limit is not set, so TradingView's default of 50 lines applies (matters for the midlines).

Main logic blocks

⏱️ Flow 0 — Order of work on every candle

  • The indicator works on every candle of the chart, oldest to newest, and remembers things between candles in lists (arrays — numbered lists of values) that live as long as the chart.
  • On each candle: ① fetch numbers from the chosen timeframe → ② find when the key prices happened and compute the buy/sell split → ③ detect a new gap and draw it → ④ clean up filled gaps (this includes a gap just created) → ⑤ redraw the table (if on) → ⑥ update the trend line.
  • Unlike many similar scripts, the clean-up runs after creation. A new gap is therefore checked on its own birth candle, but it cannot be filled there (its midline lies inside the gap, away from the newest candle's low/high).

📥 Flow 1 — Fetching the candles of the chosen timeframe

  • Two requests go to the chosen timeframe (request.security — "ask another timeframe for numbers"). Request A returns six numbers: c1 = close, h / l = high / low of the newest candle, h2 / l2 = high / low two candles earlier, and v = volume. Request B returns wick = the newest candle's body (|close − open|) and avgFVG = the average of all bodies so far.
  • Concrete example (XAUUSD M15, empty timeframe): candle two bars ago — high 2644, low 2638; the middle candle jumps from 2643 to 2651; the newest candle — open 2651, high 2656, low 2647, close 2655. So c1 = 2655, h = 2656, l = 2647, h2 = 2644, l2 = 2638, wick = 4; suppose avgFVG = 2.5.
  • Because there is no one-candle shift, the "newest candle" is the one still being formed on the live bar.

🎯 Flow 2 — Is there a gap? Is it big enough? Is it new?

  • Bullish gap: BullFVG = l > h2 (the second condition, c1 > h2, is automatically true when the first is). Bearish gap: BearFVG = h < l2. The middle candle is not looked at.
  • Example: l = 2647 > h2 = 2644 → a bullish gap exists, covering 2644 to 2647 (3 points), midline 2645.5.
  • Newness: a gap is drawn only when it is true now and was false on the previous candle. In a strong trend, if the next candle also gaps over the one before it, the condition stays true and no second box is drawn — only the first gap of such a series appears.
  • Size filter: wick ≥ avgFVG × BodySens. Example: 4 ≥ 2.5 × 1.0 = 2.5 → passes; at BodySens = 2 it needs 5 → rejected, nothing is drawn.
  • Only when all three agree is a box created, and the trend level is moved (Flow 7).

📦 Flow 3 — Locating the gap in time and drawing the box

  • The numbers from Flow 1 carry prices but no time. A helper scans the chart bars from the newest backwards (up to 5000) and returns the time of the first bar whose high (or low) is exactly equal to the price it is looking for: HBack (for h), LBack (for l), H2Back (for h2), L2Back (for l2). If nothing matches, it uses the current bar's time.
  • Bullish box: from h2 (bottom) up to l (top). Left edge = H2Back; right edge = HBack + extendLength chart bars. Bearish box: from h (bottom) up to l2 (top). Left edge = L2Back; right edge = LBack + extendLength chart bars.
  • Three drawings per gap: the grey box, a white dashed midline at (l + h2) ÷ 2 (bullish) or (l2 + h) ÷ 2 (bearish), and the two half-boxes of Flow 4. All are stored in lists (newest first), separately for bullish and bearish gaps.
  • Concrete example: gap 2644–2647, midline 2645.5. On M15, the box starts at the bar where 2644 was the high (two candles earlier) and ends 10 bars after the bar where 2656 was the high.

⚖️ Flow 4 — The buy / sell split inside the box

  • It describes the newest candle, not the gap: buyVol = (close − low) ÷ (high − low) × 100 and sellVol = (high − close) ÷ (high − low) × 100. The volume number cancels out (it only adds rounding), so this is not volume.
  • The upper half of the gap (midline to top): a green-aqua bar, length = box width × buyVol ÷ 100. The lower half (bottom to midline): a red bar, length = box width × sellVol ÷ 100. Both start at the box's left edge. The same layout is used for bullish and bearish gaps.
  • Concrete example: close 2655, low 2647, high 2656 → buy = 8 ÷ 9 ≈ 89%, sell = 1 ÷ 9 ≈ 11%. On a box 12 bars wide: an aqua bar about 10.7 bars long in the upper half, a red bar about 1.3 bars in the lower half → the candle closed strongly, near its high.
  • If the candle has no range (high = low) or no volume, the division fails and the result is "no value"; the box may then not draw correctly.

🧹 Flow 5 — Keeping gaps alive: mitigation

  • On every chart candle, the code walks through the stored gaps (bullish list, then bearish list) and tests the current chart candle's low / high against each.
  • Bullish gap, mit on: low ≤ midline; off: low ≤ bottom of the gap. Bearish gap, mit on: high ≥ midline; off: high ≥ top of the gap. When true, the box, its midline and both half-boxes are deleted and removed from the lists.
  • Concrete example (bullish gap 2644–2647, midline 2645.5): a candle with low 2646 → nothing. A candle with low 2645.4 → deleted when mit is on; with it off, it survives until a low of 2644 or lower.

🗂️ Flow 6 — The FVG table (only when "Show FVG table" is on)

  • On every candle the previous copies are deleted and rebuilt. First a transparent frame from the lowest low to the highest high of the entire chart history, spanning TableLeft to TableRight bars after the current candle.
  • Then, for each live bullish and then each bearish gap, a copy of the box is drawn in that column at the same price levels, with the gap's start date/time as text. Colour: red if the close is below the gap's bottom, otherwise green-aqua.
  • Example: a live bullish gap 2644–2647 created on 2026-10-14 09:15 appears in the column with that text; with a close of 2640 it is red, with 2650 it is green-aqua.

📈 Flow 7 — The FVG trend line

  • The gap level. A running number starts at 0.0. Each time a gap is created (bullish or bearish — direction does not matter) the new level = the average of the current candle's (open + high + low + close) ÷ 4 and the previous level. Between gaps it stays flat. Example: previous 2600, candle average 2660 → 2630.
  • The filter input. On every candle the line is fed src = (h + l + level) ÷ 3: the newest candle's high and low count for two thirds, the gap level for one third. Example: h 2656, l 2647, level 2630 → src = 2644.3. At the very start, level = 0 → src ≈ (2656 + 2647 + 0) ÷ 3 = 1767.7, far below price; the first gap lifts the level to 2660 ÷ 2 = 1330 (src ≈ 2211), and each following gap halves the remaining distance, so it takes roughly 8–10 gaps before the line sits on price.
  • The smoothing. src goes through a second-order low-pass filter (a formula blending the newest value with the two previous outputs). fc sets the speed (default 0.1 ≈ a few bars of lag), rp the damping. The result is the plotted "FVG Trend Filter" line.
  • The colour: lime when the gap level just rose, red when it fell; while flat it keeps the previous colour. Start colour: grey. The colour follows the gap level, not the plotted line's slope.
  • The fill: a gradient between the filtered line and a 10-bar EMA of the gap level (an invisible helper line), in the trend colour at 70% transparency. Hidden together with the line when showTrend is off.

Outputs & their role in trading

  • The FVG box + midline: a map of unfilled imbalances with a "half-filled" level.
  • The buy / sell bars: a quick quality hint on how the gap-forming candle closed.
  • The FVG table: a tidy list of live gaps with dates.
  • The FVG trend line: a smooth line that mostly follows price, coloured lime / red by the last gap level move.
💡 Important technical notes:
  • No alerts. The script has no alertcondition() at all — no "FVG created", no "FVG filled". Anything event-based must be added by hand.
  • Look-ahead and repainting on higher timeframes. Data is requested with lookahead_on and without the usual one-candle shift. On historical bars of a higher timeframe, the finished candle of that timeframe is already visible at its first chart bar, so gaps appear earlier in history than they would have live. On the live bar the gap flag can appear and disappear until the higher-timeframe candle closes. Leaving the timeframe empty (chart timeframe) or going higher is the safer use; a timeframe lower than the chart is not reliable.
  • "Wick" is really the body. The size filter compares the candle's open-to-close distance with the average body. A candle with a huge wick but a small body fails the filter. Also, the average is taken over all history from the start of the data, not a recent window, so in a market that became much more volatile than it used to be, almost every candle passes (and vice versa). The list behind it also grows with every candle and, most likely, with every live tick, so the average can drift slightly on a live chart.
  • Pattern, not volume. The "buy / sell" split is only the close position inside the newest candle's range. It says nothing about real volume, and it describes the candle that completed the gap, not the gap itself.
  • The middle candle is never checked. Only the newest and the two-bars-earlier candle matter. The gap is "fair value" in the simplified sense of a non-overlapping pair, not a verified three-candle pattern with a strong middle body.
  • Time anchoring uses exact price equality. Each box edge in time is "the most recent chart bar whose high (or low) equals that price". A newer bar printing the exact same price moves the anchor there; if none is found within 5000 bars, the current bar is used. On a higher timeframe, the anchor is the bar that made the extreme, not the start of the candle. The four scans run on every candle (up to 20,000 steps each), which makes the script heavy on long charts.
  • The trend line starts below price and mostly follows price. Because one third of its input is the gap level (starting at 0.0), the beginning of the chart shows a line well under price. Judging by the formula, rp acts as a damping factor: the default 10 dB gives a heavily damped, slower curve, higher values are smoother still, and values near 0.1 respond faster with a little overshoot — the opposite of the tooltip wording ("higher = more fluctuations").
  • Removing while looping. The clean-up deletes entries from the lists while it is looping over them. If two gaps are filled on the same candle, one of them may be skipped until the next candle.
  • Gaps never expire by time. Only price can delete a gap, so on a long chart the number of live gaps can grow. Each gap uses 3 boxes (plus 1 line), and with the table on, one more box per gap. The default 50-line limit and the 500-box limit can be reached on long histories: the oldest midlines disappear first, and past the box limit TradingView deletes the oldest boxes.
  • Name trap in the code: the object called bv is the bullish group, while its field bv holds the buy-volume bars; sv is the bearish group and its field sv the sell-volume bars. Only readability is affected.
Zoom/Pan Layered Image
Background Overlay
− +

The indicator above just became a TRADING BOT — 1 AI click

📊Original indicator
→
🤖AI 1-click convert
→
⚙️Bot trading 24/7