MM Flow
FlowScripts

Perfected FlowScript

Market Sessions • [Leviathan]

Market Sessions [Leviathan] Perfected is indexed as 064_market_sessions_leviathan.flowscript. The exact FlowScript is viewable here; chart observe and trading automation use the current mmflow chart/recipe signal proxy until FlowScript v2 transpilation is available.

This exact FlowScript uses the v2 source dialect. It is viewable and connected to the chart/automation proxy, but direct editor execution needs the FlowScript v2 transpiler.

Dialect

flowscript-v2

Compatibility

flowscript-v2-needs-transpile

Position

onchart

Axis

false

Size

23.3 KB

Lines

624

Native Signal Candidates

8 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.

8/8 guarded

Tokyo Open

line 354:5

Trigger

(showOpenMarkers && tokOpenEvent)

Value

tokOpen

Deps

showOpenMarkers:input, tokOpenEvent:var

London Open

line 405:5

Trigger

(showOpenMarkers && lonOpenEvent)

Value

lonOpen

Deps

lonOpenEvent:var, showOpenMarkers:input

NY Open

line 456:5

Trigger

(showOpenMarkers && nyOpenEvent)

Value

nyOpen

Deps

nyOpenEvent:var, showOpenMarkers:input

Sydney Open

line 507:5

Trigger

(showOpenMarkers && sydOpenEvent)

Value

sydOpen

Deps

showOpenMarkers:input, sydOpenEvent:var

Asian KZ Start

line 558:5

Trigger

(showKZMarkers && kzAsianEvent)

Value

l

Deps

kzAsianEvent:var, showKZMarkers:input

London KZ Start

line 568:5

Trigger

(showKZMarkers && kzLondonEvent)

Value

l

Deps

kzLondonEvent:var, showKZMarkers:input

NY KZ Start

line 578:5

Trigger

(showKZMarkers && kzNyEvent)

Value

l

Deps

kzNyEvent:var, showKZMarkers:input

Unlabeled shape

line 613:9

Trigger

(showSessionLabels && isLastBar) && (sessLabel != "")

Value

h

Deps

isLastBar:builtin, sessLabel:var, showSessionLabels:input

064_market_sessions_leviathan.flowscript

source path: kscripts/perfected/064_market_sessions_leviathan.flowscript · sha256:65d8716ad88447ecce95a82fd3c816f7afbb056d5ac0ccfd51180c5f66f2eeb3

hash verified
//@version=2
// Source: kiyotaka.ai/hub/kscript (original) — Perfected by kScript_Perfection_Engineer

// ============================================================================
// Market Sessions — Trading Session Detection & Killzones [Leviathan Perfected]
// Author: Leviathan (@Leviathan) — Perfected by kScript_Perfection_Engineer
// Tags: CORE, #session, #killzone, #marketprofile, #initialbalance, #leviathan
//
// Production-grade session detection with anchored session high/low boxes,
// ICT killzone highlighting, session-open markers, overlap detection, and
// initial-balance tracking. Implements proper session tracking using static
// variables for cumulative session ranges rather than naive rolling-window
// approximations.
//
// Research papers underpinning this design:
//  - Harris (1986), "A Transaction Data Study of Weekly and Intradaily
//    Patterns in Stock Returns": seminal intraday seasonality; U-shaped
//    volume/volatility curves; first 45-min opening effects; negative Monday
//    close-to-close returns accrue between Friday close and Monday open.
//  - Ito & Hashimoto (2006), "Intraday Seasonality in Activities of the
//    Foreign Exchange Markets": overlapping sessions (London/NY) generate
//    highest volatility and volume clustering; no daily U-shape for NY.
//  - Heston, Korajczyk & Sadka (2010), "Intra-day Patterns in the Cross-
//    Section of Stock Returns": first and last half-hour effects; 11 bps
//    opening half-hour decile spread; return effect persists across days.
//  - Steidlmayer & Hawkins (2002), "Steidlmayer on Markets": Initial Balance
//    concept (price range in first hour) as reference for remainder of session.
//  - ICT / Huddleston (2010–present), Killzone methodology: Asian (00:00–05:00),
//    London (07:00–10:00), NY (13:00–16:00) as liquidity windows where
//    institutional order flow creates directional moves.
// ============================================================================

define(
    title="Market Sessions [Leviathan] Perfected",
    position="onchart",
    axis=false
)

// ---------------------------------------------------------------------------
// User Inputs
// ---------------------------------------------------------------------------

// --- Session Configuration ---
var tokyoStart   = input(name="tokyoStart",   type="number", defaultValue=0,  label="Tokyo Start (UTC hour)",   constraints={min: 0, max: 23, step: 1}, group="Session Config")
var tokyoEnd     = input(name="tokyoEnd",     type="number", defaultValue=9,  label="Tokyo End (UTC hour)",     constraints={min: 0, max: 23, step: 1}, group="Session Config")
var londonStart  = input(name="londonStart",  type="number", defaultValue=8,  label="London Start (UTC hour)",  constraints={min: 0, max: 23, step: 1}, group="Session Config")
var londonEnd    = input(name="londonEnd",    type="number", defaultValue=16, label="London End (UTC hour)",    constraints={min: 0, max: 23, step: 1}, group="Session Config")
var nyStart      = input(name="nyStart",      type="number", defaultValue=13, label="New York Start (UTC hour)", constraints={min: 0, max: 23, step: 1}, group="Session Config")
var nyEnd        = input(name="nyEnd",        type="number", defaultValue=21, label="New York End (UTC hour)",   constraints={min: 0, max: 23, step: 1}, group="Session Config")
var sydneyStart  = input(name="sydneyStart",  type="number", defaultValue=22, label="Sydney Start (UTC hour)",  constraints={min: 0, max: 23, step: 1}, group="Session Config")
var sydneyEnd    = input(name="sydneyEnd",    type="number", defaultValue=7,  label="Sydney End (UTC hour)",    constraints={min: 0, max: 23, step: 1}, group="Session Config")
var tzOffsetH    = input(name="tzOffsetH",    type="number", defaultValue=0,  label="Timezone Offset (hours from UTC)", constraints={min: -12, max: 14, step: 1}, group="Session Config")

// --- Killzone Configuration ---
var showKillzones = input(name="showKillzones", type="boolean", defaultValue=true, label="Show Killzones", group="Killzones")
var asianKZStart  = input(name="asianKZStart",  type="number", defaultValue=0,  label="Asian KZ Start (UTC)",  constraints={min: 0, max: 23, step: 1}, group="Killzones")
var asianKZEnd    = input(name="asianKZEnd",    type="number", defaultValue=5,  label="Asian KZ End (UTC)",    constraints={min: 0, max: 23, step: 1}, group="Killzones")
var londonKZStart = input(name="londonKZStart", type="number", defaultValue=7,  label="London KZ Start (UTC)", constraints={min: 0, max: 23, step: 1}, group="Killzones")
var londonKZEnd   = input(name="londonKZEnd",   type="number", defaultValue=10, label="London KZ End (UTC)",  constraints={min: 0, max: 23, step: 1}, group="Killzones")
var nyKZStart     = input(name="nyKZStart",     type="number", defaultValue=13, label="NY KZ Start (UTC)",    constraints={min: 0, max: 23, step: 1}, group="Killzones")
var nyKZEnd       = input(name="nyKZEnd",       type="number", defaultValue=16, label="NY KZ End (UTC)",      constraints={min: 0, max: 23, step: 1}, group="Killzones")
var showKZMarkers = input(name="showKZMarkers", type="boolean", defaultValue=true, label="Show KZ Start Markers", group="Killzones")

// --- Display ---
var showSessionBoxes   = input(name="showSessionBoxes",   type="boolean", defaultValue=true,  label="Show Session Boxes", group="Display")
var showSessionHiLo    = input(name="showSessionHiLo",    type="boolean", defaultValue=true,  label="Show Session Hi/Lo Lines", group="Display")
var showSessionLabels  = input(name="showSessionLabels",  type="boolean", defaultValue=true,  label="Show Session Labels", group="Display")
var showOpenMarkers    = input(name="showOpenMarkers",    type="boolean", defaultValue=true,  label="Show Session Open Markers", group="Display")
var showOverlap        = input(name="showOverlap",        type="boolean", defaultValue=true,  label="Show Overlap Highlight", group="Display")
var showInitialBalance = input(name="showInitialBalance", type="boolean", defaultValue=false, label="Show Initial Balance (first hour)", group="Display")
var lineWidth          = input(name="lineWidth",          type="number",  defaultValue=2,     label="Line Width", constraints={min: 1, max: 4, step: 1}, group="Display")
var shapeSize          = input(name="shapeSize",          type="number",  defaultValue=2,     label="Shape Size", constraints={min: 1, max: 4, step: 1}, group="Display")

// --- Colors ---
var tokyoColor   = input(name="tokyoColor",   type="color", defaultValue="#ffeb3b80", label="Tokyo Color",   group="Colors")
var londonColor  = input(name="londonColor",  type="color", defaultValue="#42a5f580", label="London Color",  group="Colors")
var nyColor      = input(name="nyColor",      type="color", defaultValue="#ab47bc80", label="New York Color", group="Colors")
var sydneyColor  = input(name="sydneyColor",  type="color", defaultValue="#26a69a80", label="Sydney Color",  group="Colors")
var kzColor      = input(name="kzColor",      type="color", defaultValue="#ff174490", label="Killzone Color", group="Colors")
var overlapColor = input(name="overlapColor", type="color", defaultValue="#ffffff40", label="Overlap Color", group="Colors")
var ibColor      = input(name="ibColor",      type="color", defaultValue="#ff980080", label="Initial Balance Color", group="Colors")

// ---------------------------------------------------------------------------
// Data Sources
// ---------------------------------------------------------------------------
timeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries t = bars.time
timeseries h = bars.high
timeseries l = bars.low
timeseries c = bars.close
timeseries v = bars.volume

// isnan guard: prevent computation on incomplete data
if (isnan(t[0]) || isnan(h[0]) || isnan(l[0]) || isnan(c[0]) || isnan(v[0])) {
    return
}

// ---------------------------------------------------------------------------
// Time Derivation (Calendar Math)
// ---------------------------------------------------------------------------
timeseries rawH = math.floor((t / 3600000) % 24)
timeseries utcH = ((rawH + tzOffsetH) % 24 + 24) % 24
var dayId = math.floor(t / 86400000)

// ---------------------------------------------------------------------------
// Session Detection (wraparound-aware hour logic)
// ---------------------------------------------------------------------------
// A session spans [start, end UTC hours. If start > end, the session wraps
// across midnight (e.g., Sydney 22:00–07:00).
var isTokyo   = tokyoStart   <= tokyoEnd   ? (utcH >= tokyoStart   && utcH < tokyoEnd)   : (utcH >= tokyoStart   || utcH < tokyoEnd)
var isLondon  = londonStart  <= londonEnd  ? (utcH >= londonStart  && utcH < londonEnd)  : (utcH >= londonStart  || utcH < londonEnd)
var isNy      = nyStart      <= nyEnd      ? (utcH >= nyStart      && utcH < nyEnd)      : (utcH >= nyStart      || utcH < nyEnd)
var isSydney  = sydneyStart  <= sydneyEnd  ? (utcH >= sydneyStart  && utcH < sydneyEnd)  : (utcH >= sydneyStart  || utcH < sydneyEnd)

// ---------------------------------------------------------------------------
// Killzone Detection (ICT liquidity windows)
// ---------------------------------------------------------------------------
var isAsianKZ  = asianKZStart  <= asianKZEnd  ? (utcH >= asianKZStart  && utcH < asianKZEnd)  : (utcH >= asianKZStart  || utcH < asianKZEnd)
var isLondonKZ = londonKZStart <= londonKZEnd ? (utcH >= londonKZStart && utcH < londonKZEnd) : (utcH >= londonKZStart || utcH < londonKZEnd)
var isNyKZ     = nyKZStart     <= nyKZEnd     ? (utcH >= nyKZStart     && utcH < nyKZEnd)     : (utcH >= nyKZStart     || utcH < nyKZEnd)

// ---------------------------------------------------------------------------
// Overlap Detection (London/NY overlap = highest volatility)
// ---------------------------------------------------------------------------
var isOverlap = isLondon && isNy

// ---------------------------------------------------------------------------
// Static Session State (anchored tracking per session)
// ---------------------------------------------------------------------------
// Session entry flags (0 = not in session, 1 = in session)
static inTokyo = 0
static inLondon = 0
static inNy = 0
static inSydney = 0

// Anchored session high/low (reset on session entry)
static tokHi = 0.0
static tokLo = 0.0
static lonHi = 0.0
static lonLo = 0.0
static nyHi = 0.0
static nyLo = 0.0
static sydHi = 0.0
static sydLo = 0.0

// Session open price (first close of the session)
static tokOpen = 0.0
static lonOpen = 0.0
static nyOpen = 0.0
static sydOpen = 0.0

// Session volume (cumulative)
static tokVol = 0.0
static lonVol = 0.0
static nyVol = 0.0
static sydVol = 0.0

// Initial Balance (first hour of session)
static tokIBHi = 0.0
static tokIBLo = 0.0
static lonIBHi = 0.0
static lonIBLo = 0.0
static nyIBHi = 0.0
static nyIBLo = 0.0
static sydIBHi = 0.0
static sydIBLo = 0.0
static tokIBDone = 0
static lonIBDone = 0
static nyIBDone = 0
static sydIBDone = 0

// Bar indices for event tracking
static tokOpenBar = 0
static lonOpenBar = 0
static nyOpenBar = 0
static sydOpenBar = 0

static kzAsianBar = 0
static kzLondonBar = 0
static kzNyBar = 0

static barCount = 0
if (!isLiveUpdate) {
    barCount = barCount + 1
}

// ---------------------------------------------------------------------------
// State Update (only on bar close for consistency)
// ---------------------------------------------------------------------------
if (!isLiveUpdate) {
    // --- Tokyo session ---
    if (isTokyo && inTokyo == 0) {
        inTokyo = 1
        tokHi = h
        tokLo = l
        tokOpen = c
        tokVol = v
        tokOpenBar = barCount
        tokIBDone = 0
        tokIBHi = h
        tokIBLo = l
    } else if (!isTokyo && inTokyo == 1) {
        inTokyo = 0
    }
    if (inTokyo == 1) {
        tokHi = math.max(tokHi, h)
        tokLo = math.min(tokLo, l)
        tokVol = tokVol + v
        if (tokIBDone == 0) {
            tokIBHi = math.max(tokIBHi, h)
            tokIBLo = math.min(tokIBLo, l)
            if (barCount - tokOpenBar >= 3) { // ~1 hour on 15-min or 4 bars on 15m
                tokIBDone = 1
            }
        }
    }

    // --- London session ---
    if (isLondon && inLondon == 0) {
        inLondon = 1
        lonHi = h
        lonLo = l
        lonOpen = c
        lonVol = v
        lonOpenBar = barCount
        lonIBDone = 0
        lonIBHi = h
        lonIBLo = l
    } else if (!isLondon && inLondon == 1) {
        inLondon = 0
    }
    if (inLondon == 1) {
        lonHi = math.max(lonHi, h)
        lonLo = math.min(lonLo, l)
        lonVol = lonVol + v
        if (lonIBDone == 0) {
            lonIBHi = math.max(lonIBHi, h)
            lonIBLo = math.min(lonIBLo, l)
            if (barCount - lonOpenBar >= 3) {
                lonIBDone = 1
            }
        }
    }

    // --- New York session ---
    if (isNy && inNy == 0) {
        inNy = 1
        nyHi = h
        nyLo = l
        nyOpen = c
        nyVol = v
        nyOpenBar = barCount
        nyIBDone = 0
        nyIBHi = h
        nyIBLo = l
    } else if (!isNy && inNy == 1) {
        inNy = 0
    }
    if (inNy == 1) {
        nyHi = math.max(nyHi, h)
        nyLo = math.min(nyLo, l)
        nyVol = nyVol + v
        if (nyIBDone == 0) {
            nyIBHi = math.max(nyIBHi, h)
            nyIBLo = math.min(nyIBLo, l)
            if (barCount - nyOpenBar >= 3) {
                nyIBDone = 1
            }
        }
    }

    // --- Sydney session ---
    if (isSydney && inSydney == 0) {
        inSydney = 1
        sydHi = h
        sydLo = l
        sydOpen = c
        sydVol = v
        sydOpenBar = barCount
        sydIBDone = 0
        sydIBHi = h
        sydIBLo = l
    } else if (!isSydney && inSydney == 1) {
        inSydney = 0
    }
    if (inSydney == 1) {
        sydHi = math.max(sydHi, h)
        sydLo = math.min(sydLo, l)
        sydVol = sydVol + v
        if (sydIBDone == 0) {
            sydIBHi = math.max(sydIBHi, h)
            sydIBLo = math.min(sydIBLo, l)
            if (barCount - sydOpenBar >= 3) {
                sydIBDone = 1
            }
        }
    }

    // --- Killzone start tracking ---
    if (isAsianKZ && kzAsianBar != barCount) {
        kzAsianBar = barCount
    }
    if (isLondonKZ && kzLondonBar != barCount) {
        kzLondonBar = barCount
    }
    if (isNyKZ && kzNyBar != barCount) {
        kzNyBar = barCount
    }
}

// ---------------------------------------------------------------------------
// Event Flags for Plotting
// ---------------------------------------------------------------------------
var tokOpenEvent = tokOpenBar == barCount
var lonOpenEvent = lonOpenBar == barCount
var nyOpenEvent  = nyOpenBar == barCount
var sydOpenEvent = sydOpenBar == barCount

var kzAsianEvent  = kzAsianBar == barCount
var kzLondonEvent = kzLondonBar == barCount
var kzNyEvent     = kzNyBar == barCount

// ---------------------------------------------------------------------------
// Plotting: Tokyo Session
// ---------------------------------------------------------------------------
if (showSessionBoxes && inTokyo == 1) {
    var tokFill = opacity(tokyoColor, 25)
    plotLine(
        value=[tokHi, tokLo],
        width=1,
        colors=[tokyoColor, tokyoColor],
        fill=tokFill,
        label=["Tokyo Box", "Tokyo Box"],
        desc=["Tokyo session high/low anchored range", "Tokyo session low boundary"]
    )
}
if (showSessionHiLo && inTokyo == 1) {
    plotLine(
        value=tokHi,
        width=lineWidth,
        colors=[tokyoColor],
        label=["Tokyo Hi"],
        desc=["Tokyo session anchored high"]
    )
    plotLine(
        value=tokLo,
        width=lineWidth,
        colors=[tokyoColor],
        label=["Tokyo Lo"],
        desc=["Tokyo session anchored low"]
    )
}
if (showOpenMarkers && tokOpenEvent) {
    plotShape(
        value=tokOpen,
        shape="triangleup",
        colorIndex=tokyoColor,
        width=shapeSize,
        label=["Tokyo Open"],
        desc=["Tokyo session open marker"]
    )
}
if (showInitialBalance && inTokyo == 1 && tokIBDone == 1) {
    plotLine(
        value=[tokIBHi, tokIBLo],
        width=1,
        colors=[ibColor, ibColor],
        fill=opacity(ibColor, 20),
        label=["Tokyo IB", "Tokyo IB"],
        desc=["Tokyo Initial Balance (first hour) high", "Tokyo Initial Balance low"]
    )
}

// ---------------------------------------------------------------------------
// Plotting: London Session
// ---------------------------------------------------------------------------
if (showSessionBoxes && inLondon == 1) {
    var lonFill = opacity(londonColor, 25)
    plotLine(
        value=[lonHi, lonLo],
        width=1,
        colors=[londonColor, londonColor],
        fill=lonFill,
        label=["London Box", "London Box"],
        desc=["London session high/low anchored range", "London session low boundary"]
    )
}
if (showSessionHiLo && inLondon == 1) {
    plotLine(
        value=lonHi,
        width=lineWidth,
        colors=[londonColor],
        label=["London Hi"],
        desc=["London session anchored high"]
    )
    plotLine(
        value=lonLo,
        width=lineWidth,
        colors=[londonColor],
        label=["London Lo"],
        desc=["London session anchored low"]
    )
}
if (showOpenMarkers && lonOpenEvent) {
    plotShape(
        value=lonOpen,
        shape="triangleup",
        colorIndex=londonColor,
        width=shapeSize,
        label=["London Open"],
        desc=["London session open marker"]
    )
}
if (showInitialBalance && inLondon == 1 && lonIBDone == 1) {
    plotLine(
        value=[lonIBHi, lonIBLo],
        width=1,
        colors=[ibColor, ibColor],
        fill=opacity(ibColor, 20),
        label=["London IB", "London IB"],
        desc=["London Initial Balance (first hour) high", "London Initial Balance low"]
    )
}

// ---------------------------------------------------------------------------
// Plotting: New York Session
// ---------------------------------------------------------------------------
if (showSessionBoxes && inNy == 1) {
    var nyFill = opacity(nyColor, 25)
    plotLine(
        value=[nyHi, nyLo],
        width=1,
        colors=[nyColor, nyColor],
        fill=nyFill,
        label=["NY Box", "NY Box"],
        desc=["New York session high/low anchored range", "NY session low boundary"]
    )
}
if (showSessionHiLo && inNy == 1) {
    plotLine(
        value=nyHi,
        width=lineWidth,
        colors=[nyColor],
        label=["NY Hi"],
        desc=["New York session anchored high"]
    )
    plotLine(
        value=nyLo,
        width=lineWidth,
        colors=[nyColor],
        label=["NY Lo"],
        desc=["New York session anchored low"]
    )
}
if (showOpenMarkers && nyOpenEvent) {
    plotShape(
        value=nyOpen,
        shape="triangleup",
        colorIndex=nyColor,
        width=shapeSize,
        label=["NY Open"],
        desc=["New York session open marker"]
    )
}
if (showInitialBalance && inNy == 1 && nyIBDone == 1) {
    plotLine(
        value=[nyIBHi, nyIBLo],
        width=1,
        colors=[ibColor, ibColor],
        fill=opacity(ibColor, 20),
        label=["NY IB", "NY IB"],
        desc=["NY Initial Balance (first hour) high", "NY Initial Balance low"]
    )
}

// ---------------------------------------------------------------------------
// Plotting: Sydney Session
// ---------------------------------------------------------------------------
if (showSessionBoxes && inSydney == 1) {
    var sydFill = opacity(sydneyColor, 25)
    plotLine(
        value=[sydHi, sydLo],
        width=1,
        colors=[sydneyColor, sydneyColor],
        fill=sydFill,
        label=["Sydney Box", "Sydney Box"],
        desc=["Sydney session high/low anchored range", "Sydney session low boundary"]
    )
}
if (showSessionHiLo && inSydney == 1) {
    plotLine(
        value=sydHi,
        width=lineWidth,
        colors=[sydneyColor],
        label=["Sydney Hi"],
        desc=["Sydney session anchored high"]
    )
    plotLine(
        value=sydLo,
        width=lineWidth,
        colors=[sydneyColor],
        label=["Sydney Lo"],
        desc=["Sydney session anchored low"]
    )
}
if (showOpenMarkers && sydOpenEvent) {
    plotShape(
        value=sydOpen,
        shape="triangleup",
        colorIndex=sydneyColor,
        width=shapeSize,
        label=["Sydney Open"],
        desc=["Sydney session open marker"]
    )
}
if (showInitialBalance && inSydney == 1 && sydIBDone == 1) {
    plotLine(
        value=[sydIBHi, sydIBLo],
        width=1,
        colors=[ibColor, ibColor],
        fill=opacity(ibColor, 20),
        label=["Sydney IB", "Sydney IB"],
        desc=["Sydney Initial Balance (first hour) high", "Sydney Initial Balance low"]
    )
}

// ---------------------------------------------------------------------------
// Plotting: Killzone Overlays
// ---------------------------------------------------------------------------
if (showKillzones && isAsianKZ) {
    plotLine(
        value=h,
        width=1,
        colors=[kzColor],
        label=["Asian KZ"],
        desc=["Asian killzone (ICT): 00:00-05:00 UTC — institutional liquidity window"]
    )
}
if (showKillzones && isLondonKZ) {
    plotLine(
        value=h,
        width=1,
        colors=[kzColor],
        label=["London KZ"],
        desc=["London killzone (ICT): 07:00-10:00 UTC — often sets daily high/low"]
    )
}
if (showKillzones && isNyKZ) {
    plotLine(
        value=h,
        width=1,
        colors=[kzColor],
        label=["NY KZ"],
        desc=["NY killzone (ICT): 13:00-16:00 UTC — intense US index volatility"]
    )
}
if (showKZMarkers && kzAsianEvent) {
    plotShape(
        value=l,
        shape="triangleup",
        colorIndex=kzColor,
        width=shapeSize,
        label=["Asian KZ Start"],
        desc=["Asian killzone start — potential liquidity injection point"]
    )
}
if (showKZMarkers && kzLondonEvent) {
    plotShape(
        value=l,
        shape="triangleup",
        colorIndex=kzColor,
        width=shapeSize,
        label=["London KZ Start"],
        desc=["London killzone start — highest probability daily high/low"]
    )
}
if (showKZMarkers && kzNyEvent) {
    plotShape(
        value=l,
        shape="triangleup",
        colorIndex=kzColor,
        width=shapeSize,
        label=["NY KZ Start"],
        desc=["NY killzone start — US institutional order flow window"]
    )
}

// ---------------------------------------------------------------------------
// Plotting: Overlap Highlight (London/NY = highest volatility)
// ---------------------------------------------------------------------------
if (showOverlap && isOverlap) {
    plotLine(
        value=[h, l],
        width=1,
        colors=[overlapColor, overlapColor],
        fill=overlapColor,
        label=["Overlap", "Overlap"],
        desc=["London/NY overlap: highest volatility and volume clustering (Ito & Hashimoto 2006)"]
    )
}

// ---------------------------------------------------------------------------
// Plotting: Session Labels (current active sessions on last bar)
// ---------------------------------------------------------------------------
if (showSessionLabels && isLastBar) {
    var sessLabel = ""
    if (isTokyo)   { sessLabel = sessLabel + "Tokyo " }
    if (isLondon)  { sessLabel = sessLabel + "London " }
    if (isNy)      { sessLabel = sessLabel + "NY " }
    if (isSydney)  { sessLabel = sessLabel + "Sydney " }
    if (isOverlap) { sessLabel = sessLabel + "(Overlap)" }
    if (sessLabel != "") {
        plotPriceLabel(
            price=h,
            text=sessLabel,
            type="callout",
            color="#ffffff",
            backgroundColor="#424242",
            size=8,
            fontWeight=700
        )
    }
}