本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Previous Day High/Low (NY)", "PDH/PDL NY", overlay = true, max_lines_count = 500, max_labels_count = 500)
// ── Levels ──
mode = input.string("NY Session", "Range", options = ["NY Session", "NY Day"], group = "Levels")
sess = input.session("0930-1600:23456", "NY session hours (ET)", group = "Levels")
hiCol = input.color(#F23645, "PDH color", group = "Levels")
loCol = input.color(#089981, "PDL color", group = "Levels")
extend = input.int(20, "Extend right (bars)", minval = 0, group = "Levels")
txtSz = input.string(size.small, "Text size", options = [size.tiny, size.small, size.normal], group = "Levels")
// ── Session markers ──
showLines = input.bool(true, "Show open/close lines", group = "Session")
showText = input.bool(true, "Show open/close text", group = "Session")
showBg = input.bool(true, "Shade session", group = "Session")
sessCol = input.color(color.new(#2962FF, 40), "Line color", group = "Session")
bgCol = input.color(color.new(#2962FF, 93), "Shade color", group = "Session")
tz = "America/New_York"
inSess = not na(time(timeframe.period, sess, tz))
sessOpen = inSess and not inSess[1]
sessClose = not inSess and inSess[1]
newNYDay = dayofmonth(time, tz) != dayofmonth(time[1], tz)
inRange = mode == "NY Day" ? true : inSess
start = mode == "NY Day" ? newNYDay : sessOpen
// ── Session open / close markers ──
bgcolor(showBg and inSess ? bgCol : na, title = "NY session shade")
if sessOpen or sessClose
if showLines
line.new(time, high, time, low, xloc.bar_time, extend.both, sessCol, line.style_dotted, 1)
if showText
label.new(time, high, sessOpen ? "NY Open" : "NY Close", xloc.bar_time, yloc.abovebar, color.new(color.black, 100), label.style_label_down, sessCol, size.tiny)
// ── Track previous range ──
var float curH = na
var int curHT = na
var float curL = na
var int curLT = na
var float pdh = na
var int pdhT = na
var float pdl = na
var int pdlT = na
if start
pdh := curH
pdhT := curHT
pdl := curL
pdlT := curLT
curH := high
curHT := time
curL := low
curLT := time
else if inRange
if na(curH) or high > curH
curH := high
curHT := time
if na(curL) or low < curL
curL := low
curLT := time
// ── Draw PDH / PDL ──
var line hLine = na
var line lLine = na
var label hLbl = na
var label lLbl = na
if barstate.islast and not na(pdh) and not na(pdl)
x2 = time + extend * timeframe.in_seconds() * 1000
if na(hLine)
hLine := line.new(pdhT, pdh, x2, pdh, xloc.bar_time, color = hiCol, width = 1)
lLine := line.new(pdlT, pdl, x2, pdl, xloc.bar_time, color = loCol, width = 1)
hLbl := label.new(x2, pdh, "PDH", xloc.bar_time, style = label.style_label_left, color = color.new(color.black, 100), textcolor = hiCol, size = txtSz)
lLbl := label.new(x2, pdl, "PDL", xloc.bar_time, style = label.style_label_left, color = color.new(color.black, 100), textcolor = loCol, size = txtSz)
else
line.set_xy1(hLine, pdhT, pdh)
line.set_xy2(hLine, x2, pdh)
line.set_xy1(lLine, pdlT, pdl)
line.set_xy2(lLine, x2, pdl)
label.set_xy(hLbl, x2, pdh)
label.set_xy(lLbl, x2, pdl)