本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © raptoralgo
//@version=6
indicator("DrFX God Mode X - Fusion17 Adaptive Consensus", shorttitle="DrFX F17", overlay=true, max_labels_count=350, max_lines_count=180, max_boxes_count=220, max_bars_back=650)
// ── 01. CONTROLS ────────────────────────────────────────────────────────────
string G1 = "01 | Intelligence & signal engine"
int fastLen = input.int(21, "Fast EMA", minval=2, maxval=200, group=G1)
int slowLen = input.int(55, "Slow EMA", minval=3, maxval=300, group=G1)
int biasLen = input.int(200, "Macro EMA", minval=20, maxval=500, group=G1)
int pivotLen = input.int(5, "Confirmed swing depth", minval=2, maxval=20, group=G1)
int minScore = input.int(62, "Minimum 17-engine agreement (not a probability)", minval=35, maxval=95, group=G1)
int minEdge = input.int(20, "Minimum long / short score edge", minval=0, maxval=70, group=G1)
int cooldownBars = input.int(8, "Bars between signals", minval=0, maxval=100, group=G1)
int regLen = input.int(24, "Regime lookback", minval=8, maxval=100, group=G1)
string G2 = "02 | Confirmed higher timeframes"
string htf1 = input.timeframe("60", "Higher timeframe 1", group=G2)
string htf2 = input.timeframe("240", "Higher timeframe 2", group=G2)
string G3 = "03 | Structure / liquidity / volume"
bool showFVG = input.bool(true, "Fair value gaps", group=G3)
bool showZones = input.bool(true, "Displacement supply/demand", group=G3)
bool showSweeps = input.bool(true, "Liquidity sweep markers", group=G3)
bool showStructure= input.bool(true, "BOS / CHoCH markers", group=G3)
float fvgAtrMin = input.float(0.22, "Minimum FVG width (ATR)", minval=0.05, maxval=2.0, step=0.01, group=G3)
int maxGaps = input.int(6, "Live gaps per side", minval=1, maxval=15, group=G3)
int maxZones = input.int(4, "Live zones per side", minval=1, maxval=12, group=G3)
bool showProfile = input.bool(true, "Right-edge volume distribution / POC", group=G3)
int profileLookback = input.int(110, "Profile bars", minval=30, maxval=250, group=G3)
int profileBins = input.int(28, "Profile price bins", minval=12, maxval=40, group=G3)
int profileWidth = input.int(20, "Profile width (future bars)", minval=8, maxval=40, group=G3)
string G4 = "04 | Risk visualizer (illustrative)"
bool showRisk = input.bool(true, "Draw last signal risk geometry", group=G4)
float atrStop = input.float(1.8, "Stop distance (ATR)", minval=0.3, maxval=6, step=0.1, group=G4)
float rr1 = input.float(1.5, "Take profit 1 (R)", minval=0.5, maxval=8, step=0.25, group=G4)
float rr2 = input.float(3.0, "Take profit 2 (R)", minval=1.0, maxval=15, step=0.25, group=G4)
int projection = input.int(22, "Projection width (bars)", minval=5, maxval=100, group=G4)
string G5 = "05 | GOD MODE visual HUD"
bool showHUD = input.bool(true, "Enable large intelligence dashboard", group=G5)
string hudLoc = input.string("Top Right", "Dashboard position", options=["Top Right", "Top Left", "Middle Right", "Bottom Right", "Bottom Left"], group=G5)
string hudScale = input.string("Compact", "Dashboard text size", options=["Compact", "Large"], group=G5)
bool showCloud = input.bool(true, "Neon trend cloud", group=G5)
bool showVWAP = input.bool(true, "Session VWAP (intraday)", group=G5)
bool colorBars = input.bool(true, "Adaptive candle colors", group=G5)
bool showHeat = input.bool(false, "Soft market-state background", group=G5)
bool pulseHUD = input.bool(true, "Tick-driven HUD pulse", group=G5, tooltip="Updates only when TradingView processes new price updates. Pine cannot run an independent animation timer.")
string G6 = "06 | Fusion17 precision and computational budgets"
string computeMode = input.string("Full analysis", "Computation profile", options=["Performance", "Full analysis"], group=G6, tooltip="Both modes calculate 17 analytical modules. Performance reduces the entropy sample window and limits profile refresh during realtime updates.")
int entropyWindow = input.int(28, "Entropy sample window", minval=12, maxval=60, group=G6)
int channelLen = input.int(21, "Adaptive price channel window", minval=8, maxval=60, group=G6)
bool requireTrend = input.bool(true, "Require trend alignment for signals", group=G6)
bool disallowChop = input.bool(true, "Avoid new signals during strong choppiness", group=G6)
bool showWave = input.bool(true, "Quantum-style spectral price ribbon", group=G6)
bool showPrevDay = input.bool(true, "Previous day range reference", group=G6)
bool showSignalTrace = input.bool(true, "Confirmed setup trace labels", group=G6)
string G7 = "07 | Ultra intelligence diagnostics"
bool radarEnabled = input.bool(true, "Right-edge confluence radar", group=G7)
int radarDistance = input.int(60, "Radar distance (bars ahead)", minval=40, maxval=180, group=G7)
float radarScale = input.float(2.2, "Radar vertical scaling (ATR)", minval=0.6, maxval=8.0, step=0.2, group=G7)
bool showLadder = input.bool(true, "Smart liquidity price ladder", group=G7)
int ladderWidth = input.int(18, "Ladder extension (bars)", minval=5, maxval=90, group=G7)
bool showQualityGate = input.bool(false, "Require directional engine breadth", group=G7)
int minEngineBreadth = input.int(7, "Minimum directional engine breadth", minval=3, maxval=15, group=G7)
bool showSignalLifecycle = input.bool(true, "Monitor last signal's hypothetical outcome", group=G7)
bool adaptiveWeighting = input.bool(true, "Adjust engine weights by regime", group=G7)
bool showResearchRibbons = input.bool(true, "Multi-scale statistical ribbons", group=G7)
int ribbonLength = input.int(34, "Statistical ribbon window", minval=12, maxval=120, group=G7)
int ribbonExtension = input.int(12, "Ribbon visual reach (bars)", minval=3, maxval=50, group=G7)
bool showTacticalMetrics = input.bool(true, "Display extended analysis in HUD", group=G7)
// Prevent configurations that invert the named EMA hierarchy or risk targets.
if barstate.isfirst and (fastLen >= slowLen or slowLen >= biasLen)
runtime.error("EMA settings must satisfy Fast EMA < Slow EMA < Macro EMA.")
if barstate.isfirst and rr2 <= rr1
runtime.error("Take profit 2 (R) must be greater than Take profit 1 (R).")
// ── 02. BRAND PALETTE ───────────────────────────────────────────────────────
color ink = color.rgb(8, 13, 27)
color panel = color.rgb(13, 23, 41)
color panel2 = color.rgb(18, 33, 54)
color grid = color.rgb(38, 66, 86)
color white = color.rgb(230, 244, 251)
color mute = color.rgb(127, 156, 178)
color cyan = color.rgb(35, 222, 234)
color green = color.rgb(26, 231, 160)
color red = color.rgb(255, 79, 122)
color gold = color.rgb(253, 193, 85)
color violet = color.rgb(147, 114, 255)
color electricBlue= color.rgb(60, 128, 253)
color amber = color.rgb(255, 146, 67)
f_clamp(float x, float lo, float hi) => math.min(hi, math.max(lo, x))
f_pct(float v) => na(v) ? "N/A" : str.tostring(math.round(v)) + "%"
f_score(float v) => na(v) ? "N/A" : str.tostring(math.round(v)) + "/100"
f_px(float v) => na(v) ? "—" : str.tostring(v, format.mintick)
f_meter(float pct) =>
int n = int(math.round(f_clamp(nz(pct, 0.0), 0.0, 100.0) / 10.0))
string meter = ""
for i = 1 to 10
meter += i <= n ? "▰" : "▱"
meter
f_stateColor(float value) => value >= 70.0 ? green : value >= 50.0 ? gold : red
f_cell(table t, int c, int r, string s, color fg, color bg, bool strong=false) =>
table.cell(t, c, r, s, text_color=fg, bgcolor=bg, text_size=strong ? (hudScale == "Large" ? size.normal : size.small) : (hudScale == "Large" ? size.small : size.tiny), text_halign=text.align_center)
f_pair(table t, int r, string k1, string v1, string k2, string v2, color v1col, color v2col) =>
f_cell(t, 0, r, k1, mute, panel)
f_cell(t, 1, r, v1, v1col, panel, true)
f_cell(t, 3, r, k2, mute, panel)
f_cell(t, 4, r, v2, v2col, panel, true)
// ── 03. SHARED FEATURE EXTRACTION ──────────────────────────────────────────
float emaFast = ta.ema(close, fastLen)
float emaSlow = ta.ema(close, slowLen)
float emaBias = ta.ema(close, biasLen)
float vwapNow = ta.vwap(hlc3)
float atr = ta.atr(14)
float atrAverage = ta.sma(atr, 50)
float volatilityPct = atrAverage > 0 ? atr / atrAverage * 100.0 : na
float rsi = ta.rsi(close, 14)
[macdLine, macdSignal, macdHist] = ta.macd(close, 12, 26, 9)
[plusDI, minusDI, adx] = ta.dmi(14, 14)
float volMean = ta.sma(volume, 20)
bool hasVol = not na(volume) and not na(volMean) and volMean > 0
float relVol = hasVol ? volume / volMean : na
float volProxyRaw = hasVol ? volume * (close - open) / math.max(high - low, syminfo.mintick) : na
float flowSignedEma = ta.ema(volProxyRaw, 5)
float volumeEma = ta.ema(volume, 5)
float flowProxy = hasVol and not na(flowSignedEma) and not na(volumeEma) ? 100.0 * flowSignedEma / math.max(volumeEma, 1.0) : na
float distanceMoved = math.abs(close - nz(close[regLen], close))
float traveled = ta.sma(math.abs(ta.change(close)), regLen) * regLen
float efficiency = traveled > 0 ? f_clamp(distanceMoved / traveled, 0.0, 1.0) : 0.0
bool trending = adx >= 23 and efficiency >= 0.28
bool choppy = adx < 17 or efficiency < 0.17
string regime = trending ? "DIRECTIONAL" : choppy ? "RANGE / CHOP" : "TRANSITION"
string volState = na(volatilityPct) ? "WARMING UP" : volatilityPct >= 145 ? "EXPANSION" : volatilityPct <= 75 ? "COMPRESSION" : "NORMAL"
bool vwapValid = timeframe.isintraday and not na(vwapNow)
float profileHigh = ta.highest(high, profileLookback)
float profileLow = ta.lowest(low, profileLookback)
// Multi-scale statistics: carefully bounded, dimensionless descriptive features.
// They are not quantum computation, AI inference or predictive probabilities.
float regr34 = ta.linreg(close, ribbonLength, 0)
float regr34Prior = ta.linreg(close, ribbonLength, 1)
float slopeATR = (regr34 - regr34Prior) / math.max(atr, syminfo.mintick)
float ribbonMean = ta.ema(hlc3, ribbonLength)
float ribbonSigma = ta.stdev(hlc3, ribbonLength)
float ribbonZ = ribbonSigma > 0 ? f_clamp((close - ribbonMean) / ribbonSigma, -4.0, 4.0) : 0.0
float wickSkew = (math.min(open, close) - low - (high - math.max(open, close))) / math.max(high - low, syminfo.mintick)
float bodyFraction = math.abs(close - open) / math.max(high - low, syminfo.mintick)
float closeLocation = ((close - low) / math.max(high - low, syminfo.mintick) - 0.5) * 2.0
float trEnergy = math.log(1.0 + math.max(ta.tr(true), syminfo.mintick) / math.max(atr, syminfo.mintick))
float rocNormalized = 100.0 * (close / math.max(math.abs(nz(close[5], close)), syminfo.mintick) - 1.0)
float multiscaleDrift = ((close - nz(close[3], close)) + (close - nz(close[8], close)) * 0.55 + (close - nz(close[21], close)) * 0.28) / math.max(atr, syminfo.mintick)
float driftStrength = f_clamp(math.abs(multiscaleDrift) / 7.0 * 100.0, 0.0, 100.0)
float returnNoise = ta.stdev(ta.change(close), 18)
float noiseSignal = returnNoise > 0 ? (close - nz(close[18], close)) / returnNoise / math.sqrt(18) : 0.0
float statisticalConviction = f_clamp(math.abs(noiseSignal) * 21.0, 0.0, 100.0)
// Closed HTF values: the [1] offsets prevent future leakage with lookahead_on.
[htfClose1, htfEma1] = request.security(syminfo.tickerid, htf1, [close[1], ta.ema(close, 50)[1]], lookahead=barmerge.lookahead_on)
[htfClose2, htfEma2] = request.security(syminfo.tickerid, htf2, [close[1], ta.ema(close, 50)[1]], lookahead=barmerge.lookahead_on)
bool validHTF1 = timeframe.in_seconds(htf1) > timeframe.in_seconds(timeframe.period) and not na(htfClose1) and not na(htfEma1)
bool validHTF2 = timeframe.in_seconds(htf2) > timeframe.in_seconds(timeframe.period) and not na(htfClose2) and not na(htfEma2)
bool htfBull1 = validHTF1 and not na(htfClose1) and not na(htfEma1) and htfClose1 > htfEma1
bool htfBear1 = validHTF1 and not na(htfClose1) and not na(htfEma1) and htfClose1 < htfEma1
bool htfBull2 = validHTF2 and not na(htfClose2) and not na(htfEma2) and htfClose2 > htfEma2
bool htfBear2 = validHTF2 and not na(htfClose2) and not na(htfEma2) and htfClose2 < htfEma2
// ── 04. CONFIRMED MARKET STRUCTURE ─────────────────────────────────────────
float pivotHi = ta.pivothigh(high, pivotLen, pivotLen)
float pivotLo = ta.pivotlow(low, pivotLen, pivotLen)
var float lastSwingHigh = na
var float lastSwingLow = na
var int marketStructure = 0
if not na(pivotHi) and barstate.isconfirmed
lastSwingHigh := pivotHi
if not na(pivotLo) and barstate.isconfirmed
lastSwingLow := pivotLo
bool bullBreak = barstate.isconfirmed and not na(lastSwingHigh) and close > lastSwingHigh and close[1] <= lastSwingHigh
bool bearBreak = barstate.isconfirmed and not na(lastSwingLow) and close < lastSwingLow and close[1] >= lastSwingLow
bool bullChoch = bullBreak and marketStructure == -1
bool bearChoch = bearBreak and marketStructure == 1
if bullBreak
marketStructure := 1
if bearBreak
marketStructure := -1
bool sweepHigh = barstate.isconfirmed and not na(lastSwingHigh) and high > lastSwingHigh and close < lastSwingHigh
bool sweepLow = barstate.isconfirmed and not na(lastSwingLow) and low < lastSwingLow and close > lastSwingLow
string structureName = marketStructure == 1 ? "BULLISH" : marketStructure == -1 ? "BEARISH" : "UNDEFINED"
// ── 05. FVG LIFECYCLE / DISPLACEMENT ZONES ──────────────────────────────────
var array<box> bullGaps = array.new<box>()
var array<box> bearGaps = array.new<box>()
var array<box> demandZones = array.new<box>()
var array<box> supplyZones = array.new<box>()
var float activeBullFvgTop = na
var float activeBullFvgBottom = na
var float activeBearFvgTop = na
var float activeBearFvgBottom = na
// FVG mitigation is wick-based on CLOSED bars; created boxes are considered only on subsequent bars.
if barstate.isconfirmed
if not na(activeBullFvgBottom) and low <= activeBullFvgBottom
activeBullFvgTop := na
activeBullFvgBottom := na
if not na(activeBearFvgTop) and high >= activeBearFvgTop
activeBearFvgTop := na
activeBearFvgBottom := na
int ig = 0
while ig < array.size(bullGaps)
box b = array.get(bullGaps, ig)
if low <= box.get_bottom(b)
box.delete(b)
array.remove(bullGaps, ig)
else
ig += 1
ig := 0
while ig < array.size(bearGaps)
box b = array.get(bearGaps, ig)
if high >= box.get_top(b)
box.delete(b)
array.remove(bearGaps, ig)
else
ig += 1
ig := 0
while ig < array.size(demandZones)
box b = array.get(demandZones, ig)
if close < box.get_bottom(b)
box.delete(b)
array.remove(demandZones, ig)
else
ig += 1
ig := 0
while ig < array.size(supplyZones)
box b = array.get(supplyZones, ig)
if close > box.get_top(b)
box.delete(b)
array.remove(supplyZones, ig)
else
ig += 1
bool bullFVG = barstate.isconfirmed and bar_index >= 2 and low > high[2] and (low - high[2]) >= atr * fvgAtrMin
bool bearFVG = barstate.isconfirmed and bar_index >= 2 and high < low[2] and (low[2] - high) >= atr * fvgAtrMin
if bullFVG
activeBullFvgTop := low
activeBullFvgBottom := high[2]
if showFVG
box b = box.new(left=bar_index - 2, top=low, right=bar_index + 1, bottom=high[2], bgcolor=color.new(green, 86), border_color=color.new(green, 48), extend=extend.right)
array.push(bullGaps, b)
if array.size(bullGaps) > maxGaps
box.delete(array.shift(bullGaps))
if bearFVG
activeBearFvgTop := low[2]
activeBearFvgBottom := high
if showFVG
box b = box.new(left=bar_index - 2, top=low[2], right=bar_index + 1, bottom=high, bgcolor=color.new(red, 86), border_color=color.new(red, 48), extend=extend.right)
array.push(bearGaps, b)
if array.size(bearGaps) > maxGaps
box.delete(array.shift(bearGaps))
if showZones and bullBreak
float originLow = na
float originTop = na
int originBar = na
for k = 1 to 8
if na(originLow) and close[k] < open[k]
originLow := low[k]
originTop := math.max(open[k], close[k])
originBar := bar_index - k
if not na(originLow) and originTop > originLow
box z = box.new(left=originBar, right=bar_index + 1, top=originTop, bottom=originLow, extend=extend.right, bgcolor=color.new(cyan, 91), border_color=color.new(cyan, 60))
array.push(demandZones, z)
if array.size(demandZones) > maxZones
box.delete(array.shift(demandZones))
if showZones and bearBreak
float originHigh = na
float originBottom = na
int originBar = na
for k = 1 to 8
if na(originHigh) and close[k] > open[k]
originHigh := high[k]
originBottom := math.min(open[k], close[k])
originBar := bar_index - k
if not na(originHigh) and originHigh > originBottom
box z = box.new(left=originBar, right=bar_index + 1, top=originHigh, bottom=originBottom, extend=extend.right, bgcolor=color.new(violet, 91), border_color=color.new(violet, 60))
array.push(supplyZones, z)
if array.size(supplyZones) > maxZones
box.delete(array.shift(supplyZones))
// ── 05b. LOW-COST ESTIMATED FIXED-RANGE VOLUME DISTRIBUTION ───────────────────
// Unlike exchange footprint/order-book data, the profile below estimates volume
// across each candle range, assuming a uniform intra-candle distribution.
// It is recomputed only on the last bar to prevent historical O(bars × bins) loops.
var array<float> vpHist = array.new<float>(profileBins, 0.0)
var array<box> vpBoxes = array.new<box>()
var line pocLine = na
var float vpPOC = na
var float vpVAH = na
var float vpVAL = na
if barstate.islast and showProfile and hasVol and profileHigh > profileLow and (computeMode == "Full analysis" or barstate.isconfirmed or not barstate.isrealtime)
array.fill(vpHist, 0.0)
float binSize = math.max((profileHigh - profileLow) / profileBins, syminfo.mintick)
for i = 0 to profileLookback - 1
if not na(high[i]) and not na(low[i]) and not na(volume[i])
float candleRange = high[i] - low[i]
// A zero-range candle has no overlap length: assign its volume to its price bin.
if candleRange <= syminfo.mintick * 0.001
int atBin = int(f_clamp(math.floor((close[i] - profileLow) / binSize), 0, profileBins - 1))
array.set(vpHist, atBin, array.get(vpHist, atBin) + volume[i])
else
for j = 0 to profileBins - 1
float priceBottom = profileLow + j * binSize
float covered = math.max(0.0, math.min(high[i], priceBottom + binSize) - math.max(low[i], priceBottom))
float approxVol = volume[i] * covered / candleRange
array.set(vpHist, j, array.get(vpHist, j) + approxVol)
float peakVol = array.max(vpHist)
if peakVol > 0
int pocIdx = array.indexof(vpHist, peakVol)
vpPOC := profileLow + (pocIdx + 0.5) * binSize
float targetVol = array.sum(vpHist) * 0.70
float capturedVol = peakVol
int vaLow = pocIdx
int vaHigh = pocIdx
for j = 0 to profileBins - 1
if capturedVol < targetVol
float downVol = vaLow > 0 ? array.get(vpHist, vaLow - 1) : -1.0
float upVol = vaHigh < profileBins - 1 ? array.get(vpHist, vaHigh + 1) : -1.0
if upVol >= downVol and upVol >= 0
vaHigh += 1
capturedVol += upVol
else if downVol >= 0
vaLow -= 1
capturedVol += downVol
vpVAH := profileLow + (vaHigh + 1) * binSize
vpVAL := profileLow + vaLow * binSize
if array.size(vpBoxes) == 0
for j = 0 to profileBins - 1
array.push(vpBoxes, box.new(left=bar_index + 3, right=bar_index + 5, top=close, bottom=close - syminfo.mintick, bgcolor=color.new(cyan, 80), border_color=color.new(grid, 85)))
for j = 0 to profileBins - 1
box b = array.get(vpBoxes, j)
float power = array.get(vpHist, j) / peakVol
int barsWide = int(math.max(1, math.round(power * profileWidth)))
color levelColor = j == pocIdx ? gold : j >= vaLow and j <= vaHigh ? cyan : violet
box.set_left(b, bar_index + 3)
box.set_right(b, bar_index + 3 + barsWide)
box.set_top(b, profileLow + (j + 1) * binSize)
box.set_bottom(b, profileLow + j * binSize)
box.set_bgcolor(b, color.new(levelColor, j == pocIdx ? 18 : 68))
box.set_border_color(b, color.new(levelColor, 76))
if na(pocLine)
pocLine := line.new(bar_index - 10, vpPOC, bar_index + 3 + profileWidth, vpPOC, color=gold, style=line.style_dotted, width=2)
else
line.set_xy1(pocLine, bar_index - 10, vpPOC)
line.set_xy2(pocLine, bar_index + 3 + profileWidth, vpPOC)
// ─────────────────────────────────────────────────────────────────────────────
// 06 | FUSION17 REFACTORED ANALYTICAL ENGINES
// Independent new formulations inspired by the 17 supplied study categories.
// These are NOT verbatim ports of the original scripts and cannot claim to be
// mathematically equivalent to the sources. Each module supplies a bounded
// directional vote in [-1,+1]. Composite modules have reduced weights to
// mitigate duplicate evidence. Scores represent weighted rule agreement only.
// ─────────────────────────────────────────────────────────────────────────────
f_vote(float v) => math.max(-1.0, math.min(1.0, nz(v)))
f_bullVote(float v) => f_clamp((v + 0.12) / 1.12, 0.0, 1.0)
f_bearVote(float v) => f_clamp((-v + 0.12) / 1.12, 0.0, 1.0)
f_signed(float v) => v >= 0.24 ? "▲ BULL" : v <= -0.24 ? "▼ BEAR" : "◆ NEUTRAL"
f_votecol(float v) => v >= 0.24 ? green : v <= -0.24 ? red : gold
f_pretty(float v) => str.tostring(v, "#.00")
f_bar(float value) =>
int n = int(math.round(f_clamp(math.abs(value), 0.0, 1.0) * 8.0))
string meter = ""
for k = 1 to 8
meter += k <= n ? "▰" : "▱"
meter
// SOURCE 01 / APEX: user-selectable control-plane and regime/trend context.
float e01 = f_vote(((emaFast - emaSlow) / math.max(atr, syminfo.mintick)) * 0.65 + ((close - emaBias) / math.max(atr, syminfo.mintick)) * 0.25)
// SOURCE 02 / Crypto Hunter: breakout channel + normalized momentum.
float channelUpper = ta.highest(high, channelLen)[1]
float channelLower = ta.lowest(low, channelLen)[1]
float sevenRoc = ta.roc(close, 7)
bool confirmedHighBreak = not na(channelUpper) and close > channelUpper
bool confirmedLowBreak = not na(channelLower) and close < channelLower
float e02 = f_vote((confirmedHighBreak ? 0.60 : confirmedLowBreak ? -0.60 : 0.0) + (sevenRoc / math.max(100.0 * atr / math.max(math.abs(close), syminfo.mintick), 0.1)) * 0.12)
// SOURCE 03 / Dark Knight: true Supertrend and DMI/ADX regime vote.
[superValue, superDir] = ta.supertrend(2.7, 11)
float e03 = f_vote((superDir < 0 ? 1.0 : -1.0) * f_clamp(adx / 27.0, 0.2, 1.0))
// SOURCE 04 / Fury FX: directional pressure estimate; NO actual trade delta.
float candlePressure = (close - open) / math.max(high - low, syminfo.mintick)
float pressure = ta.ema(candlePressure, 8)
float e04 = hasVol ? f_vote(nz(flowProxy, 0.0) / 55.0 * 0.6 + pressure * 0.4) : na
// SOURCE 05 / FX Pro: original KAMA-style adaptive trend calculation.
float kamaDelta = math.abs(close - nz(close[10], close))
float kamaNoise = ta.sma(math.abs(ta.change(close)), 10) * 10.0
float kamaER = kamaNoise > 0.0 ? kamaDelta / kamaNoise : 0.0
float kamaFastSC = 2.0 / 3.0
float kamaSlowSC = 2.0 / 31.0
float kamaSC = math.pow(kamaER * (kamaFastSC - kamaSlowSC) + kamaSlowSC, 2.0)
var float adaptiveKama = na
adaptiveKama := na(adaptiveKama[1]) ? close : adaptiveKama[1] + kamaSC * (close - adaptiveKama[1])
float e05 = f_vote(((close - adaptiveKama) / math.max(atr, syminfo.mintick)) * 0.35 + ((adaptiveKama - nz(adaptiveKama[3], adaptiveKama)) / math.max(atr, syminfo.mintick)) * 0.8)
// SOURCE 06 / GOD MODE Scalper + Prop Hunter: previous-day range expansion.
// Use the last completed daily candle, never the unfinished D range.
[prevDayHigh, prevDayLow] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead=barmerge.lookahead_on)
bool dayFilterAvailable = timeframe.in_seconds(timeframe.period) < 86400 and not na(prevDayHigh) and not na(prevDayLow)
float prevDayMid = (prevDayHigh + prevDayLow) / 2.0
float e06 = dayFilterAvailable ? f_vote((close > prevDayHigh ? 0.85 : close < prevDayLow ? -0.85 : (close - prevDayMid) / math.max(prevDayHigh - prevDayLow, syminfo.mintick)) * 0.95) : na
// SOURCE 07 / ICT Dr FX: structure + wick raid + 3-bar FVG confluence.
float structureInfluence = marketStructure == 1 ? 0.48 : marketStructure == -1 ? -0.48 : 0.0
float liquidityInfluence = bullFVG ? 0.35 : bearFVG ? -0.35 : sweepLow ? 0.30 : sweepHigh ? -0.30 : 0.0
float e07 = f_vote(structureInfluence + liquidityInfluence)
// SOURCE 08 / QMAE: three-state Shannon return entropy (not transfer entropy).
// This interpretable entropy proxy expresses market-state uncertainty.
int actualEntropyWindow = computeMode == "Performance" ? math.min(entropyWindow, 18) : entropyWindow
float sumUp = 0.0
float sumFlat = 0.0
float sumDown = 0.0
if bar_index > actualEntropyWindow
for n = 0 to actualEntropyWindow - 1
float move = close[n] - close[n + 1]
float border = math.max(nz(atr[n], syminfo.mintick), syminfo.mintick) * 0.16
if move > border
sumUp += 1.0
else if move < -border
sumDown += 1.0
else
sumFlat += 1.0
float upP = sumUp / actualEntropyWindow
float flatP = sumFlat / actualEntropyWindow
float downP = sumDown / actualEntropyWindow
float shannon = -(upP > 0 ? upP * math.log(upP) : 0.0) - (flatP > 0 ? flatP * math.log(flatP) : 0.0) - (downP > 0 ? downP * math.log(downP) : 0.0)
float entropy = bar_index > actualEntropyWindow ? f_clamp(shannon / math.log(3.0), 0.0, 1.0) : na
float entropyConviction = 1.0 - nz(entropy, 1.0)
float e08 = f_vote((upP - downP) * (0.42 + entropyConviction))
// SOURCE 09 / RAPTOR FX: Haar-like two-scale wave and normalized slope.
float waveShort = (close - nz(close[2], close)) / math.max(atr, syminfo.mintick)
float waveLong = (nz(close[2], close) - nz(close[4], close)) / math.max(atr, syminfo.mintick)
float spectralImpulse = ta.ema(waveShort - waveLong, 5)
float regression = ta.linreg(close, 30, 0)
float regressionSlope = (regression - nz(regression[4], regression)) / math.max(atr, syminfo.mintick)
float e09 = f_vote(0.45 * spectralImpulse + 0.55 * regressionSlope)
// SOURCE 10 / Star Wars Force Oscillator: normalized energy/force estimator.
// OHLCV-based force is NOT an exchange order-flow or footprint calculation.
float forceRaw = candlePressure * (hasVol ? f_clamp(nz(relVol), 0.0, 2.5) / 1.4 : 1.0)
float forceSmoothed = ta.ema(forceRaw, 5)
float e10 = f_vote(forceSmoothed)
// SOURCE 11 / Trader Scalper Pro: price-action engulf + volatility channel.
bool bullEngulf = close > open and close[1] < open[1] and close >= open[1] and open <= close[1]
bool bearEngulf = close < open and close[1] > open[1] and close <= open[1] and open >= close[1]
float deviation = (close - ta.ema(close, 34)) / math.max(atr, syminfo.mintick)
float e11 = f_vote(deviation * 0.52 + (bullEngulf ? 0.42 : bearEngulf ? -0.42 : 0.0))
// SOURCE 12 / Trading Room Hunter: confirmed displacement-origin zone map.
// Analytical state is always updated, independently of the showZones drawing option.
// Zone quality: relative body displacement and proximity to most recent zone.
var float liveDemandTop = na
var float liveDemandBottom = na
var float liveSupplyTop = na
var float liveSupplyBottom = na
if bullBreak
liveDemandTop := na
liveDemandBottom := na
for k = 1 to 8
if na(liveDemandTop) and close[k] < open[k]
liveDemandTop := math.max(open[k], close[k])
liveDemandBottom := low[k]
if bearBreak
liveSupplyTop := na
liveSupplyBottom := na
for k = 1 to 8
if na(liveSupplyTop) and close[k] > open[k]
liveSupplyTop := high[k]
liveSupplyBottom := math.min(open[k], close[k])
if barstate.isconfirmed
if not na(liveDemandBottom) and close < liveDemandBottom
liveDemandTop := na
liveDemandBottom := na
if not na(liveSupplyTop) and close > liveSupplyTop
liveSupplyTop := na
liveSupplyBottom := na
bool demandTouch = not na(liveDemandTop) and low <= liveDemandTop + atr * 0.5 and close > liveDemandBottom
bool supplyTouch = not na(liveSupplyBottom) and high >= liveSupplyBottom - atr * 0.5 and close < liveSupplyTop
float displacement = math.abs(close - open) / math.max(atr, syminfo.mintick)
float e12 = f_vote((demandTouch ? 0.55 : supplyTouch ? -0.55 : 0.0) + (bullBreak ? 0.45 : bearBreak ? -0.45 : 0.0) * f_clamp(displacement, 0.25, 1.4))
// SOURCE 13 / VENOM RAPTOR: lower-weighted directional cross-confirmation.
float trendSign = emaFast > emaSlow ? 1.0 : -1.0
float e13 = f_vote((trendSign + (superDir < 0 ? 1.0 : -1.0) + (macdHist > 0 ? 1.0 : -1.0)) / 3.0 * f_clamp(adx / 23.0, 0.35, 1.0))
// SOURCE 14 / Volume Profile Vision: history-safe volume-weighted acceptance.
// The full visual estimated POC is computed only at the right edge. For historical
// scoring we use a rolling VWMA instead; this is NOT the same as a volume profile.
float volumeMean = ta.vwma(close, 34)
float e14 = hasVol and not na(volumeMean) ? f_vote((close - volumeMean) / math.max(atr, syminfo.mintick) * 0.58) : na
// SOURCE 15 / Volume Trader: money flow index + relative volume intensity.
float moneyFlowIdx = ta.mfi(hlc3, 14)
float e15 = hasVol and not na(moneyFlowIdx) ? f_vote(((moneyFlowIdx - 50.0) / 50.0) * 0.8 + f_clamp(nz(relVol) - 1.0, -1.0, 1.0) * candlePressure * 0.2) : na
// SOURCE 16 / Diamond Algo: closed-bar higher-timeframe directional agreement.
float htfSum = (validHTF1 ? (htfBull1 ? 1.0 : -1.0) : 0.0) + (validHTF2 ? (htfBull2 ? 1.0 : -1.0) : 0.0)
int htfAvailable = (validHTF1 ? 1 : 0) + (validHTF2 ? 1 : 0)
float e16 = htfAvailable > 0 ? f_vote(htfSum / htfAvailable) : na
// SOURCE 17 / AtroNox: intraday VWAP + macro bias oscillator.
float vwapVote = vwapValid ? (close > vwapNow ? 1.0 : -1.0) : (close > emaBias ? 1.0 : -1.0)
float e17 = f_vote((vwapVote + (rsi > 50 ? 1.0 : -1.0) + (emaSlow > emaSlow[3] ? 1.0 : -1.0)) / 3.0)
// ------------------------------------
// Additional bounded descriptive features
// These are shared context outputs, not eighteenth through thirty-second
// source-code ports. The original 17 votes remain explicitly identifiable.
// ------------------------------------
float channelCenter = (ta.highest(high, 55) + ta.lowest(low, 55)) * 0.5
float channelSpan = math.max(ta.highest(high, 55) - ta.lowest(low, 55), syminfo.mintick)
float channelPosition = f_clamp((close - channelCenter) / channelSpan * 2.0, -1.0, 1.0)
float rsiSlope = ta.ema(ta.change(rsi), 5)
float macdCurvature = macdHist - 2.0 * nz(macdHist[1], macdHist) + nz(macdHist[2], macdHist)
float volumeImbalanceProxy = f_vote(closeLocation * f_clamp(nz(relVol, 1.0), 0.0, 3.0) / 2.0)
float liqSweepContext = f_vote((sweepLow ? 1.0 : sweepHigh ? -1.0 : 0.0) + wickSkew * 0.25)
float meanReversionContext = f_vote(-ribbonZ * (choppy ? 0.5 : 0.12))
float priceDiscoveryContext = f_vote(channelPosition * (trending ? 1.0 : 0.38))
float trendPersistenceContext = f_vote(multiscaleDrift * 0.08 + slopeATR * 1.7)
float cycleContext = f_vote(spectralImpulse * 0.26 + macdCurvature / math.max(atr, syminfo.mintick))
float breakoutContext = f_vote((confirmedHighBreak ? 0.8 : confirmedLowBreak ? -0.8 : 0.0) + channelPosition * 0.2)
float statisticalContext = f_vote(noiseSignal / 2.5)
float directionalCandleContext = f_vote((closeLocation + candlePressure + wickSkew) / 3.0)
float volumeAvailabilityFlag = hasVol ? 1.0 : 0.0
float longWickShare = (high - math.max(open, close)) / math.max(high - low, syminfo.mintick)
float shortWickShare = (math.min(open, close) - low) / math.max(high - low, syminfo.mintick)
float displacementScore = f_clamp(bodyFraction * trEnergy * 100.0, 0.0, 100.0)
float exhaustionContext = f_vote((rsi > 74 ? -0.45 : rsi < 26 ? 0.45 : 0.0) + wickSkew * 0.4)
float structureBalance = f_vote(structureInfluence + liqSweepContext * 0.35)
float intrabarStrengthProxy = f_vote((closeLocation + volumeImbalanceProxy) / 2.0)
float volatilityExpansion = f_clamp(nz(volatilityPct, 100.0) / 100.0, 0.0, 3.0)
float closeToVWAPATR = vwapValid ? (close - vwapNow) / math.max(atr, syminfo.mintick) : na
float meanDeviation = (close - ribbonMean) / math.max(atr, syminfo.mintick)
float macroDeviation = (close - emaBias) / math.max(atr, syminfo.mintick)
float structuralDistance = marketStructure == 1 and not na(lastSwingLow) ? (close - lastSwingLow) / math.max(atr, syminfo.mintick) : marketStructure == -1 and not na(lastSwingHigh) ? (lastSwingHigh - close) / math.max(atr, syminfo.mintick) : na
float valueAcceptanceContext = hasVol and not na(volumeMean) ? f_vote((close - volumeMean) / math.max(atr, syminfo.mintick)) : na
float htfAgreementContext = e16
// The following weights are published, deterministic and availability-adjusted.
// Composite modules (VENOM, Diamond, AtroNox) deliberately have lower weights.
array<float> eVotes = array.from(e01, e02, e03, e04, e05, e06, e07, e08, e09, e10, e11, e12, e13, e14, e15, e16, e17)
array<float> eWeights = array.from(1.25, 1.00, 1.10, 0.80, 1.00, 0.75, 1.20, 0.75, 0.90, 0.70, 0.90, 1.00, 0.55, 0.70, 0.75, 0.65, 0.60)
// Independent per-update copy: one adjustable weight per Fusion17 engine.
array<float> eEffectiveWeights = array.copy(eWeights)
var array<string> eNames = array.from("APEX Control", "Crypto Hunter", "Dark Knight", "Fury FX", "FX Pro Adaptive", "GOD / Prop Hunt", "ICT Structure", "QMAE Entropy", "RAPTOR Wave", "SW Force", "Trader Scalper", "TRH Zones", "VENOM Fusion", "VP Vision", "Volume Trader", "Diamond HTF", "AtroNox VWAP")
float bullishPoints = 0.0
float bearishPoints = 0.0
float possiblePoints = 0.0
float weightedImpulse = 0.0
int activeModules = 0
for k = 0 to 16
float v = array.get(eVotes, k)
float w = array.get(eWeights, k)
// Muting highly correlated trend-driven modules in rotational/choppy regimes
// reduces evidence duplication without suppressing their raw dashboard votes.
if adaptiveWeighting
if choppy and (k == 0 or k == 1 or k == 2 or k == 8 or k == 12)
w *= 0.72
if trending and (k == 6 or k == 11)
w *= 1.14
if nz(entropy, 1.0) > 0.92 and (k == 1 or k == 8)
w *= 0.79
if volatilityExpansion > 1.55 and (k == 3 or k == 9)
w *= 0.85
array.set(eEffectiveWeights, k, w)
if not na(v)
bullishPoints += f_bullVote(v) * w
bearishPoints += f_bearVote(v) * w
possiblePoints += w
weightedImpulse += v * w
activeModules += 1
float bullScore = possiblePoints > 0 ? f_clamp(100.0 * bullishPoints / possiblePoints, 0.0, 100.0) : 0.0
float bearScore = possiblePoints > 0 ? f_clamp(100.0 * bearishPoints / possiblePoints, 0.0, 100.0) : 0.0
float signedEdge = bullScore - bearScore
float fusionImpulse = possiblePoints > 0 ? weightedImpulse / possiblePoints : 0.0
// Breadth and coherence are observable vote measurements, never calibrated confidence.
int bullEngineBreadth = 0
int bearEngineBreadth = 0
float magnitudeWeights = 0.0
float squaredWeights = 0.0
float directionalDispersion = 0.0
for n = 0 to 16
float voteN = array.get(eVotes, n)
float weightN = array.get(eWeights, n)
if not na(voteN)
if voteN > 0.24
bullEngineBreadth += 1
if voteN < -0.24
bearEngineBreadth += 1
magnitudeWeights += math.abs(voteN) * weightN
squaredWeights += weightN * weightN
directionalDispersion += math.abs(voteN - fusionImpulse) * weightN
float activeStrength = possiblePoints > 0 ? 100.0 * magnitudeWeights / possiblePoints : 0.0
float disagreement = possiblePoints > 0 ? 100.0 * directionalDispersion / possiblePoints : na
float diversification = squaredWeights > 0 ? (possiblePoints * possiblePoints) / squaredWeights : 0.0
float agreementDensity = activeModules > 0 ? 100.0 * math.max(bullEngineBreadth, bearEngineBreadth) / activeModules : 0.0
float currentCoherence = f_clamp(100.0 - nz(disagreement, 100.0) * 0.6, 0.0, 100.0)
float stableMomentum = ta.ema(fusionImpulse, 8)
float impulseVelocity = fusionImpulse - nz(fusionImpulse[1], fusionImpulse)
float impulseAcceleration = impulseVelocity - nz(impulseVelocity[1], impulseVelocity)
float impulseSmoothing = ta.ema(math.abs(impulseVelocity), 8)
float kineticStress = f_clamp(impulseSmoothing * 240.0, 0.0, 100.0)
float signalStability = f_clamp(100.0 - kineticStress, 0.0, 100.0)
int dominantBreadth = math.max(bullEngineBreadth, bearEngineBreadth)
string bias = signedEdge > 18 ? "BULLISH CONFLUENCE" : signedEdge < -18 ? "BEARISH CONFLUENCE" : "MIXED / NEUTRAL"
color biasCol = signedEdge > 18 ? green : signedEdge < -18 ? red : gold
bool chopVeto = disallowChop and choppy and nz(entropy, 1.0) > 0.89
bool trendLongGate = not requireTrend or (emaFast > emaSlow and close >= emaBias)
bool trendShortGate = not requireTrend or (emaFast < emaSlow and close <= emaBias)
bool breadthLongGate = not showQualityGate or bullEngineBreadth >= minEngineBreadth
bool breadthShortGate = not showQualityGate or bearEngineBreadth >= minEngineBreadth
// Bar-close setup triggers. Alignment alone must not produce repeated signals.
bool crossUp = ta.crossover(close, emaFast)
bool crossDown = ta.crossunder(close, emaFast)
bool emaCrossUp = ta.crossover(emaFast, emaSlow)
bool emaCrossDown = ta.crossunder(emaFast, emaSlow)
bool superCrossLong = ta.crossunder(superDir, 0)
bool superCrossShort = ta.crossover(superDir, 0)
bool longTrigger = crossUp or emaCrossUp or bullBreak or bullFVG or superCrossLong or (bullEngulf and close > adaptiveKama) or (confirmedHighBreak and close[1] <= nz(channelUpper[1], channelUpper))
bool shortTrigger = crossDown or emaCrossDown or bearBreak or bearFVG or superCrossShort or (bearEngulf and close < adaptiveKama) or (confirmedLowBreak and close[1] >= nz(channelLower[1], channelLower))
var int lastAlertBar = na
bool cooled = na(lastAlertBar) or bar_index - lastAlertBar > cooldownBars
bool enoughHistory = bar_index > math.max(biasLen, entropyWindow) and not na(atr) and not na(adx) and not na(adaptiveKama)
bool longSignal = barstate.isconfirmed and enoughHistory and cooled and not chopVeto and longTrigger and trendLongGate and bullScore >= minScore and signedEdge >= minEdge and breadthLongGate
bool shortSignal = barstate.isconfirmed and enoughHistory and cooled and not chopVeto and shortTrigger and trendShortGate and bearScore >= minScore and signedEdge <= -minEdge and breadthShortGate
if longSignal or shortSignal
lastAlertBar := bar_index
// ── 07. PRICE-ANCHORED VISUAL INTELLIGENCE ───────────────────────────────────
color ribbonCol = emaFast >= emaSlow ? green : red
pFast = plot(showCloud ? emaFast : na, "Fast EMA", color=color.new(cyan, 5), linewidth=2)
pSlow = plot(showCloud ? emaSlow : na, "Slow EMA", color=color.new(violet, 5), linewidth=2)
fill(pFast, pSlow, color=showCloud ? color.new(ribbonCol, 87) : na, title="Adaptive trend cloud")
plot(emaBias, "Macro EMA", color=color.new(gold, 20), linewidth=2)
plot(showVWAP and vwapValid ? vwapNow : na, "Session VWAP", color=color.new(white, 34), linewidth=1)
barcolor(colorBars ? color.new(biasCol, 25) : na, title="Adaptive score candles")
bgcolor(showHeat and trending ? color.new(biasCol, 95) : na, title="Directional backdrop")
plotshape(longSignal, title="Confirmed long signal", location=location.belowbar, style=shape.labelup, color=green, text="▲ LONG", textcolor=ink, size=size.small)
plotshape(shortSignal, title="Confirmed short signal", location=location.abovebar, style=shape.labeldown, color=red, text="▼ SHORT", textcolor=white, size=size.small)
plotshape(showSweeps and sweepLow, title="Sell-side liquidity sweep", location=location.belowbar, style=shape.diamond, color=cyan, text="SWP", textcolor=cyan, size=size.tiny)
plotshape(showSweeps and sweepHigh, title="Buy-side liquidity sweep", location=location.abovebar, style=shape.diamond, color=violet, text="SWP", textcolor=violet, size=size.tiny)
plotshape(showStructure and bullBreak and not bullChoch, title="Bullish BOS", location=location.belowbar, style=shape.circle, color=cyan, text="BOS", textcolor=cyan, size=size.tiny)
plotshape(showStructure and bearBreak and not bearChoch, title="Bearish BOS", location=location.abovebar, style=shape.circle, color=gold, text="BOS", textcolor=gold, size=size.tiny)
plotshape(showStructure and bullChoch, title="Bullish CHoCH", location=location.belowbar, style=shape.triangleup, color=green, text="CHoCH", textcolor=green, size=size.tiny)
plotshape(showStructure and bearChoch, title="Bearish CHoCH", location=location.abovebar, style=shape.triangledown, color=red, text="CHoCH", textcolor=red, size=size.tiny)
// Signal markers display the actual score; the number is rule confluence, not statistical confidence.
if longSignal
label.new(bar_index, low - atr * 0.75, "GOD X | LONG\n" + f_score(bullScore) + " rule score" + (bullChoch ? " · CHoCH" : ""), style=label.style_label_up, color=color.new(green, 5), textcolor=ink, size=size.small)
if shortSignal
label.new(bar_index, high + atr * 0.75, "GOD X | SHORT\n" + f_score(bearScore) + " rule score" + (bearChoch ? " · CHoCH" : ""), style=label.style_label_down, color=color.new(red, 5), textcolor=white, size=size.small)
// ── 08. SINGLE-SETUP RISK / REWARD GEOMETRY ──────────────────────────────────
var float lastEntry = na
var float lastStop = na
var float lastTP1 = na
var float lastTP2 = na
var int lastSide = 0
var int lastSignalTime = na
var line entryLine = na
var line stopLine = na
var line tp1Line = na
var line tp2Line = na
var box riskBox = na
var box rewardBox = na
var label tradeCaption = na
if longSignal or shortSignal
lastSide := longSignal ? 1 : -1
lastEntry := close
float riskDistance = atr * atrStop
lastStop := lastSide == 1 ? close - riskDistance : close + riskDistance
lastTP1 := lastSide == 1 ? close + riskDistance * rr1 : close - riskDistance * rr1
lastTP2 := lastSide == 1 ? close + riskDistance * rr2 : close - riskDistance * rr2
lastSignalTime := time
if not na(entryLine)
line.delete(entryLine)
if not na(stopLine)
line.delete(stopLine)
if not na(tp1Line)
line.delete(tp1Line)
if not na(tp2Line)
line.delete(tp2Line)
if not na(riskBox)
box.delete(riskBox)
if not na(rewardBox)
box.delete(rewardBox)
if not na(tradeCaption)
label.delete(tradeCaption)
if showRisk
entryLine := line.new(bar_index, lastEntry, bar_index + projection, lastEntry, color=white, style=line.style_solid, width=2)
stopLine := line.new(bar_index, lastStop, bar_index + projection, lastStop, color=red, style=line.style_dashed, width=2)
tp1Line := line.new(bar_index, lastTP1, bar_index + projection, lastTP1, color=green, style=line.style_dotted, width=2)
tp2Line := line.new(bar_index, lastTP2, bar_index + projection, lastTP2, color=cyan, style=line.style_dashed, width=2)
riskBox := box.new(left=bar_index, right=bar_index + projection, top=math.max(lastEntry, lastStop), bottom=math.min(lastEntry, lastStop), border_color=color.new(red, 80), bgcolor=color.new(red, 91))
rewardBox := box.new(left=bar_index, right=bar_index + projection, top=math.max(lastEntry, lastTP2), bottom=math.min(lastEntry, lastTP2), border_color=color.new(green, 80), bgcolor=color.new(green, 93))
tradeCaption := label.new(bar_index + projection, lastTP2, "EST TP2 " + f_px(lastTP2) + "\n" + str.tostring(rr2, "#.##") + "R", style=label.style_label_left, color=color.new(panel, 10), textcolor=cyan, size=size.small)
// Observational reference lifecycle for the most recently confirmed signal.
// This is not a backtest: when the same candle crosses both target and stop,
// the outcome is AMBIGUOUS because OHLC alone cannot establish event order.
var int referenceSignalBar = na
var string referenceState = "NO REFERENCE"
var int referenceStateBar = na
var int referenceOutcomeCode = 0
if longSignal or shortSignal
referenceSignalBar := bar_index
referenceState := "ACTIVE REFERENCE"
referenceStateBar := bar_index
referenceOutcomeCode := 0
if showSignalLifecycle and barstate.isconfirmed and not na(referenceSignalBar) and bar_index > referenceSignalBar and referenceOutcomeCode == 0 and not na(lastStop) and not na(lastTP1)
bool stopTouched = lastSide == 1 ? low <= lastStop : high >= lastStop
bool target1Touched = lastSide == 1 ? high >= lastTP1 : low <= lastTP1
if stopTouched and target1Touched
referenceOutcomeCode := 3
referenceState := "AMBIGUOUS PATH"
referenceStateBar := bar_index
else if stopTouched
referenceOutcomeCode := 2
referenceState := "STOP REFERENCE TOUCHED"
referenceStateBar := bar_index
else if target1Touched
referenceOutcomeCode := 1
referenceState := "TP1 REFERENCE TOUCHED"
referenceStateBar := bar_index
// ── 08B | Spectral envelopes and previous completed daily price range ──────
float sUpper = adaptiveKama + atr * (0.55 + entropyConviction * 0.70)
float sLower = adaptiveKama - atr * (0.55 + entropyConviction * 0.70)
pUpper = plot(showWave ? sUpper : na, "Adaptive spectral upper", color=color.new(electricBlue, 74), linewidth=1)
pLower = plot(showWave ? sLower : na, "Adaptive spectral lower", color=color.new(violet, 74), linewidth=1)
fill(pUpper, pLower, title="Spectral energy envelope", color=showWave ? color.new(fusionImpulse >= 0 ? cyan : red, 95) : na)
plot(showWave ? adaptiveKama : na, "FX Pro adaptive central rail", color=color.new(gold, 22), linewidth=2)
plot(showPrevDay and dayFilterAvailable ? prevDayHigh : na, "Prior day high (confirmed)", color=color.new(gold, 67), style=plot.style_linebr)
plot(showPrevDay and dayFilterAvailable ? prevDayLow : na, "Prior day low (confirmed)", color=color.new(gold, 67), style=plot.style_linebr)
plotshape(showSignalTrace and longSignal, "Confirmed long setup trace", shape.labelup, location.belowbar, color.new(green, 65), text="F17", textcolor=white, size=size.tiny)
plotshape(showSignalTrace and shortSignal, "Confirmed short setup trace", shape.labeldown, location.abovebar, color.new(red, 65), text="F17", textcolor=white, size=size.tiny)
// Research channel: visualizes rolling descriptive statistics only.
plot(showResearchRibbons ? ribbonMean + 1.65 * ribbonSigma : na, "Research sigma upper", color=color.new(electricBlue, 82), linewidth=1)
plot(showResearchRibbons ? ribbonMean - 1.65 * ribbonSigma : na, "Research sigma lower", color=color.new(violet, 82), linewidth=1)
plot(showResearchRibbons ? regr34 : na, "Research regression path", color=color.new(gold, 47), linewidth=1)
// ─────────────────────────────────────────────────────────────────────────────
// 09 | FUSION17 LIVE VISUAL COMMAND MATRIX
// 8 columns / 32 rows. All 17 modules report current bounded directional vote.
// Only last-bar redraws; historical CPU stays allocated to analytics, not the HUD.
// No CSS/HTML/WebGL or independent timers: color/pulse updates only on market data.
// ─────────────────────────────────────────────────────────────────────────────
varip int liveTickCount = 0
if barstate.isnew
liveTickCount := 0
else if barstate.isrealtime
liveTickCount += 1
bool tickFlash = pulseHUD and barstate.isrealtime and liveTickCount % 2 == 0
string realtimeState = barstate.isrealtime ? "● LIVE TICK " + str.tostring(liveTickCount) : "◌ HISTORICAL"
string frameState = barstate.isconfirmed ? "CLOSED BAR" : "FORMING BAR"
string modeState = chopVeto ? "CHOP FILTER" : trending ? "DIRECTIONAL" : choppy ? "RANGE / CHOP" : "TRANSITION"
string htfState1 = not validHTF1 ? "N/A" : htfBull1 ? "▲ BULL" : "▼ BEAR"
string htfState2 = not validHTF2 ? "N/A" : htfBull2 ? "▲ BULL" : "▼ BEAR"
string lastTrade = lastSide == 1 ? "LAST: LONG" : lastSide == -1 ? "LAST: SHORT" : "LAST: NONE"
string volCaption = not hasVol ? "NO VOLUME" : str.tostring(relVol, "#.00") + "x RVOL"
string volClass = not hasVol ? "UNAVAILABLE" : relVol >= 1.6 ? "HIGH" : relVol <= 0.65 ? "LOW" : "NORMAL"
string scoreCaption = "LONG " + str.tostring(bullScore, "#.0") + " | SHORT " + str.tostring(bearScore, "#.0")
string moduleCaption = str.tostring(activeModules) + " / 17 COMPUTED • NON-PROBABILISTIC AGREEMENT"
string sessionName = "OTHER"
bool inNy = not na(time(timeframe.period, "0930-1600", "America/New_York"))
bool inLondon = not na(time(timeframe.period, "0800-1630", "Europe/London"))
bool inTokyo = not na(time(timeframe.period, "0900-1500", "Asia/Tokyo"))
sessionName := inNy and inLondon ? "LONDON + NY" : inNy ? "NEW YORK" : inLondon ? "LONDON" : inTokyo ? "TOKYO" : "OTHER"
hudPosition = hudLoc == "Top Left" ? position.top_left : hudLoc == "Middle Right" ? position.middle_right : hudLoc == "Bottom Right" ? position.bottom_right : hudLoc == "Bottom Left" ? position.bottom_left : position.top_right
var table hud = table.new(hudPosition, 8, 32, bgcolor=ink, frame_color=grid, frame_width=2, border_color=color.new(grid, 38), border_width=1)
if barstate.isfirst
table.merge_cells(hud, 0, 0, 7, 0)
table.merge_cells(hud, 0, 1, 7, 1)
table.merge_cells(hud, 0, 2, 3, 2)
table.merge_cells(hud, 4, 2, 7, 2)
table.merge_cells(hud, 0, 3, 3, 3)
table.merge_cells(hud, 4, 3, 7, 3)
table.merge_cells(hud, 0, 4, 3, 4)
table.merge_cells(hud, 4, 4, 7, 4)
table.merge_cells(hud, 0, 5, 7, 5)
table.merge_cells(hud, 1, 6, 2, 6)
table.merge_cells(hud, 3, 6, 4, 6)
for r = 7 to 23
table.merge_cells(hud, 1, r, 2, r)
table.merge_cells(hud, 3, r, 4, r)
table.merge_cells(hud, 0, 24, 7, 24)
table.merge_cells(hud, 0, 25, 7, 25)
table.merge_cells(hud, 0, 26, 3, 26)
table.merge_cells(hud, 4, 26, 7, 26)
table.merge_cells(hud, 0, 27, 3, 27)
table.merge_cells(hud, 4, 27, 7, 27)
table.merge_cells(hud, 0, 28, 3, 28)
table.merge_cells(hud, 4, 28, 7, 28)
table.merge_cells(hud, 0, 29, 3, 29)
table.merge_cells(hud, 4, 29, 7, 29)
table.merge_cells(hud, 0, 30, 7, 30)
table.merge_cells(hud, 0, 31, 7, 31)
if showHUD and barstate.islast
color liveAccent = tickFlash ? cyan : violet
string pulseGlyph = tickFlash ? "◉" : "◎"
f_cell(hud, 0, 0, "DRFX / GOD MODE X / FUSION 17 " + pulseGlyph + " REAL-TIME VISUAL INTELLIGENCE", liveAccent, panel2, true)
f_cell(hud, 0, 1, syminfo.ticker + " · " + timeframe.period + " · " + realtimeState + " · " + frameState + " · " + sessionName, mute, ink)
f_cell(hud, 0, 2, "REGIME " + modeState + " | ADX " + str.tostring(adx, "#.0"), chopVeto ? amber : trending ? green : gold, panel, true)
f_cell(hud, 4, 2, "VOL STATE " + volState + " | ATR " + f_px(atr), cyan, panel, true)
f_cell(hud, 0, 3, "▲ BULL " + f_meter(bullScore), green, panel2, true)
f_cell(hud, 4, 3, "▼ BEAR " + f_meter(bearScore), red, panel2, true)
f_cell(hud, 0, 4, "BULL AGREEMENT " + f_score(bullScore), green, panel, true)
f_cell(hud, 4, 4, "BEAR AGREEMENT " + f_score(bearScore), red, panel, true)
f_cell(hud, 0, 5, "◈ 17-ENGINE DIAGNOSTIC MATRIX / " + moduleCaption, electricBlue, panel2, true)
f_cell(hud, 0, 6, "ID", mute, panel)
f_cell(hud, 1, 6, "ANALYTICAL ENGINE", mute, panel)
f_cell(hud, 3, 6, "SIGNAL INTENSITY", mute, panel)
f_cell(hud, 5, 6, "VOTE", mute, panel)
f_cell(hud, 6, 6, "WEIGHT", mute, panel)
f_cell(hud, 7, 6, "DIRECTION", mute, panel)
for k = 0 to 16
int r = k + 7
float v = array.get(eVotes, k)
float w = array.get(eEffectiveWeights, k)
color rowBg = k % 2 == 0 ? panel : ink
color directionalColor = na(v) ? mute : f_votecol(v)
f_cell(hud, 0, r, str.tostring(k + 1, "00"), mute, rowBg)
f_cell(hud, 1, r, array.get(eNames, k), white, rowBg)
f_cell(hud, 3, r, na(v) ? "○○○○○○○○" : f_bar(v), directionalColor, rowBg, true)
f_cell(hud, 5, r, na(v) ? "N/A" : str.tostring(v, "#.00"), directionalColor, panel2, true)
f_cell(hud, 6, r, na(v) ? "--" : str.tostring(w, "#.00"), mute, rowBg)
f_cell(hud, 7, r, na(v) ? "OFF" : f_signed(v), directionalColor, rowBg)
f_cell(hud, 0, 24, "COMPOSITE EDGE " + str.tostring(signedEdge, "#.0") + " pts | " + bias + " | FUSION PRESSURE " + str.tostring(fusionImpulse, "#.00"), biasCol, panel2, true)
f_cell(hud, 0, 25, "▰▰▰ SIGNAL GATES " + (chopVeto ? "CHOP BLOCKED" : "REGIME ALLOWED") + " · MIN " + str.tostring(minScore) + " / EDGE " + str.tostring(minEdge) + " ▰▰▰", chopVeto ? red : cyan, ink)
f_cell(hud, 0, 26, "MARKET STRUCTURE " + structureName + " | " + (sweepLow ? "SELL SIDE SWEEP" : sweepHigh ? "BUY SIDE SWEEP" : "NO NEW SWEEP"), marketStructure == 1 ? green : marketStructure == -1 ? red : gold, panel)
f_cell(hud, 4, 26, "FVG / ZONES " + (bullFVG ? "NEW BULL FVG" : bearFVG ? "NEW BEAR FVG" : "STRUCTURE ACTIVE"), cyan, panel)
f_cell(hud, 0, 27, "HTF " + htf1 + " " + htfState1 + " / HTF " + htf2 + " " + htfState2, e16 > 0 ? green : e16 < 0 ? red : gold, panel)
f_cell(hud, 4, 27, "ENTROPY " + (na(entropy) ? "N/A" : str.tostring(entropy, "#.00")) + " | EFF " + str.tostring(efficiency, "#.00") + " | COH " + str.tostring(currentCoherence, "#.0") + " | STAB " + str.tostring(signalStability, "#.0"), nz(entropy, 1.0) >= 0.90 ? amber : cyan, panel)
f_cell(hud, 0, 28, "VOLUME " + volCaption + " / " + volClass + " / MFI " + (hasVol ? str.tostring(moneyFlowIdx, "#.0") : "N/A"), hasVol ? cyan : amber, panel)
f_cell(hud, 4, 28, "EST PROFILE POC " + f_px(vpPOC) + " | VWMA " + f_px(volumeMean), gold, panel)
f_cell(hud, 0, 29, "REFERENCE ENTRY " + f_px(lastEntry) + " / STOP " + f_px(lastStop) + (showSignalLifecycle ? " / " + referenceState : ""), white, panel)
f_cell(hud, 4, 29, "REFERENCE TP1 " + f_px(lastTP1) + " / TP2 " + f_px(lastTP2) + (showTacticalMetrics ? " / BREADTH " + str.tostring(dominantBreadth) : ""), cyan, panel)
f_cell(hud, 0, 30, (longSignal ? "▲ NEW CONFIRMED LONG" : shortSignal ? "▼ NEW CONFIRMED SHORT" : lastTrade) + " · " + scoreCaption + " · COMPUTE " + computeMode, longSignal ? green : shortSignal ? red : gold, panel2, true)
f_cell(hud, 0, 31, "INDICATOR ONLY | NO VERIFIED WIN RATE | VOLUME PROXIES | LIVE HUD MAY CHANGE | SIGNALS CONFIRM AT BAR CLOSE", mute, ink)
if not showHUD and barstate.islast
table.clear(hud, 0, 0, 7, 31)
// ---------------------------------------------------------------------------
// ULTRA VISUAL | eight-axis confluence radar (chart-space schematic)
// Not a separate pixel canvas. Geometry is drawn with chart bar/time units.
// Dynamic objects are created once and updated only on the last bar.
// The radar summarizes descriptive votes and is NOT an order-flow footprint.
// ---------------------------------------------------------------------------
var array<line> radarRim = array.new<line>()
var array<line> radarBody = array.new<line>()
var array<line> radarSpokes = array.new<line>()
var array<label> radarNames = array.new<label>()
var label radarCenterCaption = na
if barstate.islast and radarEnabled
string[] radarAxisNames = array.from("TREND", "MOM", "STRUCT", "VOLUME", "REGIME", "HTF", "FORCE", "ADAPT")
float[] radarAxisValues = array.from((e01 + e03 + trendPersistenceContext) / 3.0, (e09 + e10 + directionalCandleContext) / 3.0, (e07 + structureBalance + liqSweepContext) / 3.0, (nz(e04, 0.0) + nz(e14, 0.0) + nz(e15, 0.0) + nz(valueAcceptanceContext, 0.0) + intrabarStrengthProxy) / 5.0, (e08 + e13 + meanReversionContext + priceDiscoveryContext) / 4.0, (nz(e16, 0.0) + nz(e06, 0.0)) * 0.5, (e02 + exhaustionContext + breakoutContext) / 3.0, (e17 + e05 + cycleContext + statisticalContext) / 4.0)
float centerY = close
int centerX = bar_index + radarDistance
float pxRadius = math.max(atr * radarScale, syminfo.mintick * 15.0)
if array.size(radarRim) == 0
for i = 0 to 7
array.push(radarRim, line.new(bar_index, close, bar_index + 1, close, color=color.new(violet, 58), width=1))
array.push(radarBody, line.new(bar_index, close, bar_index + 1, close, color=cyan, width=2))
array.push(radarSpokes, line.new(bar_index, close, bar_index + 1, close, color=color.new(grid, 25), style=line.style_dotted))
array.push(radarNames, label.new(bar_index, close, "", style=label.style_none, color=color.new(ink, 100), textcolor=white, size=size.tiny))
radarCenterCaption := label.new(bar_index, close, "", style=label.style_none, color=color.new(ink, 100), textcolor=gold, size=size.small)
for i = 0 to 7
int j = (i + 1) % 8
float angleI = math.pi * 2.0 * i / 8.0
float angleJ = math.pi * 2.0 * j / 8.0
float axisI = f_clamp(math.abs(nz(array.get(radarAxisValues, i), 0.0)), 0.02, 1.0)
float axisJ = f_clamp(math.abs(nz(array.get(radarAxisValues, j), 0.0)), 0.02, 1.0)
int wholeX = centerX + int(math.round(16.0 * math.cos(angleI)))
int nextX = centerX + int(math.round(16.0 * math.cos(angleJ)))
float wholeY = centerY + pxRadius * math.sin(angleI)
float nextY = centerY + pxRadius * math.sin(angleJ)
int scoreX = centerX + int(math.round(16.0 * axisI * math.cos(angleI)))
int scoreX2 = centerX + int(math.round(16.0 * axisJ * math.cos(angleJ)))
float scoreY = centerY + pxRadius * axisI * math.sin(angleI)
float scoreY2 = centerY + pxRadius * axisJ * math.sin(angleJ)
line.set_xy1(array.get(radarRim, i), wholeX, wholeY)
line.set_xy2(array.get(radarRim, i), nextX, nextY)
line.set_xy1(array.get(radarBody, i), scoreX, scoreY)
line.set_xy2(array.get(radarBody, i), scoreX2, scoreY2)
line.set_color(array.get(radarBody, i), nz(array.get(radarAxisValues, i), 0.0) >= 0.0 ? cyan : red)
line.set_xy1(array.get(radarSpokes, i), centerX, centerY)
line.set_xy2(array.get(radarSpokes, i), wholeX, wholeY)
label.set_xy(array.get(radarNames, i), centerX + int(math.round(22.0 * math.cos(angleI))), centerY + pxRadius * 1.22 * math.sin(angleI))
label.set_text(array.get(radarNames, i), array.get(radarAxisNames, i) + " " + str.tostring(array.get(radarAxisValues, i), "#.00"))
label.set_textcolor(array.get(radarNames, i), nz(array.get(radarAxisValues, i), 0.0) >= 0 ? green : red)
label.set_xy(radarCenterCaption, centerX, centerY)
label.set_text(radarCenterCaption, "F17\nRADAR")
if barstate.islast and not radarEnabled and array.size(radarRim) > 0
for i = 0 to 7
line.delete(array.get(radarRim, i))
line.delete(array.get(radarBody, i))
line.delete(array.get(radarSpokes, i))
label.delete(array.get(radarNames, i))
array.clear(radarRim)
array.clear(radarBody)
array.clear(radarSpokes)
array.clear(radarNames)
label.delete(radarCenterCaption)
radarCenterCaption := na
// ---------------------------------------------------------------------------
// SMART LIQUIDITY LADDER
// Uses confirmed previous-day levels + previously confirmed swing points.
// VAH / VAL levels, when present, are from approximate range volume allocation.
// Labels deliberately say REFERENCE rather than executable order-book liquidity.
// ---------------------------------------------------------------------------
var array<line> ladderLines = array.new<line>()
var array<label> ladderLabels = array.new<label>()
if barstate.islast and showLadder
float[] ladderPrices = array.from(lastSwingHigh, lastSwingLow, dayFilterAvailable ? prevDayHigh : na, dayFilterAvailable ? prevDayLow : na, vpVAH, vpVAL)
string[] ladderTitles = array.from("SWING H", "SWING L", "PREV D H", "PREV D L", "EST VAH", "EST VAL")
if array.size(ladderLines) == 0
for i = 0 to 5
array.push(ladderLines, line.new(bar_index, close, bar_index + 1, close, color=color.new(violet, 90), style=line.style_dotted))
array.push(ladderLabels, label.new(bar_index, close, "", style=label.style_label_left, textcolor=mute, color=color.new(panel, 45), size=size.tiny))
for i = 0 to 5
float price = array.get(ladderPrices, i)
line lineId = array.get(ladderLines, i)
label labelId = array.get(ladderLabels, i)
if not na(price)
line.set_xy1(lineId, bar_index - 2, price)
line.set_xy2(lineId, bar_index + ladderWidth, price)
line.set_color(lineId, color.new(i < 2 ? cyan : i < 4 ? gold : violet, 52))
label.set_xy(labelId, bar_index + ladderWidth, price)
label.set_text(labelId, array.get(ladderTitles, i) + " | " + f_px(price))
label.set_textcolor(labelId, color.new(i < 2 ? cyan : i < 4 ? gold : violet, 5))
else
line.set_color(lineId, color.new(ink, 100))
label.set_text(labelId, "")
if barstate.islast and not showLadder and array.size(ladderLines) > 0
for i = 0 to 5
line.delete(array.get(ladderLines, i))
label.delete(array.get(ladderLabels, i))
array.clear(ladderLines)
array.clear(ladderLabels)
// ── 10 | RESEARCH ALERTS; no orders and no guaranteed outcomes ──────────────
alertcondition(longSignal, title="DrFX Fusion17 | Confirmed long", message="Fusion17 LONG confirmed | {{ticker}} {{interval}} | close={{close}}")
alertcondition(shortSignal, title="DrFX Fusion17 | Confirmed short", message="Fusion17 SHORT confirmed | {{ticker}} {{interval}} | close={{close}}")
alertcondition(longSignal or shortSignal, title="DrFX Fusion17 | Any signal", message="Fusion17 directional signal confirmed | {{ticker}} {{interval}} | close={{close}}")
alertcondition(bullBreak or bearBreak, title="DrFX Fusion17 | BOS", message="Confirmed structure break | {{ticker}} {{interval}}")
alertcondition(sweepLow or sweepHigh, title="DrFX Fusion17 | Sweep", message="Confirmed wick sweep of prior swing | {{ticker}} {{interval}}")
if longSignal
alert("DRFX FUSION17 | LONG | " + syminfo.ticker + " | rule-agreement=" + f_score(bullScore) + " | refEntry=" + f_px(lastEntry) + " | theoreticalStop=" + f_px(lastStop) + " | TP1=" + f_px(lastTP1) + " | TP2=" + f_px(lastTP2), alert.freq_once_per_bar_close)
if shortSignal
alert("DRFX FUSION17 | SHORT | " + syminfo.ticker + " | rule-agreement=" + f_score(bearScore) + " | refEntry=" + f_px(lastEntry) + " | theoreticalStop=" + f_px(lastStop) + " | TP1=" + f_px(lastTP1) + " | TP2=" + f_px(lastTP2), alert.freq_once_per_bar_close)
// Diagnostics intentionally excluded from alertcondition except confirmed level events.
// No raw intrabar signals are advertised as closed-candle confirmations.