Eye Aurora Flow [EyeAlgo]

eyealgo · study · 186 行 · 点赞 47 · 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/
// © EyeAlgo
//@version=6
indicator("Eye Aurora Flow [EyeAlgo]", shorttitle = "Eye Aurora Flow [EyeAlgo]", overlay = true, max_bars_back = 5000)
 
// ───────── Inputs ─────────
G1 = "Flow engine"
fastLen  = input.int(9,   "Fast flow length (early colour)", minval = 2, group = G1)
slowLen  = input.int(34,  "Slow flow length (trend)",        minval = 5, group = G1)
atrLen   = input.int(14,  "ATR length",                      minval = 2, group = G1)
eLen     = input.int(200, "Energy lookback (bars)",          minval = 20, group = G1)
 
G2 = "Aurora shape"
cLen     = input.int(21,    "Aurora centre length",              minval = 2, group = G2)
minW     = input.float(0.6, "Calm width (× ATR)",                minval = 0.1, step = 0.1, group = G2)
spreadW  = input.float(2.2, "Extra width at full energy (× ATR)", minval = 0.0, step = 0.1, group = G2)
asym     = input.float(0.6, "Stretch toward momentum side",       minval = 0.0, maxval = 2.0, step = 0.1, group = G2)
ripple   = input.float(0.6, "Curtain ripple",                     minval = 0.0, maxval = 1.0, step = 0.1, group = G2)
baseT    = input.int(58,    "Glow strength (lower = brighter)",   minval = 0, maxval = 90, group = G2)
showCore = input.bool(true, "Show aurora core line", group = G2)
showBg   = input.bool(true, "Sky glow in background", group = G2)
bgT      = input.int(92,    "Sky glow transparency", minval = 80, maxval = 99, group = G2)
 
G3 = "Colours"
bullIn   = input.color(#00E676, "Bull inner (green)",     group = G3)
bullOut  = input.color(#00E5FF, "Bull outer (cyan)",      group = G3)
bearIn   = input.color(#FF2BD6, "Bear inner (magenta)",   group = G3)
bearOut  = input.color(#7C4DFF, "Bear outer (violet)",    group = G3)
neutralC = input.color(#9FB4D0, "Neutral (fading flow)",  group = G3)
 
G4 = "Signals"
showShift = input.bool(true, "Show colour-shift warnings", group = G4)
showFlip  = input.bool(true, "Show trend flips",           group = G4)
win       = input.int(20,    "Shift → flip window (bars)", minval = 2, group = G4)
 
G5 = "Aurora dashboard"
showDash = input.bool(true, "Show aurora curtain dashboard (top right)", group = G5)
dashTxt  = input.string(size.small, "Text size", options = [size.tiny, size.small, size.normal], group = G5)
 
// ───────── Flow engine (own calculation) ─────────
f_clamp(x) => math.max(-1.0, math.min(1.0, x))
 
a        = math.max(ta.atr(atrLen), syminfo.mintick)
flowFast = ta.ema((close - ta.ema(close, fastLen)) / a, 3)
flowSlow = ta.ema((close - ta.ema(close, slowLen)) / a, 5)
 
// hue: -1 = full bear, 0 = neutral, +1 = full bull. Fast flow leads, so colour drifts before trend flips
hue    = f_clamp(0.65 * flowFast / 1.5 + 0.35 * flowSlow / 2.5)
rawE   = nz(ta.percentrank(math.abs(flowFast) + math.abs(flowSlow), eLen), 50) / 100.0
energy = nz(ta.ema(rawE, 3), 0.5)
 
trendUp = flowSlow > 0
 
// ───────── Aurora layers ─────────
center = ta.ema(hl2, cLen)
w      = a * (minW + energy * spreadW)
upK    = 1 + asym * math.max(hue, 0)
dnK    = 1 + asym * math.max(-hue, 0)
 
f_off(int i, float k) =>
    w * k * (i / 6.0 + ripple * energy * 0.07 * math.sin(bar_index * 0.21 + i * 0.85))
 
f_hueCol(float h, color bc, color rc) =>
    h >= 0 ? color.from_gradient(h, 0, 1, neutralC, bc) : color.from_gradient(h, -1, 0, rc, neutralC)
 
f_col(int i) =>
    bc = color.from_gradient(i, 1, 6, bullIn, bullOut)
    rc = color.from_gradient(i, 1, 6, bearIn, bearOut)
    t  = math.min(97, baseT + (i - 1) * 6 + (1 - energy) * 25)
    color.new(f_hueCol(hue, bc, rc), t)
 
up1 = center + f_off(1, upK)
up2 = center + f_off(2, upK)
up3 = center + f_off(3, upK)
up4 = center + f_off(4, upK)
up5 = center + f_off(5, upK)
up6 = center + f_off(6, upK)
dn1 = center - f_off(1, dnK)
dn2 = center - f_off(2, dnK)
dn3 = center - f_off(3, dnK)
dn4 = center - f_off(4, dnK)
dn5 = center - f_off(5, dnK)
dn6 = center - f_off(6, dnK)
 
coreCol = f_hueCol(hue, bullIn, bearIn)
 
pc  = plot(center, "Aurora Core", color = showCore ? color.new(coreCol, 15) : na, linewidth = 2)
pu1 = plot(up1, "Aurora Up 1",   display = display.none, editable = false)
pu2 = plot(up2, "Aurora Up 2",   display = display.none, editable = false)
pu3 = plot(up3, "Aurora Up 3",   display = display.none, editable = false)
pu4 = plot(up4, "Aurora Up 4",   display = display.none, editable = false)
pu5 = plot(up5, "Aurora Up 5",   display = display.none, editable = false)
pu6 = plot(up6, "Aurora Up 6",   display = display.none, editable = false)
pd1 = plot(dn1, "Aurora Down 1", display = display.none, editable = false)
pd2 = plot(dn2, "Aurora Down 2", display = display.none, editable = false)
pd3 = plot(dn3, "Aurora Down 3", display = display.none, editable = false)
pd4 = plot(dn4, "Aurora Down 4", display = display.none, editable = false)
pd5 = plot(dn5, "Aurora Down 5", display = display.none, editable = false)
pd6 = plot(dn6, "Aurora Down 6", display = display.none, editable = false)
 
fill(pc,  pu1, f_col(1), "Aurora Glow Up 1")
fill(pu1, pu2, f_col(2), "Aurora Glow Up 2")
fill(pu2, pu3, f_col(3), "Aurora Glow Up 3")
fill(pu3, pu4, f_col(4), "Aurora Glow Up 4")
fill(pu4, pu5, f_col(5), "Aurora Glow Up 5")
fill(pu5, pu6, f_col(6), "Aurora Glow Up 6")
fill(pc,  pd1, f_col(1), "Aurora Glow Down 1")
fill(pd1, pd2, f_col(2), "Aurora Glow Down 2")
fill(pd2, pd3, f_col(3), "Aurora Glow Down 3")
fill(pd3, pd4, f_col(4), "Aurora Glow Down 4")
fill(pd4, pd5, f_col(5), "Aurora Glow Down 5")
fill(pd5, pd6, f_col(6), "Aurora Glow Down 6")
 
bgcolor(showBg ? color.new(coreCol, math.min(99, bgT + (1 - energy) * 5)) : na, title = "Sky Glow")
 
// ───────── Colour shift (early warning) + trend flip ─────────
xUp = ta.crossover(flowFast, 0)
xDn = ta.crossunder(flowFast, 0)
shiftBull = barstate.isconfirmed and not trendUp and xUp
shiftBear = barstate.isconfirmed and trendUp and xDn
flipUp    = barstate.isconfirmed and not na(flowSlow[1]) and trendUp and not trendUp[1]
flipDn    = barstate.isconfirmed and not na(flowSlow[1]) and not trendUp and trendUp[1]
 
plotshape(showShift and shiftBull, "Colour Shift → Bull", shape.diamond, location.belowbar, bullOut, size = size.tiny)
plotshape(showShift and shiftBear, "Colour Shift → Bear", shape.diamond, location.abovebar, bearOut, size = size.tiny)
plotshape(showFlip and flipUp, "Aurora Flip Bull", shape.triangleup,   location.belowbar, bullIn, size = size.small)
plotshape(showFlip and flipDn, "Aurora Flip Bear", shape.triangledown, location.abovebar, bearIn, size = size.small)
 
// ───────── Self-measured: how often a colour shift leads to a trend flip ─────────
var int pendDir = 0
var int pendBar = 0
var int nShift  = 0
var int nHit    = 0
var int sumLead = 0
 
if barstate.isconfirmed
    if pendDir != 0 and bar_index > pendBar
        if (pendDir == 1 and trendUp) or (pendDir == -1 and not trendUp)
            nHit    += 1
            sumLead += bar_index - pendBar
            pendDir := 0
        else if bar_index - pendBar >= win
            pendDir := 0
    if pendDir == 0 and (shiftBull or shiftBear)
        pendDir := shiftBull ? 1 : -1
        pendBar := bar_index
        nShift  += 1
 
// ───────── Aurora curtain dashboard (top right) ─────────
// 12 columns = last 12 bars (newest on the right). Curtain height = energy, colour = flow of that bar.
NCOL  = 12
NROW  = 8
SKY   = #0B1026
var table dash   = table.new(position.top_right, NCOL, NROW + 3, bgcolor = SKY, border_width = 1, border_color = SKY, frame_width = 1, frame_color = color.new(#00E5FF, 60))
 
if barstate.isfirst
    table.merge_cells(dash, 0, 0, NCOL - 1, 0)
    table.merge_cells(dash, 0, NROW + 1, NCOL - 1, NROW + 1)
    table.merge_cells(dash, 0, NROW + 2, NCOL - 1, NROW + 2)
 
if showDash and barstate.islast
    table.cell(dash, 0, 0, "EYE AURORA FLOW", text_color = coreCol, text_size = dashTxt, text_font_family = font.family_monospace, text_halign = text.align_left)
    for c = 0 to NCOL - 1
        k  = NCOL - 1 - c
        eK = nz(energy[k])
        cK = f_hueCol(nz(hue[k]), bullIn, bearIn)
        for r = 1 to NROW
            lvl  = 1.0 * (NROW + 1 - r) / NROW
            isOn = eK >= lvl - 0.5 / NROW
            table.cell(dash, c, r, "", width = 0.6, height = 0.9, bgcolor = isOn ? color.new(cK, (r - 1) * 6) : SKY)
    nRes    = nShift - (pendDir != 0 ? 1 : 0)
    stateTx = (trendUp ? "▲ Bull flow" : "▼ Bear flow") + " · Energy " + str.tostring(energy * 100, "0") + "%"
    shiftTx = pendDir == 1 ? "  ⚠ shift → BULL" : pendDir == -1 ? "  ⚠ shift → BEAR" : ""
    rateTx  = nRes > 0 ? str.tostring(100.0 * nHit / nRes, "0") + "%" : "—"
    leadTx  = nHit > 0 ? str.tostring(1.0 * sumLead / nHit, "0.0") : "—"
    statTx  = "Shift→flip " + rateTx + " (≤" + str.tostring(win) + " bars, n=" + str.tostring(nRes) + ") · avg " + leadTx + " bars"
    table.cell(dash, 0, NROW + 1, stateTx + shiftTx, text_color = #E8F1FF, text_size = dashTxt, text_font_family = font.family_monospace, text_halign = text.align_left)
    table.cell(dash, 0, NROW + 2, statTx, text_color = neutralC, text_size = dashTxt, text_font_family = font.family_monospace, text_halign = text.align_left)
 
// ───────── Alerts ─────────
alertcondition(shiftBull, "Colour Shift → Bull", "Eye Aurora Flow: colour shifting to BULL (early warning)")
alertcondition(shiftBear, "Colour Shift → Bear", "Eye Aurora Flow: colour shifting to BEAR (early warning)")
alertcondition(flipUp,    "Aurora Flip Bull",    "Eye Aurora Flow: trend flipped to BULL")
alertcondition(flipDn,    "Aurora Flip Bear",    "Eye Aurora Flow: trend flipped to BEAR")
eSurge = ta.crossover(energy, 0.8)
alertcondition(barstate.isconfirmed and eSurge, "Energy Surge", "Eye Aurora Flow: energy above 80%")

← 返回列表