INVITE-ONLY SCRIPT
Telah dikemas kini

Liquidity Sweep & FVG Strategy

106
This strategy combines higher-timeframe liquidity levels, stop-hunt (sweep) logic, Fair Value Gaps (FVGs) and structure-based take-profits into a single execution engine.
It is not a simple mash-up of indicators: every module (HTF levels, sweeps, FVGs, ZigZag, sessions) feeds the same entry/exit logic.


1. Core Idea

The script looks for situations where price:

Sweeps a higher-timeframe high/low (takes liquidity around obvious levels),

Then forms a displacement candle with a gap (FVG) in the opposite direction,

Then uses the edge of that FVG as a limit entry,

And manages exits using unswept structural levels (ZigZag swings or HTF levels) as targets.

The intent is to systematically trade failed breakouts / stop hunts with a defined structure and risk model.
It is a backtesting / study tool, not a signal service.

2. How the Logic Works (Conceptual)
a) Higher-Timeframe Liquidity Engine

Daily, Weekly and Monthly highs/lows are pulled via request.security() and stored as HTF liquidity levels.

Each level is drawn as a line with optional label (1D/1W/1M High/Low).

A level is marked as “swept” once price trades through it; swept levels may be removed or shortened depending on settings.

b) Sweep & Manipulation Filter

A low sweep occurs when the current low trades through a stored HTF low.

A high sweep occurs when the current high trades through a stored HTF high.

If both a high and a low are swept in the same bar, the script flags this as “manipulation” and blocks new entries around that noise.

The script also tracks the sweep wick, bar index and HTF timeframe for later use in SL placement and labels.

c) FVG Detection & Management

FVGs are defined using a 3-candle displacement model:

Bullish FVG: high[2] < low

Bearish FVG: low[2] > high

Only gaps larger than a minimum size (ATR-based if no manual value is set) are kept.

FVGs are stored in arrays as boxes with: top, bottom, mid (CE), direction, and state (filled / reclaimed).

Boxes are auto-extended and visually faded when price is far away, or deleted when filled.

d) Entry Conditions (Sweep + FVG)

For each recent sweep window:

After a low sweep, the script searches for the nearest bullish FVG below price and uses its top edge as a long limit entry.

After a high sweep, it searches for the nearest bearish FVG above price and uses its bottom edge as a short limit entry.

A “knife protection” check blocks trades where price is already trading through the proposed stop.

Only one entry per sweep is allowed; entries are only placed inside the configured NY trading sessions and only if no manipulation flag is active and EOD protection allows it.

e) Stop-Loss Placement (“Tick-Free” SL)

The stop is not placed directly on the HTF level; instead, the script scans a window around the sweep bar to find a local extreme:

Longs: lowest low in a configurable bar window around the sweep.

Shorts: highest high in that window.

This produces a structure-based SL that is generally outside the main sweep wick.

f) Take-Profit Logic (ZigZag + HTF Levels)

A lightweight ZigZag engine tracks swing highs/lows and removes levels that have already been broken.

For intraday timeframes (< 1h), TP candidates come from unswept ZigZag swings above/below the entry.

For higher timeframes (≥ 1h), TP candidates fall back to unswept HTF liquidity levels.

The script picks up to two targets:

TP1: nearest valid target in the trade direction (or a 2R fallback if none exists),

TP2: second target (or a 4R fallback if none exists).

A multi-TP model is used: typically 50% at TP1, remainder managed towards TP2 with breakeven plus offset once TP1 is hit.

g) Session & End-of-Day Filters

Three predefined NY sessions (Early, Open, Afternoon) are available; entries are only allowed inside active sessions.

An End-of-Day filter checks a user-defined NY close time and:

Blocks new entries close to the end of the day,

Optionally forces flat before the close.

3. Inputs Overview (Conceptual)

Liquidity settings: which HTF levels to track (1D/1W/1M), how many to show, and sweep priority (highest TF vs nearest vs any).

FVG settings: visibility radius, search window after a sweep, minimum FVG size.

ZigZag settings: swing length used for TP discovery.

Execution & protection: limit order timeout, breakeven offset, EOD protection.

Visuals: labels, sweep markers, manipulation warning, session highlighting, TP lines, etc.

For exact meaning of each input, please refer to the inline comments in the open-source code.

4. Strategy Properties & Backtesting Notes

Default strategy properties in this script:

Initial capital: 100,000

Order size: 10% of equity (strategy.percent_of_equity)

Commission: 0.01% per trade (adjust as needed for your broker/asset)

Slippage: must be set manually in the Strategy Tester (recommended: at least a few ticks on fast markets).

Even though the order size is 10% of equity, actual risk per trade depends on the SL distance and is typically much lower than 10% of the account. You should still adjust these values to keep risk within what you personally consider sustainable (e.g. somewhere in the 1–2% range per trade).

For more meaningful results:

Test on liquid instruments (e.g. major indices, FX, or liquid futures).

Use enough history to reach 100+ closed trades on your market/timeframe.

Always include realistic commission and slippage.

Do not assume that past performance will continue.

5. How to Use

Apply the strategy to your preferred symbol and timeframe.

Set broker-like commission and slippage in the Strategy Tester.

Adjust:

HTF levels (1D/1W/1M),

Sessions (NY windows),

FVG search window and minimum size,

ZigZag length and EOD filter.

Observe how entries only appear:

After a HTF sweep,

In the configured session,

At a FVG edge,

With TP lines anchored at unswept structure / liquidity.

Use this primarily as a research and backtesting tool to study how your own ICT / SMC ideas behave over a large sample of trades.

6. Disclaimer

This script is for educational and research purposes only.
It does not constitute financial advice, and it does not guarantee profitability. Always validate results with realistic assumptions and use your own judgment before trading live.
Nota Keluaran
This update refines the Liquidity Sweep & FVG Strategy’s execution, filters and visuals without changing its core concept. Main changes:

1. Session & Time Filters

Simplified the trading session logic to a single NY time window (02:00–15:00) used both for filtering trades and optional background shading.

Fixed End-of-Day protection at 15:00 NY time, removing the user input and reducing configuration ambiguity.

f_isInTradingWindow() and f_isEndOfDay() are now explicit and easier to understand from the code.

2. Liquidity & FVG Management

Adjusted the lookback lengths for Daily / Weekly / Monthly liquidity levels to focus on more recent HTF zones by default.

Added array size management for FVG storage so that old FVGs are automatically removed once a limit is reached, improving performance and avoiding unnecessary objects.

Kept the same 3-candle FVG definition, but clarified the minimum FVG size logic (min_fvg_size with ATR-based fallback).

3. Sweep, SL and Target Logic

Maintained the same HTF sweep detection logic (D/W/M), but tightened its interaction with the trading window and manipulation filter.

Updated f_getCenteredSL() to include a safety bound on the lookback window so that stop calculation does not reference excessively old bars.

Kept the multi-TP model, but refined the ZigZag-based target engine:

ZigZag arrays (zz_highs, zz_lows) now have an explicit size cap and active “swept level” cleanup.

Targets are still chosen from unswept swings or HTF levels depending on timeframe.

4. Visual & Usability Improvements

Streamlined the visual session highlight: a single “Active Session” label/colour instead of multiple named sessions.

Cleaned up old labels more aggressively based on the user-defined retention in keep_days_labels.

Kept TP lines and entry labels, but reset them more consistently whenever the position is flat.

5. Strategy Behaviour & Backtesting Notes

Strategy properties remain transparent:

Initial capital: 100,000

Order size: 10% of equity

Commission: 0.01% per trade (user should still align this with their broker and add slippage in the Strategy Tester).

Because the time filters, FVG management and ZigZag targets were adjusted, backtest results may differ from previous versions. Users are encouraged to re-run tests on their own symbols and timeframes and to treat the script as a research tool, not a guarantee of performance.
Nota Keluaran
This update adds time-based risk protection to the existing Liquidity Sweep & FVG Strategy. A fixed End-of-Day filter at 15:00 New York time and an optional Friday cut-off window were introduced to automatically block new entries and force-close open positions before the weekend. Core sweep, FVG and targeting logic remain unchanged; only trade timing and safety handling have been improved.

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.