Guard Rails [Aurabot]

AuraSznfx · study · 174 行 · 点赞 34 · 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/
// © AuraSznfx
// ◈ AURΔBØT™ GUARD RAILS · the overnight trend tunnel
// Midnight to 8 AM ET: a straight trend line is fitted through the overnight closes (the "angle"), and the tunnel is the
// slanted channel that held every overnight candle. At the lock time the tunnel is fixed and projected forward through the
// day, with outer guard rails one tunnel height (default x2) beyond each edge. While it forms overnight it draws dotted.
// The tunnel itself is often broken during New York. The rails mark the edge of the expected move, not a bounce.
// Visual context only, you decide.
//@version=6
indicator("Guard Rails [Aurabot]", "◈ AURΔBØT™ GUARD RAILS", overlay = true, max_lines_count = 200)
 
tz      = input.string("America/New_York", "Timezone", group = "◈ Tunnel")
gB = "◈ Tunnel"
startH  = input.int(0, "Angle measured from (hour, ET)", minval = 0, maxval = 12, group = gB)
lockH   = input.int(8, "Locks at (hour, ET)", minval = 1, maxval = 12, group = gB, tooltip = "The trend from the start hour to this hour sets the angle. 7 or 8 AM works best: before the 8:30 news.")
railK   = input.float(2.0, "Outer rails = tunnel height x", minval = 0.5, maxval = 5.0, step = 0.25, group = gB)
keepN   = input.int(3, "Days of tunnels kept on the chart", minval = 1, maxval = 10, group = gB)
showForm = input.bool(true, "Show the tunnel forming overnight (dotted)", group = gB)
gL = "◈ Look"
showFill = input.bool(true, "Shade the tunnel and the rail zones", group = gL)
themeChoice = input.string("Aurabot", "◈ Color Theme", group = gL, options = ["Aurabot", "Neon Cyber", "Midnight Aura", "Sunset Blaze", "Ocean Depth", "Ghost Protocol", "Classic", "Neon Violet", "Plasma", "Blade Runner", "Toxic", "Ghost Wire", "Midnight Blue", "Ember Gold", "Stealth Dark", "Clean Light", "Custom"], tooltip = "Sets the whole colour palette at once. Same themes as the other Aurabot scripts. Pick Custom to use your own colors below.")
cu_lo = input.color(#00D9FF, "↳ Custom lower rail", group = gL)
cu_hi = input.color(#FF427E, "↳ Custom upper rail", group = gL)
cu_ac = input.color(#FACC15, "↳ Custom tunnel", group = gL)
 
cLo = switch themeChoice
    "Aurabot"         => #00D9FF
    "Neon Cyber"      => #00E676
    "Midnight Aura"   => #6366F1
    "Sunset Blaze"    => #FBBF24
    "Ocean Depth"     => #22D3EE
    "Ghost Protocol"  => #A1A1AA
    "Classic"         => #089981
    "Neon Violet"     => #B388FF
    "Plasma"          => #00FFF5
    "Blade Runner"    => #448AFF
    "Toxic"           => #76FF03
    "Ghost Wire"      => #84FFFF
    "Midnight Blue"   => #00B0FF
    "Ember Gold"      => #FFD740
    "Stealth Dark"    => #A5D6A7
    "Clean Light"     => #2E7D32
    => cu_lo
cHi = switch themeChoice
    "Aurabot"         => #FF427E
    "Neon Cyber"      => #FF1744
    "Midnight Aura"   => #F472B6
    "Sunset Blaze"    => #EF4444
    "Ocean Depth"     => #F97316
    "Ghost Protocol"  => #52525B
    "Classic"         => #F23645
    "Neon Violet"     => #FF4081
    "Plasma"          => #FF006E
    "Blade Runner"    => #FF6E40
    "Toxic"           => #FF1744
    "Ghost Wire"      => #FF80AB
    "Midnight Blue"   => #FF5252
    "Ember Gold"      => #FF6E40
    "Stealth Dark"    => #EF9A9A
    "Clean Light"     => #C62828
    => cu_hi
cAc = switch themeChoice
    "Aurabot"         => #FACC15
    "Neon Cyber"      => #FFEA00
    "Midnight Aura"   => #A78BFA
    "Sunset Blaze"    => #FB923C
    "Ocean Depth"     => #38BDF8
    "Ghost Protocol"  => #D4D4D8
    "Classic"         => #FF9800
    "Neon Violet"     => #E040FB
    "Plasma"          => #FFD60A
    "Blade Runner"    => #FFAB40
    "Toxic"           => #C6FF00
    "Ghost Wire"      => #EEFF41
    "Midnight Blue"   => #FFD166
    "Ember Gold"      => #FFAB00
    "Stealth Dark"    => #FFE082
    "Clean Light"     => #EF6C00
    => cu_ac
 
float tfMin = timeframe.in_seconds() / 60.0
bool  okTf  = timeframe.isintraday and tfMin <= 60
int   hm    = hour(time, tz) * 60 + minute(time, tz)
bool  inSeg = okTf and hm >= startH * 60 and hm < lockH * 60
bool  segStart = inSeg and (not inSeg[1] or dayofmonth(time, tz) != dayofmonth(time[1], tz))
bool  lockNow  = okTf and not inSeg and inSeg[1]
 
// regression sums over the overnight closes (x = bar_index)
var float n = 0.0
var float sx = 0.0
var float sy = 0.0
var float sxy = 0.0
var float sxx = 0.0
var int   x0 = na
var array<int>   xs = array.new_int()
var array<float> hs = array.new_float()
var array<float> ls = array.new_float()
if segStart
    n := 0.0, sx := 0.0, sy := 0.0, sxy := 0.0, sxx := 0.0
    x0 := bar_index
    xs.clear(), hs.clear(), ls.clear()
if inSeg
    float x = bar_index
    n += 1, sx += x, sy += close, sxy += x * close, sxx += x * x
    xs.push(bar_index), hs.push(high), ls.push(low)
 
f_fit() =>
    float den = n * sxx - sx * sx
    float b = den != 0 ? (n * sxy - sx * sy) / den : 0.0
    float a = n > 0 ? (sy - b * sx) / n : na
    float top = -1e12
    float bot = 1e12
    if xs.size() > 0
        for i = 0 to xs.size() - 1
            float ln = a + b * xs.get(i)
            top := math.max(top, hs.get(i) - ln)
            bot := math.min(bot, ls.get(i) - ln)
    [a, b, top, bot]
 
// drawn tunnels: 5 lines + 3 fills each
var array<line>     L  = array.new<line>()
var array<linefill> LF = array.new<linefill>()
var line fC = na
var line fT = na
var line fB = na
var float la = na
var float lb = na
var float lTop = na
var float lBot = na
 
f_clearForming() =>
    line.delete(fC)
    line.delete(fT)
    line.delete(fB)
 
if showForm and inSeg and n >= 8 and barstate.isconfirmed
    [a, b, top, bot] = f_fit()
    f_clearForming()
    fC := line.new(x0, a + b * x0, bar_index, a + b * bar_index, color = color.new(cAc, 40), style = line.style_dotted, width = 1)
    fT := line.new(x0, a + b * x0 + top, bar_index, a + b * bar_index + top, color = color.new(cHi, 40), style = line.style_dotted, width = 1)
    fB := line.new(x0, a + b * x0 + bot, bar_index, a + b * bar_index + bot, color = color.new(cLo, 40), style = line.style_dotted, width = 1)
 
if lockNow and n >= 8
    f_clearForming()
    [a, b, top, bot] = f_fit()
    la := a, lb := b, lTop := top, lBot := bot
    float hgt = top - bot
    int ahead = int(math.min(499, math.max(1, (1440 - hm) / tfMin)))
    int x2 = bar_index + ahead
    line lC  = line.new(x0, a + b * x0, x2, a + b * x2, color = color.new(cAc, 30), style = line.style_dashed, width = 1)
    line lT  = line.new(x0, a + b * x0 + top, x2, a + b * x2 + top, color = color.new(cAc, 10), width = 1)
    line lB  = line.new(x0, a + b * x0 + bot, x2, a + b * x2 + bot, color = color.new(cAc, 10), width = 1)
    line lRT = line.new(x0, a + b * x0 + top + railK * hgt, x2, a + b * x2 + top + railK * hgt, color = cHi, width = 2)
    line lRB = line.new(x0, a + b * x0 + bot - railK * hgt, x2, a + b * x2 + bot - railK * hgt, color = cLo, width = 2)
    L.push(lC), L.push(lT), L.push(lB), L.push(lRT), L.push(lRB)
    if showFill
        LF.push(linefill.new(lT, lB, color.new(cAc, 93)))
        LF.push(linefill.new(lRT, lT, color.new(cHi, 92)))
        LF.push(linefill.new(lB, lRB, color.new(cLo, 92)))
    while L.size() > keepN * 5
        line.delete(L.shift())
    while LF.size() > keepN * 3
        linefill.delete(LF.shift())
 
// live values of today's locked tunnel, for alerts and the data window
float hgtNow = lTop - lBot
float railUp = na(la) ? na : la + lb * bar_index + lTop + railK * hgtNow
float railDn = na(la) ? na : la + lb * bar_index + lBot - railK * hgtNow
plot(railUp, "Upper rail (value)", display = display.data_window)
plot(railDn, "Lower rail (value)", display = display.data_window)
if segStart
    la := na
alertcondition(not na(railUp) and close > railUp and not (close[1] > railUp[1]), "Closed above the upper rail", "Guard Rails: close above the upper rail")
alertcondition(not na(railDn) and close < railDn and not (close[1] < railDn[1]), "Closed below the lower rail", "Guard Rails: close below the lower rail")

← 返回列表