OPEN-SOURCE SCRIPT
Diupdate LSD Zone Detector V2.5

LSD Zone Detector
LSD Zone Detector is a supply and demand indicator that automatically identifies, manages, and invalidates zones using a rule-based detection engine. The indicator is designed to highlight areas where strong directional movement originated and to maintain only zones that remain structurally valid.
Overview
The indicator searches for demand and supply zones by combining a marking-candle model with Fair Value Gap (FVG) confirmation.
For demand zones, the script identifies a bearish marking candle and then scans subsequent candles for bullish imbalance conditions. For supply zones, the process is reversed using a bullish marking candle and bearish imbalance confirmation.
Only zones that satisfy the internal validation rules are plotted.
Zone Detection Logic
Demand Zones
A demand zone is created when:
A bearish marking candle is identified.
A bullish Fair Value Gap is found within the configured detection window.
No conflicting bearish candle interacts with the marking candle's range during validation.
Supply Zones
A supply zone is created when:
A bullish marking candle is identified.
A bearish Fair Value Gap is found within the configured detection window.
No conflicting bullish candle interacts with the marking candle's range during validation.
This approach attempts to isolate the origin of strong directional movement while filtering out many overlapping or low-quality areas.
Accuracy Zone Boundaries
The indicator uses a boundary refinement method to reduce unnecessarily large zones.
For demand zones:
If the marking candle's upper wick extends beyond the next candle's high, the zone's upper boundary is reduced to the candle body rather than using the full wick.
For supply zones:
If the marking candle's lower wick extends beyond the next candle's low, the zone's lower boundary is reduced to the candle body rather than using the full wick.
This process can create tighter zones while still preserving the original price area that generated the move.
Zone Lifecycle
Every zone passes through a simple lifecycle:
Zone is detected and drawn.
Zone remains active while valid.
Zone extends forward automatically.
First touch converts the zone into a tapped zone.
Invalid zones are removed from the chart.
Only the most recent tapped zones are retained to reduce visual clutter.
Invalidation Rules
A zone is considered invalid when price closes through the opposite side of the zone.
Demand Zone:
Invalidated when a candle body closes below the zone.
Supply Zone:
Invalidated when a candle body closes above the zone.
When invalidated, the zone is removed rather than remaining on the chart as an inactive object.
Break of Structure (BoS)
The indicator includes optional Break of Structure detection.
BoS is generated using an internal pivot-state machine that tracks confirmed swing transitions rather than relying solely on rolling highs and lows.
For demand zones:
A bullish BoS is displayed when price closes above a confirmed structural pivot formed after the zone was created.
For supply zones:
A bearish BoS is displayed when price closes below a confirmed structural pivot formed after the zone was created.
Each zone can trigger a structure break only once.
Inputs
Zone Extension
Controls how far active zones extend into future bars.
Maximum Zones Per Side
Limits the number of active demand and supply zones maintained on the chart.
FVG Window
Defines how many candles are searched when validating imbalance conditions after the marking candle.
BoS Sensitivity
Controls the pivot lookback used by the structure engine.
Show Break of Structure
Enables or disables BoS plotting.
BoS Colors
Allows customization of bullish and bearish structure-break colors.
Intended Use
The indicator is designed as a market structure and supply/demand analysis tool. It can be used to identify potential reaction areas, monitor zone validity, and observe structural changes in price action.
As with any technical analysis tool, signals should be evaluated within a broader trading plan and risk management framework.
LSD Zone Detector is a supply and demand indicator that automatically identifies, manages, and invalidates zones using a rule-based detection engine. The indicator is designed to highlight areas where strong directional movement originated and to maintain only zones that remain structurally valid.
Overview
The indicator searches for demand and supply zones by combining a marking-candle model with Fair Value Gap (FVG) confirmation.
For demand zones, the script identifies a bearish marking candle and then scans subsequent candles for bullish imbalance conditions. For supply zones, the process is reversed using a bullish marking candle and bearish imbalance confirmation.
Only zones that satisfy the internal validation rules are plotted.
Zone Detection Logic
Demand Zones
A demand zone is created when:
A bearish marking candle is identified.
A bullish Fair Value Gap is found within the configured detection window.
No conflicting bearish candle interacts with the marking candle's range during validation.
Supply Zones
A supply zone is created when:
A bullish marking candle is identified.
A bearish Fair Value Gap is found within the configured detection window.
No conflicting bullish candle interacts with the marking candle's range during validation.
This approach attempts to isolate the origin of strong directional movement while filtering out many overlapping or low-quality areas.
Accuracy Zone Boundaries
The indicator uses a boundary refinement method to reduce unnecessarily large zones.
For demand zones:
If the marking candle's upper wick extends beyond the next candle's high, the zone's upper boundary is reduced to the candle body rather than using the full wick.
For supply zones:
If the marking candle's lower wick extends beyond the next candle's low, the zone's lower boundary is reduced to the candle body rather than using the full wick.
This process can create tighter zones while still preserving the original price area that generated the move.
Zone Lifecycle
Every zone passes through a simple lifecycle:
Zone is detected and drawn.
Zone remains active while valid.
Zone extends forward automatically.
First touch converts the zone into a tapped zone.
Invalid zones are removed from the chart.
Only the most recent tapped zones are retained to reduce visual clutter.
Invalidation Rules
A zone is considered invalid when price closes through the opposite side of the zone.
Demand Zone:
Invalidated when a candle body closes below the zone.
Supply Zone:
Invalidated when a candle body closes above the zone.
When invalidated, the zone is removed rather than remaining on the chart as an inactive object.
Break of Structure (BoS)
The indicator includes optional Break of Structure detection.
BoS is generated using an internal pivot-state machine that tracks confirmed swing transitions rather than relying solely on rolling highs and lows.
For demand zones:
A bullish BoS is displayed when price closes above a confirmed structural pivot formed after the zone was created.
For supply zones:
A bearish BoS is displayed when price closes below a confirmed structural pivot formed after the zone was created.
Each zone can trigger a structure break only once.
Inputs
Zone Extension
Controls how far active zones extend into future bars.
Maximum Zones Per Side
Limits the number of active demand and supply zones maintained on the chart.
FVG Window
Defines how many candles are searched when validating imbalance conditions after the marking candle.
BoS Sensitivity
Controls the pivot lookback used by the structure engine.
Show Break of Structure
Enables or disables BoS plotting.
BoS Colors
Allows customization of bullish and bearish structure-break colors.
Intended Use
The indicator is designed as a market structure and supply/demand analysis tool. It can be used to identify potential reaction areas, monitor zone validity, and observe structural changes in price action.
As with any technical analysis tool, signals should be evaluated within a broader trading plan and risk management framework.
Catatan Rilis
# LSD Zone Detector — Changelog---
## V4.0 — Full LSD Setup State Machine
**Type:** Major feature release
### Added
- Per-zone state machine: `AWAIT_LIQ` → `AWAIT_BOS` → `ARMED` → `TAPPED` → `ENTRY`
- Liquidity detection via `ta.pivotlow`/`ta.pivothigh` with dotted `LIQ` line drawn at confirmed level
- Liquidity validity rules: min 2 candles forming the swing, must not touch zone, must sit within 50% proximity of setup range
- Strategy-specific BoS anchored to the origin high/low that created the liquidity (replaces generic pivot BoS)
- Premature tap kills the zone — if price reaches zone before liquidity + BoS, zone is deleted
- Close-inside-zone now draws a gray `✗ CLOSED INSIDE` box and invalidates the setup
- Entry signals: `ENTRY ▲/▼` label, SL at deepest wick, TP at configurable R:R (default 1:4)
- Setup expiry after configurable bars (default 108 ≈ 9h on 5m)
- `ARMED` state visual: label updates to `DEMAND ✔` / `SUPPLY ✔`, border thickens
- Four alert conditions: Setup Armed and Entry for both sides
- FVG always detected, never a filter — zones auto-label as `DEMAND+`/`SUPPLY+` with gold border
### Changed
- Mxwll pivot state machine removed; BoS now computed per-zone from setup high/low
- `useFVG` and `fvgHighlight` checkboxes removed — FVG is always on
- Zone labels are now state-aware (`DEMAND`, `DEMAND+`, `DEMAND ✔`, etc.)
- Tapped boxes replaced by entry/invalid result boxes
---
## V3.1 — Detection Engine Overhaul
**Type:** Refactor + inputs improvement
### Added
- `lookbackBars`, `minImpulse`, `impulseWindow` inputs replacing hardcoded values
- `useFVG` / `fvgHighlight` toggles and `DEMAND ✦`/`SUPPLY ✦` FVG labels
- Grouped inputs and tooltips throughout
### Changed
- Impulse detection decoupled from FVG — counts directional candles independently, tolerates mixed candles
- Dedup now tracks marking candle `bar_index` instead of box left edge
- Zone left edge set to the marking candle's absolute bar position
- Clean check capped at 15 bars to avoid distant price action falsely dirtying zones
### Fixed
- Dedup was suppressing valid zones that shared the same box left edge
---
## V2.5 — Initial Release
### Features
- Accuracy zone boundaries, FVG-based detection, clean check
- Mxwll pivot state machine for generic BoS lines
- Three-state zone visual: active → tapped → deleted
- Hard invalidation on body close through zone
- `extendBars`, `maxZones`, `bosSens` inputs
### Known Issues
- Dedup by left edge caused false suppression (fixed V3.1)
- Impulse conflated with FVG window (fixed V3.1)
- BoS not anchored to liquidity origin (fixed V4.0)
- No liquidity detection or setup state machine (added V4.0)
- Close-inside-zone not distinguished from valid tap (fixed V4.0)
- `demandBottom`/`supplyTop` unconditional wick merge bug (open)
- Clean check coverage gap beyond 15 bars (open)
Catatan Rilis
V4.3 — PR DescriptionType: Bug fixes + zone quality filters
Fixed
Runtime error RE10045 — proximity dedup loops crashed on empty arrays (for ck = 0 to -1 executes one iteration in Pine); both loops now guarded with array.size() > 0
Clean check coverage gap — removed the 15-bar cap; all bars between impulse end and current bar are now checked, so opposing-candle touches no longer slip through and create already-invalid zones
Added
Price-proximity dedup — new zones overlapping ≥70% with an existing active same-side zone are skipped; prevents stacked duplicate zones at the same price level
Max zone size filter — new Max Zone Size (× ATR) input (default 2.0); zones taller than this multiple of ATR(14) are skipped at creation, per the strategy rule that massive zones don't pinpoint a specific area
ATR(14) computed at global scope for the size filter
Notes
Dedup compares same-side zones only (demand vs demand, supply vs supply) — intentional
Known open issue carried forward: accuracy-zone deep-side wick merge remains unconditional
Catatan Rilis
LSD Zone Detector V4.3 — A TradingView Pine Script v6 indicator that automatically detects and manages Liquidity Supply & Demand (LSD) zones on the chart. It identifies demand and supply zones based on impulse moves, tracks liquidity swing pivots and breaks of structure, then fires entry signals with SL/TP lines when a valid directional close occurs off the zone. Includes session backgrounds (Asia/London/NY/Overlap) with a live dashboard showing active session, time remaining, and UTC clock.Catatan Rilis
sssCatatan Rilis
1. Dashboard text size — all size.small → size.normal in every table.cell call across both the setRow helper and the header row.2. Unified zone labels — zoneLabelText() no longer takes a hasFVG parameter. Both FVG and non-FVG zones use identical names (DEMAND / DEMAND ✔ / SUPPLY / SUPPLY ✔) and identical border color/width (demandBorder/supplyBorder, width 1). The fvgBorder color input still exists in the settings panel (harmless to leave it there), and the FVG detection logic is still running internally — just not reflected in any visual difference on the zone box.
Catatan Rilis
fixing the clockCatatan Rilis
tweaking the values !Catatan Rilis
1. Accuracy Zones — Forex Only (Brand New)What changed:
Previously accuracy zone logic applied to all pairs
Now split into two separate drawing functions:
demandTopStd / demandBottomStd — standard full candle, used for futures/crypto/commodities
demandTopAcc / demandBottomAcc — accuracy zone, used for forex only
A router function automatically picks which one based on syminfo.type == "forex"
Which pairs get which:
PairsZone DrawingEURUSD, AUDJPY, USDJPYAccuracy (body + inner wick)XAUUSD, XAGUSD, BTCUSDT, USOIL, ES1!, NQ1!Standard (full candle)
Dashboard update:
Row added to session dashboard showing "✔ Accuracy" (gold) or "Standard" (grey) so you always know which mode is active on the current chart
2. Entry Type Labels (Brand New)
What changed:
V4.4 only had generic ENTRY ▲ and ENTRY ▼ labels
V4.5 now shows exactly which entry type fired on the chart label and on the result box
New labels on chart:
OldNewENTRY ▲ENTRY ▲ | CLOSE or ENTRY ▲ | BOC or ENTRY ▲ | FLIPENTRY ▼ENTRY ▼ | CLOSE or ENTRY ▼ | BOC or ENTRY ▼ | FLIP
Colour coding:
EntryDemand ColourSupply ColourCLOSEGreenRedBOCBlue (#00BFFF)Pink (#FF69B4)FLIPGreenRed
3. Break of Candle Detection (Brand New)
What was added:
New detection block inside both state 2 and state 3 of both demand and supply machines
Demand BOC: fires when high > high[1] (current candle breaks above previous candle's wick) while price is still within the zone tap
Supply BOC: fires when low < low[1] (current candle breaks below previous candle's wick) while price is still within the zone tap
SL placed at high[1] for demand BOC or low[1] for supply BOC — the break point itself
New storage:
Nothing extra needed — BOC uses existing zone state arrays
4. Flip Entry Detection (Brand New)
What was added:
Two new HTF candle open detectors:
is_new_30m — fires when a new 30min candle opens
is_new_1h — fires when a new 1hr candle opens
Combined into isHTFOpen boolean
New input group "Flip Entry (Advanced)" with toggles:
Enable/disable flip detection entirely
Toggle 30m detection on/off
Toggle 1hr detection on/off
New demandWickMade and supplyWickMade boolean arrays track whether a wick into the zone has already been created — flip only fires after the wick is confirmed
Logic:
Demand flip: isHTFOpen AND close > open AND wickMade — candle flips bullish on HTF open after wick
Supply flip: isHTFOpen AND close < open AND wickMade — candle flips bearish on HTF open after wick
Works in both state 2 and state 3
5. New Alert Messages (Updated)
What changed:
V4.4 had 6 alerts
V4.5 has 10 alerts
All alert messages now include {{ticker}} and {{interval}} — so your phone notification immediately tells you which pair and timeframe fired
4 new alerts added:
#Alert6Demand Entry — BOC7Demand Entry — FLIP9Supply Entry — BOC10Supply Entry — FLIP
Alert message format (new):
LSD V4.5 | 🟢 DEMAND ENTRY | CLOSE | XAUUSD 5 — Bullish directional close off demand zone.
LSD V4.5 | 🔴 SUPPLY ENTRY | BOC | EURUSD 5 — Break of candle below prior low.
LSD V4.5 | ⚡ DEMAND TAPPED | NQ1! 5 — Armed demand zone touched on candle close.
6. New Storage Arrays (Internal)
Two new arrays added to track flip entry eligibility:
demandWickMade[] — bool per demand zone, set to true when wick first enters zone
supplyWickMade[] — bool per supply zone, set to true when wick first enters zone
Both pushed and shifted alongside all other zone arrays to stay in sync
Summary of All Changes
FeatureV4.4V4.5Accuracy zonesAll pairsForex onlyZone drawing for futures/cryptoAccuracyStandardDashboard zone mode displayNoYesEntry labelsGeneric ▲▼CLOSE / BOC / FLIPBOC detectionNoYesFlip detectionNoYesHTF candle open detectionNoYes (30m + 1hr toggleable)Total alerts610Ticker in alert messageNoYes {{ticker}} {{interval}}New storage arrays1 (tapAlerted)3 (tapAlerted + wickMade × 2)
Catatan Rilis
alert messages changedCatatan Rilis
test conditionsCatatan Rilis
no tap signal if candle closed insideCatatan Rilis
Bug fixes:TAP alert now only fires when candle closes outside the zone (close > zTop for demand, close < zBot for supply) — closed-inside check runs first so TAP can never fire on an invalidating candle
Body invalidation (bodyBot < zBot / bodyTop > zTop) restricted to states 0/1 only — armed zones (state 2/3) are no longer silently killed by approach candles
BOC entry now requires close > zTop (demand) and close < zBot (supply) — previously fired even when candle closed inside the zone
Liquidity proximity formula corrected from zBot + to zTop + for demand zones
Alerts:
Stripped down to 2 alerts only — Armed Demand Zone Tapped and Armed Supply Zone Tapped
All other alerts (armed, entry close, BOC, flip) removed entirely
Overlap:
Denominator changed to smallerRange (minimum of the two zone sizes) so small zones fully inside large ones are always caught
Safety guard math.max(..., 0.000001) added to prevent division issues
Threshold set to 70%
Visual:
Armed zones that get a candle closing inside now show ✗ CLOSED INSIDE grey box instead of disappearing silently
Unarmed zones (states 0/1) still silently delete as before — no chart clutter
Catatan Rilis
zone invalidation stricterCatatan Rilis
LSD Zone Detector V4.9 — Release NotesThis update focuses on signal quality and chart clarity. Zones now carry a return-leg structure check (External BoS) that flags when price broke real structure on its way back to a zone before tapping it — purely informational, so it never blocks a trade. Every tap is now graded directly on the zone itself: A+ for a clean directional close, B+ for everything else that still qualifies, with the grade carrying through into the entry marker so you can see at a glance which setups were the strongest. Alongside that, we cleaned up the chart — removed redundant pop-up labels (ARMED, NO BoS), fixed the mini-chart timeframe tag so it's visible on any theme, and capped high-frequency diagnostic labels so they stop crowding out the signals that actually matter. Net result: fewer distractions, clearer grading, same reliable zone detection underneath.
Catatan Rilis
⚡ New: Secondary Detection EngineAdded a second, faster liquidity engine that runs alongside the main one — catches valid setups the primary engine sometimes flags too late (fast, small retracements that reverse before the main pivot logic confirms).
How it works: looks for exactly 2 consecutive same-color candles forming the retracement (per the strategy rules), and arms the zone instantly instead of waiting on pivot confirmation. Break of structure still has to clear the real high/low of the whole retracement leg — this only speeds up detection, it doesn't loosen the rules.
How to spot it on chart:
Dashed border = secondary engine caught this one
LIQ⚡ label instead of LIQ
⚡FAST tag in the zone text, all the way through tap/entry
Settings: Feature 7 — Fast Liquidity/BoS (Secondary Engine) group
Enable Secondary Engine — on/off
Rolling Window (hours) — how far back a zone can still qualify for fast-arming (default 8h)
Show Secondary Engine Debug Row — adds a count to the debug table so you can see how often it's firing
Catatan Rilis
Removed Feature 2 (Require Left-Side Break of Structure) entirely:The requireLeftBoS toggle input and its related inputs (bosLookback, bosSwingStrength, rejectFillTransp, rejectBorderTransp)
The findLeftBoSHigh() and findLeftBoSLow() helper functions
The per-zone demandLeftBoS / supplyLeftBoS tracking arrays
The conditional "rejected style" coloring logic in zone creation and at BoS confirmation — zones now just always use the normal dimmed/full coloring (Feature 1's logic), since the pass/fail gate no longer exists
Explained Feature 4 (Grade Debug table) — confirmed it's just a diagnostic counter table (bottom-left) tracking A+/B+ tap counts and pivot-vs-fast-engine arm counts; purely informational, no effect on signals.
Stopped zones from over-extending into future price space:
Demand and supply zone boxes now get created with right=bar_index instead of right=bar_index + extendBars
The per-bar update (box.set_right(...)) now pins the right edge to bar_index each bar instead of projecting 50 bars ahead
Net effect: zone boxes hug the current candle instead of sticking out into empty future space
Left untouched: the LIQ/LIQ⚡ liquidity marker lines, which still extend extendBars into the future (let me know if you want those trimmed too)
Catatan Rilis
Higher time frame chart fixes and reason for entry added on entry bannerCatatan Rilis
LSD Zone Detector V4.10 — ChangelogOpposing-candle invalidation is now color-aware. Pre-BOS (state 0/1), a zone only invalidates when the opposing-color candle touches it (bearish for demand, bullish for supply) — a same-color candle wicking in early no longer kills it.
Zone cleanliness check now validates against the real drawn zone, not just the raw marking candle's high/low. demandTop()/demandBottom()/supplyTop()/supplyBottom() (which extend for wick-inclusion / forex accuracy-zone mode) are used directly, so a candle sitting in that extended sliver can no longer sneak past undetected.
Cleanliness check now scans every candle from the marking candle to the present bar — the old exemption for candles inside the impulse window is gone. An opposing-color candle sitting right next to the impulse cluster now correctly disqualifies that marking candle instead of slipping through.
Duplicate-zone overlap threshold is now adjustable (Duplicate-Zone Overlap Reject (%), default 40%, was a hardcoded 70%) — catches near-duplicate zones that were previously similar enough to look identical but different enough to both get drawn and both fire entries.
Catatan Rilis
some changesCatatan Rilis
Chart is back to just the live zones — dead ones disappear silently again. The actual fix from last message (BoS target frozen at arm time instead of ratcheting to the leg's extreme, plus immediate promotion if BoS already happened during confirmation lag) is untouched and still in.Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
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.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
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.