本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Economic Release & Earnings Highlighter + Open Marker + MAs + Levels + Holidays", overlay=true, max_bars_back=5000, max_labels_count=500, max_lines_count=500)
// ============================================================================
// Economic Release & Earnings Highlighter + Ultimate Open Marker + 11 MAs
// + Previous Day / Overnight Levels + Market Holidays / Early Closes
//
// SOURCES / CONFIDENCE:
// - CPI, NFP, PPI, PCE: BLS/BEA official schedules (bls.gov, bea.gov) and
// ALFRED (St. Louis Fed) historical release-date archives. High confidence,
// includes actual 2025 shutdown-disrupted dates.
// - FOMC & FOMC Minutes: federalreserve.gov calendar. Minutes are always
// exactly 21 days after the decision, 2:00 PM ET — derived, not guessed.
// - Jackson Hole: Kansas City Fed symposium keynote (final-day Friday). High confidence.
// - Triple/Quad Witching: COMPUTED (3rd Friday of Mar/Jun/Sep/Dec) — not
// hardcoded, so it never goes stale.
// - Earnings (AAPL/MSFT/NVDA/AMZN/GOOGL/META/COST/WMT/TGT/JPM): 2026 dates
// checked against company releases / SEC filings; 2021-2025 mostly
// compiled from reporting patterns (lower confidence). BMO earnings
// (WMT/TGT/JPM) highlight a 6:00-9:30 AM ET WINDOW rather than one
// timestamp, since exact release minute varies company to company and
// the real reaction often keeps building into the cash open (this fixed
// a real miss on TGT 8/19/26).
// - Market holidays / early closes (2015-2030): NYSE calendar, generated
// from two independent calendar libraries that agreed on every date.
// Includes the special closures (12/05/2018 Bush, 01/09/2025 Carter days
// of mourning) and the Juneteenth holiday from 2022. 2027-2030 are
// rule-projected (NYSE has not necessarily published them all yet).
//
// ECON / EARNINGS ON DAILY CHARTS: on intraday charts each release highlights
// the bar containing its release time. On daily charts the whole daily bar
// of that trading day is highlighted/labeled (the daily bar is stamped at the
// 18:00 ET session start, so its date is taken from the futures-day bucket).
// Weekly/monthly charts are not supported.
//
// OPEN MARKER (merged in): marks the first bar containing the 9:30 AM ET
// cash open each trading day (marker, time/date label, optional vertical
// lines, background highlight). Intraday charts only. Has its own master
// switch under "OPEN MARKER" in the settings.
//
// MOVING AVERAGES (merged in): 11 configurable MA slots (10 SMA + 1 slot
// defaulting to a 9 EMA, with an SMA/EMA toggle), each with its own show
// toggle, length, source, color, style (Line / Diamond / Dots) and
// thickness-or-size (1-4). Diamond uses the stepline-diamond plot style.
// All 11 slots have a Timeframe field (blank = chart timeframe) via
// request.security. Master switch under "MOVING AVERAGES".
//
// LEVELS (merged in): Previous Day High/Low (full prior futures day, 18:00 ET
// open through 16:00 ET RTH close) and optional Overnight High/Low
// (18:00 ET through 09:30 ET). Drawn with line.new(), so they cost no plots.
// Both are off by default.
//
// MARKET HOLIDAYS (merged in): completely separate from the Open Marker (it
// works with the Open Marker switched off). Shades the whole futures session
// (18:00 ET the evening before through the close) of every full market
// holiday, early-close day, and optionally the trading day right after
// (and/or before) a holiday, with a label on the first bar of that session
// so the "why does this day look weird" answer is on the chart from the
// moment the session starts. Own master switch under "MARKET HOLIDAYS".
// Works on intraday and daily charts.
//
// LEGEND TABLE: optional, off by default ("Show legend table" under Toggles).
//
// PLOT BUDGET (64-plot limit): 11 bgcolor() (7 econ + 1 open marker + 3 holiday)
// + 11 plot() (one per MA) = 22 of 64. The levels use lines, not plots.
// Labels/lines/tables have separate limits, set to 500 above.
// NOTE: the 500-label pool is shared by econ labels, open-marker labels and
// holiday labels; the 500-line pool is shared by the levels and the optional
// vertical lines.
//
// MAINTENANCE: CPI/NFP/PPI/FOMC/Minutes now run through Dec 2027. Earnings
// need the most upkeep — append new YYYYMMDD values as each company confirms.
// Holidays/early closes run through Dec 2030; append to holClosed3 / holHalf.
// PENDING (not officially announced yet, so not included): Jackson Hole 2027;
// PCE for Dec 2026 / Jan 2027 / Nov 2027 data; NVDA, WMT, TGT November 2026;
// COST December 2026; JPM January 2027.
// Last verified: Nov 9, 2026.
// ============================================================================
// ---------------- Inputs ----------------
showCPI = input.bool(true, "Show CPI", group = "Toggles")
showNFP = input.bool(true, "Show NFP", group = "Toggles")
showFOMC = input.bool(true, "Show FOMC", group = "Toggles")
showMinutes = input.bool(true, "Show FOMC Minutes", group = "Toggles")
showPPI = input.bool(true, "Show PPI", group = "Toggles")
showPCE = input.bool(true, "Show PCE", group = "Toggles")
showJH = input.bool(true, "Show Jackson Hole", group = "Toggles")
showWitching = input.bool(true, "Show Triple/Quad Witching", group = "Toggles")
showEarnings = input.bool(true, "Show Earnings", group = "Toggles")
showLabels = input.bool(true, "Show text labels on release bars", group = "Toggles")
showLegend = input.bool(false, "Show legend table", group = "Toggles",
tooltip="Color legend for the release / holiday highlights, top right of the chart.")
colorCPI = input.color(color.new(#ffeb3b, 80), "CPI color", group = "Colors")
colorNFP = input.color(color.new(#2962ff, 62), "NFP color", group = "Colors")
colorFOMC = input.color(color.new(#00bcd4, 77), "FOMC color", group = "Colors")
colorMinutes = input.color(color.new(#ce93d8, 42), "FOMC Minutes color", group = "Colors")
colorPPI = input.color(color.new(#dbdbdb, 42), "PPI color", group = "Colors")
colorPCE = input.color(color.new(#f77c80, 77), "PCE color", group = "Colors")
colorJH = input.color(color.new(#e91e63, 77), "Jackson Hole color", group = "Colors")
colorWitching = input.color(color.new(#e132ff, 77), "Witching color", group = "Colors")
colorEarnBMO = input.color(color.new(#da3cf5, 62), "Earnings BMO color", group = "Colors")
colorEarnAMC = input.color(color.new(#ff813e, 52), "Earnings AMC color", group = "Colors")
labelSize = input.string("small", "Label size", options = ["tiny", "small", "normal"], group = "Toggles")
lblSize = labelSize == "tiny" ? size.tiny : labelSize == "normal" ? size.normal : size.small
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — INPUTS
// ══════════════════════════════════════════════════════════════════════════════
string GRP_MARKER = "═══ OPEN MARKER: MARKER SETTINGS ═══"
showOpenMarker = input.bool(true, "Enable Open Marker (master switch)", group=GRP_MARKER,
tooltip="Turns the entire 9:30 AM ET Open Marker feature on/off (marker, labels, lines, background).")
markerEnabled = input.bool(true, "Show Marker", group=GRP_MARKER)
markerType = input.string("Label Flag", "Marker Type",
options=["Label Flag", "Arrow", "Arrow Thin", "Triangle", "Triangle Small", "Diamond"],
group=GRP_MARKER,
tooltip="Label Flag: pointed label box\nArrow: bold arrow\nArrow Thin: sleek arrow\nTriangle: solid triangle\nTriangle Small: compact triangle\nDiamond: diamond pointer")
markerSize = input.string("normal", "Marker Size",
options=["tiny", "small", "normal", "large", "huge"],
group=GRP_MARKER)
markerColor = input.color(color.new(#00BFFF, 0), "Marker Color", group=GRP_MARKER,
tooltip="Default: Sky Blue (#00BFFF) - visible on both light and dark backgrounds")
markerPosition = input.string("Auto (Above Bear / Below Bull)", "Marker Position",
options=["Auto (Above Bear / Below Bull)", "Always Above", "Always Below"],
group=GRP_MARKER)
markerOffset = input.int(-7, "Vertical Offset (ticks)", minval=-50, maxval=50, group=GRP_MARKER,
tooltip="Fine-tune marker distance from candle. Positive = further away, Negative = closer")
markerSpacing = input.int(3, "Base Spacing from Candle", minval=1, maxval=50, group=GRP_MARKER,
tooltip="Base distance between marker and candle. Increase for more separation.")
string GRP_BG = "═══ OPEN MARKER: BACKGROUND HIGHLIGHT ═══"
showBgHighlight = input.bool(true, "Highlight Open Bar Background", group=GRP_BG)
bgBullColor = input.color(color.new(#00C853, 85), "Bullish Background Color", group=GRP_BG)
bgBearColor = input.color(color.new(#FF1744, 85), "Bearish Background Color", group=GRP_BG)
string GRP_TIME = "═══ OPEN MARKER: TIME LABEL ═══"
showTimeLabel = input.bool(true, "Show Time Label", group=GRP_TIME)
timeLabelColor = input.color(color.new(#00BFFF, 0), "Time Label Color", group=GRP_TIME)
timeLabelSize = input.string("normal", "Time Label Size",
options=["tiny", "small", "normal", "large", "huge"], group=GRP_TIME)
string GRP_DATE = "═══ OPEN MARKER: DATE LABEL ═══"
showDateLabel = input.bool(true, "Show Date Label", group=GRP_DATE)
dateFormat = input.string("MM/DD/YY (American)", "Date Format",
options=["MM/DD/YY (American)", "DD/MM/YY (European)", "DD Mon 'YY (Written)", "Mon DD, YYYY (Full)"],
group=GRP_DATE)
showDayOfWeek = input.bool(true, "Include Day of Week", group=GRP_DATE)
dayOfWeekFormat = input.string("Short (Mon, Tue...)", "Day Format",
options=["Short (Mon, Tue...)", "Full (Monday, Tuesday...)"], group=GRP_DATE)
dateLabelColor = input.color(color.new(#00BFFF, 0), "Date Label Color", group=GRP_DATE)
dateLabelSize = input.string("small", "Date Label Size",
options=["tiny", "small", "normal", "large", "huge"], group=GRP_DATE)
string GRP_LINE_OPEN = "═══ OPEN MARKER: VERTICAL LINE (ON OPEN) ═══"
showOpenLine = input.bool(false, "Show Line on Open", group=GRP_LINE_OPEN)
openLineColor = input.color(color.new(#00BFFF, 50), "Line Color", group=GRP_LINE_OPEN)
openLineStyle = input.string("Dotted", "Line Style", options=["Solid", "Dotted", "Dashed"], group=GRP_LINE_OPEN)
openLineWidth = input.int(1, "Line Width", minval=1, maxval=4, group=GRP_LINE_OPEN)
string GRP_LINE_PRE = "═══ OPEN MARKER: VERTICAL LINE (BEFORE OPEN) ═══"
showPreOpenLine = input.bool(false, "Show Line Before Open", group=GRP_LINE_PRE,
tooltip="Draws a line on the candle just before the open. Helps visually separate pre-market from open.")
preOpenLineColor = input.color(color.new(#FFD700, 50), "Line Color", group=GRP_LINE_PRE)
preOpenLineStyle = input.string("Dotted", "Line Style", options=["Solid", "Dotted", "Dashed"], group=GRP_LINE_PRE)
preOpenLineWidth = input.int(1, "Line Width", minval=1, maxval=4, group=GRP_LINE_PRE)
// ══════════════════════════════════════════════════════════════════════════════
// MOVING AVERAGES — INPUTS
// ══════════════════════════════════════════════════════════════════════════════
string GRP_MA_ALL = "═══ MOVING AVERAGES ═══"
showMAs = input.bool(true, "Show Moving Averages (master switch)", group=GRP_MA_ALL)
string GRP_MA1 = "═══ MA SLOT 1 ═══"
ma1Show = input.bool(true, "Show", group=GRP_MA1)
ma1Len = input.int(8, "Length", minval=1, group=GRP_MA1)
ma1Src = input.source(close, "Source", group=GRP_MA1)
ma1Tf = input.timeframe("", "Timeframe", group=GRP_MA1)
ma1Col = input.color(#00BFFF, "Color", group=GRP_MA1)
ma1Style = input.string("Line", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA1)
ma1Wid = input.int(1, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA1)
string GRP_MA2 = "═══ MA SLOT 2 ═══"
ma2Show = input.bool(true, "Show", group=GRP_MA2)
ma2Len = input.int(16, "Length", minval=1, group=GRP_MA2)
ma2Src = input.source(close, "Source", group=GRP_MA2)
ma2Tf = input.timeframe("", "Timeframe", group=GRP_MA2)
ma2Col = input.color(#FFFF00, "Color", group=GRP_MA2)
ma2Style = input.string("Diamond", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA2)
ma2Wid = input.int(2, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA2)
string GRP_MA3 = "═══ MA SLOT 3 ═══"
ma3Show = input.bool(true, "Show", group=GRP_MA3)
ma3Len = input.int(20, "Length", minval=1, group=GRP_MA3)
ma3Src = input.source(close, "Source", group=GRP_MA3)
ma3Tf = input.timeframe("", "Timeframe", group=GRP_MA3)
ma3Col = input.color(#00BFFF, "Color", group=GRP_MA3)
ma3Style = input.string("Line", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA3)
ma3Wid = input.int(3, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA3)
string GRP_MA4 = "═══ MA SLOT 4 ═══"
ma4Show = input.bool(true, "Show", group=GRP_MA4)
ma4Len = input.int(40, "Length", minval=1, group=GRP_MA4)
ma4Src = input.source(close, "Source", group=GRP_MA4)
ma4Tf = input.timeframe("", "Timeframe", group=GRP_MA4)
ma4Col = input.color(#FF0000, "Color", group=GRP_MA4)
ma4Style = input.string("Line", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA4)
ma4Wid = input.int(4, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA4)
string GRP_MA5 = "═══ MA SLOT 5 ═══"
ma5Show = input.bool(true, "Show", group=GRP_MA5)
ma5Len = input.int(80, "Length", minval=1, group=GRP_MA5)
ma5Src = input.source(close, "Source", group=GRP_MA5)
ma5Tf = input.timeframe("", "Timeframe", group=GRP_MA5)
ma5Col = input.color(#00C853, "Color", group=GRP_MA5)
ma5Style = input.string("Diamond", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA5)
ma5Wid = input.int(3, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA5)
string GRP_MA6 = "═══ MA SLOT 6 ═══"
ma6Show = input.bool(true, "Show", group=GRP_MA6)
ma6Len = input.int(160, "Length", minval=1, group=GRP_MA6)
ma6Src = input.source(close, "Source", group=GRP_MA6)
ma6Tf = input.timeframe("", "Timeframe", group=GRP_MA6)
ma6Col = input.color(#00BFFF, "Color", group=GRP_MA6)
ma6Style = input.string("Dots", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA6)
ma6Wid = input.int(4, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA6)
string GRP_MA7 = "═══ MA SLOT 7 ═══"
ma7Show = input.bool(true, "Show", group=GRP_MA7)
ma7Len = input.int(200, "Length", minval=1, group=GRP_MA7)
ma7Src = input.source(close, "Source", group=GRP_MA7)
ma7Tf = input.timeframe("", "Timeframe", group=GRP_MA7)
ma7Col = input.color(#2962FF, "Color", group=GRP_MA7)
ma7Style = input.string("Line", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA7)
ma7Wid = input.int(4, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA7)
string GRP_MA8 = "═══ MA SLOT 8 ═══"
ma8Show = input.bool(true, "Show", group=GRP_MA8)
ma8Len = input.int(40, "Length", minval=1, group=GRP_MA8)
ma8Src = input.source(close, "Source", group=GRP_MA8)
ma8Tf = input.timeframe("240", "Timeframe", group=GRP_MA8)
ma8Col = input.color(#FF4081, "Color", group=GRP_MA8)
ma8Style = input.string("Dots", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA8)
ma8Wid = input.int(4, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA8)
string GRP_MA9 = "═══ MA SLOT 9 ═══"
ma9Show = input.bool(true, "Show", group=GRP_MA9)
ma9Len = input.int(200, "Length", minval=1, group=GRP_MA9)
ma9Src = input.source(close, "Source", group=GRP_MA9)
ma9Tf = input.timeframe("240", "Timeframe", group=GRP_MA9)
ma9Col = input.color(#87CEFA, "Color", group=GRP_MA9)
ma9Style = input.string("Diamond", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA9)
ma9Wid = input.int(3, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA9)
string GRP_MA10 = "═══ MA SLOT 10 ═══"
ma10Show = input.bool(true, "Show", group=GRP_MA10)
ma10Len = input.int(200, "Length", minval=1, group=GRP_MA10)
ma10Src = input.source(close, "Source", group=GRP_MA10)
ma10Tf = input.timeframe("D", "Timeframe", group=GRP_MA10)
ma10Col = input.color(#6A9F6E, "Color", group=GRP_MA10)
ma10Style = input.string("Diamond", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA10)
ma10Wid = input.int(3, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA10)
string GRP_MA11 = "═══ MA SLOT 11 ═══"
ma11Show = input.bool(true, "Show", group=GRP_MA11)
ma11Len = input.int(9, "Length", minval=1, group=GRP_MA11)
ma11Src = input.source(close, "Source", group=GRP_MA11)
ma11Tf = input.timeframe("", "Timeframe", group=GRP_MA11)
ma11Col = input.color(#FFA500, "Color", group=GRP_MA11)
ma11Style = input.string("Line", "Style", options=["Line", "Diamond", "Dots"], group=GRP_MA11)
ma11Wid = input.int(1, "Thickness / Size (1-4)", minval=1, maxval=4, group=GRP_MA11)
ma11Type = input.string("EMA", "MA Type", options=["SMA", "EMA"], group=GRP_MA11)
// ══════════════════════════════════════════════════════════════════════════════
// LEVELS — INPUTS
// ══════════════════════════════════════════════════════════════════════════════
string GRP_PDHL = "═══ PREVIOUS DAY HIGH / LOW ═══"
showPrevDayHL = input.bool(false, "Show Previous Day High/Low", group=GRP_PDHL,
tooltip="Calculated over the full prior futures day: 18:00 ET open through 16:00 ET RTH close. Displayed across the current day's session (18:00 open to 16:00 RTH close).")
pdHighColor = input.color(color.new(#FE0014, 0), "Previous Day High Color", group=GRP_PDHL)
pdHighStyle = input.string("Solid", "Previous Day High Style", options=["Solid", "Dotted", "Dashed"], group=GRP_PDHL)
pdHighWidth = input.int(4, "Previous Day High Width", minval=1, maxval=4, group=GRP_PDHL)
pdLowColor = input.color(color.new(#4CEA53, 0), "Previous Day Low Color", group=GRP_PDHL)
pdLowStyle = input.string("Solid", "Previous Day Low Style", options=["Solid", "Dotted", "Dashed"], group=GRP_PDHL)
pdLowWidth = input.int(4, "Previous Day Low Width", minval=1, maxval=4, group=GRP_PDHL)
string GRP_ONHL = "═══ OVERNIGHT HIGH / LOW ═══"
showOvernightHL = input.bool(false, "Show Overnight High/Low", group=GRP_ONHL,
tooltip="Overnight range: 18:00 ET open through 09:30 ET open. Line first appears at 09:00 ET and can still adjust its level until 09:30 ET if a new high/low prints in that half hour, then holds through 16:00 ET RTH close.")
onHighColor = input.color(color.new(#F23645, 0), "Overnight High Color", group=GRP_ONHL)
onHighStyle = input.string("Dashed", "Overnight High Style", options=["Solid", "Dotted", "Dashed"], group=GRP_ONHL)
onHighWidth = input.int(4, "Overnight High Width", minval=1, maxval=4, group=GRP_ONHL)
onLowColor = input.color(color.new(#00E676, 0), "Overnight Low Color", group=GRP_ONHL)
onLowStyle = input.string("Dashed", "Overnight Low Style", options=["Solid", "Dotted", "Dashed"], group=GRP_ONHL)
onLowWidth = input.int(4, "Overnight Low Width", minval=1, maxval=4, group=GRP_ONHL)
// ══════════════════════════════════════════════════════════════════════════════
// MARKET HOLIDAYS — INPUTS (independent of the Open Marker)
// ══════════════════════════════════════════════════════════════════════════════
string GRP_HOL = "═══ MARKET HOLIDAYS / EARLY CLOSES ═══"
showHolidays = input.bool(true, "Enable Holiday Markers (master switch)", group=GRP_HOL,
tooltip="Independent of the Open Marker. Dates follow the NYSE calendar (2015-2030). Futures usually still trade a shortened or thin session on these days, so you will see bars, just not normal ones.")
showHolClosed = input.bool(true, "Show Market Holidays", group=GRP_HOL)
showHolHalf = input.bool(true, "Show Early-Close Days", group=GRP_HOL,
tooltip="1:00 PM ET equity early closes: day after Thanksgiving, Christmas Eve, and July 3rd when applicable.")
showHolAfter = input.bool(true, "Show Day After Holiday", group=GRP_HOL,
tooltip="The first normal trading day after a full market holiday (e.g. the Tuesday after a Monday holiday, the Monday after Good Friday).")
showHolBefore = input.bool(false, "Show Day Before Holiday", group=GRP_HOL)
holSpan = input.string("Full futures day (18:00-18:00 ET)", "Highlight Span",
options=["Full futures day (18:00-18:00 ET)", "Regular hours (9:30-16:00 ET)", "Label only (no shading)"],
group=GRP_HOL,
tooltip="Full futures day shades from the 18:00 ET Globex open the evening before, so you can see it from the very start of the session. On daily charts the whole bar is shaded regardless.")
holLabels = input.bool(true, "Show Labels", group=GRP_HOL,
tooltip="One label per flagged day, on the first bar of the highlighted span, using the label size from the Toggles group.")
colorHolClosed = input.color(color.new(#ff1744, 72), "Market Holiday Color", group=GRP_HOL)
colorHolHalf = input.color(color.new(#ffc400, 72), "Early Close Color", group=GRP_HOL)
colorHolAdj = input.color(color.new(#00e676, 85), "Day After / Before Color", group=GRP_HOL)
// ---------------- Econ release dates (YYYYMMDD) ----------------
var int[] cpiDates = array.from(
20210113,20210210,20210310,20210413,20210512,20210610,20210713,20210811,20210914,20211013,20211110,20211210,
20220112,20220210,20220310,20220412,20220511,20220610,20220713,20220810,20220913,20221013,20221110,20221213,
20230112,20230214,20230314,20230412,20230510,20230613,20230712,20230810,20230913,20231012,20231114,20231212,
20240111,20240213,20240312,20240410,20240515,20240612,20240711,20240814,20240911,20241010,20241113,20241211,
20250115,20250212,20250312,20250410,20250513,20250611,20250715,20250812,20250911,20251024,20251218,
20260113,20260213,20260311,20260410,20260512,20260610,20260714,20260812,20260911,20261014,20261110,20261210,
20270113,20270211,20270310,20270413,20270512,20270610,20270714,20270811,20270914,20271014,20271110,20271210)
var int[] nfpDates = array.from(
20210108,20210205,20210305,20210402,20210507,20210604,20210702,20210806,20210903,20211008,20211105,20211203,
20220107,20220204,20220304,20220401,20220506,20220603,20220708,20220805,20220902,20221007,20221104,20221202,
20230106,20230203,20230310,20230407,20230505,20230602,20230707,20230804,20230901,20231006,20231103,20231208,
20240105,20240202,20240308,20240405,20240503,20240607,20240705,20240802,20240906,20241004,20241101,20241206,
20250110,20250207,20250307,20250404,20250502,20250606,20250703,20250801,20250905,20251120,20251216,
20260109,20260211,20260306,20260403,20260508,20260605,20260702,20260807,20260904,20261002,20261106,20261204,
20270108,20270205,20270305,20270402,20270507,20270604,20270702,20270806,20270903,20271008,20271105,20271203)
var int[] fomcDates = array.from(
20210127,20210317,20210428,20210616,20210728,20210922,20211103,20211215,
20220126,20220316,20220504,20220615,20220727,20220921,20221102,20221214,
20230201,20230322,20230503,20230614,20230726,20230920,20231101,20231213,
20240131,20240320,20240501,20240612,20240731,20240918,20241107,20241218,
20250129,20250319,20250507,20250618,20250730,20250917,20251029,20251210,
20260128,20260318,20260429,20260617,20260729,20260916,20261028,20261209,
20270127,20270317,20270428,20270609,20270728,20270915,20271027,20271208,
20280126)
// Derived: 21 days after each FOMC decision, always a Wednesday, 2:00 PM ET
var int[] fomcMinutesDates = array.from(
20210217,20210407,20210519,20210707,20210818,20211013,20211124,20220105,
20220216,20220406,20220525,20220706,20220817,20221012,20221123,20230104,
20230222,20230412,20230524,20230705,20230816,20231011,20231122,20240103,
20240221,20240410,20240522,20240703,20240821,20241009,20241128,20250108,
20250219,20250409,20250528,20250709,20250820,20251008,20251119,20251231,
20260218,20260408,20260520,20260708,20260819,20261007,20261118,20261230,
20270217,20270407,20270519,20270630,20270818,20271006,20271117,20271229,
20280216)
var int[] ppiDates = array.from(
20210115,20210217,20210312,20210409,20210513,20210615,20210714,20210812,20210910,20211014,20211109,20211214,
20220113,20220215,20220315,20220413,20220512,20220614,20220714,20220811,20220914,20221012,20221115,20221209,
20230118,20230216,20230315,20230413,20230511,20230614,20230713,20230811,20230914,20231011,20231115,20231213,
20240112,20240216,20240314,20240411,20240514,20240613,20240712,20240813,20240912,20241011,20241114,20241212,
20250114,20250213,20250313,20250411,20250515,20250612,20250716,20250814,20250910,20251125,
20260114,20260130,20260227,20260318,20260414,20260513,20260611,20260715,20260813,20260910,20261015,20261113,20261215,
20270114,20270212,20270312,20270414,20270513,20270611,20270715,20270810,20270910,20271015,20271112,20271215)
var int[] pceDates = array.from(
20210129,20210226,20210326,20210430,20210528,20210625,20210730,20210827,20211001,20211029,20211124,20211223,
20220128,20220225,20220331,20220429,20220527,20220630,20220729,20220826,20220930,20221028,20221201,20221223,
20230127,20230224,20230331,20230428,20230526,20230630,20230728,20230831,20230929,20231027,20231130,20231222,
20240126,20240229,20240329,20240426,20240531,20240628,20240726,20240830,20240927,20241031,20241127,20241220,
20250131,20250228,20250328,20250430,20250530,20250627,20250731,20250829,20250926,20251205,20251223,
20260122,20260220,20260313,20260409,20260430,20260528,20260625,20260730,20260826,20260930,20261029,20261125,20261223,
20270331,20270429,20270527,20270625,20270729,20270825,20270930,20271028,20271124)
// Jackson Hole Fed Chair keynote (final day of symposium, Friday, ~10:00 AM ET)
var int[] jhDates = array.from(20210827,20220826,20230825,20240823,20250822,20260828)
// ---------------- Earnings dates (YYYYMMDD) — BMO names ----------------
var int[] wmtDates = array.from(
20210218,20210518,20210817,20211116,
20220217,20220517,20220816,20221115,
20230221,20230518,20230817,20231116,
20240220,20240516,20240815,20241119,
20250220,20250515,20250821,20251120,
20260219,20260521,20260820)
var int[] tgtDates = array.from(
20210302,20210519,20210818,20211117,
20220301,20220518,20220817,20221116,
20230301,20230517,20230816,20231115,
20240305,20240522,20240821,20241120,
20250304,20250521,20250820,20251119,
20260303,20260520,20260819)
var int[] jpmDates = array.from(
20210115,20210414,20210713,20211013,
20220114,20220413,20220714,20221014,
20230113,20230414,20230714,20231013,
20240112,20240412,20240712,20241011,
20250115,20250411,20250715,20251014,
20260113,20260414,20260714,20261013)
// ---------------- Earnings dates (YYYYMMDD) — AMC names ----------------
var int[] aaplDates = array.from(
20210127,20210428,20210727,20211028,
20220127,20220428,20220728,20221027,
20230202,20230504,20230803,20231102,
20240201,20240502,20240801,20241031,
20250130,20250501,20250731,20251030,
20260129,20260430,20260730,20261102)
var int[] msftDates = array.from(
20210126,20210427,20210727,20211026,
20220125,20220426,20220726,20221025,
20230124,20230425,20230725,20231024,
20240130,20240425,20240730,20241030,
20250129,20250430,20250730,20251029,
20260128,20260429,20260729,20261028)
var int[] nvdaDates = array.from(
20210224,20210526,20210818,20211117,
20220216,20220525,20220824,20221116,
20230222,20230524,20230823,20231121,
20240221,20240522,20240828,20241120,
20250226,20250528,20250827,20251119,
20260225,20260520,20260826)
var int[] amznDates = array.from(
20210202,20210429,20210729,20211028,
20220203,20220428,20220728,20221027,
20230202,20230427,20230803,20231026,
20240201,20240430,20240801,20241031,
20250206,20250501,20250731,20251030,
20260205,20260429,20260730,20261029)
var int[] googlDates = array.from(
20210202,20210427,20210727,20211026,
20220201,20220426,20220726,20221025,
20230202,20230425,20230725,20231024,
20240130,20240425,20240723,20241029,
20250204,20250424,20250723,20251029,
20260204,20260429,20260722,20261028)
var int[] metaDates = array.from(
20210127,20210428,20210728,20211025,
20220202,20220427,20220727,20221026,
20230201,20230426,20230726,20231025,
20240201,20240424,20240731,20241030,
20250129,20250430,20250730,20251029,
20260128,20260429,20260729,20261021)
var int[] costDates = array.from(
20210304,20210527,20210923,20211209,
20220303,20220526,20220922,20221208,
20230302,20230525,20230926,20231214,
20240307,20240530,20240926,20241212,
20250306,20250529,20250925,20251211,
20260305,20260528,20260924)
// ---------------- Market holiday dates (YYYYMMDD) ----------------
// Full market closures 2015-2019 (NYSE calendar; includes 12/05/2018 Bush day of mourning)
var int[] holClosed1 = array.from(
20150101,20150119,20150216,20150403,20150525,20150703,20150907,20151126,20151225,
20160101,20160118,20160215,20160325,20160530,20160704,20160905,20161124,20161226,
20170102,20170116,20170220,20170414,20170529,20170704,20170904,20171123,20171225,
20180101,20180115,20180219,20180330,20180528,20180704,20180903,20181122,20181205,20181225,
20190101,20190121,20190218,20190419,20190527,20190704,20190902,20191128,20191225)
// Full market closures 2020-2024
var int[] holClosed2 = array.from(
20200101,20200120,20200217,20200410,20200525,20200703,20200907,20201126,20201225,
20210101,20210118,20210215,20210402,20210531,20210705,20210906,20211125,20211224,
20220117,20220221,20220415,20220530,20220620,20220704,20220905,20221124,20221226,
20230102,20230116,20230220,20230407,20230529,20230619,20230704,20230904,20231123,20231225,
20240101,20240115,20240219,20240329,20240527,20240619,20240704,20240902,20241128,20241225)
// Full market closures 2025-2030 (includes 01/09/2025 Carter day of mourning; 2027+ rule-projected)
var int[] holClosed3 = array.from(
20250101,20250109,20250120,20250217,20250418,20250526,20250619,20250704,20250901,20251127,20251225,
20260101,20260119,20260216,20260403,20260525,20260619,20260703,20260907,20261126,20261225,
20270101,20270118,20270215,20270326,20270531,20270618,20270705,20270906,20271125,20271224,
20280117,20280221,20280414,20280529,20280619,20280704,20280904,20281123,20281225,
20290101,20290115,20290219,20290330,20290528,20290619,20290704,20290903,20291122,20291225,
20300101,20300121,20300218,20300419,20300527,20300619,20300704,20300902,20301128,20301225)
// Early-close (1:00 PM ET equity) days 2015-2030
var int[] holHalf = array.from(
20151127,20151224,
20161125,
20170703,20171124,
20180703,20181123,20181224,
20190703,20191129,20191224,
20201127,20201224,
20211126,
20221125,
20230703,20231124,
20240703,20241129,20241224,
20250703,20251128,20251224,
20261127,20261224,
20271126,
20280703,20281124,
20290703,20291123,20291224,
20300703,20301129,20301224)
// ---------------- Logic ----------------
f_match(arr, val) => array.indexof(arr, val) >= 0
// A daily bar is stamped at the 18:00 ET session start of the evening before, so its own
// calendar date is the previous day. Shifting by 6 hours lands on the trading date.
evtTime = timeframe.isdaily ? time + 6 * 60 * 60 * 1000 : time
nyYear = year(evtTime, "America/New_York")
nyMonth = month(evtTime, "America/New_York")
nyDay = dayofmonth(evtTime, "America/New_York")
dateVal = nyYear * 10000 + nyMonth * 100 + nyDay
t_830 = timestamp("America/New_York", nyYear, nyMonth, nyDay, 8, 30)
t_1000 = timestamp("America/New_York", nyYear, nyMonth, nyDay, 10, 0) // Jackson Hole keynote
t_1400 = timestamp("America/New_York", nyYear, nyMonth, nyDay, 14, 0) // FOMC / Minutes
t_amc = timestamp("America/New_York", nyYear, nyMonth, nyDay, 16, 0) // earnings AMC
t_bmoStart = timestamp("America/New_York", nyYear, nyMonth, nyDay, 6, 0)
t_bmoEnd = timestamp("America/New_York", nyYear, nyMonth, nyDay, 9, 30)
t_witchStart = timestamp("America/New_York", nyYear, nyMonth, nyDay, 15, 0)
t_witchEnd = timestamp("America/New_York", nyYear, nyMonth, nyDay, 16, 0)
// On a daily chart the bar covers the whole trading day, so the intraday time window always applies
f_inBar(t) => timeframe.isdaily or (t >= time and t < time_close)
f_inRange(rangeStart, rangeEnd) => timeframe.isdaily or (time < rangeEnd and time_close > rangeStart)
isCPI = showCPI and f_match(cpiDates, dateVal) and f_inBar(t_830)
isNFP = showNFP and f_match(nfpDates, dateVal) and f_inBar(t_830)
isFOMC = showFOMC and f_match(fomcDates, dateVal) and f_inBar(t_1400)
isMinutes = showMinutes and f_match(fomcMinutesDates, dateVal) and f_inBar(t_1400)
isPPI = showPPI and f_match(ppiDates, dateVal) and f_inBar(t_830)
isPCE = showPCE and f_match(pceDates, dateVal) and f_inBar(t_830)
isJH = showJH and f_match(jhDates, dateVal) and f_inBar(t_1000)
isWitchingMonth = nyMonth == 3 or nyMonth == 6 or nyMonth == 9 or nyMonth == 12
isThirdFriday = dayofweek(evtTime, "America/New_York") == dayofweek.friday and nyDay >= 15 and nyDay <= 21
isWitching = showWitching and isWitchingMonth and isThirdFriday and f_inRange(t_witchStart, t_witchEnd)
isWMT = showEarnings and f_match(wmtDates, dateVal) and f_inRange(t_bmoStart, t_bmoEnd)
isTGT = showEarnings and f_match(tgtDates, dateVal) and f_inRange(t_bmoStart, t_bmoEnd)
isJPM = showEarnings and f_match(jpmDates, dateVal) and f_inRange(t_bmoStart, t_bmoEnd)
isAAPL = showEarnings and f_match(aaplDates, dateVal) and f_inBar(t_amc)
isMSFT = showEarnings and f_match(msftDates, dateVal) and f_inBar(t_amc)
isNVDA = showEarnings and f_match(nvdaDates, dateVal) and f_inBar(t_amc)
isAMZN = showEarnings and f_match(amznDates, dateVal) and f_inBar(t_amc)
isGOOGL= showEarnings and f_match(googlDates,dateVal) and f_inBar(t_amc)
isMETA = showEarnings and f_match(metaDates, dateVal) and f_inBar(t_amc)
isCOST = showEarnings and f_match(costDates, dateVal) and f_inBar(t_amc)
isBMOEarn = isWMT or isTGT or isJPM
isAMCEarn = isAAPL or isMSFT or isNVDA or isAMZN or isGOOGL or isMETA or isCOST
isEarnings = isBMOEarn or isAMCEarn
earnLabel = isWMT ? "WMT" : isTGT ? "TGT" : isJPM ? "JPM" : isAAPL ? "AAPL" : isMSFT ? "MSFT" : isNVDA ? "NVDA" : isAMZN ? "AMZN" : isGOOGL ? "GOOGL" : isMETA ? "META" : isCOST ? "COST" : na
// ---------------- Rendering ----------------
bgcolor(isFOMC ? colorFOMC : isNFP ? colorNFP : isCPI ? colorCPI : na, title = "Econ release highlight")
bgcolor(isMinutes ? colorMinutes : na, title = "FOMC Minutes highlight")
bgcolor(isPPI ? colorPPI : na, title = "PPI highlight")
bgcolor(isPCE ? colorPCE : na, title = "PCE highlight")
bgcolor(isJH ? colorJH : na, title = "Jackson Hole highlight")
bgcolor(isWitching ? colorWitching : na, title = "Witching highlight")
bgcolor(isEarnings ? (isBMOEarn ? colorEarnBMO : colorEarnAMC) : na, title = "Earnings highlight")
if showLabels and isCPI
label.new(bar_index, high, "CPI", style = label.style_label_down, color = color.new(colorCPI, 0), textcolor = color.black, size = lblSize)
if showLabels and isNFP
label.new(bar_index, high, "NFP", style = label.style_label_down, color = color.new(colorNFP, 0), textcolor = color.white, size = lblSize)
if showLabels and isFOMC
label.new(bar_index, low, "FOMC", style = label.style_label_up, color = color.new(colorFOMC, 0), textcolor = color.white, size = lblSize)
if showLabels and isMinutes
label.new(bar_index, low, "MIN", style = label.style_label_up, color = color.new(colorMinutes, 0), textcolor = color.white, size = lblSize)
if showLabels and isPPI
label.new(bar_index, high, "PPI", style = label.style_label_down, color = color.new(colorPPI, 0), textcolor = color.black, size = lblSize)
if showLabels and isPCE
label.new(bar_index, high, "PCE", style = label.style_label_down, color = color.new(colorPCE, 0), textcolor = color.white, size = lblSize)
if showLabels and isJH
label.new(bar_index, low, "JH", style = label.style_label_up, color = color.new(colorJH, 0), textcolor = color.white, size = lblSize)
if showLabels and isWitching
label.new(bar_index, high, "OPEX", style = label.style_label_down, color = color.new(colorWitching, 0), textcolor = color.white, size = lblSize)
if showLabels and isEarnings
label.new(bar_index, isBMOEarn ? low : high, earnLabel, style = isBMOEarn ? label.style_label_up : label.style_label_down, color = color.new(isBMOEarn ? colorEarnBMO : colorEarnAMC, 0), textcolor = color.white, size = lblSize)
// ---------------- Legend table (optional, off by default) ----------------
var table legend = showLegend ? table.new(position.top_right, 1, 14, bgcolor = color.new(color.black, 70), border_width = 1) : na
if barstate.islast and showLegend
table.cell(legend, 0, 0, "Releases", text_color = color.white, text_size = size.small)
table.cell(legend, 0, 1, "■ CPI", text_color = colorCPI, text_size = size.small)
table.cell(legend, 0, 2, "■ NFP", text_color = colorNFP, text_size = size.small)
table.cell(legend, 0, 3, "■ FOMC", text_color = colorFOMC, text_size = size.small)
table.cell(legend, 0, 4, "■ FOMC Minutes", text_color = colorMinutes, text_size = size.small)
table.cell(legend, 0, 5, "■ PPI", text_color = colorPPI, text_size = size.small)
table.cell(legend, 0, 6, "■ PCE", text_color = colorPCE, text_size = size.small)
table.cell(legend, 0, 7, "■ Jackson Hole", text_color = colorJH, text_size = size.small)
table.cell(legend, 0, 8, "■ Witching", text_color = colorWitching, text_size = size.small)
table.cell(legend, 0, 9, "■ Earnings (BMO)", text_color = colorEarnBMO, text_size = size.small)
table.cell(legend, 0, 10, "■ Earnings (AMC)", text_color = colorEarnAMC, text_size = size.small)
table.cell(legend, 0, 11, "■ Market Holiday", text_color = colorHolClosed, text_size = size.small)
table.cell(legend, 0, 12, "■ Early Close", text_color = colorHolHalf, text_size = size.small)
table.cell(legend, 0, 13, "■ Day After/Before Holiday", text_color = colorHolAdj, text_size = size.small)
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — HELPER FUNCTIONS
// ══════════════════════════════════════════════════════════════════════════════
isIntraday = timeframe.isintraday
getLabelSize(string s) =>
result = size.normal
if s == "tiny"
result := size.tiny
else if s == "small"
result := size.small
else if s == "normal"
result := size.normal
else if s == "large"
result := size.large
else if s == "huge"
result := size.huge
result
getSmallerSize(string s) =>
result = size.small
if s == "tiny"
result := size.tiny
else if s == "small"
result := size.tiny
else if s == "normal"
result := size.small
else if s == "large"
result := size.normal
else if s == "huge"
result := size.large
result
getLineStyle(string s) =>
result = line.style_dotted
if s == "Solid"
result := line.style_solid
else if s == "Dotted"
result := line.style_dotted
else if s == "Dashed"
result := line.style_dashed
result
getMonthName(int m) =>
result = "???"
if m == 1
result := "Jan"
else if m == 2
result := "Feb"
else if m == 3
result := "Mar"
else if m == 4
result := "Apr"
else if m == 5
result := "May"
else if m == 6
result := "Jun"
else if m == 7
result := "Jul"
else if m == 8
result := "Aug"
else if m == 9
result := "Sep"
else if m == 10
result := "Oct"
else if m == 11
result := "Nov"
else if m == 12
result := "Dec"
result
getMonthNameFull(int m) =>
result = "???"
if m == 1
result := "January"
else if m == 2
result := "February"
else if m == 3
result := "March"
else if m == 4
result := "April"
else if m == 5
result := "May"
else if m == 6
result := "June"
else if m == 7
result := "July"
else if m == 8
result := "August"
else if m == 9
result := "September"
else if m == 10
result := "October"
else if m == 11
result := "November"
else if m == 12
result := "December"
result
getDayShort(int d) =>
result = "???"
if d == 1
result := "Sun"
else if d == 2
result := "Mon"
else if d == 3
result := "Tue"
else if d == 4
result := "Wed"
else if d == 5
result := "Thu"
else if d == 6
result := "Fri"
else if d == 7
result := "Sat"
result
getDayFull(int d) =>
result = "???"
if d == 1
result := "Sunday"
else if d == 2
result := "Monday"
else if d == 3
result := "Tuesday"
else if d == 4
result := "Wednesday"
else if d == 5
result := "Thursday"
else if d == 6
result := "Friday"
else if d == 7
result := "Saturday"
result
padZero(int n) =>
n < 10 ? "0" + str.tostring(n) : str.tostring(n)
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — DYNAMIC SPACING
// ══════════════════════════════════════════════════════════════════════════════
atrValue = nz(ta.atr(14), close * 0.01)
baseSpacing = atrValue * markerSpacing / 10
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — DETECT MARKET OPEN (NY 9:30 AM ET)
// ══════════════════════════════════════════════════════════════════════════════
string marketTz = "America/New_York"
int openHour = 9
int openMinute = 30
openTimeMinutes = openHour * 60 + openMinute
barOpenH = hour(time, marketTz)
barOpenM = minute(time, marketTz)
barOpenMinutes = barOpenH * 60 + barOpenM
barCloseH = hour(time_close, marketTz)
barCloseM = minute(time_close, marketTz)
barCloseMinutes = barCloseH * 60 + barCloseM
bool isOpenBar = false
if barCloseMinutes == barOpenMinutes
isOpenBar := true
else if barCloseMinutes > barOpenMinutes
isOpenBar := barOpenMinutes <= openTimeMinutes and openTimeMinutes < barCloseMinutes
else
isOpenBar := barOpenMinutes <= openTimeMinutes or openTimeMinutes < barCloseMinutes
tzDayOfWeek = dayofweek(time, marketTz)
isTradingDay = tzDayOfWeek >= 2 and tzDayOfWeek <= 6
var int lastMarkedDay = 0
currentDay = dayofmonth(time, marketTz)
currentMonth = month(time, marketTz)
currentYear = year(time, marketTz)
uniqueDayID = currentYear * 10000 + currentMonth * 100 + currentDay
isFirstOpenOfDay = showOpenMarker and isIntraday and isOpenBar and isTradingDay and (uniqueDayID != lastMarkedDay)
if isFirstOpenOfDay
lastMarkedDay := uniqueDayID
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — CANDLE TYPE AND POSITION
// ══════════════════════════════════════════════════════════════════════════════
isBullish = close >= open
isBearish = close < open
isAboveCandle = markerPosition == "Always Above" or (markerPosition == "Auto (Above Bear / Below Bull)" and isBearish)
isBelowCandle = markerPosition == "Always Below" or (markerPosition == "Auto (Above Bear / Below Bull)" and isBullish)
float offsetAmount = baseSpacing * markerOffset / 10
float markerY = isAboveCandle ? high + baseSpacing + offsetAmount : low - baseSpacing - offsetAmount
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — DRAW MARKER
// ══════════════════════════════════════════════════════════════════════════════
if isFirstOpenOfDay and markerEnabled
markerStyle = label.style_label_down
useSmallSize = false
if markerType == "Label Flag"
markerStyle := isAboveCandle ? label.style_label_down : label.style_label_up
else if markerType == "Arrow"
markerStyle := isAboveCandle ? label.style_arrowdown : label.style_arrowup
else if markerType == "Arrow Thin"
markerStyle := isAboveCandle ? label.style_arrowdown : label.style_arrowup
useSmallSize := true
else if markerType == "Triangle"
markerStyle := isAboveCandle ? label.style_triangledown : label.style_triangleup
else if markerType == "Triangle Small"
markerStyle := isAboveCandle ? label.style_triangledown : label.style_triangleup
useSmallSize := true
else if markerType == "Diamond"
markerStyle := label.style_diamond
finalSize = useSmallSize ? getSmallerSize(markerSize) : getLabelSize(markerSize)
label.new(bar_index, markerY, "",
style=markerStyle,
color=markerColor,
size=finalSize,
textcolor=color.white)
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — COMBINED TIME / DATE LABEL
// ══════════════════════════════════════════════════════════════════════════════
if isFirstOpenOfDay and (showTimeLabel or showDateLabel)
float extraOffset = baseSpacing * 2
float omLabelY = isAboveCandle ? high + baseSpacing + offsetAmount + extraOffset : low - baseSpacing - offsetAmount - extraOffset
omLabelStyle = isAboveCandle ? label.style_label_down : label.style_label_up
// Build the combined label text
string omLabelText = ""
// Time line
if showTimeLabel
omLabelText := "9:30 AM ET"
// Date line
if showDateLabel
string yy = padZero(currentYear % 100)
string mm = padZero(currentMonth)
string dd = padZero(currentDay)
string dateStr = mm + "/" + dd + "/" + yy
if dateFormat == "DD/MM/YY (European)"
dateStr := dd + "/" + mm + "/" + yy
else if dateFormat == "DD Mon 'YY (Written)"
dateStr := dd + " " + getMonthName(currentMonth) + ". '" + yy
else if dateFormat == "Mon DD, YYYY (Full)"
dateStr := getMonthNameFull(currentMonth) + " " + dd + ", " + str.tostring(currentYear)
if showDayOfWeek
string dayStr = dayOfWeekFormat == "Short (Mon, Tue...)" ? getDayShort(tzDayOfWeek) : getDayFull(tzDayOfWeek)
dateStr := dayStr + " " + dateStr
if showTimeLabel
omLabelText := omLabelText + "\n" + dateStr
else
omLabelText := dateStr
omLabelSize = showTimeLabel ? getLabelSize(timeLabelSize) : getLabelSize(dateLabelSize)
omLabelColor = showTimeLabel ? timeLabelColor : dateLabelColor
label.new(bar_index, omLabelY, omLabelText,
style=omLabelStyle,
color=color.new(omLabelColor, 80),
textcolor=omLabelColor,
size=omLabelSize)
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — VERTICAL LINES
// ══════════════════════════════════════════════════════════════════════════════
if isFirstOpenOfDay and showOpenLine
line.new(bar_index, low - atrValue * 2,
bar_index, high + atrValue * 2,
extend=extend.both,
color=openLineColor,
style=getLineStyle(openLineStyle),
width=openLineWidth)
if isFirstOpenOfDay and showPreOpenLine
line.new(bar_index - 1, low[1] - atrValue * 2,
bar_index - 1, high[1] + atrValue * 2,
extend=extend.both,
color=preOpenLineColor,
style=getLineStyle(preOpenLineStyle),
width=preOpenLineWidth)
// ══════════════════════════════════════════════════════════════════════════════
// OPEN MARKER — BACKGROUND HIGHLIGHT
// ══════════════════════════════════════════════════════════════════════════════
bgcolor(isFirstOpenOfDay and showBgHighlight ? (isBullish ? bgBullColor : bgBearColor) : na, title = "Open bar highlight")
// ══════════════════════════════════════════════════════════════════════════════
// MOVING AVERAGES — CALCULATION & PLOTS
// ══════════════════════════════════════════════════════════════════════════════
// ---- MA slot 1 ----
ma1 = request.security(syminfo.tickerid, ma1Tf, ta.sma(ma1Src, ma1Len), lookahead=barmerge.lookahead_off)
ma1On = showMAs and ma1Show
ma1PlotStyle = ma1Style == "Diamond" ? plot.style_stepline_diamond : ma1Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma1On ? ma1 : na, "MA 1", color=ma1Col, linewidth=ma1Wid, style=ma1PlotStyle)
// ---- MA slot 2 ----
ma2 = request.security(syminfo.tickerid, ma2Tf, ta.sma(ma2Src, ma2Len), lookahead=barmerge.lookahead_off)
ma2On = showMAs and ma2Show
ma2PlotStyle = ma2Style == "Diamond" ? plot.style_stepline_diamond : ma2Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma2On ? ma2 : na, "MA 2", color=ma2Col, linewidth=ma2Wid, style=ma2PlotStyle)
// ---- MA slot 3 ----
ma3 = request.security(syminfo.tickerid, ma3Tf, ta.sma(ma3Src, ma3Len), lookahead=barmerge.lookahead_off)
ma3On = showMAs and ma3Show
ma3PlotStyle = ma3Style == "Diamond" ? plot.style_stepline_diamond : ma3Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma3On ? ma3 : na, "MA 3", color=ma3Col, linewidth=ma3Wid, style=ma3PlotStyle)
// ---- MA slot 4 ----
ma4 = request.security(syminfo.tickerid, ma4Tf, ta.sma(ma4Src, ma4Len), lookahead=barmerge.lookahead_off)
ma4On = showMAs and ma4Show
ma4PlotStyle = ma4Style == "Diamond" ? plot.style_stepline_diamond : ma4Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma4On ? ma4 : na, "MA 4", color=ma4Col, linewidth=ma4Wid, style=ma4PlotStyle)
// ---- MA slot 5 ----
ma5 = request.security(syminfo.tickerid, ma5Tf, ta.sma(ma5Src, ma5Len), lookahead=barmerge.lookahead_off)
ma5On = showMAs and ma5Show
ma5PlotStyle = ma5Style == "Diamond" ? plot.style_stepline_diamond : ma5Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma5On ? ma5 : na, "MA 5", color=ma5Col, linewidth=ma5Wid, style=ma5PlotStyle)
// ---- MA slot 6 ----
ma6 = request.security(syminfo.tickerid, ma6Tf, ta.sma(ma6Src, ma6Len), lookahead=barmerge.lookahead_off)
ma6On = showMAs and ma6Show
ma6PlotStyle = ma6Style == "Diamond" ? plot.style_stepline_diamond : ma6Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma6On ? ma6 : na, "MA 6", color=ma6Col, linewidth=ma6Wid, style=ma6PlotStyle)
// ---- MA slot 7 ----
ma7 = request.security(syminfo.tickerid, ma7Tf, ta.sma(ma7Src, ma7Len), lookahead=barmerge.lookahead_off)
ma7On = showMAs and ma7Show
ma7PlotStyle = ma7Style == "Diamond" ? plot.style_stepline_diamond : ma7Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma7On ? ma7 : na, "MA 7", color=ma7Col, linewidth=ma7Wid, style=ma7PlotStyle)
// ---- MA slot 8 ----
ma8 = request.security(syminfo.tickerid, ma8Tf, ta.sma(ma8Src, ma8Len), lookahead=barmerge.lookahead_off)
ma8On = showMAs and ma8Show
ma8PlotStyle = ma8Style == "Diamond" ? plot.style_stepline_diamond : ma8Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma8On ? ma8 : na, "MA 8", color=ma8Col, linewidth=ma8Wid, style=ma8PlotStyle)
// ---- MA slot 9 ----
ma9 = request.security(syminfo.tickerid, ma9Tf, ta.sma(ma9Src, ma9Len), lookahead=barmerge.lookahead_off)
ma9On = showMAs and ma9Show
ma9PlotStyle = ma9Style == "Diamond" ? plot.style_stepline_diamond : ma9Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma9On ? ma9 : na, "MA 9", color=ma9Col, linewidth=ma9Wid, style=ma9PlotStyle)
// ---- MA slot 10 ----
ma10 = request.security(syminfo.tickerid, ma10Tf, ta.sma(ma10Src, ma10Len), lookahead=barmerge.lookahead_off)
ma10On = showMAs and ma10Show
ma10PlotStyle = ma10Style == "Diamond" ? plot.style_stepline_diamond : ma10Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma10On ? ma10 : na, "MA 10", color=ma10Col, linewidth=ma10Wid, style=ma10PlotStyle)
// ---- MA slot 11 ----
ma11Base = ma11Type == "EMA" ? ta.ema(ma11Src, ma11Len) : ta.sma(ma11Src, ma11Len)
ma11 = request.security(syminfo.tickerid, ma11Tf, ma11Base, lookahead=barmerge.lookahead_off)
ma11On = showMAs and ma11Show
ma11PlotStyle = ma11Style == "Diamond" ? plot.style_stepline_diamond : ma11Style == "Dots" ? plot.style_circles : plot.style_line
plot(ma11On ? ma11 : na, "MA 11", color=ma11Col, linewidth=ma11Wid, style=ma11PlotStyle)
// ══════════════════════════════════════════════════════════════════════════════
// LEVELS — SESSION WINDOW DETECTION
// ══════════════════════════════════════════════════════════════════════════════
// "Futures day" bucket: a bar belongs to the trading day whose RTH session it
// leads into. Shifting the timestamp 6 hours moves the 18:00 ET rollover to
// midnight, so the calendar date of the shifted time gives the correct bucket
// for both the overnight leg and the RTH leg of that day's session.
shiftedTime = time + 6 * 60 * 60 * 1000
futuresDayID = year(shiftedTime, marketTz) * 10000 + month(shiftedTime, marketTz) * 100 + dayofmonth(shiftedTime, marketTz)
inSessionWindow = barOpenMinutes >= 1080 or barOpenMinutes < 960 // 18:00 -> 16:00 next day
inOvernightWindow = barOpenMinutes >= 1080 or barOpenMinutes < 570 // 18:00 -> 09:30 next day
inDisplayWindow = barOpenMinutes >= 540 and barOpenMinutes < 960 // 09:00 -> 16:00 same day
// ── Previous Day High / Low ──
var float sessHighAcc = na
var float sessLowAcc = na
var int sessID = 0
var float prevSessHigh = na
var float prevSessLow = na
var line pdHighLine = na
var line pdLowLine = na
if isIntraday and inSessionWindow
if futuresDayID != sessID
prevSessHigh := sessHighAcc
prevSessLow := sessLowAcc
sessID := futuresDayID
sessHighAcc := high
sessLowAcc := low
if showPrevDayHL and not na(prevSessHigh)
pdHighLine := line.new(bar_index, prevSessHigh, bar_index, prevSessHigh, color=pdHighColor, width=pdHighWidth, style=getLineStyle(pdHighStyle), extend=extend.none)
pdLowLine := line.new(bar_index, prevSessLow, bar_index, prevSessLow, color=pdLowColor, width=pdLowWidth, style=getLineStyle(pdLowStyle), extend=extend.none)
else
sessHighAcc := math.max(sessHighAcc, high)
sessLowAcc := math.min(sessLowAcc, low)
if showPrevDayHL and not na(pdHighLine)
line.set_x2(pdHighLine, bar_index)
line.set_x2(pdLowLine, bar_index)
// ── Overnight High / Low ──
var float onHighAcc = na
var float onLowAcc = na
var int onID = 0
var int onLineDay = 0
var line onHighLine = na
var line onLowLine = na
if isIntraday and inOvernightWindow
if futuresDayID != onID
onID := futuresDayID
onHighAcc := high
onLowAcc := low
else
onHighAcc := math.max(onHighAcc, high)
onLowAcc := math.min(onLowAcc, low)
if isIntraday and showOvernightHL and inDisplayWindow
if uniqueDayID != onLineDay
onLineDay := uniqueDayID
if not na(onHighAcc)
onHighLine := line.new(bar_index, onHighAcc, bar_index, onHighAcc, color=onHighColor, width=onHighWidth, style=getLineStyle(onHighStyle), extend=extend.none)
onLowLine := line.new(bar_index, onLowAcc, bar_index, onLowAcc, color=onLowColor, width=onLowWidth, style=getLineStyle(onLowStyle), extend=extend.none)
if not na(onHighLine)
line.set_y1(onHighLine, onHighAcc)
line.set_y2(onHighLine, onHighAcc)
line.set_x2(onHighLine, bar_index)
line.set_y1(onLowLine, onLowAcc)
line.set_y2(onLowLine, onLowAcc)
line.set_x2(onLowLine, bar_index)
// ══════════════════════════════════════════════════════════════════════════════
// MARKET HOLIDAYS — HELPERS
// ══════════════════════════════════════════════════════════════════════════════
f_isClosed(int id) =>
f_match(holClosed1, id) or f_match(holClosed2, id) or f_match(holClosed3, id)
f_isHalf(int id) =>
f_match(holHalf, id)
// YYYYMMDD of a timestamp, in ET
f_dateID(int ts) =>
year(ts, marketTz) * 10000 + month(ts, marketTz) * 100 + dayofmonth(ts, marketTz)
// Noon ET of a YYYYMMDD id (noon keeps +/- 1h DST shifts on the same calendar date)
f_noon(int id) =>
timestamp(marketTz, int(id / 10000), int(id / 100) % 100, id % 100, 12, 0)
f_holName(int d) =>
int m = int(d / 100) % 100
int dd = d % 100
string r = "Market Holiday"
if d == 20181205
r := "Day of Mourning (G.H.W. Bush)"
else if d == 20250109
r := "Day of Mourning (Carter)"
else if m == 1
r := dd <= 3 ? "New Year's Day" : "MLK Day"
else if m == 2
r := "Presidents' Day"
else if m == 3 or m == 4
r := "Good Friday"
else if m == 5
r := "Memorial Day"
else if m == 6
r := "Juneteenth"
else if m == 7
r := "Independence Day"
else if m == 9
r := "Labor Day"
else if m == 11
r := "Thanksgiving"
else if m == 12
r := "Christmas"
r
f_halfName(int d) =>
int m = int(d / 100) % 100
string r = "Early Close"
if m == 7
r := "Early Close (Eve of July 4th)"
else if m == 11
r := "Early Close (Day After Thanksgiving)"
else if m == 12
r := "Early Close (Christmas Eve)"
r
// ══════════════════════════════════════════════════════════════════════════════
// MARKET HOLIDAYS — DETECTION
// ══════════════════════════════════════════════════════════════════════════════
// Uses the same "futures day" bucket as the Levels (18:00 ET rollover), so the
// Sunday-evening Globex open of a Monday holiday is already flagged.
bool holChartOK = timeframe.isintraday or timeframe.isdaily
bool holOn = showHolidays and holChartOK
int holNoon = f_noon(futuresDayID)
int holDow = dayofweek(holNoon, marketTz)
// previous / next weekday (skips the weekend)
int holPrevID = f_dateID(holNoon - (holDow == dayofweek.monday ? 3 : holDow == dayofweek.sunday ? 2 : 1) * 86400000)
int holNextID = f_dateID(holNoon + (holDow == dayofweek.friday ? 3 : holDow == dayofweek.saturday ? 2 : 1) * 86400000)
bool holRawClosed = f_isClosed(futuresDayID)
bool holRawHalf = f_isHalf(futuresDayID)
bool isHolClosed = holOn and showHolClosed and holRawClosed
bool isHolHalf = holOn and showHolHalf and holRawHalf
bool isHolAfter = holOn and showHolAfter and not holRawClosed and not holRawHalf and f_isClosed(holPrevID)
bool isHolBefore = holOn and showHolBefore and not holRawClosed and not holRawHalf and f_isClosed(holNextID)
bool holAny = isHolClosed or isHolHalf or isHolAfter or isHolBefore
bool holShade = holSpan != "Label only (no shading)"
bool holInBand = true
if timeframe.isintraday and holSpan == "Regular hours (9:30-16:00 ET)"
holInBand := f_inRange(t_bmoEnd, t_amc)
// ══════════════════════════════════════════════════════════════════════════════
// MARKET HOLIDAYS — RENDERING
// ══════════════════════════════════════════════════════════════════════════════
bool holBand = holAny and holShade and holInBand
bgcolor(holBand and isHolClosed ? colorHolClosed : na, title = "Market holiday highlight")
bgcolor(holBand and isHolHalf ? colorHolHalf : na, title = "Early close highlight")
bgcolor(holBand and (isHolAfter or isHolBefore) ? colorHolAdj : na, title = "Day after/before holiday highlight")
var int lastHolLabelDay = 0
bool holLabelBar = holAny and holLabels and futuresDayID != lastHolLabelDay and holInBand
if holLabelBar
lastHolLabelDay := futuresDayID
string holTxt = isHolClosed ? "MARKET HOLIDAY\n" + f_holName(futuresDayID) : isHolHalf ? "EARLY CLOSE\n" + f_halfName(futuresDayID) : isHolAfter ? "DAY AFTER HOLIDAY\n" + f_holName(holPrevID) : "DAY BEFORE HOLIDAY\n" + f_holName(holNextID)
color holCol = isHolClosed ? colorHolClosed : isHolHalf ? colorHolHalf : colorHolAdj
color holTxtCol = isHolClosed ? color.white : color.black
label.new(bar_index, high, holTxt, style = label.style_label_down, color = color.new(holCol, 0), textcolor = holTxtCol, size = lblSize)