oakscriptjs 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/cjs/box/index.d.ts +3 -3
  2. package/dist/cjs/box/index.d.ts.map +1 -1
  3. package/dist/cjs/box/index.js.map +2 -2
  4. package/dist/cjs/check/harness.d.ts.map +1 -1
  5. package/dist/cjs/check/harness.js +35 -1
  6. package/dist/cjs/check/harness.js.map +2 -2
  7. package/dist/cjs/drawing/output.d.ts +2 -1
  8. package/dist/cjs/drawing/output.d.ts.map +1 -1
  9. package/dist/cjs/drawing/output.js +5 -4
  10. package/dist/cjs/drawing/output.js.map +2 -2
  11. package/dist/cjs/index.d.ts +1 -1
  12. package/dist/cjs/index.js +1 -1
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/cjs/label/index.d.ts +2 -2
  15. package/dist/cjs/label/index.d.ts.map +1 -1
  16. package/dist/cjs/label/index.js.map +2 -2
  17. package/dist/cjs/line/index.d.ts +4 -4
  18. package/dist/cjs/line/index.d.ts.map +1 -1
  19. package/dist/cjs/line/index.js +1 -1
  20. package/dist/cjs/line/index.js.map +2 -2
  21. package/dist/cjs/polyline/index.d.ts +2 -2
  22. package/dist/cjs/polyline/index.d.ts.map +1 -1
  23. package/dist/cjs/polyline/index.js.map +2 -2
  24. package/dist/cjs/script/constants.d.ts +6 -1
  25. package/dist/cjs/script/constants.d.ts.map +1 -1
  26. package/dist/cjs/script/constants.js +2 -1
  27. package/dist/cjs/script/constants.js.map +2 -2
  28. package/dist/cjs/script/globals.d.ts +3 -0
  29. package/dist/cjs/script/globals.d.ts.map +1 -1
  30. package/dist/cjs/script/globals.js.map +1 -1
  31. package/dist/cjs/script/index.d.ts +255 -28
  32. package/dist/cjs/script/index.d.ts.map +1 -1
  33. package/dist/cjs/script/index.js +349 -34
  34. package/dist/cjs/script/index.js.map +3 -3
  35. package/dist/cjs/security/events.d.ts +16 -0
  36. package/dist/cjs/security/events.d.ts.map +1 -0
  37. package/dist/cjs/security/events.js +84 -0
  38. package/dist/cjs/security/events.js.map +7 -0
  39. package/dist/cjs/types/index.d.ts +13 -11
  40. package/dist/cjs/types/index.d.ts.map +1 -1
  41. package/dist/cjs/types/index.js +3 -1
  42. package/dist/cjs/types/index.js.map +2 -2
  43. package/dist/cjs/types/metadata.d.ts +12 -8
  44. package/dist/cjs/types/metadata.d.ts.map +1 -1
  45. package/dist/cjs/types/metadata.js.map +1 -1
  46. package/dist/esm/box/index.d.ts +3 -3
  47. package/dist/esm/box/index.d.ts.map +1 -1
  48. package/dist/esm/box/index.js +1 -1
  49. package/dist/esm/box/index.js.map +1 -1
  50. package/dist/esm/check/harness.d.ts.map +1 -1
  51. package/dist/esm/check/harness.js +25 -0
  52. package/dist/esm/check/harness.js.map +1 -1
  53. package/dist/esm/drawing/output.d.ts +2 -1
  54. package/dist/esm/drawing/output.d.ts.map +1 -1
  55. package/dist/esm/drawing/output.js +9 -7
  56. package/dist/esm/drawing/output.js.map +1 -1
  57. package/dist/esm/index.d.ts +1 -1
  58. package/dist/esm/index.js +1 -1
  59. package/dist/esm/label/index.d.ts +2 -2
  60. package/dist/esm/label/index.d.ts.map +1 -1
  61. package/dist/esm/label/index.js.map +1 -1
  62. package/dist/esm/line/index.d.ts +4 -4
  63. package/dist/esm/line/index.d.ts.map +1 -1
  64. package/dist/esm/line/index.js +3 -3
  65. package/dist/esm/line/index.js.map +1 -1
  66. package/dist/esm/polyline/index.d.ts +2 -2
  67. package/dist/esm/polyline/index.d.ts.map +1 -1
  68. package/dist/esm/polyline/index.js +1 -1
  69. package/dist/esm/polyline/index.js.map +1 -1
  70. package/dist/esm/script/constants.d.ts +6 -1
  71. package/dist/esm/script/constants.d.ts.map +1 -1
  72. package/dist/esm/script/constants.js +6 -1
  73. package/dist/esm/script/constants.js.map +1 -1
  74. package/dist/esm/script/globals.d.ts +3 -0
  75. package/dist/esm/script/globals.d.ts.map +1 -1
  76. package/dist/esm/script/globals.js.map +1 -1
  77. package/dist/esm/script/index.d.ts +255 -28
  78. package/dist/esm/script/index.d.ts.map +1 -1
  79. package/dist/esm/script/index.js +370 -38
  80. package/dist/esm/script/index.js.map +1 -1
  81. package/dist/esm/security/events.d.ts +16 -0
  82. package/dist/esm/security/events.d.ts.map +1 -0
  83. package/dist/esm/security/events.js +78 -0
  84. package/dist/esm/security/events.js.map +1 -0
  85. package/dist/esm/types/index.d.ts +13 -11
  86. package/dist/esm/types/index.d.ts.map +1 -1
  87. package/dist/esm/types/index.js +3 -1
  88. package/dist/esm/types/index.js.map +1 -1
  89. package/dist/esm/types/metadata.d.ts +12 -8
  90. package/dist/esm/types/metadata.d.ts.map +1 -1
  91. package/package.json +1 -1
  92. package/skills/oakscript/reference/pine-differences.md +2 -0
  93. package/skills/oakscript/reference/plotting.md +24 -1
  94. package/skills/oakscript/reference/timeframes-symbols.md +27 -0
  95. package/src/box/index.ts +4 -4
  96. package/src/check/harness.ts +27 -0
  97. package/src/drawing/output.ts +12 -8
  98. package/src/index.ts +1 -1
  99. package/src/label/index.ts +3 -3
  100. package/src/line/index.ts +6 -6
  101. package/src/polyline/index.ts +2 -2
  102. package/src/script/constants.ts +6 -1
  103. package/src/script/globals.ts +3 -0
  104. package/src/script/index.ts +580 -50
  105. package/src/security/events.ts +85 -0
  106. package/src/types/index.ts +13 -11
  107. package/src/types/metadata.ts +12 -8
@@ -54,7 +54,9 @@ __export(script_exports, {
54
54
  dayofmonth: () => dayofmonth,
55
55
  dayofweek: () => dayofweek,
56
56
  display: () => display,
57
+ dividends: () => dividends,
57
58
  eachBar: () => eachBar,
59
+ earnings: () => earnings,
58
60
  executeIntrabar: () => executeIntrabar,
59
61
  executeScript: () => executeScript,
60
62
  extend: () => extend,
@@ -106,6 +108,7 @@ __export(script_exports, {
106
108
  setLogLineResolver: () => setLogLineResolver,
107
109
  shape: () => shape,
108
110
  size: () => size,
111
+ splits: () => splits,
109
112
  str: () => str,
110
113
  strategy: () => strategy,
111
114
  syminfo: () => syminfo,
@@ -160,6 +163,7 @@ var import_calendar = require("../session/calendar.js");
160
163
  var import_bars = require("../session/bars.js");
161
164
  var import_resample = require("../security/resample.js");
162
165
  var import_other = require("../security/other.js");
166
+ var import_events = require("../security/events.js");
163
167
  var import_types = require("../types/index.js");
164
168
  var import_strategy = require("../strategy/index.js");
165
169
  var import_context = require("../session/context.js");
@@ -219,7 +223,8 @@ function freshCollector(inputValues) {
219
223
  alerts: [],
220
224
  alertCalls: [],
221
225
  logs: [],
222
- hasAlertFunction: false
226
+ hasAlertFunction: false,
227
+ usesVisibleRange: false
223
228
  };
224
229
  }
225
230
  function slugId(title, fallback, taken) {
@@ -296,7 +301,12 @@ function runBody(body, barsInput, inputs, chart2, options, inc) {
296
301
  mathCore.resetRandom();
297
302
  missingSymbols = [];
298
303
  try {
299
- body();
304
+ try {
305
+ body();
306
+ } catch (err) {
307
+ if (missingSymbols.length && !(err instanceof MissingSymbolDataError)) throw new MissingSymbolDataError(missingSymbols);
308
+ throw err;
309
+ }
300
310
  if (missingSymbols.length) throw new MissingSymbolDataError(missingSymbols);
301
311
  if (inc) incremental.bodyDone();
302
312
  const c = ctx;
@@ -339,7 +349,8 @@ function runBody(body, barsInput, inputs, chart2, options, inc) {
339
349
  // By bar, in call order on each bar (the top-level calls make theirs on every bar at once).
340
350
  logs: c.logs.length ? [...c.logs].sort((x, y) => x.bar - y.bar).slice(-MAX_LOG_ENTRIES) : void 0
341
351
  },
342
- hasAlertFunction: c.hasAlertFunction
352
+ hasAlertFunction: c.hasAlertFunction,
353
+ usesVisibleRange: c.usesVisibleRange
343
354
  };
344
355
  } finally {
345
356
  ctx = null;
@@ -485,10 +496,11 @@ function newActiveRun(mode, b, from, prev) {
485
496
  };
486
497
  }
487
498
  const LAST_BAR_FIELDS = /* @__PURE__ */ new Set(["lastBarConfirmed", "lastBarNew", "realtime", "now"]);
488
- function sameChart(a, b) {
499
+ const VISIBLE_RANGE_FIELDS = /* @__PURE__ */ new Set(["leftVisibleBarTime", "rightVisibleBarTime"]);
500
+ function sameChart(a, b, visibleRange = true) {
489
501
  const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
490
502
  for (const k of keys) {
491
- if (LAST_BAR_FIELDS.has(k)) continue;
503
+ if (LAST_BAR_FIELDS.has(k) || !visibleRange && VISIBLE_RANGE_FIELDS.has(k)) continue;
492
504
  if (!Object.is(a[k], b[k])) return false;
493
505
  }
494
506
  return true;
@@ -542,6 +554,7 @@ function createScriptRun(body, inputs = {}, chart2 = {}, options = {}) {
542
554
  let previousChart = chart2;
543
555
  let reason = null;
544
556
  let verifyLeft = options.verify ?? 2;
557
+ let rangeRead = false;
545
558
  let lastLogs;
546
559
  const newRun = (mode, b, from) => newActiveRun(mode, b, from, memory);
547
560
  const full = (b, c) => {
@@ -560,7 +573,7 @@ function createScriptRun(body, inputs = {}, chart2 = {}, options = {}) {
560
573
  update(b, c = previousChart) {
561
574
  const last = previous;
562
575
  const m = memory;
563
- const resumable = !reason && m !== null && last !== null && last.n >= 1 && b.length >= last.n && sameChart(previousChart, c) && sameBars(last, b, last.n - 1);
576
+ const resumable = !reason && m !== null && last !== null && last.n >= 1 && b.length >= last.n && sameChart(previousChart, c, rangeRead) && sameBars(last, b, last.n - 1);
564
577
  previousChart = c;
565
578
  let out;
566
579
  if (!resumable) {
@@ -572,6 +585,7 @@ function createScriptRun(body, inputs = {}, chart2 = {}, options = {}) {
572
585
  try {
573
586
  result = runBody(body, b, inputs, c, options, inc);
574
587
  result.result.logs = resumedLogs(lastLogs, result.result.logs, from);
588
+ result.usesVisibleRange ||= rangeRead;
575
589
  } catch (err) {
576
590
  memory = null;
577
591
  previous = null;
@@ -581,6 +595,7 @@ function createScriptRun(body, inputs = {}, chart2 = {}, options = {}) {
581
595
  if (result && verifyLeft > 0) {
582
596
  verifyLeft--;
583
597
  const check = runBody(body, b, inputs, c, options, null);
598
+ check.usesVisibleRange = result.usesVisibleRange;
584
599
  if (!sameResult(result, check)) {
585
600
  reason = "a resumed update differs from a full run (state kept outside persist()?)";
586
601
  result = check;
@@ -596,6 +611,7 @@ function createScriptRun(body, inputs = {}, chart2 = {}, options = {}) {
596
611
  }
597
612
  previous = out.incremental && last ? copyBars(b, last, last.n - 1) : copyBars(b);
598
613
  lastLogs = out.result.logs;
614
+ rangeRead = out.usesVisibleRange;
599
615
  return out;
600
616
  }
601
617
  };
@@ -1096,7 +1112,7 @@ function fixnan(source) {
1096
1112
  }
1097
1113
  function na(x) {
1098
1114
  if (x instanceof import_series.Series) return import_series.Series.fromArray(ctxBars, x.toArray().map((v) => (0, import_utils.isNA)(v) ? 1 : 0));
1099
- return (0, import_utils.isNA)(x);
1115
+ return x === "" || (0, import_utils.isNA)(x);
1100
1116
  }
1101
1117
  function nz(source, replacement = 0) {
1102
1118
  if (source instanceof import_series.Series) {
@@ -1942,10 +1958,45 @@ const strategy = Object.defineProperties(
1942
1958
  Object.assign((title, options) => declareStrategy(title, options), strategyMembers),
1943
1959
  variableGetters
1944
1960
  );
1961
+ const SYMBOL_INFO_KEYS = [
1962
+ "timezone",
1963
+ "session",
1964
+ "regularSession",
1965
+ "mintick",
1966
+ "minmove",
1967
+ "pricescale",
1968
+ "pointvalue",
1969
+ "mincontract",
1970
+ "symbolType",
1971
+ "currency",
1972
+ "basecurrency",
1973
+ "root",
1974
+ "description",
1975
+ "prefix",
1976
+ "ticker",
1977
+ "country",
1978
+ "currentContract",
1979
+ "expirationDate",
1980
+ "sector",
1981
+ "industry",
1982
+ "isin",
1983
+ "volumetype",
1984
+ "employees",
1985
+ "shareholders",
1986
+ "sharesOutstandingTotal",
1987
+ "sharesOutstandingFloat",
1988
+ "recommendations",
1989
+ "targetPrice"
1990
+ ];
1945
1991
  class MissingSymbolDataError extends Error {
1946
1992
  constructor(requests) {
1993
+ const bars2 = requests.filter((r) => !r.events);
1994
+ const events = requests.filter((r) => r.events);
1947
1995
  super(
1948
- `request.security needs the bars of ${requests.map((r) => `${r.symbol} (${r.timeframe})`).join(", ")}: pass them with ChartContext.bars.`
1996
+ [
1997
+ bars2.length ? `request.security needs the bars of ${bars2.map((r) => `${r.symbol} (${r.timeframe})`).join(", ")}: pass them with ChartContext.bars.` : "",
1998
+ events.length ? `The script needs the events of ${events.map((r) => r.symbol).join(", ")}: pass them with ChartContext.events.` : ""
1999
+ ].filter(Boolean).join(" ")
1949
2000
  );
1950
2001
  this.requests = requests;
1951
2002
  this.name = "MissingSymbolDataError";
@@ -2029,7 +2080,51 @@ function chartText(key, name) {
2029
2080
  if (value === void 0) {
2030
2081
  throw new Error(`${name} is not known: pass it as executeScript(body, bars, inputs, { ${key} }).`);
2031
2082
  }
2032
- return value;
2083
+ return value ?? "";
2084
+ }
2085
+ function symbolNumber(key, name) {
2086
+ collector();
2087
+ const value = chartCtx[key];
2088
+ if (value === void 0) {
2089
+ throw new Error(`${name} is not known: pass it as executeScript(body, bars, inputs, { ${key} }).`);
2090
+ }
2091
+ return value ?? NaN;
2092
+ }
2093
+ function analystNumber(key, field, name) {
2094
+ collector();
2095
+ const group = chartCtx[key];
2096
+ if (group === void 0) {
2097
+ throw new Error(`${name} is not known: pass it as executeScript(body, bars, inputs, { ${key} }).`);
2098
+ }
2099
+ return group === null ? NaN : group[field] ?? NaN;
2100
+ }
2101
+ function chartTickerid() {
2102
+ collector();
2103
+ if (!chartCtx.tickerid) {
2104
+ throw new Error("The chart symbol is not known: pass it as executeScript(body, bars, inputs, { tickerid }).");
2105
+ }
2106
+ return chartCtx.tickerid;
2107
+ }
2108
+ function splitTickerid(tickerid) {
2109
+ const at2 = tickerid.indexOf(":");
2110
+ return at2 < 0 ? ["", tickerid] : [tickerid.slice(0, at2), tickerid.slice(at2 + 1)];
2111
+ }
2112
+ const CONTRACT_SUFFIX = /^(.+?)[FGHJKMNQUVXZ](\d{4}|\d{2})$/;
2113
+ function tickerRoot(ticker2, symbolType) {
2114
+ const continuous = /^(.+?)\d+!$/.exec(ticker2);
2115
+ if (continuous) return continuous[1];
2116
+ const contract = symbolType === "futures" ? CONTRACT_SUFFIX.exec(ticker2) : null;
2117
+ return contract ? contract[1] : ticker2;
2118
+ }
2119
+ function visibleBarTime(value, index) {
2120
+ collector().usesVisibleRange = true;
2121
+ if (value !== void 0) return value;
2122
+ const bar = ctxBars.bars[index];
2123
+ return bar ? barTime(bar) : NaN;
2124
+ }
2125
+ function chartTypeIs(type) {
2126
+ collector();
2127
+ return (chartCtx.chartType ?? "standard") === type;
2033
2128
  }
2034
2129
  function symbolScale() {
2035
2130
  collector();
@@ -2058,11 +2153,19 @@ const syminfo = {
2058
2153
  return exchangeTimezone();
2059
2154
  },
2060
2155
  get tickerid() {
2061
- collector();
2062
- if (!chartCtx.tickerid) {
2063
- throw new Error("The chart symbol is not known: pass it as executeScript(body, bars, inputs, { tickerid }).");
2064
- }
2065
- return chartCtx.tickerid;
2156
+ return chartTickerid();
2157
+ },
2158
+ get main_tickerid() {
2159
+ const id = chartTickerid();
2160
+ return chartCtx.mainTickerid ?? id;
2161
+ },
2162
+ get ticker() {
2163
+ const id = chartTickerid();
2164
+ return chartCtx.ticker ?? splitTickerid(id)[1];
2165
+ },
2166
+ get prefix() {
2167
+ const id = chartTickerid();
2168
+ return chartCtx.prefix === void 0 ? splitTickerid(id)[0] : chartCtx.prefix ?? "";
2066
2169
  },
2067
2170
  get session() {
2068
2171
  collector();
@@ -2078,10 +2181,83 @@ const syminfo = {
2078
2181
  return chartText("basecurrency", "syminfo.basecurrency");
2079
2182
  },
2080
2183
  get root() {
2081
- return chartText("root", "syminfo.root");
2184
+ if (chartCtx.root !== void 0) return chartText("root", "syminfo.root");
2185
+ return tickerRoot(syminfo.ticker, chartCtx.symbolType);
2082
2186
  },
2083
2187
  get description() {
2084
2188
  return chartText("description", "syminfo.description");
2189
+ },
2190
+ get country() {
2191
+ return chartText("country", "syminfo.country");
2192
+ },
2193
+ get current_contract() {
2194
+ return chartText("currentContract", "syminfo.current_contract");
2195
+ },
2196
+ get expiration_date() {
2197
+ return symbolNumber("expirationDate", "syminfo.expiration_date");
2198
+ },
2199
+ get sector() {
2200
+ return chartText("sector", "syminfo.sector");
2201
+ },
2202
+ get industry() {
2203
+ return chartText("industry", "syminfo.industry");
2204
+ },
2205
+ get isin() {
2206
+ return chartText("isin", "syminfo.isin");
2207
+ },
2208
+ get volumetype() {
2209
+ return chartText("volumetype", "syminfo.volumetype");
2210
+ },
2211
+ get employees() {
2212
+ return symbolNumber("employees", "syminfo.employees");
2213
+ },
2214
+ get shareholders() {
2215
+ return symbolNumber("shareholders", "syminfo.shareholders");
2216
+ },
2217
+ get shares_outstanding_total() {
2218
+ return symbolNumber("sharesOutstandingTotal", "syminfo.shares_outstanding_total");
2219
+ },
2220
+ get shares_outstanding_float() {
2221
+ return symbolNumber("sharesOutstandingFloat", "syminfo.shares_outstanding_float");
2222
+ },
2223
+ get recommendations_buy() {
2224
+ return analystNumber("recommendations", "buy", "syminfo.recommendations_buy");
2225
+ },
2226
+ get recommendations_buy_strong() {
2227
+ return analystNumber("recommendations", "buy_strong", "syminfo.recommendations_buy_strong");
2228
+ },
2229
+ get recommendations_hold() {
2230
+ return analystNumber("recommendations", "hold", "syminfo.recommendations_hold");
2231
+ },
2232
+ get recommendations_sell() {
2233
+ return analystNumber("recommendations", "sell", "syminfo.recommendations_sell");
2234
+ },
2235
+ get recommendations_sell_strong() {
2236
+ return analystNumber("recommendations", "sell_strong", "syminfo.recommendations_sell_strong");
2237
+ },
2238
+ get recommendations_total() {
2239
+ return analystNumber("recommendations", "total", "syminfo.recommendations_total");
2240
+ },
2241
+ get recommendations_date() {
2242
+ return analystNumber("recommendations", "date", "syminfo.recommendations_date");
2243
+ },
2244
+ get target_price_average() {
2245
+ return analystNumber("targetPrice", "average", "syminfo.target_price_average");
2246
+ },
2247
+ get target_price_high() {
2248
+ return analystNumber("targetPrice", "high", "syminfo.target_price_high");
2249
+ },
2250
+ get target_price_low() {
2251
+ return analystNumber("targetPrice", "low", "syminfo.target_price_low");
2252
+ },
2253
+ get target_price_median() {
2254
+ return analystNumber("targetPrice", "median", "syminfo.target_price_median");
2255
+ },
2256
+ get target_price_estimates() {
2257
+ return analystNumber("targetPrice", "estimates", "syminfo.target_price_estimates");
2258
+ },
2259
+ get target_price_date() {
2260
+ return analystNumber("targetPrice", "date", "syminfo.target_price_date");
2085
2261
  }
2086
2262
  };
2087
2263
  function calendar(fn) {
@@ -2373,24 +2549,9 @@ function runExternal(symbol, heikin, tf, expression, ignoreInvalid, own) {
2373
2549
  let result;
2374
2550
  let values;
2375
2551
  ctxBars.setAll(bars2);
2376
- chartCtx = {
2377
- ...chartCtx,
2378
- tickerid: symbol,
2379
- timeframe: tf,
2380
- timezone: info.timezone,
2381
- session: info.session,
2382
- regularSession: info.regularSession,
2383
- mintick: info.mintick,
2384
- minmove: info.minmove,
2385
- pricescale: info.pricescale,
2386
- pointvalue: info.pointvalue,
2387
- mincontract: info.mincontract,
2388
- symbolType: info.symbolType,
2389
- currency: info.currency,
2390
- basecurrency: info.basecurrency,
2391
- root: info.root,
2392
- description: info.description
2393
- };
2552
+ const seen = { ...chartCtx, tickerid: symbol, timeframe: tf, mainTickerid: chartCtx.mainTickerid ?? chartCtx.tickerid };
2553
+ for (const key of SYMBOL_INFO_KEYS) seen[key] = info[key];
2554
+ chartCtx = seen;
2394
2555
  try {
2395
2556
  result = expression();
2396
2557
  const parts = Array.isArray(result) ? result : [result];
@@ -2467,7 +2628,129 @@ function seedCall(...args) {
2467
2628
  unsupportedSecurityArgs("request.seed", void 0, a[4]);
2468
2629
  return seed(a[0], a[1], a[2], a[3]);
2469
2630
  }
2470
- const request = strictNamespace("request", { security: securityCall, security_lower_tf: securityLowerTfCall, seed: seedCall });
2631
+ function symbolEvents(ticker2) {
2632
+ collector();
2633
+ const symbol = ticker2 === "" ? chartTickerid() : ticker2;
2634
+ const events = chartCtx.events?.(symbol);
2635
+ if (events === void 0) {
2636
+ if (!missingSymbols.some((r) => r.events && r.symbol === symbol)) missingSymbols.push({ symbol, timeframe: "", events: true });
2637
+ return {};
2638
+ }
2639
+ return events;
2640
+ }
2641
+ function eventField(list, field, name, ticker2) {
2642
+ if (list.length && list.every((e) => e[field] === void 0)) {
2643
+ throw new Error(`${name}: the ${String(field)} values of ${ticker2 || "the chart symbol"} are not known.`);
2644
+ }
2645
+ return list.map((e) => {
2646
+ const v = e[field];
2647
+ return typeof v === "number" ? v : NaN;
2648
+ });
2649
+ }
2650
+ function eventSeries(times, values, gaps, lookahead) {
2651
+ incremental.nonIncremental("request.dividends / splits / earnings");
2652
+ const opens = ctxBars.bars.map(barTime);
2653
+ const tf = chartTimeframe().period;
2654
+ const span = timeframeCore.info(tf).isticks ? 0 : timeframeCore.in_seconds(tf) * 1e3;
2655
+ const { bars: bars2 } = sessionBars();
2656
+ const closes = opens.map((t, i) => {
2657
+ const c = bars2.closeOf(t, tf);
2658
+ return Number.isFinite(c) ? c : opens[i + 1] ?? t + span;
2659
+ });
2660
+ const order2 = times.map((_, i) => i).sort((a, b) => times[a] - times[b]);
2661
+ const events = order2.map((i) => ({ time: times[i], value: values[i] }));
2662
+ return import_series.Series.fromArray(
2663
+ ctxBars,
2664
+ (0, import_events.eventsOnBars)(opens, closes, tf, events, { gaps: gaps === barmerge.gaps_on, lookahead: lookahead === barmerge.lookahead_on })
2665
+ );
2666
+ }
2667
+ const dividends = {
2668
+ net: "net",
2669
+ gross: "gross",
2670
+ /** Amount of the next dividend (net), na when none is announced */
2671
+ get future_amount() {
2672
+ return nextDividend()?.net ?? NaN;
2673
+ },
2674
+ /** Ex-date of the next dividend (ms) */
2675
+ get future_ex_date() {
2676
+ return nextDividend()?.time ?? NaN;
2677
+ },
2678
+ /** Payment date of the next dividend (ms) */
2679
+ get future_pay_date() {
2680
+ return nextDividend()?.payDate ?? NaN;
2681
+ }
2682
+ };
2683
+ const splits = { numerator: "numerator", denominator: "denominator" };
2684
+ const earnings = {
2685
+ actual: "actual",
2686
+ estimate: "estimate",
2687
+ standardized: "standardized",
2688
+ /** Estimated earnings per share of the next release */
2689
+ get future_eps() {
2690
+ return nextEarnings()?.estimate ?? NaN;
2691
+ },
2692
+ /** Estimated revenue of the next release */
2693
+ get future_revenue() {
2694
+ return nextEarnings()?.revenueEstimate ?? NaN;
2695
+ },
2696
+ /** Time of the next release (ms) */
2697
+ get future_time() {
2698
+ return nextEarnings()?.time ?? NaN;
2699
+ },
2700
+ /** End of the fiscal period of the next release (ms) */
2701
+ get future_period_end_time() {
2702
+ return nextEarnings()?.periodEnd ?? NaN;
2703
+ }
2704
+ };
2705
+ function nextEvent(kind) {
2706
+ const events = symbolEvents("");
2707
+ if (!Object.keys(events).length) return void 0;
2708
+ if (!events.future?.[kind]) throw new Error(`${kind}.future_*: the announced ${kind} of ${chartTickerid()} are not known.`);
2709
+ return events[kind]?.find((e) => e.time > runNow);
2710
+ }
2711
+ const nextDividend = () => nextEvent("dividends");
2712
+ const nextEarnings = () => nextEvent("earnings");
2713
+ const DIVIDENDS_PARAMETERS = ["ticker", "field", "gaps", "lookahead", "ignore_invalid_symbol", "currency"];
2714
+ const SPLITS_PARAMETERS = ["ticker", "field", "gaps", "lookahead", "ignore_invalid_symbol"];
2715
+ function dividendsCall(...args) {
2716
+ const a = (0, import_drawing_args.namedArguments)("request.dividends", DIVIDENDS_PARAMETERS, args);
2717
+ unsupportedSecurityArgs("request.dividends", a[5], void 0);
2718
+ const ticker2 = a[0] ?? "";
2719
+ const field = a[1] ?? dividends.net;
2720
+ if (field !== dividends.net && field !== dividends.gross) throw new Error(`request.dividends(): unknown field "${field}": dividends.net or dividends.gross.`);
2721
+ const list = symbolEvents(ticker2).dividends ?? [];
2722
+ const values = field === dividends.gross ? list.map((d) => d.gross ?? d.net) : eventField(list, "net", "request.dividends", ticker2);
2723
+ return eventSeries(list.map((d) => d.time), values, a[2], a[3]);
2724
+ }
2725
+ function splitsCall(...args) {
2726
+ const a = (0, import_drawing_args.namedArguments)("request.splits", SPLITS_PARAMETERS, args);
2727
+ const ticker2 = a[0] ?? "";
2728
+ const field = a[1];
2729
+ if (field !== splits.numerator && field !== splits.denominator) {
2730
+ throw new Error("request.splits(): the field is splits.numerator or splits.denominator.");
2731
+ }
2732
+ const list = symbolEvents(ticker2).splits ?? [];
2733
+ return eventSeries(list.map((s) => s.time), eventField(list, field, "request.splits", ticker2), a[2], a[3]);
2734
+ }
2735
+ function earningsCall(...args) {
2736
+ const a = (0, import_drawing_args.namedArguments)("request.earnings", DIVIDENDS_PARAMETERS, args);
2737
+ unsupportedSecurityArgs("request.earnings", a[5], void 0);
2738
+ const ticker2 = a[0] ?? "";
2739
+ const field = a[1] ?? earnings.actual;
2740
+ if (field !== earnings.actual && field !== earnings.estimate && field !== earnings.standardized) {
2741
+ throw new Error(`request.earnings(): unknown field "${field}": earnings.actual, earnings.estimate or earnings.standardized.`);
2742
+ }
2743
+ const list = (symbolEvents(ticker2).earnings ?? []).filter((e) => e.time <= runNow);
2744
+ return eventSeries(list.map((e) => e.time), eventField(list, field, "request.earnings", ticker2), a[2], a[3]);
2745
+ }
2746
+ const request = strictNamespace("request", {
2747
+ security: securityCall,
2748
+ security_lower_tf: securityLowerTfCall,
2749
+ seed: seedCall,
2750
+ dividends: dividendsCall,
2751
+ splits: splitsCall,
2752
+ earnings: earningsCall
2753
+ });
2471
2754
  const loopBar = () => currentBar;
2472
2755
  function drawings(name, members, all) {
2473
2756
  const out = (0, import_drawing_args.drawingNamespace)(name, members, loopBar);
@@ -2496,6 +2779,38 @@ const chart = {
2496
2779
  get bg_color() {
2497
2780
  return chartText("backgroundColor", "chart.bg_color");
2498
2781
  },
2782
+ /** Time (ms) of the first bar in view (PineScript `chart.left_visible_bar_time`), from the chart context; without it,
2783
+ * of the first bar. */
2784
+ get left_visible_bar_time() {
2785
+ return visibleBarTime(chartCtx.leftVisibleBarTime, 0);
2786
+ },
2787
+ /** Time (ms) of the last bar in view (PineScript `chart.right_visible_bar_time`), from the chart context; without it,
2788
+ * of the last bar. */
2789
+ get right_visible_bar_time() {
2790
+ return visibleBarTime(chartCtx.rightVisibleBarTime, ctxBars.bars.length - 1);
2791
+ },
2792
+ /** The chart is not one of the types below (PineScript `chart.is_standard`). */
2793
+ get is_standard() {
2794
+ return chartTypeIs("standard");
2795
+ },
2796
+ get is_heikinashi() {
2797
+ return chartTypeIs("heikinashi");
2798
+ },
2799
+ get is_renko() {
2800
+ return chartTypeIs("renko");
2801
+ },
2802
+ get is_kagi() {
2803
+ return chartTypeIs("kagi");
2804
+ },
2805
+ get is_linebreak() {
2806
+ return chartTypeIs("linebreak");
2807
+ },
2808
+ get is_pnf() {
2809
+ return chartTypeIs("pnf");
2810
+ },
2811
+ get is_range() {
2812
+ return chartTypeIs("range");
2813
+ },
2499
2814
  point: {
2500
2815
  ...chartPointCore,
2501
2816
  now(price) {