本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Días de dato macro", shorttitle = "Datos macro", overlay = true, max_lines_count = 100, max_labels_count = 100)
// The scheduled US releases of the coming weeks (inflation CPI and PPI, payrolls, retail sales, GDP, personal income
// and outlays PCE, the Fed's decision, the manufacturing survey), marked on the chart at their New York time, and for
// the market of the chart what we measured after each kind of release over the last 3 years:
// - the range of the hour after the release against the same hour of the 20 previous sessions without a release
// (the median multiple and its 95% interval: "1.0" = a normal hour; an interval that holds 1 reads "igual al azar");
// - how often the close kept the sign of the first 5 minutes after the release ("1st reaction held", with its 95%
// interval: an interval that holds 50% reads "igual al azar"); the sign itself is never shown.
// Each figure carries its n (releases measured).
//
// The calendar is written into the script when it is built (DATA_THROUGH): it holds the dates published by then, and
// the table says through which date the monthly release dates were listed. A date marked "est." is a rule-based
// estimate, "aprox." an approximation (the manufacturing survey: the first weekday of the month). A release moved
// after the build is not known here.
//
// Size and frequency only: nothing here says which way the market goes after a release or what to trade. Not a signal.
// --- BEGIN GENERATED CONSTANTS
// Written by scripts/build_tradingview_constants.py. Do not edit by hand.
// Calendar built 2026-10-16 (10 releases, monthly release dates listed through 2026-12-16); 8 markets with measured reactions. Dates, hours, sizes, rates and counts only.
string DATA_THROUGH = "2026-10-16"
string CAL_LISTED = "2026-12-16"
f_parent(string r) =>
switch r
"MES" => "ES"
"MNQ" => "NQ"
"M2K" => "RTY"
"MYM" => "YM"
"MGC" => "GC"
"SIL" => "SI"
"MHG" => "HG"
"MCL" => "CL"
"QM" => "CL"
"MNG" => "NG"
"QG" => "NG"
"MBT" => "BTC"
"MET" => "ETH"
"M6E" => "6E"
"M6A" => "6A"
"M6B" => "6B"
"E7" => "6E"
"J7" => "6J"
"XC" => "ZC"
"XK" => "ZS"
"XW" => "ZW"
"10Y" => "ZN"
"MTN" => "ZN"
"MWN" => "ZB"
=> r
f_cal() =>
"2026-10-28,1400,fomc,0;2026-10-29,0830,gdp,0;2026-10-29,0830,pce,0;2026-11-02,1000,ism,2;2026-11-06,0830,nfp,0;2026-11-10,0830,cpi,0;2026-11-13,0830,ppi,0;2026-11-17,0830,retail,0;2026-11-25,0830,gdp,0;2026-11-25,0830,pce,0"
f_mr(string r) =>
switch r
"ES" => "MR1|ES|2026-10-17|2023-10-17|cpi:35,3.17,2.99,4.42,35,65.7,49.2,79.2,35,1.163,0.869,1.348,35|nfp:34,2.915,2.3548,3.7,34,60.6,43.7,75.3,33,1.3815,1.0825,1.612,34|ppi:34,1.885,1.58,2.13,34,55.9,39.5,71.1,34,1.143,0.925,1.4115,34|retail:36,1.49,1.27,1.86,36,50,34.5,65.5,36,0.995,0.919,1.1052,36|gdp:37,1.23,1.09,1.59,37,47.2,32,63,36,1.11,0.972,1.216,37|pce:35,1.38,1.27,1.79,35,45.7,30.5,61.8,35,1.216,1.09,1.41,35|fomc:24,3.14,2.25,4.86,24,58.3,38.8,75.5,24,1.465,1.004,1.833,24|ism:36,1.265,1.025,1.69,36,57.6,40.8,72.8,33,1.2365,1.0955,1.509,36"
"NQ" => "MR1|NQ|2026-10-17|2023-10-17|cpi:35,2.94,2.59,3.58,35,71.4,54.9,83.7,35,1.042,0.886,1.32,35|nfp:34,2.65,2.255,2.99,34,72.7,55.8,84.9,33,1.239,0.9796,1.5765,34|ppi:34,1.785,1.48,2.225,34,61.8,45,76.1,34,1.044,0.914,1.2295,34|retail:36,1.49,1.29,1.79,36,55.6,39.6,70.5,36,1.003,0.8965,1.128,36|gdp:37,1.2,1.09,1.6,37,40.5,26.3,56.5,37,1.173,0.987,1.321,37|pce:35,1.52,1.2985,1.84,35,60,43.6,74.4,35,1.134,1.033,1.321,35|fomc:24,3.17,2.29,4.08,24,58.3,38.8,75.5,24,1.2895,1.071,1.4215,24|ism:36,1.4,1.12,1.5802,36,55.9,39.5,71.1,34,1.2055,1.07,1.5325,36"
"YM" => "MR1|YM|2026-10-17|2023-10-17|cpi:35,3,2.24,3.5405,35,57.1,40.9,72,35,1.012,0.943,1.294,35|nfp:34,2.54,1.99,3.11,34,60.6,43.7,75.3,33,1.1535,0.9979,1.444,34|ppi:34,1.69,1.42,2.24,34,58.8,42.2,73.6,34,1.08,0.97,1.301,34|retail:36,1.415,1.19,1.66,36,52.8,37,68,36,1.0125,0.833,1.1205,36|gdp:37,1.32,1.07,1.49,37,52.8,37,68,36,1.06,0.876,1.265,37|pce:35,1.43,1.28,1.57,35,45.7,30.5,61.8,35,1.232,1.1536,1.424,35|fomc:24,2.99,2.38,4.16,24,62.5,42.7,78.8,24,1.625,1.152,1.8105,24|ism:36,1.37,1.065,1.72,36,64.7,47.9,78.5,34,1.2715,1.0975,1.4976,36"
"RTY" => "MR1|RTY|2026-10-17|2023-10-17|cpi:35,4.49,3.58,5.39,35,71.4,54.9,83.7,35,1.102,0.804,1.448,35|nfp:34,3.745,3.19,4.395,34,72.7,55.8,84.9,33,1.1175,0.923,1.3406,34|ppi:34,2.325,1.86,3.025,34,70.6,53.8,83.2,34,1.1395,0.9302,1.3921,34|retail:36,1.595,1.26,2.07,36,63.9,47.6,77.5,36,0.979,0.849,1.2579,36|gdp:37,1.57,1.34,1.86,37,48.6,33.4,64.1,37,1.025,0.916,1.08,37|pce:35,1.62,1.42,2.54,35,57.1,40.9,72,35,1.052,0.932,1.2622,35|fomc:24,4.41,3.34,6.4,24,70.8,50.8,85.1,24,1.8015,1.356,2.141,24|ism:36,1.4,1.19,1.54,36,55.9,39.5,71.1,34,1.2595,1.0465,1.505,36"
"ZN" => "MR1|ZN|2026-10-17|2023-10-17|cpi:35,3.56,3.07,4.78,35,77.1,61,87.9,35,1.062,0.909,1.44,35|nfp:35,3.89,3.44,4.67,35,91.2,77,97,34,1.294,1.059,1.356,35|ppi:34,2.19,1.76,2.645,34,75.8,59,87.2,33,1.0865,0.9377,1.1712,34|retail:36,1.925,1.645,2.44,36,76.5,60,87.6,34,1.182,0.962,1.333,36|gdp:37,1.78,1.58,2,37,66.7,50.3,79.8,36,0.952,0.816,1.097,37|pce:35,1.62,1.41,2,35,61.8,45,76.1,34,1,0.857,1.188,35|fomc:24,5.235,4.62,5.85,24,59.1,38.7,76.7,22,2.0115,1.5795,2.5,24|ism:36,1.765,1.6697,2,36,75,56.6,87.3,28,1.383,1.185,1.71,36"
"GC" => "MR1|GC|2026-10-17|2023-10-17|cpi:35,2.29,1.62,3.11,35,74.3,57.9,85.8,35,1.201,1.0229,1.507,35|nfp:34,2.795,2.11,3.13,34,67.6,50.8,80.9,34,1.29,1.0846,1.4667,34|ppi:34,1.445,1.23,1.65,34,61.8,45,76.1,34,1.0765,0.9622,1.1405,34|retail:36,1.355,1.16,1.575,36,45.7,30.5,61.8,35,1.051,0.946,1.178,36|gdp:37,1.37,1.1,1.79,37,56.8,40.9,71.3,37,1.078,0.886,1.251,37|pce:35,1.41,1.1,1.54,35,62.9,46.3,76.8,35,1.091,0.958,1.417,35|fomc:24,4.39,3.67,5.52,24,66.7,46.7,82,24,1.863,1.378,2.6565,24|ism:36,1.145,1.03,1.38,36,70.6,53.8,83.2,34,1.041,0.9465,1.4186,36"
"6E" => "MR1|6E|2026-10-17|2023-10-17|cpi:35,2.81,2.27,3.19,35,71.4,54.9,83.7,35,1.27,0.97,1.417,35|nfp:35,3.57,3.02,3.93,35,73.5,56.9,85.4,34,1.232,1.152,1.415,35|ppi:34,1.91,1.73,2.15,34,61.8,45,76.1,34,1.2265,0.967,1.723,34|retail:36,1.665,1.42,2.07,36,50,34.1,65.9,34,1.085,0.9383,1.289,36|gdp:37,1.59,1.39,2.04,37,64.9,48.8,78.2,37,1.197,0.964,1.419,37|pce:35,1.8,1.36,2.04,35,61.8,45,76.1,34,1.181,1.053,1.289,35|fomc:24,6.805,4.6149,7.95,24,62.5,42.7,78.8,24,1.989,1.689,2.662,24|ism:36,1.37,1.215,1.48,36,62.9,46.3,76.8,35,1.277,1.094,1.5485,36"
"CL" => "MR1|CL|2026-10-17|2023-10-17|cpi:35,1.15,0.96,1.29,35,54.5,38,70.2,33,1.124,0.944,1.264,35|nfp:34,1.105,0.965,1.43,34,50,33.6,66.4,32,1.0335,0.8127,1.189,34|ppi:34,1.135,0.945,1.325,34,54.5,38,70.2,33,1.0375,0.823,1.1645,34|retail:36,0.945,0.8249,1.13,36,47.2,32,63,36,0.984,0.818,1.131,36|gdp:37,1.14,0.91,1.2817,37,62.9,46.3,76.8,35,1.069,0.939,1.245,37|pce:35,0.99,0.8,1.15,35,63.6,46.6,77.8,33,1.126,0.992,1.245,35|fomc:24,1.255,1.14,1.72,24,50,30.7,69.3,22,1.2195,1.0327,1.521,24|ism:36,1.085,0.94,1.24,36,60.6,43.7,75.3,33,1.2745,1.057,1.5035,36"
=> ""
// --- END GENERATED CONSTANTS
// ------------------------------------------------------------------------------------------------------------ inputs
string G0 = "General"
string lang = input.string("es", "Idioma / Language / Idioma", options = ["es", "en", "pt"], group = G0)
string marketIn = input.string("Auto", "Mercado de las estadísticas / Market", options = ["Auto", "ES", "NQ", "RTY", "YM", "GC", "CL", "ZN", "6E"], group = G0, tooltip = "Auto: se toma del símbolo del gráfico (los micros usan las estadísticas de su contrato grande). Otros mercados: solo el calendario. / Auto: taken from the chart symbol.")
int maxRows = input.int(8, "Datos en la tabla", minval = 1, maxval = 12, group = G0)
bool showLines = input.bool(true, "Marcar los datos en el gráfico", group = G0)
bool showTable = input.bool(true, "Tabla", group = G0)
string tablePos = input.string("top_right", "Posición de la tabla", options = ["top_right", "top_left", "bottom_right", "bottom_left", "middle_right"], group = G0)
string G5 = "Colores / Colours"
color cLine = input.color(color.new(#a78bfa, 40), "Línea del dato", group = G5)
color cText = input.color(#c9d1d9, "Texto de la tabla", group = G5)
color cTableBg = input.color(color.new(#0d1117, 15), "Fondo de la tabla", group = G5)
f_t(string es, string en, string pt) =>
lang == "es" ? es : lang == "en" ? en : pt
string TZ = "America/New_York"
string root = marketIn == "Auto" ? f_parent(syminfo.root) : marketIn
// --------------------------------------------------------------------------------------------------------- calendar
// f_cal(): "YYYY-MM-DD,HHMM,key,flag" items separated by ";", in time order; flag 1 = estimated date, 2 = approximated
var array<int> evT = array.new<int>()
var array<string> evK = array.new<string>()
var array<int> evF = array.new<int>()
if barstate.isfirst
array<string> items = str.split(f_cal(), ";")
for it in items
array<string> p = str.split(it, ",")
if p.size() >= 4
string ds = p.get(0)
string hm = p.get(1)
int y = int(str.tonumber(str.substring(ds, 0, 4)))
int mo = int(str.tonumber(str.substring(ds, 5, 7)))
int dd = int(str.tonumber(str.substring(ds, 8, 10)))
int hh = int(str.tonumber(str.substring(hm, 0, 2)))
int mi = int(str.tonumber(str.substring(hm, 2, 4)))
evT.push(timestamp(TZ, y, mo, dd, hh, mi, 0))
evK.push(p.get(2))
evF.push(int(str.tonumber(p.get(3))))
// index of the first release at or after time t; -1 when there is none
f_nextIdx(int t) =>
int idx = -1
int n = evT.size()
if n > 0
for i = 0 to n - 1
if idx < 0 and evT.get(i) >= t
idx := i
idx
f_name(string k) =>
k == "cpi" ? f_t("Inflación CPI", "CPI inflation", "Inflação CPI") : k == "nfp" ? f_t("Empleo (nóminas)", "Payrolls", "Emprego (payroll)") : k == "ppi" ? f_t("Precios al productor PPI", "Producer prices PPI", "Preços ao produtor PPI") : k == "retail" ? f_t("Ventas minoristas", "Retail sales", "Vendas no varejo") : k == "gdp" ? f_t("PIB", "GDP", "PIB") : k == "pce" ? f_t("Ingreso y gasto (PCE)", "Income and outlays (PCE)", "Renda e gastos (PCE)") : k == "fomc" ? f_t("Decisión de la Fed", "Fed decision", "Decisão do Fed") : k == "ism" ? f_t("ISM manufacturero", "ISM manufacturing", "ISM industrial") : k
f_2(int v) =>
v < 10 ? "0" + str.tostring(v) : str.tostring(v)
f_when(int t) =>
str.tostring(year(t, TZ)) + "-" + f_2(month(t, TZ)) + "-" + f_2(dayofmonth(t, TZ))
f_hm(int t) =>
f_2(hour(t, TZ)) + ":" + f_2(minute(t, TZ))
f_flag(int f) =>
f == 1 ? f_t(" (est.)", " (est.)", " (est.)") : f == 2 ? f_t(" (aprox.)", " (approx.)", " (aprox.)") : ""
f_dec(float v, string fmt) =>
string s = na(v) ? "—" : str.tostring(v, fmt)
lang == "en" ? s : str.replace_all(s, ".", ",")
// ------------------------------------------------------------------------------------------------------- statistics
// MR1|root|built|since|key:n,range median,low,high,range n,held %,low,high,held n,session median,low,high,session n
f_stat(string line, string k) =>
array<string> out = array.new<string>()
array<string> f = str.split(line, "|")
if f.size() >= 5 and f.get(0) == "MR1"
for i = 4 to f.size() - 1
string x = f.get(i)
if str.startswith(x, k + ":")
out := str.split(str.substring(x, str.length(k) + 1), ",")
out
f_v(array<string> a, int i) =>
float v = na
if i < a.size()
v := str.tonumber(a.get(i))
v
// "×2,9 [2,4–3,7] n 34", and "igual al azar" when the interval holds 1 (a normal hour)
f_rangeTxt(array<string> a) =>
float med = f_v(a, 1)
float lo = f_v(a, 2)
float hi = f_v(a, 3)
string s = na(med) ? "—" : "×" + f_dec(med, "0.0") + " [" + f_dec(lo, "0.0") + "–" + f_dec(hi, "0.0") + "] n " + str.tostring(f_v(a, 4), "0")
not na(med) and not na(lo) and lo <= 1 and hi >= 1 ? s + f_t(" · igual al azar", " · same as chance", " · igual ao acaso") : s
// "61 % [44–75] n 33", and "igual al azar" when the interval holds 50%
f_heldTxt(array<string> a) =>
float p = f_v(a, 5)
float lo = f_v(a, 6)
float hi = f_v(a, 7)
string s = na(p) ? "—" : f_dec(p, "0") + (lang == "en" ? "%" : " %") + " [" + f_dec(lo, "0") + "–" + f_dec(hi, "0") + "] n " + str.tostring(f_v(a, 8), "0")
not na(p) and not na(lo) and lo <= 50 and hi >= 50 ? s + f_t(" · igual al azar", " · same as chance", " · igual ao acaso") : s
string MR = f_mr(root)
bool statsOn = str.startswith(MR, "MR1|")
// ---------------------------------------------------------------------------------------------------------- drawing
var array<line> lines = array.new<line>()
var array<label> labels = array.new<label>()
int barMs = timeframe.in_seconds() * 1000
var int firstTime = time
if barstate.islast and showLines and timeframe.isintraday
for ln in lines
ln.delete()
for lb in labels
lb.delete()
lines.clear()
labels.clear()
int n = evT.size()
if n > 0
for i = 0 to n - 1
int t = evT.get(i)
// releases on the loaded history and up to 500 bars ahead (the chart's limit for drawings ahead)
if t >= firstTime and t <= time + 500 * barMs and lines.size() < 40
lines.push(line.new(t, close, t, close + syminfo.mintick, xloc = xloc.bar_time, extend = extend.both, color = cLine, style = line.style_dotted, width = 1))
string k = evK.get(i)
string tip = statsOn ? f_t("1ª hora frente a una hora normal: ", "First hour against a normal hour: ", "1ª hora frente a uma hora normal: ") + f_rangeTxt(f_stat(MR, k)) + f_t(". Sostiene la 1ª reacción: ", ". First reaction held: ", ". Mantém a 1ª reação: ") + f_heldTxt(f_stat(MR, k)) + "." : ""
labels.push(label.new(t, close, f_name(k) + " " + f_hm(t) + f_flag(evF.get(i)), xloc = xloc.bar_time, style = label.style_label_lower_left, color = color.new(cLine, 85), textcolor = cText, size = size.small, tooltip = tip))
// ------------------------------------------------------------------------------------------------------------- table
f_pos(string p) =>
p == "top_left" ? position.top_left : p == "bottom_right" ? position.bottom_right : p == "bottom_left" ? position.bottom_left : p == "middle_right" ? position.middle_right : position.top_right
f_cell(table t, int col, int row, string txt, color tc, string al) =>
table.cell(t, col, row, txt, text_color = tc, text_size = size.small, text_halign = al)
true
string FOOT = f_t("Solo tamaño y frecuencia: cuánto se movió la hora siguiente al dato y con qué frecuencia el cierre conservó el signo de los primeros 5 minutos. No dice hacia dónde ni qué operar; no es una señal.", "Size and frequency only: how much the hour after the release moved and how often the close kept the sign of the first 5 minutes. It says nothing about which way nor what to trade; not a signal.", "Só tamanho e frequência: quanto se moveu a hora seguinte ao dado e com que frequência o fechamento manteve o sinal dos primeiros 5 minutos. Não diz para onde nem o que operar; não é um sinal.")
var table info = na
if barstate.islast and showTable
// a fresh table on every update: merged cells are defined once per table
if not na(info)
table.delete(info)
info := table.new(f_pos(tablePos), 5, maxRows + 5, bgcolor = cTableBg, border_width = 0)
color dim = color.new(cText, 35)
string head = f_t("Días de dato macro · ", "Macro release days · ", "Dias de dado macro · ") + root + (statsOn ? f_t(" · medido en los últimos 3 años", " · measured over the last 3 years", " · medido nos últimos 3 anos") : f_t(" · sin medición para este mercado: solo el calendario", " · not measured for this market: calendar only", " · sem medição para este mercado: só o calendário"))
f_cell(info, 0, 0, head, cText, text.align_left)
table.merge_cells(info, 0, 0, 4, 0)
string built = f_t("Calendario al ", "Calendar as of ", "Calendário em ") + DATA_THROUGH + f_t("; fechas de los datos mensuales publicadas hasta el ", "; monthly release dates listed through ", "; datas dos dados mensais publicadas até ") + CAL_LISTED + f_t(". Hora de Nueva York.", ". New York time.", ". Hora de Nova York.")
f_cell(info, 0, 1, built, dim, text.align_left)
table.merge_cells(info, 0, 1, 4, 1)
f_cell(info, 0, 2, f_t("fecha", "date", "data"), dim, text.align_left)
f_cell(info, 1, 2, f_t("hora", "time", "hora"), dim, text.align_left)
f_cell(info, 2, 2, f_t("dato", "release", "dado"), dim, text.align_left)
f_cell(info, 3, 2, f_t("1ª hora × lo normal", "1st hour × normal", "1ª hora × o normal"), dim, text.align_right)
f_cell(info, 4, 2, f_t("sostiene la 1ª reacción", "1st reaction held", "mantém a 1ª reação"), dim, text.align_right)
int first = f_nextIdx(timenow)
int row = 3
if first < 0
f_cell(info, 0, row, f_t("No quedan datos en el calendario de este script: vuelve a copiarlo para tener el calendario nuevo.", "No releases left in this script's calendar: copy it again for the new calendar.", "Não restam dados no calendário deste script: copie-o de novo para ter o calendário novo."), cText, text.align_left)
table.merge_cells(info, 0, row, 4, row)
row += 1
else
int last = math.min(evT.size() - 1, first + maxRows - 1)
for i = first to last
int t = evT.get(i)
string k = evK.get(i)
array<string> a = statsOn ? f_stat(MR, k) : array.new<string>()
f_cell(info, 0, row, f_when(t) + f_flag(evF.get(i)), cText, text.align_left)
f_cell(info, 1, row, f_hm(t), cText, text.align_left)
f_cell(info, 2, row, f_name(k), cText, text.align_left)
f_cell(info, 3, row, statsOn ? f_rangeTxt(a) : "—", cText, text.align_right)
f_cell(info, 4, row, statsOn ? f_heldTxt(a) : "—", cText, text.align_right)
row += 1
f_cell(info, 0, row, FOOT, dim, text.align_left)
table.merge_cells(info, 0, row, 4, row)
// ------------------------------------------------------------------------------------------------------------ alerts
// 30 minutes before a release of the calendar (intraday charts): a time, not a call.
int nxt = f_nextIdx(time)
int nextT = nxt >= 0 ? evT.get(nxt) : na
bool soon = timeframe.isintraday and not na(nextT) and nextT - time <= 30 * 60000
alertcondition(soon and not soon[1], "Release in 30 minutes", "Dato macro programado en 30 minutos / scheduled macro release in 30 minutes")