本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Trading Sessions | Gold V4", overlay=true, scale=scale.none, max_boxes_count=500, max_labels_count=500)
// SETTINGS
timeMode = input.string("New York", "Time Zone", options=["New York", "Oslo"])
showAsia = input.bool(true, "Show Asia")
showLondon = input.bool(true, "Show London")
showNY = input.bool(true, "Show New York")
// COLORS
boxColor = input.color(color.rgb(48, 99, 168), "Dark Blue")
opacity = input.int(62, "Transparency", minval=0, maxval=100)
edgeColor = input.color(color.rgb(65, 65, 65), "Dark Gray Border")
edgeWidth = input.int(1, "Border Width", minval=1, maxval=4)
textColor = input.color(color.black, "Text Color")
// TIME ZONE AND SESSIONS
tz = timeMode == "Oslo" ? "Europe/Oslo" : "America/New_York"
asiaSession = timeMode == "Oslo" ? "0200-1100:1234567" : "2000-0500:1234567"
londonSession = timeMode == "Oslo" ? "0900-1800:1234567" : "0300-1200:1234567"
nySession = timeMode == "Oslo" ? "1400-2300:1234567" : "0800-1700:1234567"
// DETECT ACTIVE SESSIONS
asiaActive = not na(time(timeframe.period, asiaSession, tz))
londonActive = not na(time(timeframe.period, londonSession, tz))
nyActive = not na(time(timeframe.period, nySession, tz))
// SESSION BOX FUNCTION
drawSession(bool active, bool enabled, string sessionName) =>
var box sessionBox = na
var label sessionLabel = na
var float sessionHigh = na
var float sessionLow = na
var int sessionStart = na
bool started = active and not active[1]
if enabled and started
sessionHigh := high
sessionLow := low
sessionStart := time
sessionBox := box.new(
left=sessionStart,
top=sessionHigh,
right=time_close,
bottom=sessionLow,
xloc=xloc.bar_time,
bgcolor=color.new(boxColor, opacity),
border_color=edgeColor,
border_width=edgeWidth,
force_overlay=true)
sessionLabel := label.new(
x=sessionStart,
y=sessionHigh,
text=sessionName,
xloc=xloc.bar_time,
yloc=yloc.price,
style=label.style_none,
textcolor=textColor,
size=size.tiny,
force_overlay=true)
if enabled and active and not na(sessionBox)
sessionHigh := math.max(sessionHigh, high)
sessionLow := math.min(sessionLow, low)
box.set_right(sessionBox, time_close)
box.set_top(sessionBox, sessionHigh)
box.set_bottom(sessionBox, sessionLow)
int middleTime = int(math.round((sessionStart + time_close) / 2.0))
label.set_x(sessionLabel, middleTime)
label.set_y(sessionLabel, sessionHigh)
// DRAW ALL THREE SESSIONS
drawSession(asiaActive, showAsia, "ASIA")
drawSession(londonActive, showLondon, "LONDON")
drawSession(nyActive, showNY, "NEW YORK")