本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Intraday Sessions & Sweeps [Clean Bounds]", "Sessions & Sweeps", overlay=true, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
// ==========================================
// 1. Inputs & Configuration
// ==========================================
grp_visual = "Visuals / Display"
show_lines = input.bool(true, "Show Asia High/Low Dashed Lines (00-24 UTC)", group=grp_visual)
show_sweep = input.bool(true, "Show First Sweep Markers (SWEEP H/L)", group=grp_visual)
show_dash = input.bool(true, "Show Mini Dashboard", group=grp_visual)
// Session Colors: Green (Asia), Yellow (London), Red (NY)
c_asia = #3fb950
c_lon = #e3b341
c_ny = #f85149
// ==========================================
// 2. UTC Session Engine
// ==========================================
int t_hour = hour(time, "UTC")
int t_day = dayofmonth(time, "UTC")
bool is_new_day = (t_day != t_day[1])
bool in_asia = (t_hour >= 0 and t_hour < 8)
bool in_london = (t_hour >= 8 and t_hour < 16)
bool is_asia_done = (t_hour >= 8 and t_hour[1] < 8)
// ==========================================
// 3. State Tracking Engine
// ==========================================
var float asia_hi = na
var float asia_lo = na
var int day_start_t = na
var int asia_end_t = na
var int lon_end_t = na
var int day_end_t = na
var bool swept_hi = false
var bool swept_lo = false
// Reset daily at 00:00 UTC
if is_new_day
asia_hi := high
asia_lo := low
day_start_t := timestamp("UTC", year(time, "UTC"), month(time, "UTC"), dayofmonth(time, "UTC"), 0, 0, 0)
asia_end_t := day_start_t + 28800000 // 08:00 UTC
lon_end_t := day_start_t + 57600000 // 16:00 UTC
day_end_t := day_start_t + 86400000 // 24:00 UTC
swept_hi := false
swept_lo := false
// Asia Session (00:00-08:00 UTC): Anchor formation
if in_asia
asia_hi := math.max(nz(asia_hi, high), high)
asia_lo := math.min(nz(asia_lo, low), low)
// 08:00 UTC: Draw three-segment dashed lines
if is_asia_done and show_lines
// Asia High: Green (Asia) -> Yellow (London) -> Red (NY)
line.new(day_start_t, asia_hi, asia_end_t, asia_hi, xloc=xloc.bar_time, color=c_asia, width=2, style=line.style_dashed)
line.new(asia_end_t, asia_hi, lon_end_t, asia_hi, xloc=xloc.bar_time, color=c_lon, width=2, style=line.style_dashed)
line.new(lon_end_t, asia_hi, day_end_t, asia_hi, xloc=xloc.bar_time, color=c_ny, width=2, style=line.style_dashed)
// Asia Low: Green (Asia) -> Yellow (London) -> Red (NY)
line.new(day_start_t, asia_lo, asia_end_t, asia_lo, xloc=xloc.bar_time, color=c_asia, width=2, style=line.style_dashed)
line.new(asia_end_t, asia_lo, lon_end_t, asia_lo, xloc=xloc.bar_time, color=c_lon, width=2, style=line.style_dashed)
line.new(lon_end_t, asia_lo, day_end_t, asia_lo, xloc=xloc.bar_time, color=c_ny, width=2, style=line.style_dashed)
// London Session (08:00-16:00 UTC): Deduplicated first sweep detection
bool first_sweep_hi = false
bool first_sweep_lo = false
if in_london
if high > asia_hi and not swept_hi
swept_hi := true
first_sweep_hi := true
if low < asia_lo and not swept_lo
swept_lo := true
first_sweep_lo := true
// ==========================================
// 4. Plots & Visuals
// ==========================================
plotshape(show_sweep and first_sweep_hi, "Sweep High", shape.triangledown, location.abovebar, c_lon, size=size.tiny, text="SWEEP H")
plotshape(show_sweep and first_sweep_lo, "Sweep Low", shape.triangleup, location.belowbar, c_lon, size=size.tiny, text="SWEEP L")
// ==========================================
// 5. Minimalist Dashboard
// ==========================================
var table tb = table.new(position.top_right, 2, 3, bgcolor=color.new(#121820, 15), border_color=#243040, border_width=1)
if show_dash and barstate.islast
string s_name = in_asia ? "Asia (00-08)" : in_london ? "London (08-16)" : "NY (16-24)"
string s_sweep = swept_hi and swept_lo ? "Both Swept" : swept_hi ? "Asia High Swept" : swept_lo ? "Asia Low Swept" : "Inside Range"
table.cell(tb, 0, 0, "Session", text_color=#8494a6, text_size=size.small)
table.cell(tb, 1, 0, s_name, text_color=color.white, text_size=size.small)
table.cell(tb, 0, 1, "Sweep State", text_color=#8494a6, text_size=size.small)
table.cell(tb, 1, 1, s_sweep, text_color=c_lon, text_size=size.small)
table.cell(tb, 0, 2, "Asia Range", text_color=#8494a6, text_size=size.small)
table.cell(tb, 1, 2, str.tostring(asia_hi - asia_lo, "#.#"), text_color=c_asia, text_size=size.small)