本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// QUANTUM MARKET X-RAY (QMX)
// Advanced Market Intelligence Overlay | Pine Script® v6
// ═══════════════════════════════════════════════════════════════════════════════════════════════
//
// SCRIPT IDENTITY
// ───────────────────────────────────────────────────────────────────────────────────────────────
// Indicator Name : QUANTUM MARKET X-RAY (QMX)
// Short Title : QMX
// Version : 1.0.0
// Language : Pine Script® Version 6
// Type : Overlay Indicator (drawings rendered directly on the candlestick chart)
//
// AUTHOR & PUBLISHER
// ───────────────────────────────────────────────────────────────────────────────────────────────
// Author : Michael_Fx_Trader
// Publisher : Michael_Fx_Trader
// Rights Holder : Michael_Fx_Trader
// Copyright : © 2026 Michael_Fx_Trader. All Rights Reserved.
//
// DECLARATION OF ORIGINALITY & AUTHOR VERIFICATION
// ───────────────────────────────────────────────────────────────────────────────────────────────
// I, Michael_Fx_Trader, hereby declare and verify that:
// 1. QUANTUM MARKET X-RAY (QMX) is an ORIGINAL work, designed and implemented from scratch
// according to my own specification (see "Project Specification" below).
// 2. This script is NOT copied, cloned, translated, re-skinned or derived from any third-party
// indicator, open-source script, invite-only script or commercial product.
// 3. All detection logic (liquidity levels, sweeps, traps, pressure waves, displacement,
// candle forensics, liquidity vacuum, exhaustion clouds, price gravity, dashboard scoring)
// is based exclusively on standard chart data: Open, High, Low, Close and Volume (OHLCV).
// 4. No institutional order-flow, order-book, dark-pool or hidden-liquidity data is used,
// claimed or fabricated. All "liquidity" objects are PROXIES derived from price structure.
// 5. The author, publisher and sole rights holder of this script is Michael_Fx_Trader.
//
// COPYRIGHT & LICENSE NOTICE
// ───────────────────────────────────────────────────────────────────────────────────────────────
// This source code, its architecture, visual design, scoring methodology and documentation are
// the intellectual property of Michael_Fx_Trader. Copying, redistribution, resale, republishing
// or derivative works are NOT permitted without prior written permission of the author.
//
// TECHNICAL INTEGRITY STATEMENT
// ───────────────────────────────────────────────────────────────────────────────────────────────
// • No future-data leakage: pivots are used only after full confirmation (right-side bars).
// • Detection events are processed on CONFIRMED (closed) bars only → no misleading repainting.
// • Higher-timeframe data uses request.security() with the previous CLOSED HTF bar
// (expression[1] + lookahead_on) → non-repainting multi-timeframe overview.
// • Price Gravity targets and the dashboard are live analytical read-outs of the CURRENT state.
// • Efficient arrays of typed objects, automatic cleanup of old drawings, object-limit safe.
//
// RISK DISCLAIMER
// ───────────────────────────────────────────────────────────────────────────────────────────────
// QMX is an analytical/educational tool. All zones, scores, targets and "evidence" values are
// analytical estimates, NOT predictions, NOT guarantees and NOT financial advice. Trading
// involves substantial risk of loss. Always do your own analysis and use proper risk management.
//
// PROJECT SPECIFICATION (modules)
// ───────────────────────────────────────────────────────────────────────────────────────────────
// 01 Liquidity Intelligence 02 Liquidity Sweep Detector 03 Smart Money Trap Detector
// 04 Market Pressure Waves 05 Displacement Energy 06 Candle Forensics
// 07 Liquidity Vacuum 08 Exhaustion Clouds 09 Price Gravity Engine
// 10 Quantum Dashboard 11 Visual Design 12 Technical Requirements
// ═══════════════════════════════════════════════════════════════════════════════════════════════
indicator(title = "QUANTUM MARKET X-RAY (QMX)", shorttitle = "QMX", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500, max_polylines_count = 100, max_bars_back = 500)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// INPUTS
// ═══════════════════════════════════════════════════════════════════════════════════════════════
const string G_GEN = "⚙ 00 · General"
const string G_COL = "🎨 01 · Colors"
const string G_LIQ = "02 · Liquidity Intelligence"
const string G_SWP = "03 · Liquidity Sweep Detector"
const string G_TRP = "04 · Smart Money Traps"
const string G_PRS = "05 · Market Pressure Waves"
const string G_DSP = "06 · Displacement Energy"
const string G_FOR = "07 · Candle Forensics"
const string G_VAC = "08 · Liquidity Vacuum"
const string G_EXH = "09 · Exhaustion Clouds"
const string G_GRV = "10 · Price Gravity Engine"
const string G_DSH = "11 · Quantum Dashboard"
// ── General
atrLen = input.int(14, "ATR Length", minval = 2, maxval = 100, group = G_GEN)
swingLen = input.int(5, "Swing Pivot Length (bars each side)", minval = 2, maxval = 30, group = G_GEN, tooltip = "Pivots are confirmed only after this many bars on the right side → no future leakage.")
relVolLen = input.int(20, "Relative Volume Length", minval = 5, maxval = 100, group = G_GEN)
glowOn = input.bool(true, "Layered Glow Effects", group = G_GEN)
// ── Colors
cBull = input.color(#00FF9C, "Bullish · Neon Green", group = G_COL)
cCyan = input.color(#00E5FF, "Bullish · Electric Cyan", group = G_COL)
cBear = input.color(#FF2D55, "Bearish · Neon Red", group = G_COL)
cPurple = input.color(#A855F7, "Bearish · Purple", group = G_COL)
cMagenta = input.color(#FF2BD6, "Liquidity · Magenta", group = G_COL)
cGold = input.color(#FFC400, "Exhaustion · Gold", group = G_COL)
cAmber = input.color(#FF9F1C, "Exhaustion · Amber", group = G_COL)
cSilver = input.color(#C0C6D4, "Neutral · Silver", group = G_COL)
cGrey = input.color(#6B7280, "Neutral · Grey", group = G_COL)
// ── 02 Liquidity
liqOn = input.bool(true, "Enable Liquidity Intelligence", group = G_LIQ)
showBSL = input.bool(true, "Draw Buy-Side Liquidity (BSL)", group = G_LIQ)
showSSL = input.bool(true, "Draw Sell-Side Liquidity (SSL)", group = G_LIQ)
showLiqLbl = input.bool(true, "Strength Labels", group = G_LIQ)
showEq = input.bool(true, "Equal Highs / Lows Connectors", group = G_LIQ)
eqTolAtr = input.float(0.15, "Equal Level Tolerance (× ATR)", minval = 0.02, maxval = 1.0, step = 0.01, group = G_LIQ)
zoneAtr = input.float(0.20, "Zone Half-Thickness (× ATR)", minval = 0.05, maxval = 1.0, step = 0.05, group = G_LIQ)
maxLevels = input.int(6, "Max Active Levels Per Side", minval = 2, maxval = 15, group = G_LIQ)
keepSwept = input.int(4, "Keep Swept Levels (history per side)", minval = 0, maxval = 20, group = G_LIQ)
// ── 03 Sweeps
sweepOn = input.bool(true, "Enable Sweep Detector", group = G_SWP)
sweepCircle = input.bool(true, "Circular Sweep Footprints", group = G_SWP)
sweepLabel = input.bool(true, "Sweep Strength Labels", group = G_SWP)
sweepLink = input.bool(true, "Connecting Lines To Swept Level", group = G_SWP)
sweepCandle = input.bool(true, "Highlight Sweep Candle", group = G_SWP)
minSweepStr = input.int(40, "Minimum Sweep Strength", minval = 0, maxval = 100, group = G_SWP)
minPenAtr = input.float(0.03, "Minimum Penetration (× ATR)", minval = 0.0, maxval = 1.0, step = 0.01, group = G_SWP)
// ── 04 Traps
trapOn = input.bool(true, "Enable Trap Detector", group = G_TRP)
trapBox = input.bool(true, "Trap Boxes", group = G_TRP)
trapLabel = input.bool(true, "Trap Labels", group = G_TRP)
trapLen = input.int(20, "Range Lookback For Breakouts", minval = 5, maxval = 100, group = G_TRP)
trapWin = input.int(6, "Failure Window (bars)", minval = 2, maxval = 20, group = G_TRP)
maxTraps = input.int(6, "Max Trap Boxes", minval = 1, maxval = 20, group = G_TRP)
// ── 05 Pressure waves
pressOn = input.bool(true, "Enable Pressure Waves", group = G_PRS)
showBullWave = input.bool(true, "Bullish Pressure Wave (cyan)", group = G_PRS)
showBearWave = input.bool(true, "Bearish Pressure Wave (purple)", group = G_PRS)
showCore = input.bool(true, "Wave Core Line", group = G_PRS)
showRev = input.bool(true, "Pressure Reversal Markers", group = G_PRS)
pressLen = input.int(8, "Pressure Smoothing", minval = 2, maxval = 50, group = G_PRS)
waveLen = input.int(21, "Wave Core Length", minval = 5, maxval = 100, group = G_PRS)
waveAmp = input.float(1.2, "Wave Amplitude (× ATR)", minval = 0.2, maxval = 5.0, step = 0.1, group = G_PRS)
// ── 06 Displacement
dispOn = input.bool(true, "Enable Displacement Energy", group = G_DSP)
dispOutline = input.bool(true, "Glowing Candle Outlines", group = G_DSP)
dispTrail = input.bool(true, "Energy Trails", group = G_DSP)
dispZoneOn = input.bool(true, "Displacement Zones", group = G_DSP)
dispMarker = input.bool(true, "Directional Markers", group = G_DSP)
dispLabel = input.bool(true, "Strength Labels", group = G_DSP)
dispMult = input.float(1.3, "Min Body (× ATR)", minval = 0.5, maxval = 5.0, step = 0.1, group = G_DSP)
dispVol = input.float(1.2, "Min Relative Volume (if volume exists)", minval = 0.5, maxval = 5.0, step = 0.1, group = G_DSP)
dispMinScore = input.int(45, "Min Energy Score", minval = 0, maxval = 100, group = G_DSP)
maxDisp = input.int(12, "Max Displacement Footprints", minval = 2, maxval = 40, group = G_DSP)
// ── 07 Forensics
forOn = input.bool(true, "Enable Candle Forensics", group = G_FOR)
fRejOn = input.bool(true, "Strong Rejection Candles", group = G_FOR)
fWickOn = input.bool(false, "Wick Imbalance", group = G_FOR)
fAbsOn = input.bool(true, "Absorption-Like Candles", group = G_FOR)
fFailOn = input.bool(true, "Failed Auction Proxies", group = G_FOR)
fExhOn = input.bool(true, "Momentum Exhaustion Candles", group = G_FOR)
fStrongOn = input.bool(false, "Strong Bullish / Bearish Candles", group = G_FOR)
// ── 08 Vacuum
vacOn = input.bool(true, "Enable Liquidity Vacuum", group = G_VAC)
vacLabel = input.bool(true, "Vacuum Labels (Entry / Exit / Status)", group = G_VAC)
vacMinAtr = input.float(0.40, "Min Corridor Size (× ATR)", minval = 0.1, maxval = 3.0, step = 0.05, group = G_VAC)
vacLook = input.int(40, "Historical Overlap Lookback", minval = 10, maxval = 200, group = G_VAC)
vacInt = input.float(2.5, "Max Historical Interaction", minval = 0.0, maxval = 20.0, step = 0.5, group = G_VAC)
maxVac = input.int(6, "Max Vacuum Corridors", minval = 1, maxval = 20, group = G_VAC)
// ── 09 Exhaustion
exhOn = input.bool(true, "Enable Exhaustion Clouds", group = G_EXH)
exhEarlyOn = input.bool(true, "Early Exhaustion Clouds", group = G_EXH)
exhConfOn = input.bool(true, "Confirmed Exhaustion Clouds", group = G_EXH)
exhEarlyThr = input.int(45, "Early Exhaustion Score", minval = 20, maxval = 100, group = G_EXH)
exhConfThr = input.int(32, "Confirmation Min Score", minval = 10, maxval = 100, group = G_EXH)
maxClouds = input.int(4, "Max Clouds", minval = 1, maxval = 10, group = G_EXH)
// ── 10 Gravity
gravOn = input.bool(true, "Enable Price Gravity Engine", group = G_GRV)
gravZones = input.bool(true, "Attraction Zones / Target Fields", group = G_GRV)
gravConn = input.bool(true, "Directional Connectors", group = G_GRV)
gravLbl = input.bool(true, "Target Strength / Distance Labels", group = G_GRV)
gravTargets = input.int(3, "Targets Per Direction (max 3)", minval = 1, maxval = 3, group = G_GRV)
usePDHL = input.bool(true, "Include Previous Day High / Low", group = G_GRV)
// ── 11 Dashboard
dashOn = input.bool(true, "Show Dashboard", group = G_DSH)
dashPos = input.string(position.top_right, "Position", options = [position.top_right, position.top_left, position.bottom_right, position.bottom_left, position.middle_right, position.middle_left], group = G_DSH)
tblSize = input.string(size.small, "Text Size", options = [size.tiny, size.small, size.normal], group = G_DSH)
mtfOn = input.bool(true, "Multi-Timeframe Overview", group = G_DSH)
keyOn = input.bool(true, "Key Levels Section", group = G_DSH)
tf1 = input.timeframe("5", "MTF Row 1", group = G_DSH)
tf2 = input.timeframe("15", "MTF Row 2", group = G_DSH)
tf3 = input.timeframe("60", "MTF Row 3", group = G_DSH)
tf4 = input.timeframe("240", "MTF Row 4", group = G_DSH)
tf5 = input.timeframe("D", "MTF Row 5", group = G_DSH)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// TYPES & METHODS
// ═══════════════════════════════════════════════════════════════════════════════════════════════
type Level
float price
int bar
bool isHigh
int touches = 1
float strength
float half
box bx
box gl
line ln
label lb
type Zone
box bx
box gl
line ln
line ln2
label lb
label lb2
label lb3
polyline pl
polyline pl2
float top
float bot
int dir
int t0
float score
float fillPct
float fillLvl
bool active = true
method kill(Level this) =>
if not na(this.bx)
box.delete(this.bx)
this.bx := na
if not na(this.gl)
box.delete(this.gl)
this.gl := na
if not na(this.ln)
line.delete(this.ln)
this.ln := na
if not na(this.lb)
label.delete(this.lb)
this.lb := na
true
method kill(Zone this) =>
if not na(this.bx)
box.delete(this.bx)
this.bx := na
if not na(this.gl)
box.delete(this.gl)
this.gl := na
if not na(this.ln)
line.delete(this.ln)
this.ln := na
if not na(this.ln2)
line.delete(this.ln2)
this.ln2 := na
if not na(this.lb)
label.delete(this.lb)
this.lb := na
if not na(this.lb2)
label.delete(this.lb2)
this.lb2 := na
if not na(this.lb3)
label.delete(this.lb3)
this.lb3 := na
if not na(this.pl)
polyline.delete(this.pl)
this.pl := na
if not na(this.pl2)
polyline.delete(this.pl2)
this.pl2 := na
true
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// GENERIC HELPERS (no dependency on chart-level series)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
f_clamp(float x, float lo, float hi) =>
math.max(lo, math.min(hi, x))
// Core OHLCV engine: ATR, bullish/bearish pressure (bodies, wicks, volume, range, momentum), relative volume.
// Used on the chart timeframe AND inside request.security() for the MTF overview.
f_core(int aLen, int pLen, int vLen) =>
float a = ta.atr(aLen)
float aS = math.max(nz(a, syminfo.mintick * 10), syminfo.mintick)
float r = high - low
float b = math.abs(close - open)
float u = high - math.max(open, close)
float lw = math.min(open, close) - low
float vS = ta.sma(nz(volume), vLen)
bool hv = ta.cum(nz(volume)) > 0
float rv = hv and vS > 0 ? nz(volume) / vS : 1.0
float cp = r > 0 ? (close - low) / r : 0.5
float momUp = f_clamp(nz((close - close[3]) / (aS * 3.0)), 0.0, 1.0)
float momDn = f_clamp(nz((close[3] - close) / (aS * 3.0)), 0.0, 1.0)
float rW = f_clamp(r / aS, 0.3, 2.0)
float vW = f_clamp(rv, 0.5, 2.0)
float bullRaw = 0.35 * (close > open and r > 0 ? b / r : 0.0) + 0.30 * cp + 0.15 * (r > 0 ? lw / r : 0.0) + 0.20 * momUp
float bearRaw = 0.35 * (close < open and r > 0 ? b / r : 0.0) + 0.30 * (1.0 - cp) + 0.15 * (r > 0 ? u / r : 0.0) + 0.20 * momDn
float bE = ta.ema(bullRaw * rW * vW, pLen)
float rE = ta.ema(bearRaw * rW * vW, pLen)
float t = bE + rE
float n = t > 0 ? (bE - rE) / t : 0.0
[aS, bE, rE, n, rv]
// HTF snapshot: evaluated INSIDE request.security(); returns values of the previous CLOSED HTF bar.
f_htf() =>
[a, bE, rE, n, rv] = f_core(atrLen, pressLen, relVolLen)
float mid = ta.ema(hl2, waveLen)
float slope = mid - mid[3]
float aAvg = ta.sma(a, 50)
float ratio = aAvg > 0 ? a / aAvg : 1.0
float bd = math.abs(close - open)
float rg = high - low
bool disp = rg > 0 and bd >= dispMult * a and bd / rg >= 0.6
float dispR = ta.highest(disp ? 1.0 : 0.0, 5)
[n[1], slope[1], ratio[1], dispR[1]]
f_mtf(string tf) =>
request.security(syminfo.tickerid, tf, f_htf(), lookahead = barmerge.lookahead_on)
f_cnt(array<int> a, int within) =>
int c = 0
int n = a.size()
if n > 0
for i = 0 to n - 1
if bar_index - a.get(i) <= within
c += 1
c
f_push(array<int> a) =>
a.push(bar_index)
if a.size() > 30
a.shift()
true
f_trimZones(array<Zone> arr, int maxN) =>
while arr.size() > maxN
Zone o = arr.shift()
o.kill()
true
f_topIdx(array<float> a) =>
int idx = -1
float m = 0.0
int n = a.size()
if n > 0
for i = 0 to n - 1
if a.get(i) > m
m := a.get(i)
idx := i
idx
f_bar(float pct, int n) =>
int f = int(math.round(f_clamp(pct, 0.0, 100.0) / 100.0 * n))
str.repeat("█", f) + str.repeat("░", n - f)
f_tfName(int s) =>
s < 3600 ? str.tostring(int(s / 60)) + "m" : s < 86400 ? str.tostring(int(s / 3600)) + "H" : s < 604800 ? str.tostring(int(s / 86400)) + "D" : s < 2592000 ? str.tostring(int(s / 604800)) + "W" : "1M"
f_mtfState(float n, float sl, float ra, float di) =>
di > 0 ? "Expansion" : ra < 0.75 ? "Consolidation" : n > 0.12 and sl < 0 ? "Recovery" : n < -0.12 and sl > 0 ? "Pullback" : math.abs(n) >= 0.12 ? "Trend" : "Consolidation"
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// CORE CALCULATIONS (chart timeframe)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
[atrV, bullE, bearE, net, relVol] = f_core(atrLen, pressLen, relVolLen)
bool hasVol = ta.cum(nz(volume)) > 0
float rng = high - low
float body = math.abs(close - open)
float upW = high - math.max(open, close)
float loW = math.min(open, close) - low
float closePos = rng > 0 ? (close - low) / rng : 0.5
float bodyAtr = body / atrV
float uwr = rng > 0 ? upW / rng : 0.0
float lwr = rng > 0 ? loW / rng : 0.0
float totE = bullE + bearE
float bullShare = totE > 0 ? bullE / totE : 0.5
int barMs = math.max(timeframe.in_seconds() * 1000, 1000)
float phV = ta.pivothigh(high, swingLen, swingLen)
float plV = ta.pivotlow(low, swingLen, swingLen)
float hiN = ta.highest(high, trapLen)
float loN = ta.lowest(low, trapLen)
float hi20 = ta.highest(high, 20)
float lo20 = ta.lowest(low, 20)
float hh10 = ta.highest(high, 10)
float ll10 = ta.lowest(low, 10)
float avgUw = ta.sma(uwr, 3)
float avgLw = ta.sma(lwr, 3)
float rngAvg5 = ta.sma(rng, 5)
float atrRank = ta.percentrank(atrV, 100)
float waveMid = ta.ema(hl2, waveLen)
// ── Pressure state machine (dead-band avoids whipsaw)
var int pState = 0
int pPrev = pState
if net > 0.10
pState := 1
else if net < -0.10
pState := -1
bool pressRevUp = pState == 1 and pPrev == -1
bool pressRevDn = pState == -1 and pPrev == 1
bool pressWeak = (net > 0.10 and net < net[3] - 0.04) or (net < -0.10 and net > net[3] + 0.04)
float amp0 = atrV * waveAmp
float bullAmp = ta.ema(amp0 * (0.25 + bullShare), 3)
float bearAmp = ta.ema(amp0 * (0.25 + (1.0 - bullShare)), 3)
// ── Displacement
bool rawUp = close > open and rng > 0 and bodyAtr >= dispMult and body / rng >= 0.6 and closePos >= 0.70 and (not hasVol or relVol >= dispVol)
bool rawDn = close < open and rng > 0 and bodyAtr >= dispMult and body / rng >= 0.6 and closePos <= 0.30 and (not hasVol or relVol >= dispVol)
float dirPos = rawUp ? closePos : 1.0 - closePos
float dispScore = 35.0 * f_clamp(bodyAtr / (dispMult * 1.8), 0.0, 1.0) + 25.0 * (hasVol ? f_clamp(relVol / 2.5, 0.0, 1.0) : 0.5) + 25.0 * dirPos + 15.0 * f_clamp(rng / atrV / (dispMult * 2.0), 0.0, 1.0)
bool dispUp = dispOn and rawUp and dispScore >= dispMinScore
bool dispDn = dispOn and rawDn and dispScore >= dispMinScore
var float energy = 0.0
energy := math.max((dispUp or dispDn) ? dispScore : 0.0, energy * 0.88)
// ── Candle forensics (raw conditions)
bool fRejBear = rng >= 0.6 * atrV and uwr >= 0.60 and closePos <= 0.35
bool fRejBull = rng >= 0.6 * atrV and lwr >= 0.60 and closePos >= 0.65
bool fWickBull = not fRejBull and rng >= 0.5 * atrV and loW >= 3.0 * math.max(upW, syminfo.mintick) and lwr >= 0.40
bool fWickBear = not fRejBear and rng >= 0.5 * atrV and upW >= 3.0 * math.max(loW, syminfo.mintick) and uwr >= 0.40
bool fAbsorb = hasVol and rng > 0 and relVol >= 1.6 and rng <= 0.8 * atrV and body / rng <= 0.40
bool fAbsBull = fAbsorb and closePos >= 0.5
bool fAbsBear = fAbsorb and closePos < 0.5
bool fFailUp = rng > 0 and high > hh10[1] and close < hh10[1] and closePos < 0.40 and (hasVol ? relVol <= 1.1 : bodyAtr < 0.5)
bool fFailDn = rng > 0 and low < ll10[1] and close > ll10[1] and closePos > 0.60 and (hasVol ? relVol <= 1.1 : bodyAtr < 0.5)
bool fMomExhUp = (close - close[3]) >= 1.5 * atrV and body < body[1] and upW > body
bool fMomExhDn = (close[3] - close) >= 1.5 * atrV and body < body[1] and loW > body
bool fStrongUp = close > open and rng > 0 and bodyAtr >= 0.8 and body / rng >= 0.65 and not rawUp
bool fStrongDn = close < open and rng > 0 and bodyAtr >= 0.8 and body / rng >= 0.65 and not rawDn
// ── Swing structure memory (confirmed pivots only) + divergence inputs
var float lastPH = na
var float prevPH = na
var float lastPL = na
var float prevPL = na
var float lastPHnet = na
var float prevPHnet = na
var float lastPLnet = na
var float prevPLnet = na
var int phConf = 0
var int plConf = 0
if barstate.isconfirmed and not na(phV)
prevPH := lastPH
prevPHnet := lastPHnet
lastPH := phV
lastPHnet := nz(net[swingLen])
phConf := bar_index
if barstate.isconfirmed and not na(plV)
prevPL := lastPL
prevPLnet := lastPLnet
lastPL := plV
lastPLnet := nz(net[swingLen])
plConf := bar_index
// ── Exhaustion scores
float posN = hi20 > lo20 ? (close - lo20) / (hi20 - lo20) : 0.5
bool divBear = not na(lastPH) and not na(prevPH) and lastPH > prevPH and lastPHnet < prevPHnet - 0.05 and bar_index - phConf <= 25
bool divBull = not na(lastPL) and not na(prevPL) and lastPL < prevPL and lastPLnet > prevPLnet + 0.05 and bar_index - plConf <= 25
float exUa = posN >= 0.85 ? 25.0 : posN >= 0.70 ? 12.0 : 0.0
float exUb = divBear ? 25.0 : 0.0
float exUc = (net > 0.05 and net < net[3] - 0.04) ? 20.0 : 0.0
float exUd = 20.0 * f_clamp(avgUw / 0.5, 0.0, 1.0)
float exUe = hasVol ? ((relVol >= 1.3 and bodyAtr < 0.7) ? 10.0 : 0.0) : (rng < rngAvg5 * 0.8 ? 6.0 : 0.0)
float exhUpScore = posN >= 0.70 ? exUa + exUb + exUc + exUd + exUe : 0.0
float exDa = posN <= 0.15 ? 25.0 : posN <= 0.30 ? 12.0 : 0.0
float exDb = divBull ? 25.0 : 0.0
float exDc = (net < -0.05 and net > net[3] + 0.04) ? 20.0 : 0.0
float exDd = 20.0 * f_clamp(avgLw / 0.5, 0.0, 1.0)
float exDe = hasVol ? ((relVol >= 1.3 and bodyAtr < 0.7) ? 10.0 : 0.0) : (rng < rngAvg5 * 0.8 ? 6.0 : 0.0)
float exhDnScore = posN <= 0.30 ? exDa + exDb + exDc + exDd + exDe : 0.0
float exhNow = math.max(exhUpScore, exhDnScore)
// ── HTF structural reference: previous day high / low (previous CLOSED day, no leakage)
[pdh, pdl] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead = barmerge.lookahead_on)
// ── MTF overview (previous closed HTF bar)
int s1 = timeframe.in_seconds(tf1)
int s2 = timeframe.in_seconds(tf2)
int s3 = timeframe.in_seconds(tf3)
int s4 = timeframe.in_seconds(tf4)
int s5 = timeframe.in_seconds(tf5)
[m1n, m1s, m1r, m1d] = f_mtf(tf1)
[m2n, m2s, m2r, m2d] = f_mtf(tf2)
[m3n, m3s, m3r, m3d] = f_mtf(tf3)
[m4n, m4s, m4r, m4d] = f_mtf(tf4)
[m5n, m5s, m5r, m5d] = f_mtf(tf5)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// STATE (arrays of typed objects → efficient cleanup)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
var array<Level> bslArr = array.new<Level>()
var array<Level> sslArr = array.new<Level>()
var array<Level> bslDone = array.new<Level>()
var array<Level> sslDone = array.new<Level>()
var array<Zone> sweepFx = array.new<Zone>()
var array<Zone> trapFx = array.new<Zone>()
var array<Zone> dispFx = array.new<Zone>()
var array<Zone> dZones = array.new<Zone>()
var array<Zone> vacs = array.new<Zone>()
var array<Zone> clouds = array.new<Zone>()
var array<Zone> gravFx = array.new<Zone>()
var array<int> evSwBull = array.new<int>()
var array<int> evSwBear = array.new<int>()
var array<int> evTrapBuy = array.new<int>() // trapped buyers (bearish consequence)
var array<int> evTrapSell = array.new<int>() // trapped sellers (bullish consequence)
var array<int> evDispUp = array.new<int>()
var array<int> evDispDn = array.new<int>()
var array<int> evExhUp = array.new<int>() // bullish move exhausted (gold)
var array<int> evExhDn = array.new<int>() // bearish move exhausted (purple)
var bool bkUp = false
var float bkUpLvl = na
var int bkUpBar = 0
var float bkUpExt = na
var bool bkDn = false
var float bkDnLvl = na
var int bkDnBar = 0
var float bkDnExt = na
var int exhUpSt = 0
var int exhUpBar = 0
var int exhUpLast = -1000
var Zone exhUpCloud = na
var int exhDnSt = 0
var int exhDnBar = 0
var int exhDnLast = -1000
var Zone exhDnCloud = na
var int lastVacUp = -1000
var int lastVacDn = -1000
var bool tblInit = false
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// OBJECT BUILDERS (use chart-level series declared above)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
f_lvlText(Level l) =>
string kind = l.touches >= 3 ? (l.isHigh ? "BSL Cluster ×" : "SSL Cluster ×") + str.tostring(l.touches) : l.touches == 2 ? (l.isHigh ? "BSL · Equal Highs" : "SSL · Equal Lows") : (l.isHigh ? "BSL Zone" : "SSL Zone")
kind + "\nStrength: " + str.tostring(math.round(l.strength))
f_addLevel(array<Level> arr, bool isHigh, float px, int bar, float vN, float wN) =>
float tol = atrV * eqTolAtr
bool merged = false
color c = isHigh ? cBear : cBull
bool draw = isHigh ? showBSL : showSSL
int n = arr.size()
if n > 0
for i = 0 to n - 1
Level l = arr.get(i)
if not merged and math.abs(l.price - px) <= tol
merged := true
l.touches := l.touches + 1
l.price := isHigh ? math.max(l.price, px) : math.min(l.price, px)
l.strength := math.min(100.0, l.strength + 14.0 + 6.0 * vN)
if not na(l.bx)
box.set_top(l.bx, l.price + l.half)
box.set_bottom(l.bx, l.price - l.half)
if not na(l.gl)
box.set_top(l.gl, l.price + l.half * 2.4)
box.set_bottom(l.gl, l.price - l.half * 2.4)
if draw and showEq
if na(l.ln)
l.ln := line.new(l.bar, l.price, bar, l.price, color = color.new(c, 30), style = line.style_dotted, width = 1)
else
line.set_y1(l.ln, l.price)
line.set_y2(l.ln, l.price)
line.set_x2(l.ln, bar)
if not na(l.lb)
label.set_text(l.lb, f_lvlText(l))
label.set_y(l.lb, isHigh ? l.price + l.half : l.price - l.half)
if not merged
float st = math.min(100.0, 30.0 + 20.0 * vN + 15.0 * wN)
Level nl = Level.new(price = px, bar = bar, isHigh = isHigh, touches = 1, strength = st, half = atrV * zoneAtr)
if draw
if glowOn
nl.gl := box.new(left = bar, top = px + nl.half * 2.4, right = bar_index, bottom = px - nl.half * 2.4, border_color = color.new(c, 85), border_width = 3, extend = extend.right, bgcolor = color.new(c, 93))
nl.bx := box.new(left = bar, top = px + nl.half, right = bar_index, bottom = px - nl.half, border_color = color.new(c, 25), border_width = 1, extend = extend.right, bgcolor = color.new(c, 80))
if showLiqLbl
nl.lb := label.new(math.min(bar + 3, bar_index), isHigh ? px + nl.half : px - nl.half, f_lvlText(nl), style = isHigh ? label.style_label_down : label.style_label_up, color = color.new(#0B0F1C, 15), textcolor = c, size = size.small)
arr.push(nl)
if arr.size() > maxLevels
Level old = arr.shift()
old.kill()
true
// Scans active levels for sweeps / breaks. Returns the strongest sweep of this bar.
f_sweepScan(array<Level> arr, array<Level> done, bool isHigh) =>
float best = 0.0
float bestPx = na
int bestBar = 0
bool bestRej = false
color c = isHigh ? cBear : cBull
int n = arr.size()
if n > 0
for i = n - 1 to 0
Level l = arr.get(i)
float pen = isHigh ? high - l.price : l.price - low
bool back = isHigh ? close < l.price : close > l.price
bool beyond = isHigh ? close > l.price : close < l.price
if pen > atrV * minPenAtr and back
float wickBack = rng > 0 ? (isHigh ? high - close : close - low) / rng : 0.0
float penSc = 25.0 * f_clamp(pen / (atrV * 0.5), 0.0, 1.0)
float rejSc = 30.0 * f_clamp(wickBack, 0.0, 1.0)
float backSc = 15.0 * f_clamp(math.abs(l.price - close) / (atrV * 0.5), 0.0, 1.0)
float volSc = hasVol ? 15.0 * f_clamp(relVol / 2.0, 0.0, 1.0) : 7.0
float lvSc = 15.0 * l.strength / 100.0
float sc = penSc + rejSc + backSc + volSc + lvSc
if sc > best
best := sc
bestPx := l.price
bestBar := l.bar
bestRej := wickBack >= 0.5
if not na(l.bx)
box.set_extend(l.bx, extend.none)
box.set_right(l.bx, bar_index)
box.set_bgcolor(l.bx, color.new(c, 92))
box.set_border_style(l.bx, line.style_dashed)
if not na(l.gl)
box.set_extend(l.gl, extend.none)
box.set_right(l.gl, bar_index)
if not na(l.lb)
label.delete(l.lb)
l.lb := na
if keepSwept == 0
l.kill()
else
done.push(l)
if done.size() > keepSwept
Level o = done.shift()
o.kill()
arr.remove(i)
else if beyond
l.kill()
arr.remove(i)
[best, bestPx, bestBar, bestRej]
f_drawSweep(bool bearish, float sc, float lvlPx, int lvlBar, bool rej) =>
Zone z = Zone.new(dir = bearish ? -1 : 1, t0 = bar_index, score = sc)
color c = bearish ? cBear : cBull
float y = bearish ? high : low
float off = atrV * 0.30
if sweepCircle
if glowOn
z.lb := label.new(bar_index, y, "", style = label.style_circle, color = color.new(c, 80), size = size.large)
z.lb2 := label.new(bar_index, y, "", style = label.style_circle, color = color.new(c, 10), size = size.tiny)
if sweepLink
z.ln := line.new(lvlBar, lvlPx, bar_index, lvlPx, color = color.new(c, 35), style = line.style_dotted, width = 1)
z.ln2 := line.new(bar_index, lvlPx, bar_index, y, color = color.new(c, 10), style = line.style_solid, width = 2)
if sweepLabel
z.lb3 := label.new(bar_index, y + (bearish ? off : -off), (bearish ? "Bearish Sweep" : "Bullish Sweep") + (rej ? " ⟲" : "") + "\nSQ: " + str.tostring(math.round(sc)), style = bearish ? label.style_label_down : label.style_label_up, color = color.new(#0B0F1C, 15), textcolor = c, size = size.small)
z
f_drawTrap(bool buyers, int leftBar, float top, float bot, float sc) =>
Zone z = Zone.new(dir = buyers ? -1 : 1, t0 = bar_index, score = sc)
color c = buyers ? cBear : cBull
float pad = atrV * 0.15
int lx = math.max(leftBar - 1, 0)
if trapBox
if glowOn
z.gl := box.new(left = lx, top = top + pad * 1.6, right = bar_index + 4, bottom = bot - pad * 1.6, border_color = color.new(c, 80), border_width = 4, bgcolor = na)
z.bx := box.new(left = lx, top = top + pad, right = bar_index + 4, bottom = bot - pad, border_color = color.new(c, 15), border_width = 2, bgcolor = color.new(c, 86), text = trapLabel ? (buyers ? "Trapped Buyers ⚠" : "Trapped Sellers ⚠") : "", text_color = c, text_size = size.small, text_halign = text.align_left, text_valign = text.align_top)
z
f_drawDisp(bool bull, float sc) =>
Zone z = Zone.new(dir = bull ? 1 : -1, t0 = bar_index, score = sc)
color c = bull ? cBull : cBear
int hw = int(barMs * 0.46)
float pad = atrV * 0.08
if dispOutline
if glowOn
z.gl := box.new(left = time - hw, top = high + pad * 2.0, right = time + hw, bottom = low - pad * 2.0, border_color = color.new(c, 70), border_width = 4, xloc = xloc.bar_time, bgcolor = color.new(c, 92))
z.bx := box.new(left = time - hw, top = high + pad, right = time + hw, bottom = low - pad, border_color = color.new(c, 5), border_width = 1, xloc = xloc.bar_time, bgcolor = na)
if dispTrail
z.ln2 := line.new(bar_index - 1, open, bar_index, close, color = color.new(c, 75), width = 7)
z.ln := line.new(bar_index - 1, open, bar_index, close, color = color.new(c, 0), width = 2)
if dispLabel
z.lb := label.new(bar_index, bull ? low - pad * 5.0 : high + pad * 5.0, "⚡" + str.tostring(math.round(sc)), style = bull ? label.style_label_up : label.style_label_down, color = color.new(c, 78), textcolor = color.new(cSilver, 0), size = size.tiny)
z
f_drawDZone(bool bull) =>
Zone z = Zone.new(dir = bull ? 1 : -1, t0 = bar_index, top = math.max(open, close), bot = math.min(open, close))
color c = bull ? cBull : cBear
z.bx := box.new(left = bar_index, top = z.top, right = bar_index + 1, bottom = z.bot, border_color = color.new(c, 55), border_width = 1, border_style = line.style_dashed, extend = extend.right, bgcolor = color.new(c, 90), text = "DISP", text_color = color.new(c, 30), text_size = size.tiny, text_halign = text.align_right)
z
f_vacText(Zone z) =>
string st = z.fillPct >= 0.999 ? "FILLED ✓" : z.fillPct <= 0.02 ? "UNFILLED" : "PARTIAL " + str.tostring(math.round(z.fillPct * 100)) + "%"
float en = z.dir == 1 ? z.bot : z.top
float ex = z.dir == 1 ? z.top : z.bot
(z.dir == 1 ? "VACUUM ▲ " : "VACUUM ▼ ") + st + "\nEntry " + str.tostring(en, format.mintick) + " → Exit " + str.tostring(ex, format.mintick)
f_interaction(float bot, float top) =>
float s = 0.0
float sz = math.max(top - bot, syminfo.mintick)
for i = 3 to 3 + vacLook
float ov = math.min(top, high[i]) - math.max(bot, low[i])
if ov > 0
float w = hasVol ? f_clamp(nz(relVol[i], 1.0), 0.5, 2.0) : 1.0
s += math.min(ov / sz, 1.0) * w
s
f_drawVac(bool up, float top, float bot, float sc) =>
Zone z = Zone.new(dir = up ? 1 : -1, t0 = bar_index, top = top, bot = bot, score = sc, fillPct = 0.0, fillLvl = up ? top : bot)
color c = up ? cCyan : cPurple
float pad = atrV * 0.10
if glowOn
z.gl := box.new(left = bar_index - 2, top = top + pad, right = bar_index, bottom = bot - pad, border_color = color.new(c, 85), border_width = 3, extend = extend.right, bgcolor = na)
z.bx := box.new(left = bar_index - 2, top = top, right = bar_index, bottom = bot, border_color = color.new(c, 35), border_width = 1, border_style = line.style_dashed, extend = extend.right, bgcolor = color.new(c, 88))
if vacLabel
z.lb := label.new(bar_index + 3, (top + bot) / 2.0, f_vacText(z), style = label.style_label_left, color = color.new(#0B0F1C, 25), textcolor = c, size = size.tiny)
z
f_drawCloud(bool up, float sc, bool conf) =>
Zone z = Zone.new(dir = up ? 1 : -1, t0 = bar_index, score = sc)
color c1 = up ? cGold : cPurple
color c2 = up ? cAmber : cMagenta
float sg = up ? 1.0 : -1.0
float base = up ? math.max(high, math.max(high[1], high[2])) : math.min(low, math.min(low[1], low[2]))
float h = atrV * (0.7 + sc / 100.0) * (conf ? 1.25 : 0.85)
int x0 = bar_index - 3
array<float> fx = array.from(0.0, 0.25, 0.5, 0.75, 1.0, 0.75, 0.5, 0.25)
array<float> fy = array.from(0.10, 0.55, 1.00, 0.70, 0.25, 0.12, 0.14, 0.10)
for layer = 0 to 1
float k = layer == 0 ? 1.0 : 0.6
color cc = layer == 0 ? c1 : c2
array<chart.point> pts = array.new<chart.point>()
for i = 0 to 7
int px = x0 + 6 + int(math.round((fx.get(i) - 0.5) * 12.0 * k))
float py = base + sg * h * fy.get(i) * k
pts.push(chart.point.from_index(px, py))
polyline pl = polyline.new(pts, curved = true, closed = true, line_color = color.new(cc, layer == 0 ? 55 : 35), fill_color = color.new(cc, conf ? (layer == 0 ? 82 : 70) : (layer == 0 ? 90 : 82)), line_width = 1)
if layer == 0
z.pl := pl
else
z.pl2 := pl
z.lb := label.new(x0 + 6, base + sg * h * 1.12, "Exhaustion Cloud · " + (conf ? "Confirmed" : "Early") + "\n" + (up ? "Bullish" : "Bearish") + " Exh · " + str.tostring(math.round(sc)), style = up ? label.style_label_down : label.style_label_up, color = color.new(#0B0F1C, 20), textcolor = c1, size = size.small)
z
f_gScore(float p, float s, int age, bool up) =>
float d = math.abs(p - close) / atrV
float dS = 1.0 / (1.0 + d / 2.5)
float fr = f_clamp(1.0 - age / 300.0, 0.15, 1.0)
float dp = f_clamp(0.5 + 0.5 * (up ? net : -net), 0.0, 1.0)
100.0 * (0.35 * s / 100.0 + 0.30 * dS + 0.15 * fr + 0.20 * dp)
f_drawTarget(float px, float sc, int rank, bool up) =>
Zone z = Zone.new(dir = up ? 1 : -1, t0 = bar_index, score = sc, top = px)
color c = up ? cCyan : cMagenta
float hh = atrV * 0.22
float d = math.abs(px - close)
if gravZones
if glowOn
z.gl := box.new(left = bar_index + 1, top = px + hh * 3.0, right = bar_index + 16, bottom = px - hh * 3.0, border_color = na, bgcolor = color.new(c, 94))
z.bx := box.new(left = bar_index + 1, top = px + hh, right = bar_index + 16, bottom = px - hh, border_color = color.new(c, 30), border_width = 1, bgcolor = color.new(c, 82))
if gravConn
z.ln := line.new(bar_index, close, bar_index + 3, px, color = c, style = rank == 1 ? line.style_arrow_right : line.style_dashed, width = rank == 1 ? 2 : 1)
if gravLbl
z.lb := label.new(bar_index + 8, px, "T" + str.tostring(rank) + (up ? " ▲ " : " ▼ ") + "· Str " + str.tostring(math.round(sc)) + "\n" + (up ? "+" : "-") + str.tostring(d, format.mintick) + " · " + str.tostring(d / atrV, "0.0") + " ATR", style = label.style_label_center, color = color.new(#0B0F1C, 20), textcolor = c, size = size.small, tooltip = "Analytical estimate based on liquidity strength, distance, freshness and directional pressure. Not a prediction.")
z
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// MAIN ENGINE — runs on CONFIRMED bars only (no intrabar repainting)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
bool sweepBullNow = false
bool sweepBearNow = false
bool trapSellNow = false
bool trapBuyNow = false
bool vacUpNow = false
bool vacDnNow = false
bool exhUpConfNow = false
bool exhDnConfNow = false
color candleCol = na
if barstate.isconfirmed
// ── [01/02] LIQUIDITY LEVELS + SWEEPS ─────────────────────────────────────────────────
if liqOn
if not na(phV)
f_addLevel(bslArr, true, phV, bar_index - swingLen, f_clamp(nz(relVol[swingLen], 1.0), 0.0, 2.0) / 2.0, f_clamp(nz(uwr[swingLen]), 0.0, 1.0))
if not na(plV)
f_addLevel(sslArr, false, plV, bar_index - swingLen, f_clamp(nz(relVol[swingLen], 1.0), 0.0, 2.0) / 2.0, f_clamp(nz(lwr[swingLen]), 0.0, 1.0))
[bSc, bPx, bBar, bRej] = f_sweepScan(bslArr, bslDone, true)
[sSc, sPx, sBar, sRej] = f_sweepScan(sslArr, sslDone, false)
if sweepOn
if bSc >= minSweepStr
sweepBearNow := true
f_push(evSwBear)
Zone zs = f_drawSweep(true, bSc, bPx, bBar, bRej)
sweepFx.push(zs)
f_trimZones(sweepFx, 14)
if sweepCandle
candleCol := cBear
if sSc >= minSweepStr
sweepBullNow := true
f_push(evSwBull)
Zone zs2 = f_drawSweep(false, sSc, sPx, sBar, sRej)
sweepFx.push(zs2)
f_trimZones(sweepFx, 14)
if sweepCandle
candleCol := cBull
// ── [03] SMART MONEY TRAPS (failed breakouts) ─────────────────────────────────────────
if trapOn
// Bull trap → trapped buyers
if bkUp
bkUpExt := math.max(bkUpExt, high)
if close < bkUpLvl
float tSc = 30.0 * f_clamp((bkUpExt - bkUpLvl) / atrV, 0.0, 1.0) + 25.0 * f_clamp((bkUpLvl - close) / atrV, 0.0, 1.0) + 15.0 * (hasVol ? f_clamp(relVol / 2.0, 0.0, 1.0) : 0.5) + 15.0 * (1.0 - f_clamp((bar_index - bkUpBar) / float(trapWin), 0.0, 1.0)) + 15.0 * (1.0 - closePos)
trapBuyNow := true
f_push(evTrapBuy)
Zone zt = f_drawTrap(true, bkUpBar, bkUpExt, bkUpLvl - atrV * 0.3, tSc)
trapFx.push(zt)
f_trimZones(trapFx, maxTraps)
candleCol := cMagenta
bkUp := false
else if bar_index - bkUpBar >= trapWin
bkUp := false
else if close > hiN[1] + atrV * 0.05
bkUp := true
bkUpLvl := hiN[1]
bkUpBar := bar_index
bkUpExt := high
// Bear trap → trapped sellers
if bkDn
bkDnExt := math.min(bkDnExt, low)
if close > bkDnLvl
float tSc2 = 30.0 * f_clamp((bkDnLvl - bkDnExt) / atrV, 0.0, 1.0) + 25.0 * f_clamp((close - bkDnLvl) / atrV, 0.0, 1.0) + 15.0 * (hasVol ? f_clamp(relVol / 2.0, 0.0, 1.0) : 0.5) + 15.0 * (1.0 - f_clamp((bar_index - bkDnBar) / float(trapWin), 0.0, 1.0)) + 15.0 * closePos
trapSellNow := true
f_push(evTrapSell)
Zone zt2 = f_drawTrap(false, bkDnBar, bkDnLvl + atrV * 0.3, bkDnExt, tSc2)
trapFx.push(zt2)
f_trimZones(trapFx, maxTraps)
candleCol := cCyan
bkDn := false
else if bar_index - bkDnBar >= trapWin
bkDn := false
else if close < loN[1] - atrV * 0.05
bkDn := true
bkDnLvl := loN[1]
bkDnBar := bar_index
bkDnExt := low
// ── [05] DISPLACEMENT ENERGY ──────────────────────────────────────────────────────────
if dispUp or dispDn
bool isUp = dispUp
if isUp
f_push(evDispUp)
else
f_push(evDispDn)
Zone zd = f_drawDisp(isUp, dispScore)
dispFx.push(zd)
f_trimZones(dispFx, maxDisp)
if dispZoneOn
Zone zz = f_drawDZone(isUp)
dZones.push(zz)
f_trimZones(dZones, 6)
if na(candleCol)
candleCol := isUp ? cBull : cBear
// displacement zone mitigation (close through the 50% of the body)
int nzn = dZones.size()
if nzn > 0
for i = nzn - 1 to 0
Zone dz = dZones.get(i)
float mid = (dz.top + dz.bot) / 2.0
bool mit = dz.dir == 1 ? close < mid : close > mid
if mit and bar_index > dz.t0
dz.kill()
dZones.remove(i)
// ── [07] LIQUIDITY VACUUM ─────────────────────────────────────────────────────────────
if vacOn
// update existing corridors (fill tracking)
int nv = vacs.size()
if nv > 0
for i = 0 to nv - 1
Zone vz = vacs.get(i)
if vz.active and bar_index > vz.t0 and vz.top > vz.bot
if vz.dir == 1
vz.fillLvl := math.min(vz.fillLvl, low)
vz.fillPct := f_clamp((vz.top - vz.fillLvl) / (vz.top - vz.bot), 0.0, 1.0)
else
vz.fillLvl := math.max(vz.fillLvl, high)
vz.fillPct := f_clamp((vz.fillLvl - vz.bot) / (vz.top - vz.bot), 0.0, 1.0)
if vz.fillPct >= 0.999
vz.active := false
if not na(vz.bx)
box.set_extend(vz.bx, extend.none)
box.set_right(vz.bx, bar_index)
if not na(vz.gl)
box.set_extend(vz.gl, extend.none)
box.set_right(vz.gl, bar_index)
if not na(vz.lb)
label.set_text(vz.lb, f_vacText(vz))
// new bullish corridor (up-move left an untraded band)
if low > high[2] and close[1] > open[1] and (low - high[2]) >= atrV * vacMinAtr and bar_index - lastVacUp >= 3
float vi = f_interaction(high[2], low)
if vi <= vacInt
float vsc = 50.0 * (1.0 - vi / math.max(vacInt, 0.1)) + 50.0 * f_clamp((low - high[2]) / (atrV * 1.2), 0.0, 1.0)
Zone zv = f_drawVac(true, low, high[2], vsc)
vacs.push(zv)
f_trimZones(vacs, maxVac)
lastVacUp := bar_index
vacUpNow := true
// new bearish corridor (down-move left an untraded band)
if high < low[2] and close[1] < open[1] and (low[2] - high) >= atrV * vacMinAtr and bar_index - lastVacDn >= 3
float vi2 = f_interaction(high, low[2])
if vi2 <= vacInt
float vsc2 = 50.0 * (1.0 - vi2 / math.max(vacInt, 0.1)) + 50.0 * f_clamp((low[2] - high) / (atrV * 1.2), 0.0, 1.0)
Zone zv2 = f_drawVac(false, low[2], high, vsc2)
vacs.push(zv2)
f_trimZones(vacs, maxVac)
lastVacDn := bar_index
vacDnNow := true
// ── [08] EXHAUSTION CLOUDS ────────────────────────────────────────────────────────────
if exhOn
// bullish move exhausted → GOLD cloud above price
if exhUpSt == 1
if bar_index - exhUpBar > 8
exhUpSt := 0
else if bar_index > exhUpBar and (close < low[1] or pressRevDn) and exhUpScore >= exhConfThr
if not na(exhUpCloud)
exhUpCloud.kill()
if exhConfOn
Zone zc = f_drawCloud(true, exhUpScore, true)
clouds.push(zc)
f_trimZones(clouds, maxClouds)
exhUpSt := 0
exhUpLast := bar_index
exhUpConfNow := true
f_push(evExhUp)
else if exhUpScore >= exhEarlyThr and bar_index - exhUpLast > 15
exhUpSt := 1
exhUpBar := bar_index
if exhEarlyOn
exhUpCloud := f_drawCloud(true, exhUpScore, false)
clouds.push(exhUpCloud)
f_trimZones(clouds, maxClouds)
// bearish move exhausted → PURPLE cloud below price
if exhDnSt == 1
if bar_index - exhDnBar > 8
exhDnSt := 0
else if bar_index > exhDnBar and (close > high[1] or pressRevUp) and exhDnScore >= exhConfThr
if not na(exhDnCloud)
exhDnCloud.kill()
if exhConfOn
Zone zc2 = f_drawCloud(false, exhDnScore, true)
clouds.push(zc2)
f_trimZones(clouds, maxClouds)
exhDnSt := 0
exhDnLast := bar_index
exhDnConfNow := true
f_push(evExhDn)
else if exhDnScore >= exhEarlyThr and bar_index - exhDnLast > 15
exhDnSt := 1
exhDnBar := bar_index
if exhEarlyOn
exhDnCloud := f_drawCloud(false, exhDnScore, false)
clouds.push(exhDnCloud)
f_trimZones(clouds, maxClouds)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// PLOTS — Market Pressure Waves, candle forensics markers, displacement markers
// ═══════════════════════════════════════════════════════════════════════════════════════════════
float wMid = pressOn ? waveMid : na
float wBO = pressOn and showBullWave ? waveMid + bullAmp : na
float wBI = pressOn and showBullWave ? waveMid + bullAmp * 0.55 : na
float wRO = pressOn and showBearWave ? waveMid - bearAmp : na
float wRI = pressOn and showBearWave ? waveMid - bearAmp * 0.55 : na
pMid = plot(wMid, "Wave Core", color = color.new(net >= 0 ? cCyan : cPurple, showCore ? 55 : 100), linewidth = 1)
pBO = plot(wBO, "Bullish Wave · Outer", color = color.new(cCyan, 55), linewidth = 1)
pBI = plot(wBI, "Bullish Wave · Inner", color = color.new(cCyan, 15), linewidth = 2)
pBG = plot(wBI, "Bullish Wave · Glow", color = color.new(cCyan, glowOn ? 82 : 100), linewidth = 6)
pRO = plot(wRO, "Bearish Wave · Outer", color = color.new(cPurple, 55), linewidth = 1)
pRI = plot(wRI, "Bearish Wave · Inner", color = color.new(cPurple, 15), linewidth = 2)
pRG = plot(wRI, "Bearish Wave · Glow", color = color.new(cPurple, glowOn ? 82 : 100), linewidth = 6)
fill(pMid, pBI, color = color.new(cCyan, 86), title = "Bullish Wave Fill A")
fill(pBI, pBO, color = color.new(cCyan, 93), title = "Bullish Wave Fill B")
fill(pMid, pRI, color = color.new(cPurple, 86), title = "Bearish Wave Fill A")
fill(pRI, pRO, color = color.new(cPurple, 93), title = "Bearish Wave Fill B")
bool cf = barstate.isconfirmed
plotshape(pressOn and showRev and pressRevUp and cf, "Pressure Reversal ▲", shape.square, location.belowbar, color.new(cCyan, 0), size = size.tiny)
plotshape(pressOn and showRev and pressRevDn and cf, "Pressure Reversal ▼", shape.square, location.abovebar, color.new(cPurple, 0), size = size.tiny)
plotshape(dispMarker and dispUp and cf, "Displacement ▲", shape.triangleup, location.belowbar, color.new(cBull, 0), size = size.small)
plotshape(dispMarker and dispDn and cf, "Displacement ▼", shape.triangledown, location.abovebar, color.new(cBear, 0), size = size.small)
plotshape(forOn and fRejOn and fRejBull and cf, "Rejection Bull", shape.diamond, location.belowbar, color.new(cCyan, 0), size = size.tiny)
plotshape(forOn and fRejOn and fRejBear and cf, "Rejection Bear", shape.diamond, location.abovebar, color.new(cMagenta, 0), size = size.tiny)
plotshape(forOn and fWickOn and fWickBull and cf, "Wick Imbalance Bull", shape.cross, location.belowbar, color.new(cSilver, 10), size = size.tiny)
plotshape(forOn and fWickOn and fWickBear and cf, "Wick Imbalance Bear", shape.cross, location.abovebar, color.new(cSilver, 10), size = size.tiny)
plotshape(forOn and fAbsOn and fAbsBull and cf, "Absorption Bull", shape.circle, location.belowbar, color.new(cGold, 0), size = size.tiny)
plotshape(forOn and fAbsOn and fAbsBear and cf, "Absorption Bear", shape.circle, location.abovebar, color.new(cGold, 0), size = size.tiny)
plotshape(forOn and fFailOn and fFailUp and cf, "Failed Auction High", shape.xcross, location.abovebar, color.new(cMagenta, 0), size = size.tiny)
plotshape(forOn and fFailOn and fFailDn and cf, "Failed Auction Low", shape.xcross, location.belowbar, color.new(cCyan, 0), size = size.tiny)
plotshape(forOn and fExhOn and fMomExhUp and cf, "Momentum Exhaustion Up", shape.flag, location.abovebar, color.new(cAmber, 0), size = size.tiny)
plotshape(forOn and fExhOn and fMomExhDn and cf, "Momentum Exhaustion Down", shape.flag, location.belowbar, color.new(cAmber, 0), size = size.tiny)
plotshape(forOn and fStrongOn and fStrongUp and cf, "Strong Bullish Candle", shape.arrowup, location.belowbar, color.new(cBull, 30), size = size.tiny)
plotshape(forOn and fStrongOn and fStrongDn and cf, "Strong Bearish Candle", shape.arrowdown, location.abovebar, color.new(cBear, 30), size = size.tiny)
barcolor(candleCol)
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// ALERTS
// ═══════════════════════════════════════════════════════════════════════════════════════════════
alertcondition(sweepBullNow, "QMX · Bullish Liquidity Sweep", "QMX: Bullish liquidity sweep (sell-side taken) on {{ticker}} {{interval}}")
alertcondition(sweepBearNow, "QMX · Bearish Liquidity Sweep", "QMX: Bearish liquidity sweep (buy-side taken) on {{ticker}} {{interval}}")
alertcondition(trapBuyNow, "QMX · Bull Trap (Trapped Buyers)", "QMX: Bull trap / trapped buyers on {{ticker}} {{interval}}")
alertcondition(trapSellNow, "QMX · Bear Trap (Trapped Sellers)", "QMX: Bear trap / trapped sellers on {{ticker}} {{interval}}")
alertcondition(dispUp and barstate.isconfirmed, "QMX · Bullish Displacement", "QMX: Bullish displacement candle on {{ticker}} {{interval}}")
alertcondition(dispDn and barstate.isconfirmed, "QMX · Bearish Displacement", "QMX: Bearish displacement candle on {{ticker}} {{interval}}")
alertcondition(exhUpConfNow, "QMX · Bullish Exhaustion Confirmed", "QMX: Confirmed exhaustion of the bullish move on {{ticker}} {{interval}}")
alertcondition(exhDnConfNow, "QMX · Bearish Exhaustion Confirmed", "QMX: Confirmed exhaustion of the bearish move on {{ticker}} {{interval}}")
alertcondition(vacUpNow, "QMX · Bullish Liquidity Vacuum", "QMX: New bullish liquidity vacuum corridor on {{ticker}} {{interval}}")
alertcondition(vacDnNow, "QMX · Bearish Liquidity Vacuum", "QMX: New bearish liquidity vacuum corridor on {{ticker}} {{interval}}")
alertcondition(pressRevUp and barstate.isconfirmed, "QMX · Pressure Reversal Bullish", "QMX: Market pressure reversed to bullish on {{ticker}} {{interval}}")
alertcondition(pressRevDn and barstate.isconfirmed, "QMX · Pressure Reversal Bearish", "QMX: Market pressure reversed to bearish on {{ticker}} {{interval}}")
// ═══════════════════════════════════════════════════════════════════════════════════════════════
// [09] PRICE GRAVITY ENGINE + [10] QUANTUM DASHBOARD — live read-out on the last bar
// ═══════════════════════════════════════════════════════════════════════════════════════════════
const color bgHead = #0B1226
const color bgSec = #121C38
const color bgRow = #070B16
int nRows = 19 + (mtfOn ? 7 : 0) + (keyOn ? 5 : 0)
var table dash = table.new(dashPos, 3, nRows, bgcolor = color.new(#070B16, 6), frame_color = color.new(#00E5FF, 35), frame_width = 1, border_color = color.new(#00E5FF, 80), border_width = 1)
f_cell(table t, int c, int r, string txt, color tc, color bg, string ha) =>
table.cell(t, c, r, txt, text_color = tc, bgcolor = bg, text_halign = ha, text_size = tblSize)
true
f_metric(table t, int r, string nm, float v, color c) =>
f_cell(t, 0, r, nm, cSilver, bgRow, text.align_left)
f_cell(t, 1, r, f_bar(v, 8), c, bgRow, text.align_left)
f_cell(t, 2, r, str.tostring(math.round(v)) + "%", c, bgRow, text.align_right)
true
f_kv(table t, int r, bool fd, string k, string v, color c) =>
f_cell(t, 0, r, k, cSilver, bgRow, text.align_left)
f_cell(t, 1, r, v, c, bgRow, text.align_left)
f_cell(t, 2, r, "", c, bgRow, text.align_left)
if fd
table.merge_cells(t, 1, r, 2, r)
true
f_sec(table t, int r, bool fd, string txt) =>
f_cell(t, 0, r, txt, cGold, bgSec, text.align_left)
f_cell(t, 1, r, "", cGold, bgSec, text.align_left)
f_cell(t, 2, r, "", cGold, bgSec, text.align_left)
if fd
table.merge_cells(t, 0, r, 2, r)
true
f_mtfRow(table t, int r, int sec, float n, float sl, float ra, float di) =>
bool ok = not na(n) and sec >= timeframe.in_seconds()
string b = not ok ? "—" : n > 0.12 ? "Bullish" : n < -0.12 ? "Bearish" : "Neutral"
color bc = not ok ? cGrey : n > 0.12 ? cBull : n < -0.12 ? cBear : cSilver
string s = not ok ? "—" : f_mtfState(n, sl, ra, di)
f_cell(t, 0, r, f_tfName(sec), cSilver, bgRow, text.align_left)
f_cell(t, 1, r, b, bc, bgRow, text.align_left)
f_cell(t, 2, r, s, cSilver, bgRow, text.align_right)
true
if barstate.islast
// ── clear previous gravity drawings
while gravFx.size() > 0
Zone gOld = gravFx.pop()
gOld.kill()
// ── nearest liquidity levels
float nBSL = na
float nSSL = na
float wSum = 0.0
float sSum = 0.0
for l in bslArr
if l.price > close and (na(nBSL) or l.price < nBSL)
nBSL := l.price
float w = 1.0 / (1.0 + math.abs(l.price - close) / atrV)
wSum += w
sSum += w * l.strength
for l in sslArr
if l.price < close and (na(nSSL) or l.price > nSSL)
nSSL := l.price
float w = 1.0 / (1.0 + math.abs(l.price - close) / atrV)
wSum += w
sSum += w * l.strength
float liqStr = wSum > 0 ? sSum / wSum : 0.0
// ── PRICE GRAVITY: rank liquidity + structural targets
float tUp1 = na
float tDn1 = na
if gravOn
array<float> uPx = array.new<float>()
array<float> uSt = array.new<float>()
array<float> uSc = array.new<float>()
array<float> dPx = array.new<float>()
array<float> dSt = array.new<float>()
array<float> dSc = array.new<float>()
for l in bslArr
if l.price > close
uPx.push(l.price)
uSt.push(l.strength)
uSc.push(f_gScore(l.price, l.strength, bar_index - l.bar, true))
for l in sslArr
if l.price < close
dPx.push(l.price)
dSt.push(l.strength)
dSc.push(f_gScore(l.price, l.strength, bar_index - l.bar, false))
for z in vacs
if z.active and z.top > z.bot
float vs = 60.0 * (1.0 - z.fillPct)
if z.bot > close
uPx.push(z.bot)
uSt.push(vs)
uSc.push(f_gScore(z.bot, vs, bar_index - z.t0, true))
else if z.top < close
dPx.push(z.top)
dSt.push(vs)
dSc.push(f_gScore(z.top, vs, bar_index - z.t0, false))
if usePDHL
if not na(pdh) and pdh > close
uPx.push(pdh)
uSt.push(65.0)
uSc.push(f_gScore(pdh, 65.0, 60, true))
if not na(pdl) and pdl < close
dPx.push(pdl)
dSt.push(65.0)
dSc.push(f_gScore(pdl, 65.0, 60, false))
for rk = 1 to gravTargets
int iu = f_topIdx(uSc)
if iu >= 0
float pu = uPx.get(iu)
float su = uSc.get(iu)
uSc.set(iu, -1.0)
gravFx.push(f_drawTarget(pu, su, rk, true))
if rk == 1
tUp1 := pu
int id = f_topIdx(dSc)
if id >= 0
float pd = dPx.get(id)
float sd = dSc.get(id)
dSc.set(id, -1.0)
gravFx.push(f_drawTarget(pd, sd, rk, false))
if rk == 1
tDn1 := pd
// ── EVIDENCE ENGINE (all values from real calculations above)
float bP = 0.0
float rP = 0.0
if net > 0
bP += 25.0 * math.min(net, 1.0)
else
rP += 25.0 * math.min(-net, 1.0)
bP += 15.0 * math.min(f_cnt(evDispUp, 10), 2) / 2.0
rP += 15.0 * math.min(f_cnt(evDispDn, 10), 2) / 2.0
bP += 15.0 * math.min(f_cnt(evSwBull, 25), 2) / 2.0
rP += 15.0 * math.min(f_cnt(evSwBear, 25), 2) / 2.0
bool structBull = not na(lastPH) and not na(prevPH) and not na(lastPL) and not na(prevPL) and lastPH > prevPH and lastPL > prevPL
bool structBear = not na(lastPH) and not na(prevPH) and not na(lastPL) and not na(prevPL) and lastPH < prevPH and lastPL < prevPL
if structBull
bP += 20.0
else if structBear
rP += 20.0
else
bP += 5.0
rP += 5.0
bP += 10.0 * math.min(f_cnt(evTrapSell, 30), 1)
rP += 10.0 * math.min(f_cnt(evTrapBuy, 30), 1)
bP += 10.0 * math.min(f_cnt(evExhDn, 15), 1)
rP += 10.0 * math.min(f_cnt(evExhUp, 15), 1)
if close > waveMid
bP += 5.0
else
rP += 5.0
float totP = bP + rP
float bullEv = totP > 0 ? 100.0 * bP / totP : 50.0
float bearEv = 100.0 - bullEv
bool pend = bkUp or bkDn
float trapRisk = f_clamp((pend ? 22.0 : 0.0) + 14.0 * math.min(f_cnt(evTrapBuy, 30) + f_cnt(evTrapSell, 30), 3) + 20.0 * math.max(avgUw, avgLw) + 16.0 * math.min(f_cnt(evSwBull, 20) + f_cnt(evSwBear, 20), 2) / 2.0, 0.0, 100.0)
float conf = f_clamp(0.5 * math.abs(bullEv - bearEv) + 0.3 * totP + 0.2 * (100.0 - trapRisk), 0.0, 100.0)
int bias = bullEv >= 58 ? 1 : bullEv <= 42 ? -1 : 0
bool expUp = f_cnt(evDispUp, 6) > 0
bool expDn = f_cnt(evDispDn, 6) > 0
string phase = "Consolidation"
color phaseCol = cSilver
if f_cnt(evExhUp, 10) > 0
phase := "Bullish Exhaustion ⚠"
phaseCol := cGold
else if f_cnt(evExhDn, 10) > 0
phase := "Bearish Exhaustion ⚠"
phaseCol := cPurple
else if bias == 1
phase := expUp ? "Bullish Expansion" : structBear ? "Bullish Recovery" : "Bullish Trend"
phaseCol := cBull
else if bias == -1
phase := expDn ? "Bearish Expansion" : structBull ? "Bearish Pullback" : "Bearish Trend"
phaseCol := cBear
string volState = atrRank < 25 ? "Low" : atrRank < 60 ? "Normal" : atrRank < 85 ? "High" : "Extreme"
color volCol = atrRank < 25 ? cGrey : atrRank < 60 ? cSilver : atrRank < 85 ? cAmber : cBear
string prsState = (net > 0.10 ? "Bullish" : net < -0.10 ? "Bearish" : "Neutral") + (pressWeak ? " · Weakening" : "") + " (" + (net >= 0 ? "+" : "") + str.tostring(math.round(net * 100)) + ")"
color prsCol = net > 0.10 ? cBull : net < -0.10 ? cBear : cSilver
string liqState = liqStr >= 70 ? "Strong" : liqStr >= 45 ? "Moderate" : "Weak"
color liqCol = liqStr >= 70 ? cCyan : liqStr >= 45 ? cSilver : cGrey
string exhState = exhNow < 35 ? "Low" : exhNow < 60 ? "Medium" : "High"
color exhCol = exhNow < 35 ? cGrey : exhNow < 60 ? cAmber : cGold
// ── DASHBOARD TABLE
if dashOn
bool fd = not tblInit
int r = 0
f_cell(dash, 0, r, "♛ QUANTUM MARKET X-RAY", cCyan, bgHead, text.align_center)
f_cell(dash, 1, r, "", cCyan, bgHead, text.align_center)
f_cell(dash, 2, r, "", cCyan, bgHead, text.align_center)
if fd
table.merge_cells(dash, 0, r, 2, r)
r += 1
f_cell(dash, 0, r, "LIVE MARKET INTELLIGENCE", cSilver, bgHead, text.align_center)
f_cell(dash, 1, r, "", cSilver, bgHead, text.align_center)
f_cell(dash, 2, r, "", cSilver, bgHead, text.align_center)
if fd
table.merge_cells(dash, 0, r, 2, r)
r += 1
f_cell(dash, 0, r, "Market", cSilver, bgRow, text.align_left)
f_cell(dash, 1, r, syminfo.ticker, cCyan, bgRow, text.align_left)
f_cell(dash, 2, r, "TF: " + timeframe.period, cCyan, bgRow, text.align_right)
r += 1
f_cell(dash, 0, r, "Price", cSilver, bgRow, text.align_left)
f_cell(dash, 1, r, str.tostring(close, format.mintick), cSilver, bgRow, text.align_left)
f_cell(dash, 2, r, "ATR " + str.tostring(atrV, format.mintick), cGrey, bgRow, text.align_right)
r += 1
f_kv(dash, r, fd, "Market Bias", bias == 1 ? "● Bullish" : bias == -1 ? "● Bearish" : "● Neutral", phaseCol == cSilver ? cSilver : (bias == 1 ? cBull : bias == -1 ? cBear : cSilver))
r += 1
f_kv(dash, r, fd, "Phase", phase, phaseCol)
r += 1
f_sec(dash, r, fd, "INTELLIGENCE SCORE")
r += 1
f_metric(dash, r, "Bullish Evidence", bullEv, cBull)
r += 1
f_metric(dash, r, "Bearish Evidence", bearEv, cBear)
r += 1
f_metric(dash, r, "Liquidity Strength", liqStr, cCyan)
r += 1
f_metric(dash, r, "Trap Risk", trapRisk, cAmber)
r += 1
f_metric(dash, r, "Displacement", energy, cBull)
r += 1
f_metric(dash, r, "Market Confidence", conf, cCyan)
r += 1
f_sec(dash, r, fd, "MARKET CONDITIONS")
r += 1
f_kv(dash, r, fd, "Volatility", volState, volCol)
r += 1
f_kv(dash, r, fd, "Pressure", prsState, prsCol)
r += 1
f_kv(dash, r, fd, "Liquidity", liqState, liqCol)
r += 1
f_kv(dash, r, fd, "Exhaustion", exhState, exhCol)
r += 1
if mtfOn
f_sec(dash, r, fd, "MTF OVERVIEW")
r += 1
f_cell(dash, 0, r, "TF", cGold, bgHead, text.align_left)
f_cell(dash, 1, r, "Bias", cGold, bgHead, text.align_left)
f_cell(dash, 2, r, "State", cGold, bgHead, text.align_right)
r += 1
f_mtfRow(dash, r, s1, m1n, m1s, m1r, m1d)
r += 1
f_mtfRow(dash, r, s2, m2n, m2s, m2r, m2d)
r += 1
f_mtfRow(dash, r, s3, m3n, m3s, m3r, m3d)
r += 1
f_mtfRow(dash, r, s4, m4n, m4s, m4r, m4d)
r += 1
f_mtfRow(dash, r, s5, m5n, m5s, m5r, m5d)
r += 1
if keyOn
f_sec(dash, r, fd, "KEY LEVELS")
r += 1
f_kv(dash, r, fd, "Buy-Side Liquidity", na(nBSL) ? "—" : str.tostring(nBSL, format.mintick), cBear)
r += 1
f_kv(dash, r, fd, "Sell-Side Liquidity", na(nSSL) ? "—" : str.tostring(nSSL, format.mintick), cBull)
r += 1
f_kv(dash, r, fd, "Nearest Target ↑", na(tUp1) ? "—" : str.tostring(tUp1, format.mintick), cCyan)
r += 1
f_kv(dash, r, fd, "Nearest Target ↓", na(tDn1) ? "—" : str.tostring(tDn1, format.mintick), cMagenta)
r += 1
f_cell(dash, 0, r, "Analytical estimates · not advice", cGrey, bgHead, text.align_center)
f_cell(dash, 1, r, "", cGrey, bgHead, text.align_center)
f_cell(dash, 2, r, "", cGrey, bgHead, text.align_center)
if fd
table.merge_cells(dash, 0, r, 2, r)
tblInit := true