PROTECTED SOURCE SCRIPT

Premarket Break 5m (Close Above/Below Prem High/Low)

9
//version=5
indicator("Premarket Break 5m (Close Above/Below Prem High/Low)", overlay = true)

// === SETTINGS ===
premarketSession = input.session("0400-0930", "Premarket Session (ET)")
regularSession = input.session("0930-1600", "Regular Session (ET)")

// === HELPERS ===
isNewDay = ta.change(time("D")) != 0

// Track premarket high/low each day
var float pmHigh = na
var float pmLow = na

// Reset at the start of each new day
if isNewDay
pmHigh := na
pmLow := na

// Are we inside premarket session?
inPremarket = not na(time(timeframe.period, premarketSession, "America/New_York"))

// Update premarket high/low during premarket
if inPremarket
pmHigh := na(pmHigh) ? high : math.max(pmHigh, high)
pmLow := na(pmLow) ? low : math.min(pmLow, low)

// Are we inside regular session?
inRegular = not na(time(timeframe.period, regularSession, "America/New_York"))

// === SIGNALS: 5m close above/below premarket high/low ===
// Require previous close to be on the other side to avoid spam
bullBreak = inRegular and not na(pmHigh) and close > pmHigh and close[1] <= pmHigh
bearBreak = inRegular and not na(pmLow) and close < pmLow and close[1] >= pmLow

// === PLOTS ===
plot(pmHigh, title = "Premarket High", color = color.new(color.green, 0), linewidth = 2)
plot(pmLow, title = "Premarket Low", color = color.new(color.red, 0), linewidth = 2)

plotshape(bullBreak, title = "Close Above Prem High", style = shape.labelup,
text = "Close > PM High", location = location.belowbar, size = size.tiny)
plotshape(bearBreak, title = "Close Below Prem Low", style = shape.labeldown,
text = "Close < PM Low", location = location.abovebar, size = size.tiny)

// === ALERTS ===
// These fire once per bar close when the condition is true
if bullBreak
alert("5m candle CLOSED above Premarket High.", alert.freq_once_per_bar_close)

if bearBreak
alert("5m candle CLOSED below Premarket Low.", alert.freq_once_per_bar_close)

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。