本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Previous Day Levels + London Open
// Previous day's high, low and close (non-repainting) and the London session
// opening price, with breakout alerts on candle close during London.
indicator("Previous Day Levels + London Open", overlay = true)
// ───── Inputs ─────
g1 = "Session"
tz = input.string("Europe/London", "Time zone", group = g1)
londonSess = input.session("0800-1700", "London session", group = g1)
g2 = "Levels"
showPDH = input.bool(true, "Previous day high (PDH)", group = g2)
showPDL = input.bool(true, "Previous day low (PDL)", group = g2)
showPDC = input.bool(false, "Previous day close (PDC)", group = g2)
showLO = input.bool(true, "London open", group = g2)
colH = input.color(color.teal, "PDH color", group = g2)
colL = input.color(color.red, "PDL color", group = g2)
colC = input.color(color.gray, "PDC color", group = g2)
colLO = input.color(color.orange, "London open color", group = g2)
// ───── Previous day (non-repainting: [1] values with lookahead) ─────
[pdh, pdl, pdc] = request.security(syminfo.tickerid, "D", [high[1], low[1], close[1]], lookahead = barmerge.lookahead_on)
chgH = ta.change(pdh)
chgL = ta.change(pdl)
newDay = chgH != 0 or chgL != 0
plot(showPDH and not newDay ? pdh : na, "PDH", colH, 2, plot.style_linebr)
plot(showPDL and not newDay ? pdl : na, "PDL", colL, 2, plot.style_linebr)
plot(showPDC and not newDay ? pdc : na, "PDC", colC, 1, plot.style_linebr)
// ───── London open ─────
inLondon = not na(time(timeframe.period, londonSess, tz))
londonStart = inLondon and not inLondon[1]
var float londonOpen = na
if londonStart
londonOpen := open
plot(showLO and inLondon and not londonStart ? londonOpen : na, "London open", colLO, 1, plot.style_linebr)
// ───── Alerts (London session only, on candle close) ─────
crossH = ta.crossover(close, pdh)
crossL = ta.crossunder(close, pdl)
breakPDH = inLondon and crossH and barstate.isconfirmed
breakPDL = inLondon and crossL and barstate.isconfirmed
plotshape(breakPDH, "PDH break", shape.triangleup, location.belowbar, colH, size = size.tiny)
plotshape(breakPDL, "PDL break", shape.triangledown, location.abovebar, colL, size = size.tiny)
alertcondition(breakPDH, "Close above PDH", "{{ticker}}: candle closed above yesterday's high during the London session")
alertcondition(breakPDL, "Close below PDL", "{{ticker}}: candle closed below yesterday's low during the London session")