本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("CryptoAUGUR 2.3", shorttitle="CrAUGUR2.3", overlay=false, max_bars_back=600, dynamic_requests=true)
// 2.3 (2026-11-07): Same-weekday UTC daily Fuel, a maximum RSI pivot gap,
// and a visible build stamp. Carries forward the 2.2 Swing Watch.
//
// Corrected CryptoAUGUR v2 lineage. Nine sensors, clustered score, LEAD/COIN,
// heuristic directional bias, duration memory, and descriptive forward record.
// This is an indicator; it does not execute orders or estimate trading returns.
// L2 is a matched perpetual/spot basis proxy, NOT realized funding.
// OI and dominance describe observable series; they do not identify order flow.
G_GENERAL = "═══ GENERAL ═══"
i_showTable = input.bool(true, "Show Table", group=G_GENERAL, display=display.none)
i_tblPos = input.string("Bottom Right", "Table Position", options=["Top Left","Top Center","Top Right","Middle Left","Middle Center","Middle Right","Bottom Left","Bottom Center","Bottom Right"], group=G_GENERAL, display=display.none)
i_alertThreshold = input.float(34, "Alert Threshold", minval=1, maxval=100, group=G_GENERAL, display=display.none)
i_showBg = input.bool(true, "Background When Above Threshold", group=G_GENERAL, display=display.none)
i_minCoverage = input.float(70, "Minimum Ready Weight (%)", minval=50, maxval=100, group=G_GENERAL, tooltip="Below this coverage the composite is withheld. Missing or warming layers never count as quiet votes.", display=display.none)
G_CAL = "═══ CALIBRATION (percentile engine) ═══"
i_pctWindow = input.int(252, "Distribution Window (days)", minval=60, maxval=500, group=G_CAL, tooltip="Previous native daily sessions in each percentile window. On a 24/7 feed, 252 observations are about eight months. At least 90% must be usable.", display=display.none)
i_pctMeaningful = input.float(80, "Meaningful Percentile", minval=60, maxval=95, step=1, group=G_CAL, tooltip="A shift beyond this percentile of its own rolling distribution counts as meaningful. Replaces v1's absolute and hardcoded magnitude thresholds for basis, BTC dominance, OI and USDT dominance.", display=display.none)
G_GRID = "═══ LEAD / COIN GRID ═══"
i_gridHi = input.float(25, "Grid High Threshold", minval=10, maxval=60, step=1, group=G_GRID, tooltip="LEAD or COIN score at or above this = hot axis.", display=display.none)
i_gridLo = input.float(12, "Grid Low Threshold", minval=2, maxval=30, step=1, group=G_GRID, display=display.none)
i_verdictHold = input.int(3, "Verdict Hold (bars)", minval=1, maxval=20, group=G_GRID, tooltip="A new verdict must persist this many bars before replacing the displayed one - hysteresis against flicker.", display=display.none)
G_PRESS = "═══ PRESSURE ENERGY (duration memory) ═══"
i_pressFloor = input.float(20, "Pressure Floor (score)", minval=5, maxval=50, step=1, group=G_PRESS, tooltip="Days with the composite above this accumulate pressure energy.", display=display.none)
i_pressMemSize = input.int(20, "Episode Memory", minval=5, maxval=100, group=G_PRESS, display=display.none)
i_pressMinSamp = input.int(3, "Min Episodes", minval=1, maxval=20, group=G_PRESS, display=display.none)
i_pressRecMin = input.float(1.0, "Min Recorded Episode", minval=0.0, maxval=20.0, step=0.5, group=G_PRESS, display=display.none)
i_pressBoot = input.float(6.0, "Bootstrap Avg Episode", minval=0.5, maxval=50.0, step=0.5, group=G_PRESS, display=display.none)
G_VAL = "═══ VALIDATION HARNESS ═══"
i_valOn = input.bool(true, "Enable Validation Harness", group=G_VAL, tooltip="Records each crossed score tier and compares close-to-close returns from the same origins at two horizons. Descriptive, not a trading backtest.", display=display.none)
i_valShow = input.bool(false, "Show Validation Table", group=G_VAL, display=display.none)
i_valPos = input.string("Bottom Left", "Validation Table Position", options=["Top Left","Top Center","Top Right","Middle Left","Middle Center","Middle Right","Bottom Left","Bottom Center","Bottom Right"], group=G_VAL, display=display.none)
i_h1 = input.int(24, "Horizon 1 (bars)", minval=5, maxval=200, group=G_VAL, display=display.none)
i_h2 = input.int(96, "Horizon 2 (bars)", minval=10, maxval=400, group=G_VAL, display=display.none)
G_L1 = "═══ L1: MOMENTUM (RSI Divergence) ═══"
i_rsiLen = input.int(14, "RSI Length", minval=5, maxval=50, group=G_L1, display=display.none)
i_divPivL = input.int(5, "Pivot Left", minval=2, maxval=20, group=G_L1, display=display.none)
i_divPivR = input.int(3, "Pivot Right", minval=1, maxval=10, group=G_L1, display=display.none)
i_divDecay = input.int(14, "Divergence Active (bars)", minval=3, maxval=50, group=G_L1, display=display.none)
i_wgtRSI = input.float(15, "Weight", minval=0, maxval=50, group=G_L1, display=display.none)
i_divMaxGap = input.int(60, "Maximum pivot gap (chart bars)", minval=5, maxval=300, group=G_L1, tooltip="Compare RSI only between consecutive eligible highs or lows no more than this many chart bars apart. Applies to Momentum divergence, not Swing Watch.", display=display.none)
G_L2 = "═══ L2: BASIS (Perpetual / Spot) ═══"
i_spotAuto = input.bool(true, "Auto Binance USDT Pair", group=G_L2, tooltip="Use the Binance USDT perpetual and spot for the chart base. Disable to select both legs manually. No venue or quote mixing.", display=display.none)
i_spotSym = input.symbol("BINANCE:BTCUSDT", "Spot Ticker (manual)", group=G_L2, display=display.none)
i_perpSym = input.symbol("BINANCE:BTCUSDT.P", "Perpetual Ticker (manual)", group=G_L2, display=display.none)
i_fundSmooth = input.int(20, "Basis Smooth (days)", minval=5, maxval=100, group=G_L2, display=display.none)
i_wgtFund = input.float(20, "Weight", minval=0, maxval=50, group=G_L2, display=display.none)
G_L3 = "═══ L3: VOL REGIME (ATR Ratio) ═══"
i_atrShort = input.int(7, "Short ATR", minval=3, maxval=20, group=G_L3, display=display.none)
i_atrLong = input.int(28, "Long ATR", minval=14, maxval=100, group=G_L3, display=display.none)
i_volExpand = input.float(1.5, "Expansion Threshold", minval=1.1, maxval=3.0, step=0.1, group=G_L3, tooltip="A short/long ATR ratio above this level activates the full expansion weight.", display=display.none)
i_wgtVolReg = input.float(10, "Weight", minval=0, maxval=50, group=G_L3, display=display.none)
G_L4 = "═══ L4: COIL (ATR Compression) ═══"
i_atrCompLen = input.int(50, "ATR Lookback", minval=20, maxval=200, group=G_L4, display=display.none)
i_atrCompLvl = input.float(65, "COILED Verdict Below (%)", minval=30, maxval=95, group=G_L4, display=display.none)
i_wgtATR = input.float(10, "Weight", minval=0, maxval=50, group=G_L4, display=display.none)
G_L5 = "═══ L5: FUEL (Volume Divergence) ═══"
i_volDivLen = input.int(20, "Volume SMA", minval=5, maxval=100, group=G_L5, display=display.none)
i_volDivDecay = input.int(10, "Fuel Active (bars)", minval=3, maxval=30, group=G_L5, display=display.none)
i_wgtVol = input.float(10, "Weight", minval=0, maxval=50, group=G_L5, display=display.none)
i_dailyFuelWeeks = input.int(8, "Daily Fuel lookback (weeks)", minval=4, maxval=16, group=G_L5, tooltip="Daily pivots use prior matching UTC trading weekdays in this many weeks. At least half the weeks and no fewer than four must have positive volume. Intraday charts still use the Volume SMA.", display=display.none)
G_L6 = "═══ L6: TREND (ADX) ═══"
i_adxLen = input.int(14, "ADX Length", minval=5, maxval=50, group=G_L6, display=display.none)
i_adxThresh = input.float(20, "Trough Threshold", minval=10, maxval=40, group=G_L6, display=display.none)
i_wgtADX = input.float(10, "Weight", minval=0, maxval=50, group=G_L6, display=display.none)
G_L7 = "═══ L7: DOMINANCE (BTC.D) ═══"
i_domSym = input.symbol("CRYPTOCAP:BTC.D", "BTC Dominance Ticker", group=G_L7, display=display.none)
i_domLen = input.int(20, "Baseline (days)", minval=5, maxval=100, group=G_L7, display=display.none)
i_wgtDom = input.float(10, "Weight", minval=0, maxval=50, group=G_L7, display=display.none)
G_L8 = "═══ L8: LEVERAGE (Open Interest) ═══"
i_enableOI = input.bool(true, "Enable OI Layer", group=G_L8, display=display.none)
i_oiLen = input.int(20, "Baseline (days)", minval=5, maxval=100, group=G_L8, display=display.none)
i_wgtOI = input.float(10, "Weight", minval=0, maxval=50, group=G_L8, display=display.none)
G_L9 = "═══ L9: STABLECOIN (USDT.D) ═══"
i_stableSym = input.symbol("CRYPTOCAP:USDT.D", "Stablecoin Dominance Ticker", group=G_L9, display=display.none)
i_stableLen = input.int(20, "Baseline (days)", minval=5, maxval=100, group=G_L9, display=display.none)
i_wgtStable = input.float(5, "Weight", minval=0, maxval=50, group=G_L9, display=display.none)
const string DAY = "1D"
const int MS_DAY = 86400000
const int MS_WEEK = 7 * MS_DAY
const string BUILD_STAMP = "2.3 · 2026-11-07"
const float TIER_1 = 20.0
const float TIER_2 = 33.0
const float TIER_3 = 45.0
bool isOneDay = timeframe.isdaily and timeframe.multiplier == 1
bool chartOK = chart.is_standard and (timeframe.isseconds or timeframe.isminutes or isOneDay)
bool confirmed = barstate.isconfirmed
string chartBase = syminfo.basecurrency
if barstate.isfirst
if not chartOK or syminfo.type != "crypto" or na(chartBase) or str.length(chartBase) == 0
runtime.error("CryptoAUGUR requires a standard crypto chart with a base currency, on a time-based intraday timeframe or 1D.")
if i_gridLo >= i_gridHi
runtime.error("Grid Low must be lower than Grid High.")
if i_atrShort >= i_atrLong
runtime.error("Short ATR must be shorter than Long ATR.")
if i_valOn and i_h1 > i_h2
runtime.error("Validation Horizon 1 must not exceed Horizon 2.")
string spotTicker = i_spotAuto ? "BINANCE:" + chartBase + "USDT" : i_spotSym
string perpTicker = i_spotAuto ? "BINANCE:" + chartBase + "USDT.P" : i_perpSym
string oiTicker = perpTicker + "_OI"
// All ranks run in native daily contexts. Missing observations consume
// window slots. Ties receive half credit, so flat history ranks at 50.
f_rank(float value) =>
int n = 0
int below = 0
int equal = 0
if not na(value)
for k = 1 to i_pctWindow
float prior = value[k]
if not na(prior)
n += 1
if prior < value
below += 1
else if prior == value
equal += 1
n >= math.ceil(i_pctWindow * 0.9) ? (below + 0.5 * equal) * 100.0 / n : na
f_smaStrict(float value, simple int length) =>
float avg = ta.sma(value, length)
float holes = math.sum(na(value) ? 1.0 : 0.0, length)
holes == 0 ? avg : na
f_up(float p) => 100.0 * math.max(0.0, math.min(1.0, (p - i_pctMeaningful) / (100.0 - i_pctMeaningful)))
f_down(float p) => 100.0 * math.max(0.0, math.min(1.0, (100.0 - i_pctMeaningful - p) / (100.0 - i_pctMeaningful)))
// Executed in the perpetual's daily context. Both price legs use prior
// completed native candles. Unshifted time is only release metadata.
f_perpPacket(string spotId) =>
[spotClose, spotStart, spotEnd, spotRelease, spotBase, spotQuote, spotVenue, spotName] = request.security(spotId, DAY, [close[1], time[1], time_close[1], math.max(time, time_close[1]), syminfo.basecurrency, syminfo.currency, syminfo.prefix, syminfo.ticker], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
int sampleStart = time[1]
int sampleEnd = time_close[1]
int releaseAt = math.max(time, sampleEnd)
bool perpOK = close[1] > 0 and str.endswith(syminfo.ticker, ".P")
bool pairOK = perpOK and spotClose > 0 and spotBase == syminfo.basecurrency and spotQuote == syminfo.currency and spotVenue == syminfo.prefix and not str.endswith(spotName, ".P") and sampleStart == spotStart and sampleEnd == spotEnd
int basisRelease = math.max(releaseAt, spotRelease)
float basis = pairOK and not na(basisRelease) and basisRelease <= time_close ? (close[1] / spotClose - 1.0) * 100.0 : na
float smooth = f_smaStrict(basis, i_fundSmooth)
float rank = f_rank(smooth)
float trend = f_smaStrict(close > 0 ? close : na, 20)[1]
[sampleStart, sampleEnd, releaseAt, syminfo.basecurrency, perpOK ? close[1] : na, trend, basisRelease, basis, smooth, rank]
f_dominancePacket(simple int length) =>
float v = close > 0 ? close : na
float avg = f_smaStrict(v, length)[1]
float delta = v - avg
float rank = f_rank(delta)
[time_close[1], math.max(time, time_close[1]), v[1], delta[1], rank[1]]
f_oiPacket() =>
float v = close > 0 ? close : na
float avg = f_smaStrict(v, i_oiLen)[1]
float delta = avg > 0 ? (v / avg - 1.0) * 100.0 : na
float shockRank = f_rank(delta)
float levelRank = f_rank(v)
[time[1], time_close[1], math.max(time, time_close[1]), v[1], delta[1], shockRank[1], levelRank[1]]
[perpStart, perpEnd, perpRelease, perpBase, perpClose, perpTrend, basisRelease, basisRaw, basisSmooth, basisRank] = request.security(perpTicker, DAY, f_perpPacket(spotTicker), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
[domEnd, domRelease, domValue, domChange, domRank] = request.security(i_domSym, DAY, f_dominancePacket(i_domLen), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
[stableEnd, stableRelease, stableValue, stableChange, stableRank] = request.security(i_stableSym, DAY, f_dominancePacket(i_stableLen), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
[oiStart, oiEnd, oiRelease, oiValue, oiChange, oiRank, oiLevelRank] = if i_enableOI and i_wgtOI > 0
request.security(oiTicker, DAY, f_oiPacket(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, ignore_invalid_symbol=true)
else
[int(na), int(na), int(na), float(na), float(na), float(na), float(na)]
f_fresh(int ended, int releasedAt) =>
not na(ended) and not na(releasedAt) and not na(time_close) and ended <= time_close and releasedAt <= time_close and time_close - ended < 2 * MS_DAY
bool basisFeed = perpBase == chartBase and not na(basisRaw) and f_fresh(perpEnd, basisRelease)
bool domFeed = domValue > 0 and f_fresh(domEnd, domRelease)
bool stableFeed = stableValue > 0 and f_fresh(stableEnd, stableRelease)
bool oiFeed = i_enableOI and perpBase == chartBase and oiValue > 0 and perpClose > 0 and oiStart == perpStart and oiEnd == perpEnd and f_fresh(oiEnd, oiRelease) and f_fresh(perpEnd, perpRelease)
bool r2 = basisFeed and not na(basisRank)
bool r7 = domFeed and not na(domRank)
bool r8 = oiFeed and not na(oiRank) and not na(oiLevelRank) and perpTrend > 0
bool r9 = stableFeed and not na(stableRank)
// Daily Fuel compares earlier occurrences of the same UTC trading weekday.
// time_tradingday is a UTC midnight stamp, so multiples of a week match
// the weekday even if the feed skips a session or the chart timezone changes.
f_dailyFuelAvg() =>
int maxBars = i_dailyFuelWeeks * 7
int maxAge = i_dailyFuelWeeks * MS_WEEK
int minSamples = math.max(4, math.ceil(i_dailyFuelWeeks / 2.0))
float total = 0.0
int count = 0
int lastAge = 0
for k = 1 to maxBars
int age = time_tradingday - time_tradingday[k]
float v = volume[k]
if age > lastAge and age <= maxAge and age % MS_WEEK == 0 and v > 0
total += v
count += 1
lastAge := age
count >= minSamples ? total / count : na
// Chart sensors: pivots become events at the confirmation close. RSI and
// volume are read on the pivot itself, without backdating the event.
float rsi = ta.rsi(close, i_rsiLen)
float pivLo = ta.pivotlow(low, i_divPivL, i_divPivR)
float pivHi = ta.pivothigh(high, i_divPivL, i_divPivR)
int pivotBar = bar_index - i_divPivR
float pivotRsi = rsi[i_divPivR]
float volAvg = ta.sma(volume, i_volDivLen)
float dailyVolAvg = isOneDay ? f_dailyFuelAvg() : na
float pivotVol = volume[i_divPivR]
// Both references predate the pivot candle, even though it is confirmed later.
float pivotAvg = isOneDay ? dailyVolAvg[i_divPivR] : volAvg[i_divPivR + 1]
var float prevLo = na
var float prevLoRsi = na
var int prevLoBar = na
var float prevHi = na
var float prevHiRsi = na
var int prevHiBar = na
var int lastBull = na
var int lastBear = na
var int lastFuelBull = na
var int lastFuelBear = na
// Keep confirmed price pivots even when RSI or volume is unavailable.
var float swingHigh = na
var float swingLow = na
if confirmed
if not na(pivLo)
swingLow := pivLo
if not na(pivotRsi)
if not na(prevLoBar) and pivotBar - prevLoBar <= i_divMaxGap and pivLo < prevLo and pivotRsi > prevLoRsi
lastBull := bar_index
prevLo := pivLo
prevLoRsi := pivotRsi
prevLoBar := pivotBar
if pivotVol > 0 and pivotAvg > 0 and pivotVol < pivotAvg * 0.8
lastFuelBull := bar_index
if not na(pivHi)
swingHigh := pivHi
if not na(pivotRsi)
if not na(prevHiBar) and pivotBar - prevHiBar <= i_divMaxGap and pivHi > prevHi and pivotRsi < prevHiRsi
lastBear := bar_index
prevHi := pivHi
prevHiRsi := pivotRsi
prevHiBar := pivotBar
if pivotVol > 0 and pivotAvg > 0 and pivotVol < pivotAvg * 0.8
lastFuelBear := bar_index
bool r1 = not na(rsi)
bool bullDiv = r1 and not na(lastBull) and bar_index - lastBull <= i_divDecay
bool bearDiv = r1 and not na(lastBear) and bar_index - lastBear <= i_divDecay
// Daily readiness uses the weekday of the candle eligible for confirmation.
bool fuelFeed = isOneDay ? pivotVol > 0 : not na(volume)
bool r5 = fuelFeed and (isOneDay ? pivotAvg > 0 : volAvg > 0)
bool fuelBull = r5 and not na(lastFuelBull) and bar_index - lastFuelBull <= i_volDivDecay
bool fuelBear = r5 and not na(lastFuelBear) and bar_index - lastFuelBear <= i_volDivDecay
float layer1 = bullDiv or bearDiv ? i_wgtRSI : 0.0
float layer5 = fuelBull or fuelBear ? i_wgtVol : 0.0
bool basisLow = r2 and basisSmooth < 0 and basisRank <= 100.0 - i_pctMeaningful
bool basisHigh = r2 and basisSmooth > 0 and basisRank >= i_pctMeaningful
float basisIntensity = basisLow ? 30.0 + 0.7 * f_down(basisRank) : basisHigh ? 30.0 + 0.7 * f_up(basisRank) : r2 and basisSmooth != 0 ? 15.0 : 0.0
float layer2 = i_wgtFund * basisIntensity / 100.0
float atrShort = ta.atr(i_atrShort)
float atrLong = ta.atr(i_atrLong)
bool r3 = atrLong > 0 and not na(atrShort)
float volRatio = r3 ? atrShort / atrLong : na
bool volExpanding = r3 and volRatio > i_volExpand
bool volContracting = r3 and volRatio < 1.0 / i_volExpand
float layer3 = volExpanding ? i_wgtVolReg : 0.0
float atr14 = ta.atr(14)
float atrAvg = ta.sma(atr14, i_atrCompLen)
bool r4 = atrAvg > 0 and not na(atr14)
float atrRatio = r4 ? 100.0 * atr14 / atrAvg : na
bool coilNow = r4 and atrRatio < i_atrCompLvl
// Continuous tightness score; the COILED setting gates the verdict.
float layer4 = r4 ? i_wgtATR * math.max(0.0, 100.0 - atrRatio) / 100.0 : 0.0
[diPlus, diMinus, adx] = ta.dmi(i_adxLen, i_adxLen)
bool r6 = not na(adx) and not na(adx[1]) and not na(adx[2]) and not na(diPlus) and not na(diMinus)
bool adxLow = r6 and adx < i_adxThresh
int adxLowAgo = ta.barssince(adxLow)
bool adxTurn = r6 and not na(adxLowAgo) and adxLowAgo <= 5 and adx > adx[1] and adx > adx[2]
float layer6 = i_wgtADX * (adxTurn ? 1.0 : adxLow ? 0.4 : 0.0)
bool btcChart = chartBase == "BTC"
bool domRising = r7 and domChange > 0 and domRank >= i_pctMeaningful
bool domFalling = r7 and domChange < 0 and domRank <= 100.0 - i_pctMeaningful
float layer7 = i_wgtDom * (domRising ? 30.0 + 0.7 * f_up(domRank) : domFalling ? 30.0 + 0.7 * f_down(domRank) : 0.0) / 100.0
bool oiRising = r8 and oiChange > 0 and oiRank >= i_pctMeaningful
bool oiFalling = r8 and oiChange < 0 and oiRank <= 100.0 - i_pctMeaningful
bool oiWeakDown = oiFalling and perpClose < perpTrend
bool oiWeakUp = oiRising and perpClose < perpTrend
bool oiStrongUp = oiRising and perpClose > perpTrend
bool oiLow = r8 and oiLevelRank <= 100.0 - i_pctMeaningful
bool oiHigh = r8 and oiLevelRank >= i_pctMeaningful
float oiIntensity = oiWeakDown ? 30.0 + 0.7 * f_down(oiRank) : oiWeakUp or oiStrongUp ? 30.0 + 0.7 * f_up(oiRank) : oiLow ? 25.0 + 0.35 * f_down(oiLevelRank) : oiHigh ? 25.0 + 0.35 * f_up(oiLevelRank) : 0.0
float layer8 = i_wgtOI * oiIntensity / 100.0
bool stableUp = r9 and stableChange > 0 and stableRank >= i_pctMeaningful
bool stableDown = r9 and stableChange < 0 and stableRank <= 100.0 - i_pctMeaningful
float layer9 = i_wgtStable * (stableUp ? 30.0 + 0.7 * f_up(stableRank) : stableDown ? 30.0 + 0.7 * f_down(stableRank) : 0.0) / 100.0
// Normalize each cluster and axis over its eligible weight. A change in the
// set of eligible layers is a new comparison baseline, not a signal edge.
f_cluster(float a, float b, float c, float d) =>
float largest = math.max(math.max(a, b), math.max(c, d))
largest + 0.5 * (a + b + c + d - largest)
float configuredOI = i_enableOI ? i_wgtOI : 0.0
float configuredW = i_wgtRSI + i_wgtFund + i_wgtVolReg + i_wgtATR + i_wgtVol + i_wgtADX + i_wgtDom + configuredOI + i_wgtStable
float w1 = r1 ? i_wgtRSI : 0.0
float w2 = r2 ? i_wgtFund : 0.0
float w3 = r3 ? i_wgtVolReg : 0.0
float w4 = r4 ? i_wgtATR : 0.0
float w5 = r5 ? i_wgtVol : 0.0
float w6 = r6 ? i_wgtADX : 0.0
float w7 = r7 ? i_wgtDom : 0.0
float w8 = r8 ? configuredOI : 0.0
float w9 = r9 ? i_wgtStable : 0.0
float readyW = w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9
float coverage = configuredW > 0 ? 100.0 * readyW / configuredW : na
int mask = (w1 > 0 ? 1 : 0) + (w2 > 0 ? 2 : 0) + (w3 > 0 ? 4 : 0) + (w4 > 0 ? 8 : 0) + (w5 > 0 ? 16 : 0) + (w6 > 0 ? 32 : 0) + (w7 > 0 ? 64 : 0) + (w8 > 0 ? 128 : 0) + (w9 > 0 ? 256 : 0)
float rawScore = f_cluster(layer2, layer3, layer8, 0.0) + f_cluster(layer7, layer9, 0.0, 0.0) + f_cluster(layer1, layer4, layer5, layer6)
float maxScore = f_cluster(w2, w3, w8, 0.0) + f_cluster(w7, w9, 0.0, 0.0) + f_cluster(w1, w4, w5, w6)
bool scoreReady = coverage >= i_minCoverage and maxScore > 0
float score = scoreReady ? math.min(100.0, 100.0 * rawScore / maxScore) : na
float leadW = w1 + w2 + w5 + w7 + w8 + w9
float coinW = w3 + w6
float leadScore = scoreReady and leadW > 0 ? 100.0 * (layer1 + layer2 + layer5 + layer7 + layer8 + layer9) / leadW : na
float coinScore = scoreReady and coinW > 0 ? 100.0 * (layer3 + layer6) / coinW : na
bool gridReady = not na(leadScore) and not na(coinScore)
string grid = not gridReady ? "" : leadScore >= i_gridHi and coinScore < i_gridLo ? "EARLY WINDOW" : leadScore >= i_gridHi and coinScore >= i_gridHi ? "STRESS LIVE" : leadScore < i_gridLo and coinScore >= i_gridHi ? "CLIMAX NO FUEL" : ""
float chartSma = ta.sma(close, 20)
bool chartUp = close > chartSma
bool chartDown = close < chartSma
float pressure = 0.0
pressure += bullDiv and not bearDiv ? layer1 : bearDiv and not bullDiv ? -layer1 : 0.0
pressure += basisLow ? layer2 : basisHigh ? -layer2 : basisSmooth < 0 ? -layer2 * 0.5 : basisSmooth > 0 ? layer2 * 0.3 : 0.0
pressure += volExpanding and chartUp ? layer3 : volExpanding and chartDown ? -layer3 : 0.0
pressure += fuelBull and not fuelBear ? layer5 : fuelBear and not fuelBull ? -layer5 : 0.0
pressure += adxTurn and diPlus > diMinus ? layer6 : adxTurn and diMinus > diPlus ? -layer6 : 0.0
pressure += not btcChart and domRising ? -layer7 : not btcChart and domFalling ? layer7 : 0.0
pressure += oiWeakDown ? layer8 : oiWeakUp ? -layer8 : oiStrongUp ? layer8 * 0.5 : 0.0
pressure += stableUp ? -layer9 : stableDown ? layer9 : 0.0
float biasW = w1 + w2 + w3 + w5 + w6 + (btcChart ? 0.0 : w7) + w8 + w9
float bias = scoreReady and biasW > 0 ? 100.0 * pressure / biasW : na
int side = na(bias) ? 0 : bias > 5.0 ? 1 : bias < -5.0 ? -1 : 0
string biasLabel = na(bias) ? "UNAVAILABLE" : side > 0 ? "BULL" : side < 0 ? "BEAR" : "NEUTRAL"
int activeLayers = (layer1 > 0 ? 1 : 0) + (layer2 > 0 ? 1 : 0) + (layer3 > 0 ? 1 : 0) + (layer4 > 0 ? 1 : 0) + (layer5 > 0 ? 1 : 0) + (layer6 > 0 ? 1 : 0) + (layer7 > 0 ? 1 : 0) + (layer8 > 0 ? 1 : 0) + (layer9 > 0 ? 1 : 0)
// Pressure uses the last confirmed chart score of each completed chart day.
// A data gap breaks an episode without recording a bogus completion.
int chartDay = time(DAY)
bool newDay = timeframe.change(DAY)
var array<float> pressMem = array.new_float()
var float pressE = 0.0
var int pressMask = na
if confirmed and newDay
bool newCoverage = not na(pressMask) and mask[1] != pressMask
bool missingDay = na(chartDay[1]) or chartDay - chartDay[1] >= 2 * MS_DAY
if newCoverage
array.clear(pressMem)
if newCoverage or missingDay or na(score[1])
pressE := 0.0
if not missingDay and not na(score[1])
if score[1] > i_pressFloor
pressE += (score[1] - i_pressFloor) / 10.0
else if pressE > 0
if pressE >= i_pressRecMin
array.push(pressMem, pressE)
if array.size(pressMem) > i_pressMemSize
array.shift(pressMem)
pressE := 0.0
pressMask := mask[1]
float typicalPress = array.size(pressMem) >= math.min(i_pressMinSamp, i_pressMemSize) ? array.avg(pressMem) : i_pressBoot
float relativePress = typicalPress > 0 ? pressE / typicalPress : 0.0
string duration = pressE <= 0 or not scoreReady or mask != pressMask ? "" : relativePress < 0.5 ? "FRESH" : relativePress < 1.0 ? "BUILDING" : relativePress < 2.0 ? "SUSTAINED" : "EXTREME"
string arrow = side > 0 ? " ▲" : side < 0 ? " ▼" : ""
bool capitulation = w2 > 0 and basisLow and ((w8 > 0 and oiWeakDown) or (w5 > 0 and fuelBull and not fuelBear and chartDown))
bool euphoria = w2 > 0 and w7 > 0 and basisHigh and domFalling
bool coilDominant = coilNow and layer4 > 0 and rawScore > 0 and layer4 >= rawScore * 0.5 and (na(bias) or math.abs(bias) < 10.0)
string tier = not scoreReady ? "UNAVAILABLE" : score >= TIER_3 ? "CRITICAL" : score >= TIER_2 ? "LOADED" : score >= TIER_1 ? "PRESSURE BUILDING" : score >= 10 ? "STIRRING" : "QUIET"
string rawVerdict = not scoreReady ? tier : capitulation and side > 0 ? "CAPITULATION SETUP ▲" : euphoria and side < 0 ? "EUPHORIA SETUP ▼" : coilDominant ? "COILED" : grid == "EARLY WINDOW" ? "EARLY SIGNAL" + arrow : grid == "STRESS LIVE" ? "STRESS CONFIRMED" + arrow : grid == "CLIMAX NO FUEL" ? "FADING — LOW FUEL" + arrow : tier + arrow
var string verdict = ""
var string pending = ""
var int pendingBars = 0
if confirmed
if not scoreReady or verdict == "" or na(score[1]) or mask != mask[1]
verdict := rawVerdict
pending := ""
pendingBars := 0
else if rawVerdict == verdict
pending := ""
pendingBars := 0
else
pendingBars := rawVerdict == pending ? pendingBars + 1 : 1
pending := rawVerdict
if pendingBars >= i_verdictHold
verdict := pending
pending := ""
pendingBars := 0
string shownVerdict = duration != "" and verdict != "QUIET" and verdict != "UNAVAILABLE" ? verdict + " · " + duration : verdict
// Validation: both returns use the same origin, maturing exactly at H2.
// Independent flags preserve every tier crossed, including multi-tier jumps.
bool comparable = confirmed and not na(score) and not na(score[1]) and mask == mask[1]
bool cross20 = comparable and score >= TIER_1 and score[1] < TIER_1
bool cross33 = comparable and score >= TIER_2 and score[1] < TIER_2
bool cross45 = comparable and score >= TIER_3 and score[1] < TIER_3
var array<int> valN = array.new_int(4, 0)
var array<float> valSum1 = array.new_float(4, 0.0)
var array<float> valSum2 = array.new_float(4, 0.0)
var array<int> valDir = array.new_int(4, 0)
var array<int> valHit = array.new_int(4, 0)
f_record(int row, float ret1, float ret2, int originSide) =>
array.set(valN, row, array.get(valN, row) + 1)
array.set(valSum1, row, array.get(valSum1, row) + ret1)
array.set(valSum2, row, array.get(valSum2, row) + ret2)
if originSide != 0
array.set(valDir, row, array.get(valDir, row) + 1)
if (originSide > 0 and ret2 > 0) or (originSide < 0 and ret2 < 0)
array.set(valHit, row, array.get(valHit, row) + 1)
int h1Offset = math.max(0, i_h2 - i_h1)
float originClose = close[i_h2]
float h1Close = close[h1Offset]
if i_valOn and confirmed and comparable[i_h2] and originClose > 0 and h1Close > 0 and close > 0
float ret1 = (h1Close / originClose - 1.0) * 100.0
float ret2 = (close / originClose - 1.0) * 100.0
int originSide = side[i_h2]
if cross20[i_h2]
f_record(0, ret1, ret2, originSide)
if cross33[i_h2]
f_record(1, ret1, ret2, originSide)
if cross45[i_h2]
f_record(2, ret1, ret2, originSide)
f_record(3, ret1, ret2, originSide)
const color INK = #FFFFFF
const color LABEL = #9CEEFF
const color HEADER = #5307F8
const color PANE = #111427
const color FRAME = #494C76
const color BULL = #50F1AA
const color BEAR = #FF648F
const color AMBER = #FFDC48
const color CYAN = #45CBFF
f_scoreColor(float value) =>
na(value) ? INK : value >= TIER_3 ? BEAR : value >= TIER_2 ? AMBER : value >= TIER_1 ? CYAN : BULL
f_closed(float value) =>
confirmed ? value : value[1]
float showScore = f_closed(score)
float showBias = f_closed(bias)
plot(showScore, "CryptoAUGUR Score", color=f_scoreColor(showScore), style=plot.style_columns)
hline(i_alertThreshold, "Alert threshold", color=color.new(INK, 30), linestyle=hline.style_dotted)
plot(na(showBias) ? na : 50.0 + math.max(-50.0, math.min(50.0, showBias)), "Bias", color=showBias > 5 ? BULL : showBias < -5 ? BEAR : INK, linewidth=2)
plot(f_closed(leadScore), "LEAD Score", color=BULL)
plot(f_closed(coinScore), "COIN Score", color=AMBER)
plot(f_closed(scoreReady ? pressE : na), "Pressure Energy", color=AMBER, display=display.data_window)
plot(f_closed(basisFeed ? basisSmooth : na), "Smoothed perp–spot basis (%)", color=AMBER, display=display.data_window)
plot(f_closed(r2 ? basisRank : na), "Basis percentile", color=AMBER, display=display.data_window)
plot(f_closed(r7 ? domRank : na), "BTC dominance percentile", color=CYAN, display=display.data_window)
plot(f_closed(r8 ? oiRank : na), "Open interest shock percentile", color=BULL, display=display.data_window)
plot(f_closed(r8 ? oiLevelRank : na), "Open interest level percentile", color=BULL, display=display.data_window)
plot(f_closed(r9 ? stableRank : na), "USDT dominance percentile", color=CYAN, display=display.data_window)
plot(f_closed(coverage), "Ready weight (%)", color=INK, display=display.data_window)
bgcolor(i_showBg and showScore >= i_alertThreshold ? color.new(f_scoreColor(showScore), 86) : na)
f_position(string name) =>
switch name
"Top Left" => position.top_left
"Top Center" => position.top_center
"Top Right" => position.top_right
"Middle Left" => position.middle_left
"Middle Center" => position.middle_center
"Middle Right" => position.middle_right
"Bottom Left" => position.bottom_left
"Bottom Center" => position.bottom_center
=> position.bottom_right
var table info = table.new(f_position(i_tblPos), 2, 16, bgcolor=PANE, border_width=1, border_color=FRAME, frame_width=1, frame_color=FRAME)
var table valTable = table.new(f_position(i_valPos), 5, 5, bgcolor=PANE, border_width=1, border_color=FRAME, frame_width=1, frame_color=FRAME)
f_row(int row, string caption, string reading, color ink, string tip) =>
color bg = row == 0 ? HEADER : PANE
table.cell(info, 0, row, caption, text_color=row == 0 ? INK : LABEL, bgcolor=bg, text_size=size.small, text_halign=text.align_left, tooltip=tip)
table.cell(info, 1, row, reading, text_color=row == 0 ? INK : ink, bgcolor=bg, text_size=size.small, text_halign=text.align_right, tooltip=tip)
f_fmt(float v, string fmt, string suffix) =>
na(v) ? "—" : str.tostring(v, fmt) + suffix
f_swingWatch(int direction, float swingHi, float swingLo, float lastClose) =>
string highText = na(swingHi) ? "—" : str.tostring(swingHi, format.mintick)
string lowText = na(swingLo) ? "—" : str.tostring(swingLo, format.mintick)
if direction > 0
na(swingHi) ? "Await swing high" : (lastClose > swingHi ? "Above high " : "Close > ") + highText
else if direction < 0
na(swingLo) ? "Await swing low" : (lastClose < swingLo ? "Below low " : "Close < ") + lowText
else
"H " + highText + " / L " + lowText
f_date(int sampleEnd) =>
na(sampleEnd) ? "—" : str.format_time(sampleEnd - 1, "yyyy-MM-dd", "UTC")
f_status(bool enabled, bool feed, bool ready, string reading) =>
not enabled ? "OFF" : not feed ? "NO MATCH / DATA" : not ready ? "WARM-UP" : reading
bool tableUpdate = barstate.islastconfirmedhistory or (barstate.islast and confirmed)
if i_showTable and tableUpdate
f_row(0, "CryptoAUGUR 2.3", scoreReady ? tier + " · " + f_fmt(score, "0.0", "") : "UNAVAILABLE", INK, "Clustered relative stress score. Direction is a separate heuristic; neither is a trading signal.")
f_row(1, "Read", shownVerdict + (na(bias) ? "" : " | " + biasLabel), side > 0 ? BULL : side < 0 ? BEAR : INK, "Confirmed verdict with a separate duration tag. Bias reflects the current confirmed bar.")
f_row(2, "Swing Watch", f_swingWatch(side, swingHigh, swingLow, close), side > 0 ? BULL : side < 0 ? BEAR : INK, "Latest confirmed pivots on this chart timeframe, using the Momentum pivot settings. The current confirmed bias selects the high or low; neutral or unavailable bias shows both. A close beyond the watched pivot is shown as Above high or Below low.")
string mom = bullDiv and bearDiv ? "MIXED" : bullDiv ? "BULL DIVERGENCE ▲" : bearDiv ? "BEAR DIVERGENCE ▼" : "—"
f_row(3, "Momentum", f_status(i_wgtRSI > 0, not na(close), r1, mom), bullDiv == bearDiv ? INK : bullDiv ? BULL : BEAR, "Compare successive confirmed price pivots and RSI on those pivot bars, up to " + str.tostring(i_divMaxGap) + " chart bars apart.")
string basisText = (basisLow ? "LOW " : basisHigh ? "HIGH " : "") + f_fmt(basisSmooth, "0.00", "%")
f_row(4, "Perp / spot basis", f_status(i_wgtFund > 0, basisFeed, r2, basisText), basisLow ? BULL : basisHigh ? BEAR : INK, perpTicker + " vs " + spotTicker + " | UTC source date " + f_date(perpEnd) + ". Matched same-venue daily closes; no actual funding payments measured.")
f_row(5, "Vol regime", f_status(i_wgtVolReg > 0, not na(close), r3, volExpanding ? "EXPANDING" : volContracting ? "CONTRACTING" : "—"), volExpanding ? AMBER : INK, "Short / long ATR. Full expansion weight when the ratio exceeds the configured threshold.")
f_row(6, "Coil", f_status(i_wgtATR > 0, not na(close), r4, coilNow ? "COILED" : atrRatio < 90.0 ? "TIGHT" : "—"), coilNow ? CYAN : INK, "ATR tightness contributes gradually; the COILED threshold applies to the verdict.")
string fuel = fuelBull and fuelBear ? "MIXED" : fuelBull ? "LOW VOL AT LOW ▲" : fuelBear ? "LOW VOL AT HIGH ▼" : "—"
string fuelTip = isOneDay ? "Pivot volume versus prior matching UTC trading weekdays. The pivot candle and any later candles are excluded." : "Pivot volume compared with its prior volume average."
f_row(7, "Fuel", f_status(i_wgtVol > 0, fuelFeed, r5, fuel), fuelBull == fuelBear ? INK : fuelBull ? BULL : BEAR, fuelTip + " The event is dated at pivot confirmation.")
string trendText = adxTurn and diPlus > diMinus ? "TURNING UP ▲" : adxTurn and diMinus > diPlus ? "TURNING DOWN ▼" : adxLow ? "LOW ADX" : "—"
f_row(8, "Trend", f_status(i_wgtADX > 0, not na(close), r6, trendText), adxTurn and diPlus != diMinus ? (diPlus > diMinus ? BULL : BEAR) : INK, "ADX trough and directional indicator comparison.")
f_row(9, "BTC dominance", f_status(i_wgtDom > 0, domFeed, r7, domRising ? "BTC SHARE UP" : domFalling ? "BTC SHARE DOWN" : "—"), btcChart ? INK : domRising ? BEAR : domFalling ? BULL : INK, i_domSym + " | UTC source date " + f_date(domEnd) + ". BTC dominance does not vote directionally on BTC charts.")
string oiText = oiWeakDown ? "OI DOWN / PRICE WEAK" : oiWeakUp ? "OI UP / PRICE WEAK" : oiStrongUp ? "OI UP / PRICE STRONG" : oiLow ? "LOW OI RANK" : oiHigh ? "HIGH OI RANK" : "—"
f_row(10, "Open interest", f_status(i_enableOI and i_wgtOI > 0, oiFeed, r8, oiText), oiWeakDown or oiStrongUp ? BULL : oiWeakUp ? BEAR : INK, oiTicker + " | UTC source date " + f_date(oiEnd) + ". Same perpetual's daily trend; one venue, feed-defined units. No long/short or liquidation counts.")
f_row(11, "USDT dominance", f_status(i_wgtStable > 0, stableFeed, r9, stableUp ? "USDT SHARE UP" : stableDown ? "USDT SHARE DOWN" : "—"), stableUp ? BEAR : stableDown ? BULL : INK, i_stableSym + " | UTC source date " + f_date(stableEnd) + ". Market-cap share proxy; no actual inflows or outflows measured.")
f_row(12, "LEAD / COIN", not gridReady ? "UNAVAILABLE" : f_fmt(leadScore, "0", "") + " / " + f_fmt(coinScore, "0", "") + (grid == "" ? "" : " · " + grid), grid == "EARLY WINDOW" ? AMBER : INK, "Leading and coincident evidence. An axis without eligible weight is unavailable.")
f_row(13, "Duration", duration == "" ? "—" : duration, duration == "" ? INK : AMBER, "Episode energy samples the last chart-bar score of each completed chart day. A data or coverage break interrupts the episode.")
f_row(14, "Ready weight", f_fmt(coverage, "0", "%"), scoreReady ? INK : AMBER, "Share of enabled layer weight with valid inputs. Needs " + f_fmt(i_minCoverage, "0", "%") + ". Native daily feeds are withheld at 48 hours old. Alerts ignore changes in coverage.")
f_row(15, "Build", BUILD_STAMP, INK, "2.3: Weekday-adjusted daily Fuel and a maximum RSI pivot gap. Includes Swing Watch.")
f_valCell(int col, int row, string value, color ink, string tip) =>
table.cell(valTable, col, row, value, text_color=ink, bgcolor=row == 0 ? HEADER : PANE, text_size=size.tiny, tooltip=tip)
f_valRow(int row, int slot, string name) =>
int n = array.get(valN, slot)
int nd = array.get(valDir, slot)
float ret1 = n > 0 ? array.get(valSum1, slot) / n : na
float ret2 = n > 0 ? array.get(valSum2, slot) / n : na
float hit = nd > 0 ? 100.0 * array.get(valHit, slot) / nd : na
f_valCell(0, row, name, LABEL, "Each tier crossed on a comparable confirmed score; one origin can appear in several tier rows.")
f_valCell(1, row, str.tostring(n), INK, "Origins with both horizons complete. Rows share the same maturity rule.")
f_valCell(2, row, f_fmt(ret1, "0.00", "%"), na(ret1) ? INK : ret1 >= 0 ? BULL : BEAR, "Average raw close-to-close return at H1.")
f_valCell(3, row, f_fmt(ret2, "0.00", "%"), na(ret2) ? INK : ret2 >= 0 ? BULL : BEAR, "Average raw close-to-close return at H2.")
f_valCell(4, row, f_fmt(hit, "0", "%"), INK, "H2 return matched the origin's BULL/BEAR lean in " + str.tostring(array.get(valHit, slot)) + " of " + str.tostring(nd) + " directional origins; flat is a miss.")
if i_valOn and i_valShow and tableUpdate
string tip = "Historical observations on this chart. Horizons count chart bars; overlapping samples, no execution or profitability model."
f_valCell(0, 0, "RECORD", INK, tip)
f_valCell(1, 0, "n", INK, tip)
f_valCell(2, 0, "H" + str.tostring(i_h1), INK, tip)
f_valCell(3, 0, "H" + str.tostring(i_h2), INK, tip)
f_valCell(4, 0, "Bias hit", INK, tip)
f_valRow(1, 0, "≥20")
f_valRow(2, 1, "≥33")
f_valRow(3, 2, "≥45")
f_valRow(4, 3, "Eligible base")
bool scoreAlert = comparable and score >= i_alertThreshold and score[1] < i_alertThreshold
bool earlyAlert = comparable and gridReady and gridReady[1] and grid == "EARLY WINDOW" and grid[1] != "EARLY WINDOW"
alertcondition(scoreAlert, "CryptoAUGUR Alert", "CryptoAUGUR crossed its confirmed score threshold. Score: {{plot_0}}")
alertcondition(earlyAlert, "Early Window", "{{ticker}} {{interval}} CryptoAUGUR: leading sensors hot, coincident sensors quiet.")
f_jsonNum(float v) =>
na(v) ? "null" : str.tostring(v, "0.00")
f_jsonString(string value) =>
string escaped = str.replace_all(value, "\\", "\\\\")
escaped := str.replace_all(escaped, '"', '\\"')
'"' + escaped + '"'
if scoreAlert
string payload = '{"version":"2.3","ticker":' + f_jsonString(syminfo.ticker) + ',"interval":' + f_jsonString(timeframe.period) + ',"augur_score":' + f_jsonNum(score) + ',"bias":' + f_jsonString(biasLabel) + ',"layers":' + str.tostring(activeLayers) + ',"verdict":' + f_jsonString(shownVerdict) + ',"lead":' + f_jsonNum(leadScore) + ',"coin":' + f_jsonNum(coinScore) + ',"grid":' + f_jsonString(grid) + ',"duration":' + f_jsonString(duration) + ',"pressE":' + f_jsonNum(pressE) + ',"coverage_pct":' + f_jsonNum(coverage) + '}'
alert(payload, alert.freq_once_per_bar_close)