本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script code is subject to the terms of the Mozilla Public License 2.0 https://mozilla.org/MPL/2.0/
// Event Window — original code by RetryLab
// Shades the chart around scheduled releases (NFP, CPI, FOMC), alerts when a window opens and closes,
// and shows how much room is left to the daily loss and max drawdown, plus the price move that would use it.
// Read-only: it does not place or close trades. Not financial advice. Event times are editable: check the official calendars.
//@version=6
indicator("Event Window - Prop Rules", shorttitle = "Event Window", overlay = true, max_labels_count = 60)
// ───── Events (times in UTC; edit them before each release) ─────
grpE = "Scheduled releases (UTC)"
e1On = input.bool(true, "", inline = "e1", group = grpE)
e1Name = input.string("NFP", "", inline = "e1", group = grpE)
e1T = input.time(timestamp("06 Nov 2026 13:30 +0000"), "", inline = "e1", group = grpE)
e2On = input.bool(true, "", inline = "e2", group = grpE)
e2Name = input.string("CPI", "", inline = "e2", group = grpE)
e2T = input.time(timestamp("10 Nov 2026 13:30 +0000"), "", inline = "e2", group = grpE)
e3On = input.bool(true, "", inline = "e3", group = grpE)
e3Name = input.string("FOMC", "", inline = "e3", group = grpE)
e3T = input.time(timestamp("09 Dec 2026 19:00 +0000"), "", inline = "e3", group = grpE)
e4On = input.bool(false, "", inline = "e4", group = grpE)
e4Name = input.string("Custom", "", inline = "e4", group = grpE)
e4T = input.time(timestamp("04 Dec 2026 13:30 +0000"), "", inline = "e4", group = grpE)
grpW = "Window"
minsBefore = input.int(15, "Minutes before the release", minval = 0, maxval = 240, group = grpW)
minsAfter = input.int(120, "Minutes after the release", minval = 0, maxval = 480, group = grpW, tooltip = "Two hours by default, so the window also covers the press conference after FOMC.")
winColor = input.color(color.new(color.orange, 85), "Window colour", group = grpW)
// ───── Prop rules (update the P&L fields by hand: the indicator cannot read your account) ─────
grpR = "Prop account (manual inputs)"
acct = input.float(100000, "Account size ($)", minval = 0, group = grpR)
dlPct = input.float(5.0, "Daily loss limit (%)", minval = 0, step = 0.5, group = grpR)
mddPct = input.float(10.0, "Max drawdown (%)", minval = 0, step = 0.5, group = grpR)
pnlToday = input.float(0, "Today's P&L so far ($)", group = grpR)
ddUsed = input.float(0, "Drawdown already used ($)", minval = 0, group = grpR)
lots = input.float(1.0, "Position size (lots)", minval = 0, step = 0.01, group = grpR)
valPerPt = input.float(100, "$ per 1.0 price move, per contract/lot", minval = 0, group = grpR, tooltip = "XAUUSD on most brokers: 100 ($1 move x 100 oz). NQ 20, MNQ 2, ES 50, MES 5. Check your broker's contract size for other symbols.")
showPanel = input.bool(true, "Show panel", group = grpR)
// ───── Logic ─────
inWin(bool on, int t) =>
on and time_close > t - minsBefore * 60000 and time < t + minsAfter * 60000
w1 = inWin(e1On, e1T)
w2 = inWin(e2On, e2T)
w3 = inWin(e3On, e3T)
w4 = inWin(e4On, e4T)
inAny = w1 or w2 or w3 or w4
activeName = w1 ? e1Name : w2 ? e2Name : w3 ? e3Name : w4 ? e4Name : ""
bgcolor(inAny ? winColor : na, title = "Event window")
// Release marker
mark(bool on, int t, string name) =>
if on and time <= t and time_close > t
label.new(bar_index, high, name, style = label.style_label_down, color = color.orange, textcolor = color.black, size = size.small)
mark(e1On, e1T, e1Name)
mark(e2On, e2T, e2Name)
mark(e3On, e3T, e3Name)
mark(e4On, e4T, e4Name)
// Alerts: create one alert with "Any alert() function call"
entering = inAny and not inAny[1]
leaving = not inAny and inAny[1]
if entering
alert("Event window OPEN: " + activeName + " on " + syminfo.ticker + ". Check size and stops before the release.", alert.freq_once_per_bar)
if leaving
alert("Event window CLOSED on " + syminfo.ticker + ".", alert.freq_once_per_bar)
alertcondition(entering, "Event window opens", "Event window opens on {{ticker}}")
alertcondition(leaving, "Event window closes", "Event window closes on {{ticker}}")
// Room to the limits
dlRoom = math.max(acct * dlPct / 100 + pnlToday, 0)
mddRoom = math.max(acct * mddPct / 100 - ddUsed, 0)
room = math.min(dlRoom, mddRoom)
moveToBreach = lots * valPerPt > 0 ? room / (lots * valPerPt) : na
// Next event (countdown)
nextT(bool on, int t, int best) =>
on and t > timenow and (na(best) or t < best) ? t : best
var int nT = na
var string nN = ""
if barstate.islast
int b = na
b := nextT(e1On, e1T, b)
b := nextT(e2On, e2T, b)
b := nextT(e3On, e3T, b)
b := nextT(e4On, e4T, b)
nT := b
nN := b == e1T ? e1Name : b == e2T ? e2Name : b == e3T ? e3Name : b == e4T ? e4Name : ""
var table panel = table.new(position.top_right, 2, 6, bgcolor = color.new(color.black, 15), border_width = 1)
if showPanel and barstate.islast
hrs = na(nT) ? na : (nT - timenow) / 3600000.0
table.cell(panel, 0, 0, "Event Window", text_color = color.white)
table.cell(panel, 1, 0, inAny ? "OPEN: " + activeName : "closed", text_color = inAny ? color.orange : color.gray)
table.cell(panel, 0, 1, "Next release", text_color = color.white)
table.cell(panel, 1, 1, na(nT) ? "none set" : nN + " in " + str.tostring(hrs, "#.#") + " h", text_color = color.white)
table.cell(panel, 0, 2, "Daily loss room", text_color = color.white)
table.cell(panel, 1, 2, "$" + str.tostring(dlRoom, "#,###"), text_color = color.white)
table.cell(panel, 0, 3, "Max DD room", text_color = color.white)
table.cell(panel, 1, 3, "$" + str.tostring(mddRoom, "#,###"), text_color = color.white)
table.cell(panel, 0, 4, "Move that uses it", text_color = color.white)
table.cell(panel, 1, 4, na(moveToBreach) ? "n/a" : str.tostring(moveToBreach, "#.##") + " pts @ " + str.tostring(lots) + " lot", text_color = color.yellow)
table.cell(panel, 0, 5, "by RetryLab", text_color = color.gray, text_size = size.tiny)
table.cell(panel, 1, 5, "read-only - not advice", text_color = color.gray, text_size = size.tiny)