本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// CYS Key Levels — previous day high/low/close, overnight high/low and session open.
// Free and open source. Levels only update on confirmed data (no repainting).
indicator("CYS Key Levels: Previous Day, Overnight & Open", shorttitle="CYS Key Levels", overlay=true, max_labels_count=50)
// ── Settings ─────────────────────────────────────────────
showPD = input.bool(true, "Previous day high / low / close", group="Levels")
showON = input.bool(true, "Overnight high / low (intraday charts)", group="Levels")
showOpen = input.bool(true, "Regular session open (intraday charts)", group="Levels")
rthSess = input.session("0930-1600", "Regular session", group="Session")
rthTz = input.string("America/New_York", "Session time zone", group="Session")
showLabels = input.bool(true, "Show price labels", group="Style")
colHi = input.color(color.new(color.teal, 0), "High levels", group="Style")
colLo = input.color(color.new(color.red, 0), "Low levels", group="Style")
colMid = input.color(color.new(color.gray, 0), "Close / open", group="Style")
isIntra = timeframe.isintraday
// ── Previous day (confirmed daily values only) ───────────
[pdh, pdl, pdc] = request.security(syminfo.tickerid, "D", [high[1], low[1], close[1]], lookahead = barmerge.lookahead_on)
// ── Overnight range and regular session open ────────────
inRth = isIntra and not na(time(timeframe.period, rthSess, rthTz))
var float onHigh = na
var float onLow = na
var float onHighF = na
var float onLowF = na
var float rthOpen = na
if isIntra and not inRth
if inRth[1] or na(onHigh)
onHigh := high
onLow := low
else
onHigh := math.max(onHigh, high)
onLow := math.min(onLow, low)
if inRth and not inRth[1]
onHighF := onHigh
onLowF := onLow
rthOpen := open
// ── Plots ────────────────────────────────────────────────
plot(showPD ? pdh : na, "Previous day high", colHi, 2, plot.style_stepline)
plot(showPD ? pdl : na, "Previous day low", colLo, 2, plot.style_stepline)
plot(showPD ? pdc : na, "Previous day close", colMid, 1, plot.style_stepline)
plot(showON and isIntra ? onHighF : na, "Overnight high", color.new(colHi, 40), 1, plot.style_stepline)
plot(showON and isIntra ? onLowF : na, "Overnight low", color.new(colLo, 40), 1, plot.style_stepline)
plot(showOpen and isIntra ? rthOpen : na, "Session open", colMid, 1, plot.style_circles)
// ── Labels on the last bar ───────────────────────────────
var array<label> labs = array.new<label>()
addLabel(array<label> arr, float price, string txt, color col) =>
if not na(price)
arr.push(label.new(bar_index + 2, price, txt + " " + str.tostring(price, format.mintick), style = label.style_label_left, color = color.new(col, 85), textcolor = col, size = size.small))
if barstate.islast and showLabels
for l in labs
label.delete(l)
labs.clear()
if showPD
addLabel(labs, pdh, "PDH", colHi)
addLabel(labs, pdl, "PDL", colLo)
addLabel(labs, pdc, "PDC", colMid)
if showON and isIntra
addLabel(labs, onHighF, "ONH", colHi)
addLabel(labs, onLowF, "ONL", colLo)
if showOpen and isIntra
addLabel(labs, rthOpen, "OPEN", colMid)
// ── Alerts ───────────────────────────────────────────────
alertcondition(ta.crossover(close, pdh), "Cross above previous day high", "{{ticker}} crossed above the previous day high")
alertcondition(ta.crossunder(close, pdl), "Cross below previous day low", "{{ticker}} crossed below the previous day low")
alertcondition(ta.crossover(close, onHighF), "Cross above overnight high", "{{ticker}} crossed above the overnight high")
alertcondition(ta.crossunder(close, onLowF), "Cross below overnight low", "{{ticker}} crossed below the overnight low")