NY Session Map: Initial Balance + Liquidity Sweeps [Aurabot]

AuraSznfx · study · 763 行 · 点赞 158 · 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/
// © AuraSznfx
//@version=6
// NY Session Map: Initial Balance + Liquidity Sweeps [Aurabot]
// A levels-first New York session map built from standard, public concepts:
// yesterday's high/low, volume profile value areas (yesterday + last week), London range, 30m buy/sell zones,
// the first hour range (Initial Balance, 9:30-10:30 ET), the Asia range read, fixed-dollar risk sizing and news/chop discipline.
// It marks WATCH spots only. A 4-year test showed these triggers lose when taken blindly,
// so the marker shows where to look and your own read decides. Educational tool, not trade signals or advice.
indicator("NY Session Map: Initial Balance + Liquidity Sweeps [Aurabot]", "NY Map", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 300, max_bars_back = 2000)
 
TZ = "America/New_York"
 
// ───────────────────────── Theme ─────────────────────────
gC = "◈ Theme"
themeChoice = input.string("Aurabot", "◈ Color Theme", group = gC, 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.", display = display.none)
cuHigh    = input.color(#FF427E, "↳ Custom Sell side", group = gC, display = display.none)
cuLow     = input.color(#00D9FF, "↳ Custom Buy side", group = gC, display = display.none)
cuAccent  = input.color(#FACC15, "↳ Custom Accent", group = gC, display = display.none)
cuNeutral = input.color(#8A8AA0, "↳ Custom Neutral", group = gC, display = display.none)
lblSize   = input.string("Small", "Text size", options = ["Tiny", "Small", "Normal"], group = gC, display = display.none)
showPx    = input.bool(true, "Show prices next to line names", group = gC, display = display.none)
showHUD   = input.bool(true, "Show the playbook panel", group = gC, display = display.none)
hudPos    = input.string("Bottom right", "Panel position", options = ["Top right", "Bottom right", "Bottom left", "Top left"], group = gC, display = display.none)
keepDays  = input.int(0, "Past days to keep on the chart", minval = 0, maxval = 10, group = gC, tooltip = "0 keeps only today's map. Raise it to scroll back and review earlier days.", display = display.none)
 
cSell = 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"    => #448AFF
    "Toxic"           => #D500F9
    "Ghost Wire"      => #FF8A80
    "Midnight Blue"   => #FF6B6B
    "Ember Gold"      => #FF6E40
    "Stealth Dark"    => #EF9A9A
    "Clean Light"     => #C62828
    => cuHigh
cBuy = 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"    => #FFAB40
    "Toxic"           => #76FF03
    "Ghost Wire"      => #84FFFF
    "Midnight Blue"   => #00B0FF
    "Ember Gold"      => #FFD740
    "Stealth Dark"    => #A5D6A7
    "Clean Light"     => #2E7D32
    => cuLow
cKey = 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"    => #FF6E40
    "Toxic"           => #C6FF00
    "Ghost Wire"      => #EEFF41
    "Midnight Blue"   => #FFD166
    "Ember Gold"      => #FFAB00
    "Stealth Dark"    => #FFE082
    "Clean Light"     => #EF6C00
    => cuAccent
cNeutral = switch themeChoice
    "Aurabot"         => #8A8AA0
    "Neon Cyber"      => #78909C
    "Midnight Aura"   => #64748B
    "Sunset Blaze"    => #9A8478
    "Ocean Depth"     => #64748B
    "Ghost Protocol"  => #71717A
    "Classic"         => #787B86
    "Neon Violet"     => #8D8FA6
    "Plasma"          => #5C6B73
    "Blade Runner"    => #607D8B
    "Toxic"           => #7A8B6F
    "Ghost Wire"      => #78909C
    "Midnight Blue"   => #546E7A
    "Ember Gold"      => #8D6E63
    "Stealth Dark"    => #6D7B6E
    "Clean Light"     => #90A4AE
    => cuNeutral
isLight = themeChoice == "Clean Light"
cText  = isLight ? #263238 : #EDE9FE
cPanel = isLight ? color.new(#FFFFFF, 5) : color.new(#07060B, 8)
cInk   = isLight ? #FFFFFF : #07060B
// value areas sit between the buy and sell colours so they read as "fair price", not a side
cValue = color.from_gradient(50, 0, 100, cSell, cBuy)
txtSz  = lblSize == "Tiny" ? size.tiny : lblSize == "Normal" ? size.normal : size.small
 
// ───────────────────────── Inputs ─────────────────────────
gL = "Levels from yesterday"
showPD   = input.bool(true, "Yesterday's high and low", group = gL, display = display.none)
showSVP  = input.bool(true, "Yesterday's value area (value high, busiest price, value low)", group = gL, display = display.none)
showWVP  = input.bool(true, "Last week's value area", group = gL, display = display.none)
vaPct    = input.float(70, "Value area %", minval = 50, maxval = 90, group = gL, tooltip = "The price range where this % of the volume traded", display = display.none)
rowPts   = input.float(0, "Profile row size (points, 0 = auto)", minval = 0, group = gL, display = display.none)
profMode = input.string("Auto", "Session used for yesterday's profile", options = ["Auto", "NY hours 9:30-4:00", "Full session 6pm-5pm"], group = gL, tooltip = "Auto: NQ uses New York hours, Gold uses the full session", display = display.none)
rthSess  = input.session("0930-1600", "New York hours", group = gL, display = display.none)
showLDN  = input.bool(true, "London high and low", group = gL, display = display.none)
ldnSess  = input.session("0200-0500", "London range (ET)", group = gL, display = display.none)
 
gZ = "Buy / sell zones (30m)"
showSD   = input.bool(true, "Show zones", group = gZ, tooltip = "The last candle before a big 30m move. Price often reacts when it comes back.", display = display.none)
sdTF     = input.timeframe("30", "Zone timeframe", group = gZ, display = display.none)
dispMult = input.float(1.6, "Big move = body at least x ATR", minval = 0.5, step = 0.1, group = gZ, display = display.none)
sdKeep   = input.int(3, "Zones kept per side", minval = 1, maxval = 8, group = gZ, display = display.none)
 
gI = "First hour range (9:30 to 10:30)"
showIB   = input.bool(true, "Show first hour high / middle / low", group = gI, display = display.none)
ibSess   = input.session("0930-1030", "First hour window (ET)", group = gI, display = display.none)
narrowX  = input.float(0.6, "Call it narrow if smaller than x times the 10-day average", minval = 0.2, maxval = 1.0, step = 0.05, group = gI, display = display.none)
showVW   = input.bool(false, "Draw the New York VWAP line", group = gI, display = display.none)
 
gS = "Watch spots"
mode     = input.string("Morning sweep", "Style", options = ["Morning sweep", "First hour playbook"], group = gS, tooltip = "Morning sweep: 9:40 to 10:30, price runs the Asia or overnight high/low and closes back inside. Max 2 a day.\nFirst hour playbook: after 10:30, a failed breakout of the first hour range or a hold of its middle.", display = display.none)
edgeWin  = input.session("0940-1030", "Morning sweep window (ET)", group = gS, display = display.none)
edgeAsia = input.session("1800-0200", "Asia range for the sweep (ET)", group = gS, display = display.none)
showFA   = input.bool(true, "Failed breakout (breaks the first hour range, closes back inside)", group = gS, display = display.none)
showMH   = input.bool(true, "Middle hold (pulls back to the middle and holds)", group = gS, display = display.none)
faBars   = input.int(6, "Failed breakout: bars allowed outside", minval = 1, maxval = 30, group = gS, display = display.none)
bufTk    = input.int(4, "Stop buffer (ticks)", minval = 0, group = gS, display = display.none)
cutoff   = input.session("1030-1500", "First hour playbook hours (ET)", group = gS, display = display.none)
maxPer   = input.int(3, "Max watch spots per day", minval = 1, maxval = 6, group = gS, display = display.none)
lunchOn  = input.bool(true, "Skip lunch", group = gS, display = display.none)
lunch    = input.session("1200-1330", "Lunch (ET)", group = gS, display = display.none)
confTol  = input.float(0.25, "How close lines must be to count as lined up", minval = 0.05, maxval = 1, step = 0.05, group = gS, display = display.none)
 
gA = "Asia"
showAs   = input.bool(true, "Asia range + overnight read", group = gA, display = display.none)
asSess   = input.session("1800-2000", "Asia range before the Tokyo open (ET)", group = gA, display = display.none)
 
gR = "Risk"
riskUSD  = input.float(200, "Risk per trade ($)", minval = 10, group = gR, display = display.none)
dllUSD   = input.float(400, "Your daily loss limit ($)", minval = 50, group = gR, display = display.none)
 
gD = "News"
newsOn   = input.bool(true, "No watch spots around news", group = gD, display = display.none)
newsBG   = input.bool(false, "Shade news times on the chart", group = gD, display = display.none)
newsList = input.string("0830,1000,1400", "News times (ET, HHMM, comma separated)", group = gD, display = display.none)
newsMin  = input.int(5, "Minutes before / after", minval = 1, maxval = 30, group = gD, display = display.none)
 
// ───────────────────────── Time helpers ─────────────────────────
inSess(s) => not na(time(timeframe.period, s, TZ))
hh = hour(time, TZ)
mm = minute(time, TZ)
dayEndT() =>
    t = timestamp(TZ, year(time, TZ), month(time, TZ), dayofmonth(time, TZ), 16, 0)
    hour(time, TZ) >= 17 ? t + 86400000 : t
newDay  = ta.change(time("D")) != 0
newWeek = ta.change(time("W")) != 0
tick    = syminfo.mintick
pv      = syminfo.pointvalue
px(float p) => str.tostring(p, format.mintick)
 
dATR = request.security(syminfo.tickerid, "D", ta.atr(14)[1], lookahead = barmerge.lookahead_on)
 
// ───────────────────────── Drawing helpers ─────────────────────────
var array<line>  dayLines  = array.new<line>()
var array<label> dayLabels = array.new<label>()
var array<label> lvlLabels = array.new<label>()
var array<line>  lvlLines  = array.new<line>()
// past days go into a short history so you can scroll back; anything older than keepDays is deleted
var int dayNum = 0
var array<line>  hLines = array.new<line>()
var array<int>   hLineDay = array.new<int>()
var array<label> hLabels = array.new<label>()
var array<int>   hLabelDay = array.new<int>()
var array<box>   hBoxes = array.new<box>()
var array<int>   hBoxDay = array.new<int>()
keepBox(box b) =>
    hBoxes.push(b)
    hBoxDay.push(dayNum)
clearDay() =>
    lvlLabels.clear()
    lvlLines.clear()
    while dayLines.size() > 0
        hLines.push(dayLines.shift())
        hLineDay.push(dayNum - 1)
    while dayLabels.size() > 0
        hLabels.push(dayLabels.shift())
        hLabelDay.push(dayNum - 1)
    while hLineDay.size() > 0 and hLineDay.first() < dayNum - keepDays
        line.delete(hLines.shift())
        hLineDay.shift()
    while hLabelDay.size() > 0 and hLabelDay.first() < dayNum - keepDays
        label.delete(hLabels.shift())
        hLabelDay.shift()
    while hBoxDay.size() > 0 and hBoxDay.first() < dayNum - keepDays
        box.delete(hBoxes.shift())
        hBoxDay.shift()
// straight line to the end of the session, name parked at the right edge (off the candles)
level(float p, string txt, color c, int w, string st) =>
    if not na(p) and (na(dATR) or math.abs(p - close) <= 2.5 * dATR)
        t2 = dayEndT()
        ln = line.new(time, p, t2, p, xloc = xloc.bar_time, color = c, width = w, style = st)
        dayLines.push(ln)
        lvlLines.push(ln)
        lb = label.new(t2, p, showPx ? txt + "  " + px(p) : txt, xloc = xloc.bar_time, style = label.style_label_left, color = color.new(#000000, 100), textcolor = c, size = txtSz)
        dayLabels.push(lb)
        lvlLabels.push(lb)
 
// ───────────────────────── Volume profile (yesterday + last week) ─────────────────────────
rowSize() =>
    r = rowPts > 0 ? rowPts : math.max(tick, math.round(nz(dATR, 40 * tick) / 40 / tick) * tick)
    math.max(r, tick)
 
addVol(map<int, float> m, float rs) =>
    lo = math.floor(low / rs)
    hi = math.floor(high / rs)
    n = math.min(hi - lo + 1, 200)
    v = nz(volume) / n
    for k = lo to lo + n - 1
        m.put(k, nz(m.get(k)) + v)
 
// returns [poc, vah, val]
valueArea(map<int, float> m, float rs) =>
    float poc = na
    float vah = na
    float val = na
    if m.size() > 0
        ks = m.keys()
        kmin = ks.min()
        kmax = ks.max()
        total = 0.0
        best = -1.0
        int pk = kmin
        for k = kmin to kmax
            v = nz(m.get(k))
            total += v
            if v > best
                best := v
                pk := k
        acc = best
        lo = pk
        hi = pk
        target = total * vaPct / 100
        while acc < target and (lo > kmin or hi < kmax)
            dn = lo > kmin ? nz(m.get(lo - 1)) : -1.0
            up = hi < kmax ? nz(m.get(hi + 1)) : -1.0
            if up >= dn
                hi += 1
                acc += up
            else
                lo -= 1
                acc += dn
        poc := (pk + 0.5) * rs
        vah := (hi + 1) * rs
        val := lo * rs
    [poc, vah, val]
 
var map<int, float> sMap = map.new<int, float>()
var map<int, float> wMap = map.new<int, float>()
var float sRow = na
var float wRow = na
var float sPOC = na, var float sVAH = na, var float sVAL = na
var float wPOC = na, var float wVAH = na, var float wVAL = na
 
inRTH = inSess(rthSess)
rthStart = inRTH and not inRTH[1]
rthEnd   = not inRTH and inRTH[1]
isGold = str.contains(syminfo.root, "GC") or str.contains(syminfo.ticker, "XAU")
fullProf = profMode == "Full session 6pm-5pm" or (profMode == "Auto" and isGold)
pStart = fullProf ? newDay : rthStart
pIn    = fullProf ? true : inRTH
pEnd   = fullProf ? newDay : rthEnd
 
if timeframe.isintraday and timeframe.in_seconds() <= 1800
    if pEnd and not na(sRow)
        [p, h, l] = valueArea(sMap, sRow)
        sPOC := p
        sVAH := h
        sVAL := l
    if pStart
        sMap.clear()
        sRow := rowSize()
    if pIn and not na(sRow)
        addVol(sMap, sRow)
    if newWeek
        if not na(wRow)
            [p2, h2, l2] = valueArea(wMap, wRow)
            wPOC := p2
            wVAH := h2
            wVAL := l2
        wMap.clear()
        wRow := rowSize() * 2
    if not na(wRow)
        addVol(wMap, wRow)
 
// ───────────────────────── Yesterday ─────────────────────────
[pdH, pdL] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead = barmerge.lookahead_on)
 
if newDay
    dayNum += 1
    clearDay()
    if showPD
        level(pdH, "Yesterday's High", cText, 2, line.style_solid)
        level(pdL, "Yesterday's Low", cText, 2, line.style_solid)
    if showSVP
        level(sVAH, "Value High", color.new(cValue, 20), 1, line.style_dashed)
        level(sPOC, "Busiest Price", cValue, 2, line.style_solid)
        level(sVAL, "Value Low", color.new(cValue, 20), 1, line.style_dashed)
    if showWVP
        level(wVAH, "Week Value High", color.new(cNeutral, 20), 1, line.style_dotted)
        level(wPOC, "Week Busiest Price", color.new(cNeutral, 10), 2, line.style_dotted)
        level(wVAL, "Week Value Low", color.new(cNeutral, 20), 1, line.style_dotted)
 
// ───────────────────────── London range ─────────────────────────
inLdn = inSess(ldnSess)
var float lH = na
var float lL = na
if inLdn and not inLdn[1]
    lH := high
    lL := low
else if inLdn
    lH := math.max(lH, high)
    lL := math.min(lL, low)
if showLDN and not inLdn and inLdn[1]
    level(lH, "London High", cNeutral, 1, line.style_dashed)
    level(lL, "London Low", cNeutral, 1, line.style_dashed)
 
// ───────────────────────── Buy / sell zones (HTF displacement) ─────────────────────────
[zO1, zH1, zL1, zC1, zO2, zH2, zL2, zC2, zATR, zT] = request.security(syminfo.tickerid, sdTF, [open[1], high[1], low[1], close[1], open[2], high[2], low[2], close[2], ta.atr(14)[1], time[1]], lookahead = barmerge.lookahead_on)
zNew = ta.change(zT) != 0
var array<box> dZones = array.new<box>()
var array<box> sZones = array.new<box>()
if showSD and zNew and not na(zATR)
    body = math.abs(zC1 - zO1)
    if body >= dispMult * zATR
        if zC1 > zO1
            dZones.push(box.new(time, math.max(zO2, zC2), time + 1, zL2, xloc = xloc.bar_time, border_color = color.new(cBuy, 55), bgcolor = color.new(cBuy, 88), extend = extend.right, text = "Buy zone · 30m", text_color = color.new(cBuy, 25), text_size = txtSz, text_halign = text.align_right, text_valign = text.align_center))
            if dZones.size() > sdKeep
                box.delete(dZones.shift())
        else
            sZones.push(box.new(time, zH2, time + 1, math.min(zO2, zC2), xloc = xloc.bar_time, border_color = color.new(cSell, 55), bgcolor = color.new(cSell, 88), extend = extend.right, text = "Sell zone · 30m", text_color = color.new(cSell, 25), text_size = txtSz, text_halign = text.align_right, text_valign = text.align_center))
            if sZones.size() > sdKeep
                box.delete(sZones.shift())
// retire a zone when price closes through it, when it is far from price, or when it is old (keeps the chart scale clean)
zoneStale(box b) =>
    far = not na(dATR) and math.abs((b.get_top() + b.get_bottom()) / 2 - close) > 2.0 * dATR
    old = time - b.get_left() > 5 * 86400000
    far or old
if dZones.size() > 0
    for i = dZones.size() - 1 to 0
        b = dZones.get(i)
        if close < b.get_bottom() or zoneStale(b)
            box.delete(b)
            dZones.remove(i)
if sZones.size() > 0
    for i = sZones.size() - 1 to 0
        b = sZones.get(i)
        if close > b.get_top() or zoneStale(b)
            box.delete(b)
            sZones.remove(i)
 
// ───────────────────────── First hour range (Initial Balance) ─────────────────────────
inIB = inSess(ibSess)
ibStartBar = inIB and not inIB[1]
ibEndBar = not inIB and inIB[1]
var float ibH = na
var float ibL = na
var float ibM = na
var bool ibDone = false
var bool narrow = false
var array<float> ibHist = array.new<float>()
var box ibBox = na
 
if ibStartBar
    ibH := high
    ibL := low
    ibM := na
    ibDone := false
    narrow := false
    ibBox := box.new(time, high, time, low, xloc = xloc.bar_time, border_color = color.new(cKey, 65), bgcolor = color.new(cKey, 92), text = "First hour range", text_color = color.new(cKey, 20), text_size = txtSz, text_halign = text.align_left, text_valign = text.align_top)
    keepBox(ibBox)
if inIB and not na(ibH)
    ibH := math.max(ibH, high)
    ibL := math.min(ibL, low)
    box.set_top(ibBox, ibH)
    box.set_bottom(ibBox, ibL)
    box.set_right(ibBox, time)
if ibEndBar and not na(ibH)
    ibDone := true
    ibM := (ibH + ibL) / 2
    rng = ibH - ibL
    avg = ibHist.size() > 0 ? ibHist.avg() : na
    narrow := not na(avg) and rng < narrowX * avg
    ibHist.push(rng)
    if ibHist.size() > 10
        ibHist.shift()
    box.set_text(ibBox, narrow ? "First hour range\nNarrow: expect a breakout or chop" : "First hour range")
    if showIB
        level(ibH, "First Hour High", cKey, 2, line.style_solid)
        level(ibM, "First Hour Middle", color.new(cKey, 30), 1, line.style_dashed)
        level(ibL, "First Hour Low", cKey, 2, line.style_solid)
if newDay
    ibDone := false
var string ibTrend = "none"
var float ibOpen = na
if ibStartBar
    ibOpen := open
if ibEndBar and not na(ibM)
    ibTrend := close > ibM and close > ibOpen ? "up" : close < ibM and close < ibOpen ? "down" : "none"
 
// New York VWAP from 9:30
var float vSum = 0.0
var float vVol = 0.0
if rthStart
    vSum := 0.0
    vVol := 0.0
if inRTH
    vSum += hlc3 * nz(volume)
    vVol += nz(volume)
nyVWAP = inRTH and vVol > 0 ? vSum / vVol : na
plot(showVW ? nyVWAP : na, "New York VWAP", cNeutral, 2, plot.style_linebr)
atr1 = ta.atr(14)
tol = confTol * atr1 * 1.4
flatVW = not na(nyVWAP) and not na(nyVWAP[12]) and math.abs(nyVWAP - nyVWAP[12]) < 0.25 * atr1
 
// ───────────────────────── News ─────────────────────────
inNews() =>
    bool hit = false
    if newsOn
        for s in str.split(newsList, ",")
            st = str.trim(s)
            if str.length(st) == 4
                nh = int(str.tonumber(str.substring(st, 0, 2)))
                nm = int(str.tonumber(str.substring(st, 2, 4)))
                d = (hh * 60 + mm) - (nh * 60 + nm)
                if d >= -newsMin and d <= newsMin
                    hit := true
    hit
newsNow = inNews()
bgcolor(newsBG and newsNow ? color.new(cSell, 90) : na, title = "News window")
 
// ───────────────────────── Watch spots ─────────────────────────
var int setupsToday = 0
var bool brokeUp = false
var bool brokeDn = false
var int upBars = 0
var int dnBars = 0
var float upExt = na
var float dnExt = na
var string trend = "none"
type Trade
    int dir
    string nm
    string why
    string conf
    float lvl
    float s
    string sizeTxt
    int bi
    int t
var Trade tr = na
var Trade lastTr = na
var int lastBi = -1
 
if newDay
    setupsToday := 0
    brokeUp := false
    brokeDn := false
    trend := "none"
    tr := na
    lastTr := na
 
// which other lines sit near price p, in plain words
stackAt(float p) =>
    array<string> out = array.new<string>()
    if not na(p)
        if not na(pdH) and math.abs(p - pdH) <= tol
            out.push("Yesterday's High")
        if not na(pdL) and math.abs(p - pdL) <= tol
            out.push("Yesterday's Low")
        if not na(sVAH) and math.abs(p - sVAH) <= tol
            out.push("Value High")
        if not na(sVAL) and math.abs(p - sVAL) <= tol
            out.push("Value Low")
        if not na(sPOC) and math.abs(p - sPOC) <= tol
            out.push("Busiest Price")
        if not na(wVAH) and math.abs(p - wVAH) <= tol
            out.push("Week Value High")
        if not na(wVAL) and math.abs(p - wVAL) <= tol
            out.push("Week Value Low")
        if not na(lH) and math.abs(p - lH) <= tol
            out.push("London High")
        if not na(lL) and math.abs(p - lL) <= tol
            out.push("London Low")
        if not na(nyVWAP) and math.abs(p - nyVWAP) <= tol * 0.6 and (hh * 60 + mm) >= 600
            out.push("VWAP")
        bool inBuy = false
        for b in dZones
            if p >= b.get_bottom() - tol and p <= b.get_top() + tol
                inBuy := true
        if inBuy
            out.push("a buy zone")
        bool inSell = false
        for b in sZones
            if p >= b.get_bottom() - tol and p <= b.get_top() + tol
                inSell := true
        if inSell
            out.push("a sell zone")
    out.join(", ")
 
// small marker at the wick + a short straight line on the level that got tested. The explanation lives in the panel.
open_trade(int dir, string nm, string why, float lvl, float s) =>
    dist = math.abs(close - s)
    cts = dist > 0 ? int(math.floor(riskUSD / (dist * pv))) : 0
    mic = dist > 0 ? int(math.floor(riskUSD / (dist * pv / 10))) : 0
    sizeTxt = cts >= 1 ? str.tostring(cts) + (cts == 1 ? " contract" : " contracts") : mic >= 1 ? str.tostring(mic) + (mic == 1 ? " micro" : " micros") : "Stop is too wide for $" + str.tostring(riskUSD, "#")
    col = dir > 0 ? cBuy : cSell
    dayLines.push(line.new(bar_index - 2, lvl, bar_index + 6, lvl, color = col, width = 3))
    dayLabels.push(label.new(bar_index, dir > 0 ? low : high, nm, style = dir > 0 ? label.style_label_up : label.style_label_down, color = color.new(col, 10), textcolor = cInk, size = txtSz))
    Trade.new(dir, nm, why, stackAt(lvl), lvl, s, sizeTxt, bar_index, time)
 
isEdge = mode == "Morning sweep"
lunchNow = lunchOn and inSess(lunch)
canTrade = not isEdge and ibDone and inSess(cutoff) and not newsNow and not lunchNow and setupsToday < maxPer and na(tr)
buf = bufTk * tick
 
if ibDone and not na(ibM)
    // track breaks of the first hour range
    if high > ibH
        if not brokeUp
            brokeUp := true
            upBars := 0
            upExt := high
        upExt := math.max(nz(upExt, high), high)
    if low < ibL
        if not brokeDn
            brokeDn := true
            dnBars := 0
            dnExt := low
        dnExt := math.min(nz(dnExt, low), low)
    if brokeUp
        upBars += 1
    if brokeDn
        dnBars += 1
    if trend == "none" and ibTrend != "none"
        trend := ibTrend
    if close > ibH
        trend := "up"
    if close < ibL
        trend := "down"
    // failed breakout: broke out, closed back inside within faBars
    if canTrade and showFA and brokeUp and upBars <= faBars and close < ibH and close[1] >= ibL
        tr := open_trade(-1, "Failed breakout", "Price broke above the First Hour High, then closed back inside", ibH, upExt + buf)
        setupsToday += 1
        brokeUp := false
    else if canTrade and showFA and brokeDn and dnBars <= faBars and close > ibL
        tr := open_trade(1, "Failed breakdown", "Price broke below the First Hour Low, then closed back inside", ibL, dnExt - buf)
        setupsToday += 1
        brokeDn := false
    // middle hold: trend side established, pullback tags the middle and rejects
    else if canTrade and showMH and not flatVW and trend == "up" and low <= ibM and close > ibM and close > open
        tr := open_trade(1, "Middle held", "Up day pulled back to the First Hour Middle and bounced", ibM, low - buf)
        setupsToday += 1
        trend := "none"
    else if canTrade and showMH and not flatVW and trend == "down" and high >= ibM and close < ibM and close < open
        tr := open_trade(-1, "Middle held", "Down day pulled back to the First Hour Middle and got rejected", ibM, high + buf)
        setupsToday += 1
        trend := "none"
    if brokeUp and upBars > faBars
        brokeUp := false
    if brokeDn and dnBars > faBars
        brokeDn := false
 
// ───── Morning sweep: 9:40-10:30, price runs the Asia / overnight extreme and closes back inside ─────
var float onHi = na
var float onLo = na
var float eaH = na
var float eaL = na
var bool usedHi = false
var bool usedLo = false
if newDay
    onHi := high
    onLo := low
    eaH := na
    eaL := na
    usedHi := false
    usedLo := false
if not inRTH and not na(onHi) and (hh >= 17 or hh < 10)
    onHi := math.max(onHi, high)
    onLo := math.min(onLo, low)
if inSess(edgeAsia)
    eaH := na(eaH) ? high : math.max(eaH, high)
    eaL := na(eaL) ? low : math.min(eaL, low)
inEdge = inSess(edgeWin)
canEdge = isEdge and inEdge and setupsToday < 2 and na(tr)
if canEdge
    float hiLvl = na
    string hiName = ""
    if not usedHi and not na(eaH) and high > eaH and close < eaH
        hiLvl := eaH
        hiName := "Asia high"
    else if not usedHi and not na(onHi) and high > onHi and close < onHi
        hiLvl := onHi
        hiName := "Overnight high"
    float loLvl = na
    string loName = ""
    if not usedLo and not na(eaL) and low < eaL and close > eaL
        loLvl := eaL
        loName := "Asia low"
    else if not usedLo and not na(onLo) and low < onLo and close > onLo
        loLvl := onLo
        loName := "Overnight low"
    if not na(hiLvl)
        tr := open_trade(-1, hiName + " swept", "Price poked above the " + str.lower(hiName) + " and closed back under it", hiLvl, high + buf)
        setupsToday += 1
        usedHi := true
    else if not na(loLvl)
        tr := open_trade(1, loName + " swept", "Price dipped below the " + str.lower(loName) + " and closed back above it", loLvl, low - buf)
        setupsToday += 1
        usedLo := true
 
newTrade = not na(tr) and tr.bi != lastBi
if newTrade
    lastTr := tr
    lastBi := tr.bi
// a watch spot stays live for 6 bars, then the next one can show
if not na(tr) and bar_index - tr.bi >= 6
    tr := na
if rthEnd
    tr := na
 
// ───────────────────────── Asia range + overnight read ─────────────────────────
inAs = inSess(asSess)
asStart = inAs and not inAs[1]
asEnd = not inAs and inAs[1]
var float aH = na
var float aL = na
var box aBox = na
var int bias = 0
var string biasTxt = "Waiting for the Asia range"
var bool asReady = false
if showAs
    if asStart
        aH := high
        aL := low
        asReady := false
        bias := 0
        biasTxt := "Asia range is building"
        aBox := box.new(time, high, time, low, xloc = xloc.bar_time, border_color = color.new(cNeutral, 50), bgcolor = color.new(cNeutral, 88), text = "Asia range", text_color = color.new(cText, 35), text_size = txtSz, text_halign = text.align_left, text_valign = text.align_top)
        keepBox(aBox)
    if inAs and not na(aH)
        aH := math.max(aH, high)
        aL := math.min(aL, low)
        box.set_top(aBox, aH)
        box.set_bottom(aBox, aL)
        box.set_right(aBox, time)
    if asEnd
        asReady := true
        biasTxt := "No lean yet. Price is still inside the Asia range"
    if asReady and not inRTH and bias == 0
        if high > aH and close < aH
            bias := -1
            biasTxt := "Leaning down. Price ran the Asia high and got pushed back in"
        else if low < aL and close > aL
            bias := 1
            biasTxt := "Leaning up. Price ran the Asia low and got pushed back in"
        else if close > aH
            bias := 1
            biasTxt := "Leaning up. Price broke out above the Asia range"
        else if close < aL
            bias := -1
            biasTxt := "Leaning down. Price broke down below the Asia range"
    if rthStart
        asReady := false
 
// ───────────────────────── Alerts ─────────────────────────
alertcondition(newTrade and tr.dir > 0, "Watch spot (a low got swept)", "NY Map: a low got swept and price closed back above it on {{ticker}} at {{close}}. Watch only, your read decides.")
alertcondition(newTrade and tr.dir < 0, "Watch spot (a high got swept)", "NY Map: a high got swept and price closed back under it on {{ticker}} at {{close}}. Watch only, your read decides.")
xUp = ta.cross(high, aH)
xDn = ta.cross(aL, low)
alertcondition(asReady and not inRTH and (xUp or xDn), "Asia range touched", "NY Map: price reached the edge of the Asia range on {{ticker}}")
 
// line names ride just right of the latest candle so they are always on screen
if barstate.islast
    tx = time + 3 * timeframe.in_seconds() * 1000
    for lb in lvlLabels
        label.set_x(lb, tx)
    for ln in lvlLines
        line.set_x2(ln, tx)
 
// ───────────────────────── Playbook panel ─────────────────────────
var table hud = table.new(hudPos == "Top right" ? position.top_right : hudPos == "Bottom left" ? position.bottom_left : hudPos == "Top left" ? position.top_left : position.bottom_right, 2, 10, bgcolor = cPanel, border_color = color.new(cNeutral, 75), border_width = 1, frame_color = color.new(cKey, 45), frame_width = 1)
nameOf(float p) =>
    p == pdH ? "Yesterday's High" : p == pdL ? "Yesterday's Low" : p == sVAH ? "Value High" : p == sPOC ? "Busiest Price" : p == sVAL ? "Value Low" : p == wVAH ? "Week Value High" : p == wPOC ? "Week Busiest Price" : p == wVAL ? "Week Value Low" : p == ibH ? "First Hour High" : p == ibM ? "First Hour Middle" : p == ibL ? "First Hour Low" : p == lH ? "London High" : p == lL ? "London Low" : "level"
nearest(bool above) =>
    float best = na
    for p in array.from(pdH, pdL, sVAH, sPOC, sVAL, wVAH, wPOC, wVAL, ibH, ibM, ibL, lH, lL)
        if not na(p)
            if above and p > close and (na(best) or p < best)
                best := p
            if not above and p < close and (na(best) or p > best)
                best := p
    best
row(int r, string k, string v, color vc) =>
    table.cell(hud, 0, r, k, text_color = color.new(cText, 40), text_size = txtSz, text_halign = text.align_left)
    table.cell(hud, 1, r, v, text_color = vc, text_size = txtSz, text_halign = text.align_left)
if showHUD and barstate.islast
    table.cell(hud, 0, 0, "NY SESSION MAP", text_color = cKey, text_size = txtSz, text_halign = text.align_left)
    table.cell(hud, 1, 0, "[Aurabot]  ·  " + mode, text_color = color.new(cText, 35), text_size = txtSz, text_halign = text.align_left)
    row(1, "Overnight", biasTxt, bias > 0 ? cBuy : bias < 0 ? cSell : color.new(cText, 30))
    row(2, "First hour", inIB ? "Building now (9:30 to 10:30)" : ibDone ? str.tostring(ibH - ibL, format.mintick) + " points wide" + (narrow ? ". Narrow day: expect a breakout or chop" : "") : "Starts at 9:30", narrow ? cKey : cText)
    up = nearest(true)
    dn = nearest(false)
    row(3, "Closest above", na(up) ? "Nothing close" : px(up) + "  " + nameOf(up), cSell)
    row(4, "Closest below", na(dn) ? "Nothing close" : px(dn) + "  " + nameOf(dn), cBuy)
    live = not na(tr)
    lc = na(lastTr) ? color.new(cText, 30) : lastTr.dir > 0 ? cBuy : cSell
    row(5, "What happened", na(lastTr) ? "Nothing yet. Let price come to a line." : str.format_time(lastTr.t, "h:mm", TZ) + "  " + lastTr.why + (str.length(lastTr.conf) > 0 ? ". Also lines up with " + lastTr.conf : ""), lc)
    row(6, "What to watch", na(lastTr) ? "Spots where several lines stack together" : (lastTr.dir > 0 ? "Buyers holding above " : "Sellers holding below ") + px(lastTr.lvl) + (live ? ". Your read decides." : ". This one has passed."), na(lastTr) ? color.new(cText, 30) : live ? lc : color.new(cText, 40))
    row(7, "If you take it", na(lastTr) or not live ? "Stop goes past the wick of the marker candle" : "Stop " + (lastTr.dir > 0 ? "under " : "over ") + px(lastTr.s) + ". " + lastTr.sizeTxt + " for $" + str.tostring(riskUSD, "#") + " risk", cText)
    row(8, "Your risk", "$" + str.tostring(riskUSD, "#") + " a trade. " + str.tostring(math.floor(dllUSD / riskUSD)) + " losses ($" + str.tostring(dllUSD, "#") + ") and you are done for the day", cText)
    string st = ""
    color sc = cText
    if isEdge
        if inEdge
            st := setupsToday >= 2 ? "Done for today. 2 watch spots already showed." : "Window is open (9:40 to 10:30). Max 2 a day."
            sc := setupsToday >= 2 ? cSell : cKey
        else if inRTH and (hh * 60 + mm) < 580
            st := "Wait. The open is choppy, the window starts at 9:40"
            sc := cSell
        else if inRTH
            st := "Window closed. Protect your day."
        else
            st := "Prep time. Mark the lines before New York opens."
    else
        if newsNow
            st := "News is out. Stay flat for a few minutes."
            sc := cSell
        else if lunchNow
            st := "Lunch. Low volume, easy to get chopped up."
            sc := cSell
        else if flatVW and inRTH
            st := "VWAP is flat. Choppy, only fades at the edges."
            sc := cSell
        else if inSess("1500-1600")
            st := "Last hour. Usually best to sit out."
            sc := cSell
        else if inSess(cutoff)
            st := "Watching the first hour lines."
            sc := cKey
        else
            st := "Opens after 10:30, once the first hour is set."
    row(9, "Right now", st, sc)

← 返回列表