[ A L P H A X ] Volatility Pressure System

AlphaX-Trade · study · 815 行 · 点赞 394 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlphaX
 
//@version=6
indicator("[ A L P H A X ] Volatility Pressure System", shorttitle="AlphaX VPS",
  overlay=true,
  max_lines_count=500,
  max_labels_count=500,
  max_boxes_count=500,
  max_polylines_count=100)
 
// ═══════════════════════════════════════════════════════════════════════════════
// ████████████████  AlphaX Volatility Pressure System  ████████████████████████
// ═══════════════════════════════════════════════════════════════════════════════
//
//  Optimized for XAUUSD / Gold 1-Minute Chart
//
//  Architecture:
//  ① Bollinger Bands (BB) — volatility envelope (tuned for gold noise)
//  ② Keltner Channels (KC) — ATR-based volatility wrapper
//  ③ BB/KC Squeeze — detects compression before explosive moves
//  ④ Linear Regression Forecast — projects BB trajectory forward
//  ⑤ Multi-Confluence Scoring — strict filter to eliminate noise signals
//  ⑥ Volatility Regime Engine — Expansion / Compression / Trend
//  ⑦ Momentum + Volume + Structure Filters — suppresses false touches
//  ⑧ AlphaX Dashboard + Alerts
//
// ═══════════════════════════════════════════════════════════════════════════════
 
 
// ─────────────────────────────────────────────────────────────────────────────
//  INPUTS
// ─────────────────────────────────────────────────────────────────────────────
 
grpBB   = "📊  Bollinger Bands"
bbLen   = input.int(30,   "BB Length",        minval=5,  maxval=200, group=grpBB, tooltip="Gold 1m: 30 smooths out micro noise better than 20")
bbMult  = input.float(2.2,"BB Multiplier",    minval=0.5,maxval=5.0, step=0.1,  group=grpBB, tooltip="Gold 1m: 2.2 reduces false band touches from gold volatility")
bbSrc   = input.source(close, "Source",                              group=grpBB)
showBB  = input.bool(true, "Show BB Cloud",                          group=grpBB)
 
grpKC   = "🔷  Keltner Channel"
kcLen   = input.int(30,   "KC Length",        minval=5,  maxval=200, group=grpKC, tooltip="Gold 1m: matched to BB length for proper squeeze detection")
kcMult  = input.float(1.8,"KC ATR Multiplier",minval=0.5,maxval=5.0, step=0.1,  group=grpKC, tooltip="Gold 1m: 1.8 tighter than default to catch gold squeezes")
kcAtrLen= input.int(20,   "KC ATR Length",    minval=5,  maxval=50,  group=grpKC, tooltip="Gold 1m: 20 for better ATR smoothing on noisy gold ticks")
showKC  = input.bool(true, "Show KC Lines",                          group=grpKC)
 
grpSQ   = "⚡  Squeeze"
showSQ  = input.bool(true,  "Show Squeeze Dots",                     group=grpSQ)
sqAlert = input.bool(true,  "Alert on Squeeze Release",              group=grpSQ)
 
grpFC   = "🔭  Forecast"
showFC  = input.bool(true,  "Show Regression Forecast",              group=grpFC)
fcBars  = input.int(20,    "Forecast Bars",   minval=5,  maxval=100, group=grpFC, tooltip="Gold 1m: 20 bars = 20 minutes lookahead, practical for scalping")
 
grpSIG  = "🎯  Signals"
showSig = input.bool(true,  "Show Band Touch Signals",               group=grpSIG)
minConf = input.int(30,    "Min Confidence %",minval=10, maxval=90,  group=grpSIG, tooltip="Gold 1m: 60% minimum filters out most noise signals")
cooldown= input.int(4,    "Signal Cooldown", minval=1,  maxval=60,  group=grpSIG, tooltip="Gold 1m: 15 bars = 15 minutes between signals")
showExit= input.bool(true,  "Show Mean Reversion Exits",             group=grpSIG)
 
grpRSI  = "📈  RSI Filter"
rsiLen  = input.int(14,   "RSI Length",       minval=5,  maxval=30,  group=grpRSI)
rsiOS   = input.float(30, "RSI Oversold",     minval=10, maxval=50,  group=grpRSI, tooltip="Gold 1m: 30 stricter than 35 to filter noise")
rsiOB   = input.float(70, "RSI Overbought",   minval=50, maxval=90,  group=grpRSI, tooltip="Gold 1m: 70 stricter than 65 to filter noise")
 
grpEMA  = "📐  EMA Trend Filter"
showEMA = input.bool(true,  "Show Trend EMA",                        group=grpEMA)
emaLen  = input.int(100,   "EMA Length",       minval=10, maxval=500, group=grpEMA, tooltip="Gold 1m: 100 EMA = ~1.5 hours of trend context")
 
grpVOL  = "📊  Volume Filter"
useVol  = input.bool(true,  "Use Volume Confirmation",               group=grpVOL, tooltip="Requires above-average volume for signal confirmation")
volMult = input.float(1.2,  "Volume Threshold Multiplier", minval=0.5, maxval=3.0, step=0.1, group=grpVOL)
volLen  = input.int(20,     "Volume MA Length", minval=5, maxval=100, group=grpVOL)
 
grpSTR  = "🏗️  Structure Filter"
useSwing = input.bool(true, "Use Swing Structure Filter",            group=grpSTR, tooltip="Requires price to form a swing low/high near bands")
swingLB  = input.int(3,     "Swing Lookback",  minval=1, maxval=10,  group=grpSTR)
 
grpCol  = "🎨  Colors"
color cBullP = input.color(#c8e624, "Bull Primary",        group=grpCol)
color cBearP = input.color(#ff1744, "Bear Primary",        group=grpCol)
color cPOC   = input.color(#ff9800, "Basis / Neutral",     group=grpCol)
color cSqOn  = input.color(#ff1744, "Squeeze ON",          group=grpCol)
color cSqOff = input.color(#c8e624, "Squeeze OFF",         group=grpCol)
color cSqNeu = input.color(#555555, "Squeeze Neutral",     group=grpCol)
color cFc    = input.color(#c8e624, "Forecast Bull",       group=grpCol)
color cFcBr  = input.color(#ff1744, "Forecast Bear",       group=grpCol)
color cDashBg= input.color(#1a1a1a, "Dashboard BG",        group=grpCol)
color cTxtL  = input.color(#cccccc, "Dashboard Text",      group=grpCol)
color cNeut  = input.color(#555555, "Neutral",             group=grpCol)
 
grpDash = "📋  Dashboard"
showDash= input.bool(true,  "Show Dashboard",                        group=grpDash)
dashPos = input.string("Top Right","Position",
  options=["Top Left","Top Right","Bottom Left","Bottom Right"],      group=grpDash)
dszInp  = input.string("Small","Text Size",
  options=["Tiny","Small","Normal"],                                  group=grpDash)
 
// ─────────────────────────────────────────────────────────────────────────────
//  HELPERS
// ─────────────────────────────────────────────────────────────────────────────
 
f_pos(p) =>
    switch p
        "Top Left"     => position.top_left
        "Top Right"    => position.top_right
        "Bottom Left"  => position.bottom_left
        "Bottom Right" => position.bottom_right
 
f_sz(s) =>
    switch s
        "Tiny"   => size.tiny
        "Small"  => size.small
        "Normal" => size.normal
 
dsz = f_sz(dszInp)
 
// ─────────────────────────────────────────────────────────────────────────────
//  ① BOLLINGER BANDS
// ─────────────────────────────────────────────────────────────────────────────
 
bbBasis = ta.sma(bbSrc, bbLen)
bbDev   = bbMult * ta.stdev(bbSrc, bbLen)
bbUpper = bbBasis + bbDev
bbLower = bbBasis - bbDev
bbWidth = (bbUpper - bbLower) / bbBasis * 100   // bandwidth %
bbPct   = (bbSrc - bbLower) / (bbUpper - bbLower) // %B: 0=lower, 1=upper
 
// ─────────────────────────────────────────────────────────────────────────────
//  ② KELTNER CHANNEL
// ─────────────────────────────────────────────────────────────────────────────
 
kcBasis = ta.ema(bbSrc, kcLen)
kcAtr   = ta.atr(kcAtrLen)
kcUpper = kcBasis + kcMult * kcAtr
kcLower = kcBasis - kcMult * kcAtr
 
// ─────────────────────────────────────────────────────────────────────────────
//  ③ SQUEEZE ENGINE
// ─────────────────────────────────────────────────────────────────────────────
 
sqOn  = bbUpper < kcUpper and bbLower > kcLower
sqWasOn = sqOn[1]
sqRelease = sqWasOn and not sqOn
 
sqMom     = ta.linreg(bbSrc - math.avg(math.avg(ta.highest(bbLen), ta.lowest(bbLen)), bbBasis), bbLen, 0)
sqMomPrev = sqMom[1]
sqBull    = sqMom > 0 and sqMom > sqMomPrev
sqBear    = sqMom < 0 and sqMom < sqMomPrev
 
sqBarsOn  = 0
for i = 0 to 19
    if sqOn[i]
        sqBarsOn += 1
 
// ─────────────────────────────────────────────────────────────────────────────
//  ④ LINEAR REGRESSION FORECAST
// ─────────────────────────────────────────────────────────────────────────────
 
basisSlope = ta.linreg(bbBasis, bbLen, 0) - ta.linreg(bbBasis, bbLen, 1)
devSlope   = ta.linreg(bbDev, bbLen, 0)   - ta.linreg(bbDev, bbLen, 1)
minBandW   = ta.lowest(bbUpper - bbLower, 50)
 
type drw
    polyline lU
    polyline lB
    polyline lL
    polyline lF
    label    lbU
    label    lbL
 
var pls = array.new<drw>()
 
if barstate.islast
    if pls.size() > 0
        for p in pls
            p.lU.delete()
            p.lB.delete()
            p.lL.delete()
            p.lF.delete()
            p.lbU.delete()
            p.lbL.delete()
        pls.clear()
 
    if showFC
        aU = array.new<chart.point>()
        aB = array.new<chart.point>()
        aL = array.new<chart.point>()
        aF = array.new<chart.point>()
 
        fcFinalBasis = 0.0
 
        for i = 0 to fcBars
            w    = i / fcBars
            bF   = bbBasis + basisSlope * i
            dF   = math.max(bbDev + devSlope * i, minBandW / 2)
            uF   = bF + dF
            lF_  = bF - dF
 
            uSm  = bbUpper * (1 - w) + uF * w
            lSm  = bbLower * (1 - w) + lF_ * w
            bSm  = bbBasis * (1 - w) + bF  * w
 
            aU.push(chart.point.from_index(bar_index + i, uSm))
            aB.push(chart.point.from_index(bar_index + i, bSm))
            aL.push(chart.point.from_index(bar_index + i, lSm))
            aF.push(chart.point.from_index(bar_index + i, uSm))
 
            if i == fcBars
                fcFinalBasis := bSm
                for k = fcBars to 0
                    w_   = k / fcBars
                    bF_  = bbBasis + basisSlope * k
                    dF_  = math.max(bbDev + devSlope * k, minBandW / 2)
                    lSm_ = bbLower * (1 - w_) + (bF_ - dF_) * w_
                    aF.push(chart.point.from_index(bar_index + k, lSm_))
 
        fcBull = bbBasis < fcFinalBasis
        fcCol  = fcBull ? cFc : cFcBr
        fcFill = fcBull ? color.new(cFc, 88) : color.new(cFcBr, 88)
 
        lU_  = polyline.new(aU, line_color=color.new(fcCol, 40), line_width=1)
        lB_  = polyline.new(aB, line_color=color.new(fcCol, 0),  line_width=2)
        lL_  = polyline.new(aL, line_color=color.new(fcCol, 40), line_width=1)
        lF_  = polyline.new(aF, closed=true, line_color=color.new(color.black, 100), fill_color=fcFill)
 
        lbU_ = label.new(aU.last(), text=str.tostring(aU.last().price, format.mintick),
          style=label.style_label_left, color=color.new(color.black, 100),
          textcolor=fcCol, size=size.small)
        lbL_ = label.new(aL.last(), text=str.tostring(aL.last().price, format.mintick),
          style=label.style_label_left, color=color.new(color.black, 100),
          textcolor=fcCol, size=size.small)
 
        pls.push(drw.new(lU_, lB_, lL_, lF_, lbU_, lbL_))
 
// ─────────────────────────────────────────────────────────────────────────────
//  ⑤ RSI
// ─────────────────────────────────────────────────────────────────────────────
 
rsiVal = ta.rsi(bbSrc, rsiLen)
 
// ─────────────────────────────────────────────────────────────────────────────
//  ⑥ EMA TREND FILTER
// ─────────────────────────────────────────────────────────────────────────────
 
emaVal     = ta.ema(bbSrc, emaLen)
emaTrend   = bbSrc > emaVal
emaSlopeUp = emaVal > emaVal[3]
 
// ─────────────────────────────────────────────────────────────────────────────
//  ⑦ VOLUME FILTER
// ─────────────────────────────────────────────────────────────────────────────
 
volMA     = ta.sma(volume, volLen)
volSpike  = volume > volMA * volMult
volOK     = not useVol or volSpike
 
// ─────────────────────────────────────────────────────────────────────────────
//  ⑧ SWING STRUCTURE FILTER
// ─────────────────────────────────────────────────────────────────────────────
 
// Swing low: current low is lowest of lookback window
isSwingLow  = low == ta.lowest(low, swingLB * 2 + 1) and low == ta.lowest(low, swingLB + 1)
isSwingHigh = high == ta.highest(high, swingLB * 2 + 1) and high == ta.highest(high, swingLB + 1)
 
// Check for recent swing within last few bars (signal can lag swing by a couple bars)
recentSwingLow  = isSwingLow  or isSwingLow[1]  or isSwingLow[2]
recentSwingHigh = isSwingHigh or isSwingHigh[1] or isSwingHigh[2]
 
swingBullOK = not useSwing or recentSwingLow
swingBearOK = not useSwing or recentSwingHigh
 
// ─────────────────────────────────────────────────────────────────────────────
//  ⑨ VOLATILITY REGIME
// ─────────────────────────────────────────────────────────────────────────────
 
bbWMA     = ta.sma(bbWidth, 20)
isExpanding   = bbWidth > bbWidth[1] and bbWidth > bbWMA
isContracting = bbWidth < bbWidth[1] and bbWidth < bbWMA
isTrending    = math.abs(basisSlope) > kcAtr * 0.01
 
regimeText = sqOn          ? "SQUEEZE 🔴" :
  sqRelease                ? "RELEASE ⚡" :
  isExpanding and isTrending ? "EXPANSION 📈" :
  isContracting            ? "COMPRESSION" : "RANGING"
 
// ─────────────────────────────────────────────────────────────────────────────
//  ⑩ CONFLUENCE SCORING ENGINE (Rebuilt for Gold 1m)
// ─────────────────────────────────────────────────────────────────────────────
 
// Additional confirmation: candle rejection (wick ratio)
bodySize    = math.abs(close - open)
upperWick   = high - math.max(close, open)
lowerWick   = math.min(close, open) - low
totalRange  = high - low
bullRejection = totalRange > 0 ? lowerWick / totalRange > 0.5 : false   // long lower wick = rejection at lows
bearRejection = totalRange > 0 ? upperWick / totalRange > 0.5 : false   // long upper wick = rejection at highs
 
// MACD for momentum confirmation
[macdLine, sigLine, histLine] = ta.macd(close, 12, 26, 9)
macdBullish = macdLine > sigLine or (histLine > histLine[1] and histLine[1] > histLine[2])
macdBearish = macdLine < sigLine or (histLine < histLine[1] and histLine[1] < histLine[2])
 
// Multi-timeframe trend: use longer SMA as structure reference
sma200 = ta.sma(close, 200)
above200 = close > sma200
below200 = close < sma200
 
calcBullScore() =>
    float s = 0.0
    
    // ── Band Touch Quality (max 20) ──
    // Must actually pierce or kiss the lower band
    touchDepth = bbLower - low
    touchPct   = bbBasis != 0 ? touchDepth / (bbUpper - bbLower) * 100 : 0.0
    s += touchDepth > 0 and touchPct > 5 ? 20.0 : touchDepth > 0 ? 15.0 : low <= bbLower * 1.001 ? 10.0 : 0.0
    
    // ── %B Position (max 10) ──
    s += bbPct < 0.0 ? 10.0 : bbPct < 0.05 ? 8.0 : bbPct < 0.15 ? 5.0 : 0.0
    
    // ── RSI Oversold (max 15) ──
    s += rsiVal < 20  ? 15.0 : rsiVal < 25 ? 12.0 : rsiVal < rsiOS ? 10.0 : rsiVal < 40 ? 3.0 : 0.0
    
    // ── EMA Trend Alignment (max 10) ──
    s += emaTrend and emaSlopeUp ? 10.0 : emaTrend ? 5.0 : 0.0
    
    // ── Squeeze Release Confluence (max 10) ──
    s += sqRelease and sqBull ? 10.0 : sqBull and not sqOn ? 5.0 : 0.0
    
    // ── Candle Rejection / Reversal Pattern (max 10) ──
    s += bullRejection and close > open ? 10.0 : bullRejection ? 7.0 : close > open ? 3.0 : 0.0
    
    // ── Volume Confirmation (max 10) ──
    s += volSpike and close > open ? 10.0 : volSpike ? 5.0 : 0.0
    
    // ── MACD Momentum (max 8) ──
    s += macdBullish ? 8.0 : 0.0
    
    // ── Structure: 200 SMA (max 7) ──
    s += above200 ? 7.0 : 0.0
    
    // ── Penalties (stricter for gold 1m) ──
    s -= not emaTrend ? 15.0 : 0.0           // trading against trend = heavy penalty
    s -= rsiVal > 55  ? 12.0 : 0.0           // RSI not supportive
    s -= sqOn         ? 8.0  : 0.0           // still in squeeze = wait
    s -= isExpanding and not isTrending ? 5.0 : 0.0  // expanding but no direction
    s -= not volSpike and useVol ? 5.0 : 0.0  // no volume support
    s -= bearRejection ? 10.0 : 0.0          // wrong candle structure
    
    math.max(0.0, math.min(100.0, s))
 
calcBearScore() =>
    float s = 0.0
    
    // ── Band Touch Quality (max 20) ──
    touchDepth = high - bbUpper
    touchPct   = bbBasis != 0 ? touchDepth / (bbUpper - bbLower) * 100 : 0.0
    s += touchDepth > 0 and touchPct > 5 ? 20.0 : touchDepth > 0 ? 15.0 : high >= bbUpper * 0.999 ? 10.0 : 0.0
    
    // ── %B Position (max 10) ──
    s += bbPct > 1.0  ? 10.0 : bbPct > 0.95 ? 8.0 : bbPct > 0.85 ? 5.0 : 0.0
    
    // ── RSI Overbought (max 15) ──
    s += rsiVal > 80  ? 15.0 : rsiVal > 75 ? 12.0 : rsiVal > rsiOB ? 10.0 : rsiVal > 60 ? 3.0 : 0.0
    
    // ── EMA Trend Alignment (max 10) ──
    s += not emaTrend and not emaSlopeUp ? 10.0 : not emaTrend ? 5.0 : 0.0
    
    // ── Squeeze Release Confluence (max 10) ──
    s += sqRelease and sqBear ? 10.0 : sqBear and not sqOn ? 5.0 : 0.0
    
    // ── Candle Rejection / Reversal Pattern (max 10) ──
    s += bearRejection and close < open ? 10.0 : bearRejection ? 7.0 : close < open ? 3.0 : 0.0
    
    // ── Volume Confirmation (max 10) ──
    s += volSpike and close < open ? 10.0 : volSpike ? 5.0 : 0.0
    
    // ── MACD Momentum (max 8) ──
    s += macdBearish ? 8.0 : 0.0
    
    // ── Structure: 200 SMA (max 7) ──
    s += below200 ? 7.0 : 0.0
    
    // ── Penalties (stricter for gold 1m) ──
    s -= emaTrend  ? 15.0 : 0.0
    s -= rsiVal < 45 ? 12.0 : 0.0
    s -= sqOn ? 8.0 : 0.0
    s -= isExpanding and not isTrending ? 5.0 : 0.0
    s -= not volSpike and useVol ? 5.0 : 0.0
    s -= bullRejection ? 10.0 : 0.0
    
    math.max(0.0, math.min(100.0, s))
 
bullScore = calcBullScore()
bearScore = calcBearScore()
 
bullTier = bullScore >= 80 ? "S" : bullScore >= 70 ? "A" : bullScore >= 60 ? "B" : "C"
bearTier = bearScore >= 80 ? "S" : bearScore >= 70 ? "A" : bearScore >= 60 ? "B" : "C"
 
// ─────────────────────────────────────────────────────────────────────────────
//  SIGNAL GENERATION (Rebuilt — much stricter for gold 1m)
// ─────────────────────────────────────────────────────────────────────────────
 
var int lastBullBar = -999
var int lastBearBar = -999
 
bullOK  = bar_index - lastBullBar >= cooldown
bearOK  = bar_index - lastBearBar >= cooldown
 
// ── Core conditions ──
// Band touch: price must actually reach or pierce the band
bullBandTouch = low <= bbLower * 1.001
bearBandTouch = high >= bbUpper * 0.999
 
// Confirmation candle: we want to see rejection, not continuation through band
bullCandleOK = close > open or bullRejection                // bullish candle or rejection wick
bearCandleOK = close < open or bearRejection                // bearish candle or rejection wick
 
// RSI must be in supportive zone (not neutral)
bullRSI_OK = rsiVal < 45      // at least leaning oversold
bearRSI_OK = rsiVal > 55      // at least leaning overbought
 
// ── Final Signal (all gates must pass) ──
bullSig = barstate.isconfirmed and
  bullBandTouch and
  bullScore >= minConf and
  bullOK and
  bullCandleOK and
  bullRSI_OK and
  volOK and
  swingBullOK and
  not sqOn                     // never signal during active squeeze
 
bearSig = barstate.isconfirmed and
  bearBandTouch and
  bearScore >= minConf and
  bearOK and
  bearCandleOK and
  bearRSI_OK and
  volOK and
  swingBearOK and
  not sqOn
 
if bullSig
    lastBullBar := bar_index
if bearSig
    lastBearBar := bar_index
 
// Mean reversion exit
var int activeDir = 0
if bullSig
    activeDir := 1
if bearSig
    activeDir := -1
 
bullExit = activeDir == 1 and barstate.isconfirmed and close >= bbBasis and close[1] < bbBasis[1]
bearExit = activeDir == -1 and barstate.isconfirmed and close <= bbBasis and close[1] > bbBasis[1]
 
if bullExit and activeDir == 1
    activeDir := 0
if bearExit and activeDir == -1
    activeDir := 0
 
// ─────────────────────────────────────────────────────────────────────────────
//  PLOT — BOLLINGER BANDS CLOUD
// ─────────────────────────────────────────────────────────────────────────────
 
basisColor = bbSrc > bbBasis ? cBullP : cBearP
 
bbUpperPlot = plot(bbUpper, "BB Upper", color=color.new(cBullP, 70), linewidth=1)
bbLowerPlot = plot(bbLower, "BB Lower", color=color.new(cBearP, 70), linewidth=1)
 
fill(bbUpperPlot, bbLowerPlot,
  color=bbSrc > bbBasis ? color.new(cBullP, 92) : color.new(cBearP, 92),
  title="BB Cloud")
 
plot(bbBasis, "BB Basis", color=basisColor, linewidth=2, style=plot.style_line)
 
// ─────────────────────────────────────────────────────────────────────────────
//  PLOT — KELTNER CHANNEL
// ─────────────────────────────────────────────────────────────────────────────
 
plot(showKC ? kcUpper : na, "KC Upper",
  color=color.new(cPOC, 60), linewidth=1, style=plot.style_circles)
plot(showKC ? kcLower : na, "KC Lower",
  color=color.new(cPOC, 60), linewidth=1, style=plot.style_circles)
 
// ─────────────────────────────────────────────────────────────────────────────
//  PLOT — EMA
// ─────────────────────────────────────────────────────────────────────────────
 
plot(showEMA ? emaVal : na, "Trend EMA",
  color=bbSrc > emaVal ? color.new(cBullP, 50) : color.new(cBearP, 50),
  linewidth=2, style=plot.style_line)
 
// ─────────────────────────────────────────────────────────────────────────────
//  PLOT — SQUEEZE DOTS
// ─────────────────────────────────────────────────────────────────────────────
 
sqColor = sqOn ? cSqOn : sqRelease ? cSqOff : color.new(cSqNeu, 40)
plot(showSQ ? bbBasis : na, "Squeeze Dot",
  color=sqColor, linewidth=3, style=plot.style_circles)
 
// ─────────────────────────────────────────────────────────────────────────────
//  PLOT — ENTRY SIGNALS (Clean, minimal labels)
// ─────────────────────────────────────────────────────────────────────────────
 
if showSig and bullSig
    tierTxt = bullTier
    confTxt = str.tostring(bullScore, "#")
    txt     = "⬆ " + tierTxt + " [" + confTxt + "%]"
    bgC     = bullScore >= 80 ? color.new(cBullP, 0) :
              bullScore >= 70 ? color.new(cBullP, 10) : color.new(cBullP, 20)
    label.new(bar_index, low,
      text=txt, yloc=yloc.belowbar,
      color=bgC, textcolor=#1a1a1a, size=size.small,
      style=label.style_label_up)
 
if showSig and bearSig
    tierTxt = bearTier
    confTxt = str.tostring(bearScore, "#")
    txt     = "⬇ " + tierTxt + " [" + confTxt + "%]"
    bgC     = bearScore >= 80 ? color.new(cBearP, 0) :
              bearScore >= 70 ? color.new(cBearP, 10) : color.new(cBearP, 20)
    label.new(bar_index, high,
      text=txt, yloc=yloc.abovebar,
      color=bgC, textcolor=#ffffff, size=size.small,
      style=label.style_label_down)
 
// ─────────────────────────────────────────────────────────────────────────────
//  PLOT — EXIT MARKERS
// ─────────────────────────────────────────────────────────────────────────────
 
if showExit and bullExit
    label.new(bar_index, high,
      text="✕", yloc=yloc.abovebar,
      color=color.new(color.black, 100), textcolor=color.new(cPOC, 0),
      size=size.tiny, style=label.style_none)
 
if showExit and bearExit
    label.new(bar_index, low,
      text="✕", yloc=yloc.belowbar,
      color=color.new(color.black, 100), textcolor=color.new(cPOC, 0),
      size=size.tiny, style=label.style_none)
 
// ─────────────────────────────────────────────────────────────────────────────
//  PLOT — SQUEEZE RELEASE FLASH MARKER
// ─────────────────────────────────────────────────────────────────────────────
 
if sqRelease
    sqDir = sqBull ? "⚡ SQ↑" : sqBear ? "⚡ SQ↓" : "⚡ SQ"
    sqC   = sqBull ? color.new(cBullP, 0) : color.new(cBearP, 0)
    label.new(bar_index, bbBasis,
      text=sqDir,
      color=color.new(#1a1a1a, 0),
      textcolor=sqC,
      size=size.tiny,
      style=label.style_none)
 
// ─────────────────────────────────────────────────────────────────────────────
//  NO BARCOLOR — turned off by default (clean chart)
// ─────────────────────────────────────────────────────────────────────────────
 
// Candle coloring intentionally removed for clean chart appearance
 
// ─────────────────────────────────────────────────────────────────────────────
//  DASHBOARD
// ─────────────────────────────────────────────────────────────────────────────
 
pctBText = str.tostring(bbPct * 100, "#.#") + "%"
pctBClr  = bbPct > 0.9 ? cBearP : bbPct < 0.1 ? cBullP :
  bbPct > 0.6 ? color.new(cBearP, 40) : bbPct < 0.4 ? color.new(cBullP, 40) : cTxtL
 
bwText = str.tostring(bbWidth, "#.##") + "%"
bwSMA  = ta.sma(bbWidth, 50)
bwClr  = bbWidth > bwSMA * 1.3 ? cBearP :
  bbWidth < bwSMA * 0.7 ? cBullP : cTxtL
 
rsiZone = rsiVal > 70 ? "OB" : rsiVal < 30 ? "OS" : rsiVal > 60 ? "HIGH" : rsiVal < 40 ? "LOW" : "MID"
rsiClr  = rsiVal > 70 ? cBearP : rsiVal < 30 ? cBullP :
  rsiVal > 60 ? color.new(cBearP, 40) : rsiVal < 40 ? color.new(cBullP, 40) : cTxtL
 
emaText = emaTrend ? (emaSlopeUp ? "▲ BULL" : "▲ RISING") : (not emaSlopeUp ? "▼ BEAR" : "▼ FALLING")
emaClr  = emaTrend ? cBullP : cBearP
 
kcText  = sqOn ? "BB INSIDE KC" : bbUpper > kcUpper ? "BB ABOVE KC" : "BB NEAR KC"
kcClr   = sqOn ? cSqOn : cTxtL
 
posText = activeDir == 1 ? "▲ LONG" : activeDir == -1 ? "▼ SHORT" : "— FLAT"
posClr  = activeDir == 1 ? cBullP : activeDir == -1 ? cBearP : cNeut
posBg   = activeDir == 1 ? color.new(cBullP, 88) : activeDir == -1 ? color.new(cBearP, 88) : color.new(cDashBg, 0)
 
color secBg = color.new(#222222, 0)
 
var table dash = na
if showDash
    dash := table.new(f_pos(dashPos), 2, 24,
      bgcolor=color.new(cDashBg, 0),
      border_width=1,
      border_color=color.new(cNeut, 70),
      frame_width=2,
      frame_color=color.new(cBullP, 60))
 
if showDash and barstate.islast
 
    // Header
    table.cell(dash, 0, 0, "AlphaX  V O L A T I L I T Y",
      text_color=cBullP, text_size=dsz,
      bgcolor=color.new(#111111, 0), text_halign=text.align_center)
    table.cell(dash, 1, 0, "PRESSURE",
      text_color=color.new(#9ab81c, 0), text_size=size.tiny,
      bgcolor=color.new(#111111, 0), text_halign=text.align_center)
 
    // ── Section: Volatility ───────────────────────────────────────────────────
    table.cell(dash, 0, 1, "─── VOLATILITY ───",
      text_color=color.new(cNeut, 20), text_size=size.tiny,
      bgcolor=secBg, text_halign=text.align_center)
    table.cell(dash, 1, 1, "", bgcolor=secBg)
 
    regClr = sqOn ? cSqOn : sqRelease ? cSqOff : isExpanding ? cBullP : cTxtL
    regBg  = sqOn ? color.new(cSqOn, 88) : sqRelease ? color.new(cSqOff, 88) : color.new(cDashBg, 0)
    table.cell(dash, 0, 2, "REGIME",
      text_color=cTxtL, text_size=dsz, bgcolor=regBg)
    table.cell(dash, 1, 2, regimeText,
      text_color=regClr, text_size=dsz, bgcolor=regBg)
 
    table.cell(dash, 0, 3, "BANDWIDTH",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 3, bwText,
      text_color=bwClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    table.cell(dash, 0, 4, "BB %B",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 4, pctBText,
      text_color=pctBClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    sqBarsText = str.tostring(sqBarsOn) + " / 20 bars"
    sqBarsClr  = sqBarsOn > 12 ? cSqOn : sqBarsOn > 6 ? cPOC : cTxtL
    table.cell(dash, 0, 5, "SQUEEZE BARS",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 5, sqBarsText,
      text_color=sqBarsClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    table.cell(dash, 0, 6, "KC RELATION",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 6, kcText,
      text_color=kcClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    // ── Section: Momentum ─────────────────────────────────────────────────────
    table.cell(dash, 0, 7, "─── MOMENTUM ───",
      text_color=color.new(cNeut, 20), text_size=size.tiny,
      bgcolor=secBg, text_halign=text.align_center)
    table.cell(dash, 1, 7, "", bgcolor=secBg)
 
    table.cell(dash, 0, 8, "RSI (" + str.tostring(rsiLen) + ")",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 8, str.tostring(rsiVal, "#.#") + "  [" + rsiZone + "]",
      text_color=rsiClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    table.cell(dash, 0, 9, "EMA (" + str.tostring(emaLen) + ")",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 9, emaText,
      text_color=emaClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    sqMomTxt = sqMom > 0 and sqBull  ? "▲▲ STRONG UP" :
      sqMom > 0 and not sqBull       ? "▲ RISING" :
      sqMom < 0 and sqBear           ? "▼▼ STRONG DOWN" :
      sqMom < 0 and not sqBear       ? "▼ FALLING" : "— FLAT"
    sqMomClr = sqMom > 0 ? cBullP : sqMom < 0 ? cBearP : cNeut
    table.cell(dash, 0, 10, "SQ MOMENTUM",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 10, sqMomTxt,
      text_color=sqMomClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    // MACD status in dashboard
    macdTxt = macdBullish ? "▲ BULLISH" : macdBearish ? "▼ BEARISH" : "— NEUTRAL"
    macdClr = macdBullish ? cBullP : macdBearish ? cBearP : cNeut
    table.cell(dash, 0, 11, "MACD",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 11, macdTxt,
      text_color=macdClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    // Volume status
    volTxt = volSpike ? "▲ ABOVE AVG" : "— NORMAL"
    volClr = volSpike ? cBullP : cNeut
    table.cell(dash, 0, 12, "VOLUME",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 12, volTxt,
      text_color=volClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    // ── Section: Signals ──────────────────────────────────────────────────────
    table.cell(dash, 0, 13, "─── CONFIDENCE ───",
      text_color=color.new(cNeut, 20), text_size=size.tiny,
      bgcolor=secBg, text_halign=text.align_center)
    table.cell(dash, 1, 13, "", bgcolor=secBg)
 
    bTier = bullScore >= 80 ? "S-TIER" : bullScore >= 70 ? "A-TIER" : bullScore >= 60 ? "B-TIER" : bullScore >= minConf ? "C-TIER" : "LOW"
    bClr  = bullScore >= 80 ? cBullP : bullScore >= 70 ? color.new(cBullP, 10) :
      bullScore >= 60 ? color.new(cBullP, 30) : bullScore >= minConf ? color.new(cBullP, 50) : cNeut
    table.cell(dash, 0, 14, "BULL CONF",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 14, str.tostring(bullScore, "#") + "%  [" + bTier + "]",
      text_color=bClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    sTier = bearScore >= 80 ? "S-TIER" : bearScore >= 70 ? "A-TIER" : bearScore >= 60 ? "B-TIER" : bearScore >= minConf ? "C-TIER" : "LOW"
    sClr  = bearScore >= 80 ? cBearP : bearScore >= 70 ? color.new(cBearP, 10) :
      bearScore >= 60 ? color.new(cBearP, 30) : bearScore >= minConf ? color.new(cBearP, 50) : cNeut
    table.cell(dash, 0, 15, "BEAR CONF",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 15, str.tostring(bearScore, "#") + "%  [" + sTier + "]",
      text_color=sClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    // ── Section: Forecast ─────────────────────────────────────────────────────
    table.cell(dash, 0, 16, "─── FORECAST ───",
      text_color=color.new(cNeut, 20), text_size=size.tiny,
      bgcolor=secBg, text_halign=text.align_center)
    table.cell(dash, 1, 16, "", bgcolor=secBg)
 
    fcDir     = basisSlope > 0 ? "▲ RISING" : basisSlope < 0 ? "▼ FALLING" : "— FLAT"
    fcDirClr  = basisSlope > 0 ? cBullP : basisSlope < 0 ? cBearP : cNeut
    table.cell(dash, 0, 17, "BASIS SLOPE",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 17, fcDir,
      text_color=fcDirClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    fcDevDir    = devSlope > 0 ? "▲ WIDENING" : devSlope < 0 ? "▼ NARROWING" : "— STABLE"
    fcDevDirClr = devSlope > 0 ? cPOC : devSlope < 0 ? cBullP : cTxtL
    table.cell(dash, 0, 18, "BAND FORECAST",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 18, fcDevDir,
      text_color=fcDevDirClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    // ── Section: Structure ────────────────────────────────────────────────────
    table.cell(dash, 0, 19, "─── STRUCTURE ───",
      text_color=color.new(cNeut, 20), text_size=size.tiny,
      bgcolor=secBg, text_halign=text.align_center)
    table.cell(dash, 1, 19, "", bgcolor=secBg)
 
    sma200Txt = above200 ? "▲ ABOVE" : "▼ BELOW"
    sma200Clr = above200 ? cBullP : cBearP
    table.cell(dash, 0, 20, "SMA 200",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 20, sma200Txt,
      text_color=sma200Clr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
    // ── Section: Trade ────────────────────────────────────────────────────────
    table.cell(dash, 0, 21, "─── TRADE STATE ───",
      text_color=color.new(cNeut, 20), text_size=size.tiny,
      bgcolor=secBg, text_halign=text.align_center)
    table.cell(dash, 1, 21, "", bgcolor=secBg)
 
    table.cell(dash, 0, 22, "POSITION",
      text_color=cTxtL, text_size=dsz, bgcolor=posBg)
    table.cell(dash, 1, 22, posText,
      text_color=posClr, text_size=dsz, bgcolor=posBg)
 
    basisDistPct = math.abs(close - bbBasis) / bbBasis * 100
    basisDistTxt = str.tostring(basisDistPct, "#.##") + "% from basis"
    basisDistClr = basisDistPct > 0.15 ? cPOC : cTxtL   // gold 1m: 0.15% is meaningful
    table.cell(dash, 0, 23, "BASIS DISTANCE",
      text_color=cTxtL, text_size=dsz, bgcolor=color.new(cDashBg, 0))
    table.cell(dash, 1, 23, basisDistTxt,
      text_color=basisDistClr, text_size=dsz, bgcolor=color.new(cDashBg, 0))
 
// ─────────────────────────────────────────────────────────────────────────────
//  ALERTS
// ─────────────────────────────────────────────────────────────────────────────
 
alertcondition(bullSig and bullScore >= 80,
  title="S-Tier Bull Band Touch",
  message="[AlphaX VPS] S-TIER BULL signal — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bullSig and bullScore >= 70 and bullScore < 80,
  title="A-Tier Bull Band Touch",
  message="[AlphaX VPS] A-TIER BULL signal — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bullSig,
  title="Any Bull Band Touch",
  message="[AlphaX VPS] BULL band touch — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bearSig and bearScore >= 80,
  title="S-Tier Bear Band Touch",
  message="[AlphaX VPS] S-TIER BEAR signal — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bearSig and bearScore >= 70 and bearScore < 80,
  title="A-Tier Bear Band Touch",
  message="[AlphaX VPS] A-TIER BEAR signal — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bearSig,
  title="Any Bear Band Touch",
  message="[AlphaX VPS] BEAR band touch — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bullSig or bearSig,
  title="Any Band Touch Signal",
  message="[AlphaX VPS] Band touch signal — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(sqRelease and sqBull,
  title="Squeeze Release — Bullish",
  message="[AlphaX VPS] ⚡ SQUEEZE RELEASE BULL — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(sqRelease and sqBear,
  title="Squeeze Release — Bearish",
  message="[AlphaX VPS] ⚡ SQUEEZE RELEASE BEAR — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(sqRelease,
  title="Any Squeeze Release",
  message="[AlphaX VPS] ⚡ Squeeze release — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bullExit,
  title="Long Exit — Mean Reversion",
  message="[AlphaX VPS] EXIT long (basis reached) — {{ticker}} {{interval}} @ {{close}}")
 
alertcondition(bearExit,
  title="Short Exit — Mean Reversion",
  message="[AlphaX VPS] EXIT short (basis reached) — {{ticker}} {{interval}} @ {{close}}")

← 返回列表