PROTECTED SOURCE SCRIPT
Diupdate

LTF FVG + IFVG + HTF Liquidity + Sessions

145
What this indicator does

This is a precision execution tool around Fair Value Gaps (FVG) and Inverted FVG (IFVG) with optional higher-timeframe confluence, HTF liquidity levels and session levels (Asia / London / Yesterday’s High–Low / Daily 50%).

By default it keeps things clean:

ON by default:

LTF FVG (nearest bullish & bearish)

LTF IFVG (inverted gaps that stay on the chart and freeze on second break)

OFF by default (you enable if you want):

HTF1 & HTF2 FVG layers

HTF liquidity levels (HTF swing highs/lows)

Asia & London session highs/lows

Yesterday’s high/low

Daily 50% line (D 50%)

Everything is time-anchored with xloc=bar_index, clamped to bar_index + 500, and trimmed by age / count so behaviour is stable in replay and on reload.

1. LTF FVG + IFVG (core engine)

Detection

Uses a 3-bar ICT-style pattern:

Bullish FVG: low[1] > high[3] and close[2] > high[3]

Bearish FVG: high[1] < low[3] and close[2] < low[3]

Runs on a Lower Timeframe (LTF):

Default: current chart timeframe

Optional: override via input.

Lifetime model

FVG lifetime is not hardcoded; it’s based on the timeframe:

Short TF → shorter lifetime in bars

Higher TF → proportionally longer lifetime

When lifetime is reached or price fully closes through the gap, the FVG is frozen:

Right edge stops where it should (expiry or break).

Zone is kept as historical structure, not deleted.

IFVG (Inverted FVG)

When an LTF FVG is broken back through:

It can spawn an Inverted FVG (IFVG) in the same price range.

Source must be younger than N LTF bars (configurable, default max age = 15).

Behaviour:

IFVGs are drawn with their own length (in bars) and color.

They stay on the chart even after being broken again.

On the next break in the opposite direction, the right side is cut:

The IFVG stops extending at that bar (second break = freeze).

Total number of IFVG boxes is capped for performance.

Visibility logic (LTF)

Indicator continuously tracks:

Nearest bearish FVG above price

Nearest bullish FVG below price

Only those two active LTF FVGs are visually highlighted (if enabled):

All other still-alive FVGs are tracked internally but muted.

Colours:

Bullish LTF zone color

Bearish LTF zone color

Separate color for IFVGs.

Result: You always see the closest upside and downside LTF imbalance + all IFVGs frozen where they were created and finally broken.

2. HTF1 & HTF2 FVG (optional)

Two higher-timeframe FVG layers for confluence:

HTF1

Timeframe:

Auto-mapped from the chart TF (e.g. 1m → 5m, 5m → 15m, 15m → 1h, 1h → 4h, 4h → Daily, etc.).

Manual override available.

Detection:

Same 3-bar FVG logic, but calculated on HTF and projected down.

Lifetime based on HTF bars, not LTF bars.

Visibility:

Only one bullish and one bearish HTF1 FVG is shown:

Nearest bearish above current price

Nearest bullish below current price

All others are tracked and culled by age/count.

HTF2

Second, higher layer (e.g. 1m → 1h, 5m → 1h, 1h → Daily, 4h → Weekly, etc.).

Same behaviour as HTF1:

FVG detection on HTF2

Lifetime in HTF2 bars

Only nearest bullish and bearish zones are drawn.

HTF visuals

HTF1

Bullish: yellow, ~20% opacity (subtle background)

Bearish: purple, ~20% opacity

HTF2

Bullish: yellow, ~40% opacity (stronger)

Bearish: purple, ~40% opacity

HTF HUD

Small two-column HUD at the bottom center:

Shows active TF for HTF1 and HTF2, e.g.
HTF1 FVG 15 | HTF2 FVG 60

If a layer is turned off, it shows HTF1 FVG: off / HTF2 FVG: off.

3. HTF Liquidity (pivot highs/lows) – optional

A separate module to track HTF liquidity levels:

HTF selection:

Auto-select HTF (mapping similar to FVG)

Or manual HTF via input.

Detection:

Uses pivot highs/lows with configurable left/right strength.

All pivots are pulled via request.security(..., lookahead_off) and anchored correctly on the LTF chart with xloc=bar_index.

Each liquidity level stores:

Price

Whether it’s a high or low

Creation bar index

Sweep status and sweep bar index.

Sweeps

A level is marked as swept when price wicks through it:

High level swept when high >= level price

Low level swept when low <= level price

Once swept:

The line is extended for a limited number of bars (configurable) and then frozen.

Sweep history:

High sweeps and low sweeps stored in arrays.

History is trimmed by bars back, not by random count – deterministic behaviour on reload.

You can turn the entire HTF Liquidity module on/off with LIQ: Show HTF Levels.

4. Sessions: Asia, London, Y-High/Y-Low, D 50% (optional)

All session features are OFF by default – you only enable what you actually want.

Asia & London highs/lows

Two time windows in Europe/Copenhagen time:

Asia session

London session

During each session:

Script tracks the session high and low plus their bar indices.

When a session ends and Show Asia/London High/Low is enabled:

A line is drawn from the session’s high/low with a label:

“Asia high”, “Asia low”, “London high”, “London low”.

Lines are anchored with xloc=bar_index, right side clamped.

Sweep behaviour

On the first sweep:

If price trades through a session high/low:

The line’s right edge is frozen at the sweep bar.

The label is also locked to that bar.

Line style switches to dashed, indicating the level has been taken.

Before sweep:

Lines & labels extend live with the chart (following the latest bar).

Yesterday’s High / Low

Tracks current day’s high & low, then rolls them into Y-high and Y-low at the new daily open.

When Show Y-high/Y-low is enabled:

Lines + labels for Y-high/Y-low are drawn from the rollover bar.

On sweep:

First touch through Y-high or Y-low:

Line is frozen at sweep bar and set to dashed.

Label is locked at that bar.

Before sweep, they extend live.

Daily Mid (D 50%)

Optional midpoint of the daily range ((dayHigh + dayLow) / 2).

Drawn as a dashed line with a “D 50%” label.

Always extends to the latest bar; not sweep-gated.

Session shading (debug)

Optional background shading when current bar is inside:

Asia session

London session

Purely visual; no effect on logic.

5. Design, performance & behaviour

All drawings are:

xloc = bar_index (sticky with scroll/zoom).

Right-clamped to bar_index + 500 to avoid runaway extensions.

Arrays and objects are trimmed:

FVG/IFVG, HTF FVG, HTF liquidity and session objects are all capped by bars back or max count.

This keeps the script stable even on long histories and in replay mode.

HTF data:

All HTF feeds use request.security(..., lookahead_off) for non-repainting behaviour.

Only preview/visual elements (HUD etc.) depend on last bar state.

TL;DR

You get:

A clean, non-spammy LTF FVG/IFVG engine that:

Shows only the nearest bullish and bearish LTF gaps,

Freezes IFVGs on second break instead of deleting them.

Optional HTF1 & HTF2 FVG context (nearest zones per direction).

Optional HTF liquidity from higher-timeframe pivot highs/lows.

Optional Asia/London session highs/lows, Yesterday’s High/Low, and D 50%, all with proper sweep freezing.

Turn on only the modules you actually trade with – the default setup is just FVG + IFVG, ready for intraday execution.
Catatan Rilis
Updated HTF1/HTF2 FVG display to show all active zones (bull + bear) instead of only the nearest above/below price.

HTF1/HTF2 FVG detection now runs regardless of the show toggles; toggles only control rendering/HUD, so zones aren’t missed when toggled off.
Catatan Rilis
Update:
– All sessions (Asia/London) now run in fixed New York time (America/New_York), independent of the viewer’s local timezone.
– Default Asia = 20:00–00:00 NY, London = 03:00–07:00 NY (converted from previous Europe/Copenhagen settings).
– Yesterday High/Low and D 50% are now based on the NY daily session using the exchange daily candle.
– Fixed “x1/x2 too far from current bar index” errors on higher timeframes by clamping session lines and D50 to the current bar_index.
Catatan Rilis
FIX: NY trading day is now anchored to 17:00 (America/New_York) instead of using daily candles.

FIX: Yesterday High/Low now starts at NY 17:00 and stops extending on sweep (levels remain on chart).

FIX: D50 (daily 50%) is calculated from the running NY-day high/low and updates live (no more “starts at load” / stale midpoint).
Catatan Rilis
Changelog:

Added optional LTF FVG width labels (points) on the right side, with configurable X offset (default 10 bars).

Improved LTF highlighting: still shows the nearest FVG above and below, and now also highlights the widest active FVG you are currently inside (using the IFVG color) while price remains inside it.

Width label is also shown for the active in-zone (widest) FVG when applicable.

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.