DrFX God Mode X - Structure and Confluence Dashboard

raptoralgo · study · 509 行 · 点赞 134 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DrFXAi — original integration, scoring framework and visualization.
// Acknowledgment: reference materials include scripts carrying "© raptoralgo" notices.
// Attribution in the publication description is required when adapting other authors' source.
//@version=6
// DrFX God Mode X - Structure and Confluence Dashboard | Version 1.0
// Indicator, not strategy: signals are conditional observations, not trade executions.
// Confluence scores (0-100) are heuristic rule-agreement scores, NOT win probabilities.
// Confirmed chart-bar signals only; higher-timeframe values use the prior closed HTF bar.
// Box-based "volume profile" is an OHLCV range-distribution approximation, not tick-level volume-at-price.
// Tick-driven HUD changes do not imply an independent animation clock or a predictive model.
indicator("DrFX God Mode X - Structure and Confluence Dashboard", shorttitle="DrFX God X", overlay=true, max_labels_count=250, max_lines_count=120, max_boxes_count=160, max_bars_back=500)
 
// ── 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(68, "Minimum confluence score", minval=45, maxval=95, group=G1)
int minEdge       = input.int(12, "Minimum score advantage", minval=0, maxval=50, 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(120, "Profile bars", minval=30, maxval=350, group=G3)
int profileBins  = input.int(24, "Profile price bins", minval=12, maxval=36, 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("Large", "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.")
// 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)
 
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)
 
// 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
    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 = math.max(high[i] - low[i], syminfo.mintick)
            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. EXPLAINABLE MULTI-ENGINE SCORE (NOT A PROBABILITY) ───────────────────
bool slowRising = emaSlow > emaSlow[3]
bool slowFalling = emaSlow < emaSlow[3]
bool flowBull = hasVol and flowProxy > 5
bool flowBear = hasVol and flowProxy < -5
bool nearBullFvg = not na(activeBullFvgTop) and not na(activeBullFvgBottom) and close > activeBullFvgBottom and close - activeBullFvgTop < atr * 2.5
bool nearBearFvg = not na(activeBearFvgBottom) and not na(activeBearFvgTop) and close < activeBearFvgTop and activeBearFvgBottom - close < atr * 2.5
float maxPoints = 34.0 + 17.0 + 15.0 + 9.0 + 8.0 + (hasVol ? 11.0 : 0.0) + (validHTF1 ? 8.0 : 0.0) + (validHTF2 ? 8.0 : 0.0)
float bullPoints = (close > emaBias ? 16.0 : 0.0) + (emaFast > emaSlow ? 12.0 : 0.0) + (vwapValid ? (close > vwapNow ? 6.0 : 0.0) : (close > emaFast ? 6.0 : 0.0)) + (marketStructure == 1 ? 17.0 : 0.0) + (rsi > 52 and macdHist > 0 ? 15.0 : rsi > 50 or macdHist > 0 ? 7.0 : 0.0) + (slowRising and adx >= 18 and efficiency >= 0.20 ? 9.0 : 0.0) + (nearBullFvg or sweepLow ? 8.0 : 0.0) + (hasVol ? (relVol >= 1.20 and flowBull ? 11.0 : relVol >= 0.9 and flowProxy >= 0 ? 6.0 : 0.0) : 0.0) + (htfBull1 ? 8.0 : 0.0) + (htfBull2 ? 8.0 : 0.0)
float bearPoints = (close < emaBias ? 16.0 : 0.0) + (emaFast < emaSlow ? 12.0 : 0.0) + (vwapValid ? (close < vwapNow ? 6.0 : 0.0) : (close < emaFast ? 6.0 : 0.0)) + (marketStructure == -1 ? 17.0 : 0.0) + (rsi < 48 and macdHist < 0 ? 15.0 : rsi < 50 or macdHist < 0 ? 7.0 : 0.0) + (slowFalling and adx >= 18 and efficiency >= 0.20 ? 9.0 : 0.0) + (nearBearFvg or sweepHigh ? 8.0 : 0.0) + (hasVol ? (relVol >= 1.20 and flowBear ? 11.0 : relVol >= 0.9 and flowProxy <= 0 ? 6.0 : 0.0) : 0.0) + (htfBear1 ? 8.0 : 0.0) + (htfBear2 ? 8.0 : 0.0)
float bullScore = maxPoints > 0 ? f_clamp(bullPoints / maxPoints * 100, 0, 100) : 0.0
float bearScore = maxPoints > 0 ? f_clamp(bearPoints / maxPoints * 100, 0, 100) : 0.0
float signedEdge = bullScore - bearScore
string bias = signedEdge >= 15 ? "BULLISH BIAS" : signedEdge <= -15 ? "BEARISH BIAS" : "NEUTRAL / CONFLICT"
color biasCol = signedEdge >= 15 ? green : signedEdge <= -15 ? red : gold
 
// Entrypoints are price-action events, not "buy on every bar" conditions.
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 longTrigger = crossUp or emaCrossUp or bullBreak or (bullFVG and close > emaSlow)
bool shortTrigger = crossDown or emaCrossDown or bearBreak or (bearFVG and close < emaSlow)
var int lastAlertBar = na
bool cooled = na(lastAlertBar) or bar_index - lastAlertBar > cooldownBars
bool enoughHistory = not na(emaBias) and not na(atr) and not na(adx) and not na(rsi) and not na(macdHist)
bool longSignal = barstate.isconfirmed and enoughHistory and cooled and longTrigger and close > emaSlow and bullScore >= minScore and signedEdge >= minEdge
bool shortSignal = barstate.isconfirmed and enoughHistory and cooled and shortTrigger and close < emaSlow and bearScore >= minScore and signedEdge <= -minEdge
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)
 
// ── 09. PANEL: LARGE VISUAL DECISION HUD ────────────────────────────────────
string sessionName = "OFF-SESSION"
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" : "OFF-SESSION"
string trendDir = emaFast > emaSlow and close > emaBias ? "BULL STACK" : emaFast < emaSlow and close < emaBias ? "BEAR STACK" : "MIXED STACK"
string rsiStatus = str.tostring(rsi, "#.0") + (rsi >= 70 ? " · HOT" : rsi <= 30 ? " · COLD" : " · MID")
string macdStatus = macdHist > 0 ? "POSITIVE" : macdHist < 0 ? "NEGATIVE" : "FLAT"
string htfStatus1 = timeframe.in_seconds(htf1) <= timeframe.in_seconds(timeframe.period) ? "INACTIVE: TF TOO LOW" : not validHTF1 ? "NO DATA" : htfBull1 ? "▲ BULL" : htfBear1 ? "▼ BEAR" : "NEUTRAL"
string htfStatus2 = timeframe.in_seconds(htf2) <= timeframe.in_seconds(timeframe.period) ? "INACTIVE: TF TOO LOW" : not validHTF2 ? "NO DATA" : htfBull2 ? "▲ BULL" : htfBear2 ? "▼ BEAR" : "NEUTRAL"
string lastTrade = lastSide == 1 ? "LAST SIGNAL: LONG" : lastSide == -1 ? "LAST SIGNAL: SHORT" : "NO SIGNAL YET"
string stopStatus = na(lastStop) ? "—" : f_px(lastStop)
string entryStatus = na(lastEntry) ? "—" : f_px(lastEntry)
string tp1Status = na(lastTP1) ? "—" : f_px(lastTP1)
string tp2Status = na(lastTP2) ? "—" : f_px(lastTP2)
string gapState = bullFVG ? "NEW BULL FVG" : bearFVG ? "NEW BEAR FVG" : array.size(bullGaps) > 0 ? "BULL GAP LIVE" : array.size(bearGaps) > 0 ? "BEAR GAP LIVE" : "NONE"
string sweepState = sweepLow ? "SELL-SIDE RAID" : sweepHigh ? "BUY-SIDE RAID" : "NO RAID"
string rvolStatus = hasVol ? str.tostring(relVol, "#.00") + "×" : "NO VOLUME"
string proxyStatus = hasVol ? str.tostring(flowProxy, "#.0") + "% PROXY" : "UNAVAILABLE"
string adrStatus = str.tostring(adx, "#.0") + " / " + str.tostring(efficiency, "#.00")
 
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, 6, 20, bgcolor=ink, frame_color=grid, frame_width=1, border_color=color.new(grid, 42), border_width=1)
if barstate.isfirst
    table.merge_cells(hud, 0, 0, 5, 0)
    table.merge_cells(hud, 0, 1, 5, 1)
    table.merge_cells(hud, 0, 2, 5, 2)
    table.merge_cells(hud, 0, 3, 2, 3)
    table.merge_cells(hud, 3, 3, 5, 3)
    table.merge_cells(hud, 0, 4, 5, 4)
    table.merge_cells(hud, 0, 6, 2, 6)
    table.merge_cells(hud, 3, 6, 5, 6)
    table.merge_cells(hud, 0, 7, 5, 7)
    for r = 8 to 11
        table.merge_cells(hud, 1, r, 2, r)
        table.merge_cells(hud, 4, r, 5, r)
    table.merge_cells(hud, 0, 12, 5, 12)
    for r = 13 to 14
        table.merge_cells(hud, 1, r, 2, r)
        table.merge_cells(hud, 4, r, 5, r)
    table.merge_cells(hud, 0, 15, 5, 15)
    for r = 16 to 17
        table.merge_cells(hud, 1, r, 2, r)
        table.merge_cells(hud, 4, r, 5, r)
    table.merge_cells(hud, 0, 18, 5, 18)
    table.merge_cells(hud, 0, 19, 5, 19)
 
if showHUD and barstate.islast
    bool flashing = pulseHUD and barstate.isrealtime and int(timenow / 900) % 2 == 0
    color pulse = flashing ? cyan : violet
    color statusColor = biasCol
    string dot = flashing ? "◉" : "●"
    f_cell(hud, 0, 0, "DrFX  /  GOD MODE X  /  STRUCTURE + CONFLUENCE  " + dot, pulse, panel2, true)
    f_cell(hud, 0, 1, syminfo.ticker + "   ·   " + timeframe.period + "   ·   " + sessionName + "   ·   " + (barstate.isrealtime ? "CURRENT BAR" : "HISTORICAL"), mute, ink)
    f_cell(hud, 0, 2, "MARKET CONDITION / HEURISTIC REGIME", cyan, panel2, true)
    f_cell(hud, 0, 3, "REGIME    " + regime, trending ? green : choppy ? gold : cyan, panel, true)
    f_cell(hud, 3, 3, "VOLATILITY    " + volState + "  " + f_pct(volatilityPct), volState == "EXPANSION" ? red : cyan, panel, true)
    f_cell(hud, 0, 4, "DIRECTIONAL CONFLUENCE - RULE SCORES / NOT PROBABILITIES", cyan, panel2, true)
    f_cell(hud, 0, 5, "LONG", green, panel, true)
    f_cell(hud, 1, 5, f_meter(bullScore), green, panel, true)
    f_cell(hud, 2, 5, f_score(bullScore), f_stateColor(bullScore), panel2, true)
    f_cell(hud, 3, 5, "SHORT", red, panel, true)
    f_cell(hud, 4, 5, f_meter(bearScore), red, panel, true)
    f_cell(hud, 5, 5, f_score(bearScore), f_stateColor(bearScore), panel2, true)
    f_cell(hud, 0, 6, "BIAS: " + bias, statusColor, panel, true)
    f_cell(hud, 3, 6, "SCORE EDGE    " + str.tostring(signedEdge, "#.0"), statusColor, panel, true)
    f_cell(hud, 0, 7, "MARKET STRUCTURE AND MOMENTUM", cyan, panel2, true)
    f_pair(hud, 8, "TREND", trendDir, "STRUCTURE", structureName, trendDir == "BULL STACK" ? green : trendDir == "BEAR STACK" ? red : gold, marketStructure == 1 ? green : marketStructure == -1 ? red : gold)
    f_pair(hud, 9, "ADX / ER", adrStatus, "VOL / RSI", rsiStatus, adx >= 23 ? green : gold, rsi >= 50 ? green : red)
    f_pair(hud, 10, "MACD", macdStatus, "REL VOL", rvolStatus, macdHist >= 0 ? green : red, hasVol and relVol >= 1.2 ? green : mute)
    f_pair(hud, 11, "FLOW EST*", proxyStatus, "LIQUIDITY", sweepState, na(flowProxy) ? mute : flowProxy >= 0 ? green : red, sweepLow ? green : sweepHigh ? red : mute)
    f_cell(hud, 0, 12, "HIGHER TIMEFRAMES / PREVIOUSLY CLOSED BARS", cyan, panel2, true)
    f_pair(hud, 13, "HTF " + htf1, htfStatus1, "HTF " + htf2, htfStatus2, htfBull1 ? green : htfBear1 ? red : gold, htfBull2 ? green : htfBear2 ? red : gold)
    f_pair(hud, 14, "FVG", gapState, "EST POC*", f_px(vpPOC), bullFVG ? green : bearFVG ? red : cyan, gold)
    f_cell(hud, 0, 15, "ILLUSTRATIVE ATR-BASED RISK LEVELS - NOT ORDERS", cyan, panel2, true)
    f_pair(hud, 16, "REF ENTRY", entryStatus, "EST STOP", stopStatus, white, red)
    f_pair(hud, 17, "EST TP1  " + str.tostring(rr1, "#.##") + "R", tp1Status, "EST TP2  " + str.tostring(rr2, "#.##") + "R", tp2Status, green, cyan)
    f_cell(hud, 0, 18, (longSignal ? "▲ NEW LONG  " + f_score(bullScore) : shortSignal ? "▼ NEW SHORT  " + f_score(bearScore) : lastTrade) + "   ·   CONFIRMED BAR-CLOSE EVENT", longSignal ? green : shortSignal ? red : gold, panel2, true)
    f_cell(hud, 0, 19, "* VOLUME / FLOW / POC ARE OHLCV ESTIMATES - NOT ORDER FLOW", mute, ink)
if not showHUD and barstate.islast
    table.clear(hud, 0, 0, 5, 19)
 
// ── 10. ALERTS: CONFIRMED SIGNALS ONLY ──────────────────────────────────────
alertcondition(longSignal, title="DrFX GOD MODE X • LONG", message="DrFX GOD MODE X confirmed LONG | {{ticker}} {{interval}} | close={{close}}")
alertcondition(shortSignal, title="DrFX GOD MODE X • SHORT", message="DrFX GOD MODE X confirmed SHORT | {{ticker}} {{interval}} | close={{close}}")
alertcondition(longSignal or shortSignal, title="DrFX GOD MODE X • ANY", message="DrFX GOD MODE X new confirmed directional signal | {{ticker}} {{interval}} | close={{close}}")
if longSignal
    alert("DrFX GOD X | LONG | " + syminfo.ticker + " | score=" + f_score(bullScore) + " | refEntry=" + f_px(lastEntry) + " | estStop=" + f_px(lastStop) + " | estTP1=" + f_px(lastTP1) + " | estTP2=" + f_px(lastTP2), alert.freq_once_per_bar_close)
if shortSignal
    alert("DrFX GOD X | SHORT | " + syminfo.ticker + " | score=" + f_score(bearScore) + " | refEntry=" + f_px(lastEntry) + " | estStop=" + f_px(lastStop) + " | estTP1=" + f_px(lastTP1) + " | estTP2=" + f_px(lastTP2), alert.freq_once_per_bar_close)

← 返回列表