oakscriptjs 0.12.3 → 0.13.1

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 (37) hide show
  1. package/dist/cjs/drawing/registry.d.ts +37 -0
  2. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  3. package/dist/cjs/drawing/registry.js +40 -0
  4. package/dist/cjs/drawing/registry.js.map +2 -2
  5. package/dist/cjs/math/index.d.ts +4 -0
  6. package/dist/cjs/math/index.d.ts.map +1 -1
  7. package/dist/cjs/math/index.js +9 -0
  8. package/dist/cjs/math/index.js.map +2 -2
  9. package/dist/cjs/script/index.d.ts +52 -1
  10. package/dist/cjs/script/index.d.ts.map +1 -1
  11. package/dist/cjs/script/index.js +222 -12
  12. package/dist/cjs/script/index.js.map +3 -3
  13. package/dist/cjs/strategy/index.d.ts +3 -0
  14. package/dist/cjs/strategy/index.d.ts.map +1 -1
  15. package/dist/cjs/strategy/index.js +1 -0
  16. package/dist/cjs/strategy/index.js.map +2 -2
  17. package/dist/esm/drawing/registry.d.ts +37 -0
  18. package/dist/esm/drawing/registry.d.ts.map +1 -1
  19. package/dist/esm/drawing/registry.js +41 -0
  20. package/dist/esm/drawing/registry.js.map +1 -1
  21. package/dist/esm/math/index.d.ts +4 -0
  22. package/dist/esm/math/index.d.ts.map +1 -1
  23. package/dist/esm/math/index.js +10 -0
  24. package/dist/esm/math/index.js.map +1 -1
  25. package/dist/esm/script/index.d.ts +52 -1
  26. package/dist/esm/script/index.d.ts.map +1 -1
  27. package/dist/esm/script/index.js +263 -13
  28. package/dist/esm/script/index.js.map +1 -1
  29. package/dist/esm/strategy/index.d.ts +3 -0
  30. package/dist/esm/strategy/index.d.ts.map +1 -1
  31. package/dist/esm/strategy/index.js +1 -0
  32. package/dist/esm/strategy/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/drawing/registry.ts +56 -0
  35. package/src/math/index.ts +11 -0
  36. package/src/script/index.ts +339 -13
  37. package/src/strategy/index.ts +4 -0
@@ -63,6 +63,8 @@ interface DrawingTypes {
63
63
  /** Default `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count`. */
64
64
  export declare const DEFAULT_MAX_COUNT = 50;
65
65
  export type DrawingLimits = Partial<Record<Exclude<DrawingKind, 'linefill' | 'table'>, number>>;
66
+ /** Kinds with a maximum count of their own. */
67
+ type CountedKind = 'line' | 'label' | 'box' | 'polyline';
66
68
  /**
67
69
  * Marks an object as held by a `var` variable (PineScript `var line l = ...` or `l := line.new(...)` on a `var`
68
70
  * variable): the maximum count never deletes it, and it still counts. Returns the object.
@@ -92,6 +94,22 @@ export declare function varDrawing<T extends object>(initial?: T): DrawingVariab
92
94
  export declare const MAX_DRAWING_BARS_BACK = 10000;
93
95
  /** Largest distance, in bars, of a bar index after the last bar of the data (PineScript runtime error RE10020 above it). */
94
96
  export declare const MAX_DRAWING_BARS_FORWARD = 500;
97
+ /** Kinds whose allowance on the last bar is the `P` they had when the bar started. */
98
+ type AllowanceKind = 'line' | 'label' | 'box';
99
+ /** State of the last bar (see the module notes). */
100
+ interface LastBar {
101
+ bar: number;
102
+ /** The objects alive when the bar started (the objects of the bars before) */
103
+ old: Set<object>;
104
+ /** `P` of lines, labels and boxes when the bar started: their allowance for the whole bar */
105
+ allowance: Record<AllowanceKind, number>;
106
+ /** `P` of polylines when the bar started */
107
+ carried: number;
108
+ /** A polyline was created on this bar */
109
+ polyline: boolean;
110
+ /** Polylines of the bars before deleted on this bar (by the count or by the script) */
111
+ oldPolylinesGone: number;
112
+ }
95
113
  /**
96
114
  * Tells the drawing functions which bar is being calculated (`bar_index`), so that a bar index more than 10,000
97
115
  * bars back throws as in PineScript; `null` turns the check off. `eachBar` of the script API calls it.
@@ -125,5 +143,24 @@ export declare function all<K extends DrawingKind>(kind: K): Array<DrawingTypes[
125
143
  export declare function resetDrawings(newLimits?: DrawingLimits): void;
126
144
  /** Changes the maximum counts without forgetting the objects (PineScript `indicator(max_*_count)`). */
127
145
  export declare function setDrawingLimits(newLimits: DrawingLimits): void;
146
+ /** The registry state of a run, saved around a nested run (see {@link restoreDrawingState}). */
147
+ export interface DrawingState {
148
+ live: {
149
+ [K in DrawingKind]: Array<DrawingTypes[K]>;
150
+ };
151
+ created: DrawingKind[];
152
+ held: WeakMap<object, number>;
153
+ releasedAt: WeakMap<object, number>;
154
+ heldAt: WeakMap<object, number>;
155
+ pending: Record<CountedKind, number>;
156
+ currentBar: number | null;
157
+ lastBarIndex: number | null;
158
+ lastBar: LastBar | null;
159
+ limits: Required<DrawingLimits>;
160
+ }
161
+ /** Saves the registry of the current run before a nested run (an intrabar run of a strategy). */
162
+ export declare function saveDrawingState(): DrawingState;
163
+ /** Puts back the registry saved by {@link saveDrawingState} after the nested run. */
164
+ export declare function restoreDrawingState(s: DrawingState): void;
128
165
  export {};
129
166
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/drawing/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAErF,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AAEvF,UAAU,YAAY;IACpB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CACd;AAED,+FAA+F;AAC/F,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAIpC,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC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M,CAAC,CAAC;IACpC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACrC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;CACjC;AAED,iGAAiG;AACjG,wBAAgB,gBAAgB,IAAI,YAAY,CAoB/C;AAED,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,YAAY,GAAG,IAAI,CAgBzD"}
@@ -30,6 +30,8 @@ __export(registry_exports, {
30
30
  releaseDrawing: () => releaseDrawing,
31
31
  remove: () => remove,
32
32
  resetDrawings: () => resetDrawings,
33
+ restoreDrawingState: () => restoreDrawingState,
34
+ saveDrawingState: () => saveDrawingState,
33
35
  setDrawingBar: () => setDrawingBar,
34
36
  setDrawingLimits: () => setDrawingLimits,
35
37
  varDrawing: () => varDrawing
@@ -247,4 +249,42 @@ function resetDrawings(newLimits = {}) {
247
249
  function setDrawingLimits(newLimits) {
248
250
  limits = { ...limits, ...Object.fromEntries(Object.entries(newLimits).filter(([, v]) => v !== void 0)) };
249
251
  }
252
+ function saveDrawingState() {
253
+ return {
254
+ live: {
255
+ line: [...live.line],
256
+ label: [...live.label],
257
+ box: [...live.box],
258
+ polyline: [...live.polyline],
259
+ linefill: [...live.linefill],
260
+ table: [...live.table]
261
+ },
262
+ created: [...created],
263
+ held,
264
+ releasedAt,
265
+ heldAt,
266
+ pending: { ...pending },
267
+ currentBar,
268
+ lastBarIndex,
269
+ lastBar,
270
+ limits: { ...limits }
271
+ };
272
+ }
273
+ function restoreDrawingState(s) {
274
+ for (const kind of Object.keys(live)) {
275
+ const list = live[kind];
276
+ list.length = 0;
277
+ list.push(...s.live[kind]);
278
+ }
279
+ created.clear();
280
+ for (const kind of s.created) created.add(kind);
281
+ held = s.held;
282
+ releasedAt = s.releasedAt;
283
+ heldAt = s.heldAt;
284
+ pending = { ...s.pending };
285
+ currentBar = s.currentBar;
286
+ lastBarIndex = s.lastBarIndex;
287
+ lastBar = s.lastBar;
288
+ limits = { ...s.limits };
289
+ }
250
290
  //# sourceMappingURL=registry.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/drawing/registry.ts"],
4
- "sourcesContent": ["/**\n * Registry of the live drawing objects (lines, labels, boxes, polylines, linefills, tables), as PineScript\n * keeps them. PineScript rules:\n *\n * - `line.all`, `label.all`, ... list the live objects in creation order (a copy of the list)\n * - `delete` removes an object; the object becomes `na`: its getters return NaN and its setters\n * do nothing. Deleting a line with `line.delete` also deletes the linefills that use it\n * - when a creation brings the count above `max_*_count + 5`, the oldest objects are deleted until\n * `max_*_count` remain (default 50). Copies count as creations. Linefills follow the same rule with\n * `max_lines_count`; lines deleted by this rule do not delete their linefills\n * - the object that was just created is never deleted by this rule\n * - an object that a `var` variable of the drawing type refers to is never deleted by this rule, and it still counts\n * (measured for lines, labels and boxes: with 9 held boxes and a maximum of 50, 9 held + 46 others stay; with 8\n * held lines and a maximum of 5, the 8 and the newest line stay). The protection starts on the bar after the\n * assignment: 12 `var` lines created on the first bar with a maximum of 5 lose the first 6. Only\n * the variable itself protects: an object in a `var` array, in a field of a user type or in a variable that got\n * another object or `na` later is deleted like any other. JavaScript has no `var` declaration to observe, so the\n * script says it: {@link varDrawing} (a variable), or {@link holdDrawing} / {@link releaseDrawing}\n * - linefills have the limit of `max_lines_count` with another rule for the held ones (measured on one script, two\n * long runs): a fill is skipped when a `var` variable holds it or released it less than 5,000 bars ago (the bar\n * of {@link setDrawingBar}); when the count is still above the maximum + 5 after that, the oldest fills are\n * deleted until the maximum remain, the held ones too\n * - the script deletes count (`line.delete`, `label.delete`, ...): each kind has a number `P` of deleted objects. A\n * delete adds 1; a creation first sets `P` to 0 when it is 5 or more (3 or more for polylines)\n * - polylines use `P` on every bar: a creation cuts when the count is above `max_polylines_count + 5 + P`, down to\n * the maximum + `P`, and the polylines of the cut are added to `P`. A script that deletes and creates one polyline\n * per bar therefore sees the cut 0, 1 or 2 bars late\n * - lines, labels and boxes use `P` on the last bar only, with its value at the start of that bar: there the cut is\n * above the maximum + 5 + `P`, down to the maximum + `P` (up to 4 more objects)\n * - the last bar has rules of its own (measured from the count after each creation, on a closed and on an open last\n * bar): a cut deletes the objects of the bars before first, at most those (a line takes its linefills with it);\n * once none is left, a cut deletes objects of the last bar as on any bar. With 10 lines and a maximum of 10, 13\n * lines on the last bar leave these 13: the cut at the 16th line deletes the 10 old ones only. Lines, labels and\n * boxes: equal to PineScript, count after every operation and objects alive at the end, on 72 of 72 runs checked\n * after the rule was written (and 218 of 218 end states before)\n * - polylines on the last bar: the `P` carried from the bar before is counted twice (the first creation adds it once\n * more, unless it sets `P` to 0), later creations do not set `P` to 0, and the polylines of the bars before that a\n * cut deletes are added to `P`. Once none is\n * left, `P` is at least the number of polylines of the bars before deleted on the last bar (by the count or by\n * the script) and a cut deletes polylines of the last bar: a script that deletes its 100 polylines and creates 200\n * on the last bar keeps them all (#176). Equal to PineScript for the polylines alive at the end on 271 of\n * 281 probe runs; the count inside the bar can differ when the script deletes polylines of the last bar\n *\n * - a bar index (`xloc.bar_index`) more than 10,000 bars before the current bar stops the script (runtime error\n * RE10026) in `line.new`, `box.new`, `label.new`, `polyline.new` and the setters of x. The current bar is the one\n * of `eachBar` in a script run; a port with its own bar loop gives it with {@link setDrawingBar}\n *\n * The script API (`executeScript`) resets the registry at the start of every run and applies the\n * `max_*_count` values of `indicator()`. Outside a script run the registry is global to the module.\n *\n * @module drawing/registry\n */\n\nimport type { Box, Label, Line, Linefill, Polyline, Table } from '../types/index.js';\n\nexport type DrawingKind = 'line' | 'label' | 'box' | 'polyline' | 'linefill' | 'table';\n\ninterface DrawingTypes {\n line: Line;\n label: Label;\n box: Box;\n polyline: Polyline;\n linefill: Linefill;\n table: Table;\n}\n\n/** Default `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count`. */\nexport const DEFAULT_MAX_COUNT = 50;\n/** Objects above the maximum that PineScript keeps before it deletes the oldest ones. */\nconst SLACK = 5;\n\nexport type DrawingLimits = Partial<Record<Exclude<DrawingKind, 'linefill' | 'table'>, number>>;\n\nconst live: { [K in DrawingKind]: Array<DrawingTypes[K]> } = {\n line: [],\n label: [],\n box: [],\n polyline: [],\n linefill: [],\n table: [],\n};\nlet limits: Required<DrawingLimits> = {\n line: DEFAULT_MAX_COUNT,\n label: DEFAULT_MAX_COUNT,\n box: DEFAULT_MAX_COUNT,\n polyline: DEFAULT_MAX_COUNT,\n};\nconst deleted = new WeakSet<object>();\n/** Objects held by a `var` variable, with the number of variables that hold them. */\nlet held = new WeakMap<object, number>();\n/** Bar on which the last `var` variable released an object (linefill rule). */\nlet releasedAt = new WeakMap<object, number>();\n/** Bars during which a released linefill is still skipped by the maximum count. */\nconst LINEFILL_RELEASE_BARS = 5000;\n/** Bar on which a `var` variable got an object: the maximum count skips it from the next bar on. */\nlet heldAt = new WeakMap<object, number>();\n/** Kinds with a maximum count of their own. */\ntype CountedKind = 'line' | 'label' | 'box' | 'polyline';\nconst COUNTED_KINDS: readonly CountedKind[] = ['line', 'label', 'box', 'polyline'];\nconst isCounted = (kind: DrawingKind): kind is CountedKind => (COUNTED_KINDS as readonly DrawingKind[]).includes(kind);\n/** `P` of the module notes: objects deleted by the script (for polylines also by the maximum count). */\nlet pending: Record<CountedKind, number> = { line: 0, label: 0, box: 0, polyline: 0 };\n/** A creation sets `P` to 0 from this value on. */\nconst PENDING_RESET: Record<CountedKind, number> = { line: 5, label: 5, box: 5, polyline: 3 };\n\n/**\n * Marks an object as held by a `var` variable (PineScript `var line l = ...` or `l := line.new(...)` on a `var`\n * variable): the maximum count never deletes it, and it still counts. Returns the object.\n */\nexport function holdDrawing<T extends object>(obj: T): T {\n if (!held.has(obj)) {\n if (currentBar === null) heldAt.delete(obj);\n else heldAt.set(obj, currentBar);\n }\n held.set(obj, (held.get(obj) ?? 0) + 1);\n return obj;\n}\n\n/** The `var` variable no longer refers to the object (it got another object or `na`). */\nexport function releaseDrawing(obj: object | null | undefined): void {\n if (!obj) return;\n const count = held.get(obj) ?? 0;\n if (count > 1) held.set(obj, count - 1);\n else if (held.delete(obj) && currentBar !== null) releasedAt.set(obj, currentBar);\n}\n\n/** Held by a `var` variable since a bar before the current one (or outside a bar loop). */\nfunction heldBefore(obj: object): boolean {\n if (!held.has(obj)) return false;\n const bar = heldAt.get(obj);\n return bar === undefined || currentBar === null || bar < currentBar;\n}\n\n/** Linefill rule: held, or released less than 5,000 bars ago. */\nfunction fillProtected(obj: object): boolean {\n if (held.has(obj)) return true;\n const bar = releasedAt.get(obj);\n return bar !== undefined && currentBar !== null && currentBar - bar < LINEFILL_RELEASE_BARS;\n}\n\n/** A `var` variable of a drawing type: see {@link varDrawing}. */\nexport interface DrawingVariable<T extends object> {\n /** The object of the variable; setting it holds the new object and releases the one before */\n value: T | undefined;\n}\n\n/**\n * A PineScript `var` variable of a drawing type (`var line l = na`). The object it refers to is not deleted by the\n * maximum count; assigning another object (or `undefined` for `na`) releases the one before.\n *\n * @example\n * ```typescript\n * // Pine: var line level = na\n * // level := line.new(bar_index, close, bar_index + 1, close)\n * const level = varDrawing<Line>();\n * level.value = line.new(i, close, i + 1, close);\n * ```\n */\nexport function varDrawing<T extends object>(initial?: T): DrawingVariable<T> {\n let current: T | undefined = initial ? holdDrawing(initial) : undefined;\n return {\n get value() {\n return current;\n },\n set value(next: T | undefined) {\n if (next === current) return;\n releaseDrawing(current);\n current = next ? holdDrawing(next) : undefined;\n },\n };\n}\n\n/** Largest distance, in bars, of a bar index before the current bar (PineScript runtime error RE10026 above it). */\nexport const MAX_DRAWING_BARS_BACK = 10000;\n/** Largest distance, in bars, of a bar index after the last bar of the data (PineScript runtime error RE10020 above it). */\nexport const MAX_DRAWING_BARS_FORWARD = 500;\nlet currentBar: number | null = null;\nlet lastBarIndex: number | null = null;\n\n/** Kinds whose allowance on the last bar is the `P` they had when the bar started. */\ntype AllowanceKind = 'line' | 'label' | 'box';\nconst isAllowanceKind = (kind: DrawingKind): kind is AllowanceKind => kind === 'line' || kind === 'label' || kind === 'box';\n\n/** State of the last bar (see the module notes). */\ninterface LastBar {\n bar: number;\n /** The objects alive when the bar started (the objects of the bars before) */\n old: Set<object>;\n /** `P` of lines, labels and boxes when the bar started: their allowance for the whole bar */\n allowance: Record<AllowanceKind, number>;\n /** `P` of polylines when the bar started */\n carried: number;\n /** A polyline was created on this bar */\n polyline: boolean;\n /** Polylines of the bars before deleted on this bar (by the count or by the script) */\n oldPolylinesGone: number;\n}\nlet lastBar: LastBar | null = null;\n\n/**\n * Tells the drawing functions which bar is being calculated (`bar_index`), so that a bar index more than 10,000\n * bars back throws as in PineScript; `null` turns the check off. `eachBar` of the script API calls it.\n *\n * The bar also dates the objects held by a `var` variable (protected from the next bar on). `last` says that it is\n * the last bar of the data, which has rules of its own for the maximum count. `lastIndex` is the bar index of the\n * last bar of the data (PineScript `last_bar_index`): with it, a bar index more than 500 bars after it throws, also\n * on the bars before the last one (RE10020).\n */\nexport function setDrawingBar(barIndex: number | null, last: boolean = false, lastIndex?: number): void {\n if (lastBar && !(last && barIndex === lastBar.bar)) lastBar = null;\n currentBar = barIndex;\n lastBarIndex = barIndex === null ? null : (lastIndex ?? (last ? barIndex : null));\n if (barIndex !== null && last && !lastBar) {\n const start = (kind: AllowanceKind): number => (pending[kind] >= PENDING_RESET[kind] ? 0 : pending[kind]);\n lastBar = {\n bar: barIndex,\n old: new Set<object>([...live.line, ...live.label, ...live.box, ...live.polyline]),\n allowance: { line: start('line'), label: start('label'), box: start('box') },\n carried: pending.polyline,\n polyline: false,\n oldPolylinesGone: 0,\n };\n }\n}\n\n/**\n * Throws the PineScript runtime error RE10026 when `x` is a bar index more than 10,000 bars before the current bar,\n * and RE10020 when it is more than 500 bars after the last bar of the data (when {@link setDrawingBar} knows it).\n * `method` and `variable` are the names of the PineScript message (\"line.new\", \"x1\").\n *\n * Returns `x`, truncated when it is a bar index: PineScript's x is an int (a box from 5537.94 starts on bar 5537,\n * #176).\n */\nexport function checkBarIndex(method: string, variable: string, x: number, xloc: string | undefined): number {\n if ((xloc ?? 'bar_index') !== 'bar_index') return x;\n x = Math.trunc(x);\n if (currentBar === null) return x;\n if (lastBarIndex !== null && x - lastBarIndex > MAX_DRAWING_BARS_FORWARD) {\n throw new Error(\n `Error on bar ${currentBar}: Objects positioned using xloc.bar_index cannot be drawn further than ` +\n `${MAX_DRAWING_BARS_FORWARD} bars into the future.`\n );\n }\n if (currentBar - x > MAX_DRAWING_BARS_BACK) {\n throw new Error(\n `Error on bar ${currentBar}: Bar index value of the \\`${variable}\\` argument (${x}) in \\`${method}()\\` is too far ` +\n 'from the current bar index. Try using `time` instead.'\n );\n }\n return x;\n}\n\n/** Numeric fields that become NaN when an object is deleted, so that its getters return `na`. */\nconst COORDINATES: { [K in DrawingKind]: Array<keyof DrawingTypes[K]> } = {\n line: ['x1', 'y1', 'x2', 'y2'],\n label: ['x', 'y'],\n box: ['left', 'top', 'right', 'bottom'],\n polyline: [],\n linefill: [],\n table: [],\n};\n\nfunction markDeleted<K extends DrawingKind>(kind: K, obj: DrawingTypes[K], explicit: boolean): void {\n deleted.add(obj);\n for (const field of COORDINATES[kind]) (obj as unknown as Record<string, unknown>)[field as string] = NaN;\n if (kind === 'line' && explicit) {\n for (const fill of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove('linefill', fill);\n }\n}\n\n/** Objects above the maximum that the rule allows for, besides the 5: `P` of the module notes. */\nfunction allowance(kind: DrawingKind): number {\n if (kind === 'polyline') return pending.polyline;\n return lastBar && isAllowanceKind(kind) ? lastBar.allowance[kind] : 0;\n}\n\n/**\n * The maximum count after the creation of `obj`: removes the objects to delete from `list` (the oldest first; the new\n * object and an object held by a `var` variable are skipped and still count) and returns them.\n */\nfunction cutOldest<K extends DrawingKind>(\n kind: K,\n list: Array<DrawingTypes[K]>,\n obj: DrawingTypes[K],\n only?: (old: object) => boolean\n): Array<DrawingTypes[K]> {\n if (kind === 'table') return []; // tables have no maximum count\n const max = limits[kind === 'linefill' ? 'line' : (kind as keyof DrawingLimits)] + allowance(kind);\n if (list.length <= max + SLACK) return [];\n const kept: Array<DrawingTypes[K]> = [];\n const cut: Array<DrawingTypes[K]> = [];\n let excess = list.length - max;\n for (const old of list) {\n if (excess > 0 && old !== obj && (!only || only(old)) && !(kind === 'linefill' ? fillProtected(old) : heldBefore(old))) {\n excess--;\n cut.push(old);\n } else kept.push(old);\n }\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (kind === 'linefill' && kept.length > max + SLACK) cut.push(...kept.splice(0, kept.length - max));\n list.length = 0;\n list.push(...kept);\n return cut;\n}\n\n/** Kinds of the objects created since the last reset (a table counts too), in no order. */\nconst created = new Set<DrawingKind>();\n\n/** The kinds of drawing objects created since the last {@link resetDrawings}, even when none is alive any more. */\nexport function createdDrawingKinds(): DrawingKind[] {\n return [...created];\n}\n\n/** Records a new object and deletes the oldest objects of its kind when the count is too high. */\nexport function register<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n const list = live[kind];\n created.add(kind);\n if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);\n if (isCounted(kind) && pending[kind] >= PENDING_RESET[kind]) pending[kind] = 0;\n list.push(obj);\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline') pending.polyline += cut.length;\n for (const old of cut) markDeleted(kind, old, false);\n return obj;\n}\n\n/** An object created on the last bar (see the module notes). */\nfunction registerLast<K extends DrawingKind>(bar: LastBar, kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n if (kind === 'polyline' && !bar.polyline) {\n bar.polyline = true;\n if (pending.polyline >= PENDING_RESET.polyline) pending.polyline = 0;\n else pending.polyline += bar.carried; // counted twice\n }\n const list = live[kind];\n list.push(obj);\n const isOld = (old: object): boolean => bar.old.has(old);\n if (list.some((old) => old !== obj && isOld(old) && !heldBefore(old))) {\n // the objects of the bars before only; a line takes its linefills with it\n const cut = cutOldest(kind, list, obj, isOld);\n if (kind === 'polyline') {\n pending.polyline += cut.length;\n bar.oldPolylinesGone += cut.length;\n }\n for (const old of cut) markDeleted(kind, old, true);\n } else {\n // the polylines of the bars before deleted on this bar count before the cut (#176)\n if (kind === 'polyline' && pending.polyline < bar.oldPolylinesGone) pending.polyline = bar.oldPolylinesGone;\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline' && cut.length > 0) pending.polyline = bar.oldPolylinesGone;\n for (const old of cut) markDeleted(kind, old, false);\n }\n return obj;\n}\n\n/** Deletes an object (no effect when it is already deleted). */\nexport function remove<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): void {\n const list = live[kind];\n const index = list.indexOf(obj);\n if (index !== -1) {\n list.splice(index, 1);\n if (isCounted(kind)) pending[kind]++;\n if (kind === 'polyline' && lastBar?.old.has(obj)) lastBar.oldPolylinesGone++;\n }\n if (!deleted.has(obj)) markDeleted(kind, obj, true);\n}\n\n/** True when the object was deleted (by `delete` or by the maximum count). */\nexport function isDeleted(obj: unknown): boolean {\n return typeof obj === 'object' && obj !== null && deleted.has(obj);\n}\n\n/** The live objects of a kind, in creation order (a new array). */\nexport function all<K extends DrawingKind>(kind: K): Array<DrawingTypes[K]> {\n return [...live[kind]] as Array<DrawingTypes[K]>;\n}\n\n/** Forgets all objects (without deleting them) and sets the maximum counts (default 50). */\nexport function resetDrawings(newLimits: DrawingLimits = {}): void {\n for (const kind of Object.keys(live) as DrawingKind[]) live[kind].length = 0;\n created.clear();\n held = new WeakMap();\n releasedAt = new WeakMap();\n heldAt = new WeakMap();\n pending = { line: 0, label: 0, box: 0, polyline: 0 };\n currentBar = null;\n lastBarIndex = null;\n lastBar = null;\n limits = {\n line: newLimits.line ?? DEFAULT_MAX_COUNT,\n label: newLimits.label ?? DEFAULT_MAX_COUNT,\n box: newLimits.box ?? DEFAULT_MAX_COUNT,\n polyline: newLimits.polyline ?? DEFAULT_MAX_COUNT,\n };\n}\n\n/** Changes the maximum counts without forgetting the objects (PineScript `indicator(max_*_count)`). */\nexport function setDrawingLimits(newLimits: DrawingLimits): void {\n limits = { ...limits, ...Object.fromEntries(Object.entries(newLimits).filter(([, v]) => v !== undefined)) };\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmEO,MAAM,oBAAoB;AAEjC,MAAM,QAAQ;AAId,MAAM,OAAuD;AAAA,EAC3D,MAAM,CAAC;AAAA,EACP,OAAO,CAAC;AAAA,EACR,KAAK,CAAC;AAAA,EACN,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,OAAO,CAAC;AACV;AACA,IAAI,SAAkC;AAAA,EACpC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AACZ;AACA,MAAM,UAAU,oBAAI,QAAgB;AAEpC,IAAI,OAAO,oBAAI,QAAwB;AAEvC,IAAI,aAAa,oBAAI,QAAwB;AAE7C,MAAM,wBAAwB;AAE9B,IAAI,SAAS,oBAAI,QAAwB;AAGzC,MAAM,gBAAwC,CAAC,QAAQ,SAAS,OAAO,UAAU;AACjF,MAAM,YAAY,CAAC,SAA4C,cAAyC,SAAS,IAAI;AAErH,IAAI,UAAuC,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,EAAE;AAEpF,MAAM,gBAA6C,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,EAAE;AAMrF,SAAS,YAA8B,KAAW;AACvD,MAAI,CAAC,KAAK,IAAI,GAAG,GAAG;AAClB,QAAI,eAAe,KAAM,QAAO,OAAO,GAAG;AAAA,QACrC,Q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Q,KAAK,QAAQ,GAAG;AAC9B,MAAI,UAAU,IAAI;AAChB,SAAK,OAAO,OAAO,CAAC;AACpB,QAAI,UAAU,IAAI,EAAG,SAAQ,IAAI;AACjC,QAAI,SAAS,cAAc,SAAS,IAAI,IAAI,GAAG,EAAG,SAAQ;AAAA,EAC5D;AACA,MAAI,CAAC,QAAQ,IAAI,GAAG,EAAG,aAAY,MAAM,KAAK,IAAI;AACpD;AAGO,SAAS,UAAU,KAAuB;AAC/C,SAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,QAAQ,IAAI,GAAG;AACnE;AAGO,SAAS,IAA2B,MAAiC;AAC1E,SAAO,CAAC,GAAG,KAAK,IAAI,CAAC;AACvB;AAGO,SAAS,cAAc,YAA2B,CAAC,GAAS;AACjE,aAAW,QAAQ,OAAO,KAAK,IAAI,EAAoB,MAAK,IAAI,EAAE,SAAS;AAC3E,UAAQ,MAAM;AACd,SAAO,oBAAI,QAAQ;AACnB,eAAa,oBAAI,QAAQ;AACzB,WAAS,oBAAI,QAAQ;AACrB,YAAU,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,EAAE;AACnD,eAAa;AACb,iBAAe;AACf,YAAU;AACV,WAAS;AAAA,IACP,MAAM,UAAU,QAAQ;AAAA,IACxB,OAAO,UAAU,SAAS;AAAA,IAC1B,KAAK,UAAU,OAAO;AAAA,IACtB,UAAU,UAAU,YAAY;AAAA,EAClC;AACF;AAGO,SAAS,iBAAiB,WAAgC;AAC/D,WAAS,EAAE,GAAG,QAAQ,GAAG,OAAO,YAAY,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,CAAC,EAAE;AAC5G;",
4
+ "sourcesContent": ["/**\n * Registry of the live drawing objects (lines, labels, boxes, polylines, linefills, tables), as PineScript\n * keeps them. PineScript rules:\n *\n * - `line.all`, `label.all`, ... list the live objects in creation order (a copy of the list)\n * - `delete` removes an object; the object becomes `na`: its getters return NaN and its setters\n * do nothing. Deleting a line with `line.delete` also deletes the linefills that use it\n * - when a creation brings the count above `max_*_count + 5`, the oldest objects are deleted until\n * `max_*_count` remain (default 50). Copies count as creations. Linefills follow the same rule with\n * `max_lines_count`; lines deleted by this rule do not delete their linefills\n * - the object that was just created is never deleted by this rule\n * - an object that a `var` variable of the drawing type refers to is never deleted by this rule, and it still counts\n * (measured for lines, labels and boxes: with 9 held boxes and a maximum of 50, 9 held + 46 others stay; with 8\n * held lines and a maximum of 5, the 8 and the newest line stay). The protection starts on the bar after the\n * assignment: 12 `var` lines created on the first bar with a maximum of 5 lose the first 6. Only\n * the variable itself protects: an object in a `var` array, in a field of a user type or in a variable that got\n * another object or `na` later is deleted like any other. JavaScript has no `var` declaration to observe, so the\n * script says it: {@link varDrawing} (a variable), or {@link holdDrawing} / {@link releaseDrawing}\n * - linefills have the limit of `max_lines_count` with another rule for the held ones (measured on one script, two\n * long runs): a fill is skipped when a `var` variable holds it or released it less than 5,000 bars ago (the bar\n * of {@link setDrawingBar}); when the count is still above the maximum + 5 after that, the oldest fills are\n * deleted until the maximum remain, the held ones too\n * - the script deletes count (`line.delete`, `label.delete`, ...): each kind has a number `P` of deleted objects. A\n * delete adds 1; a creation first sets `P` to 0 when it is 5 or more (3 or more for polylines)\n * - polylines use `P` on every bar: a creation cuts when the count is above `max_polylines_count + 5 + P`, down to\n * the maximum + `P`, and the polylines of the cut are added to `P`. A script that deletes and creates one polyline\n * per bar therefore sees the cut 0, 1 or 2 bars late\n * - lines, labels and boxes use `P` on the last bar only, with its value at the start of that bar: there the cut is\n * above the maximum + 5 + `P`, down to the maximum + `P` (up to 4 more objects)\n * - the last bar has rules of its own (measured from the count after each creation, on a closed and on an open last\n * bar): a cut deletes the objects of the bars before first, at most those (a line takes its linefills with it);\n * once none is left, a cut deletes objects of the last bar as on any bar. With 10 lines and a maximum of 10, 13\n * lines on the last bar leave these 13: the cut at the 16th line deletes the 10 old ones only. Lines, labels and\n * boxes: equal to PineScript, count after every operation and objects alive at the end, on 72 of 72 runs checked\n * after the rule was written (and 218 of 218 end states before)\n * - polylines on the last bar: the `P` carried from the bar before is counted twice (the first creation adds it once\n * more, unless it sets `P` to 0), later creations do not set `P` to 0, and the polylines of the bars before that a\n * cut deletes are added to `P`. Once none is\n * left, `P` is at least the number of polylines of the bars before deleted on the last bar (by the count or by\n * the script) and a cut deletes polylines of the last bar: a script that deletes its 100 polylines and creates 200\n * on the last bar keeps them all (#176). Equal to PineScript for the polylines alive at the end on 271 of\n * 281 probe runs; the count inside the bar can differ when the script deletes polylines of the last bar\n *\n * - a bar index (`xloc.bar_index`) more than 10,000 bars before the current bar stops the script (runtime error\n * RE10026) in `line.new`, `box.new`, `label.new`, `polyline.new` and the setters of x. The current bar is the one\n * of `eachBar` in a script run; a port with its own bar loop gives it with {@link setDrawingBar}\n *\n * The script API (`executeScript`) resets the registry at the start of every run and applies the\n * `max_*_count` values of `indicator()`. Outside a script run the registry is global to the module.\n *\n * @module drawing/registry\n */\n\nimport type { Box, Label, Line, Linefill, Polyline, Table } from '../types/index.js';\n\nexport type DrawingKind = 'line' | 'label' | 'box' | 'polyline' | 'linefill' | 'table';\n\ninterface DrawingTypes {\n line: Line;\n label: Label;\n box: Box;\n polyline: Polyline;\n linefill: Linefill;\n table: Table;\n}\n\n/** Default `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count`. */\nexport const DEFAULT_MAX_COUNT = 50;\n/** Objects above the maximum that PineScript keeps before it deletes the oldest ones. */\nconst SLACK = 5;\n\nexport type DrawingLimits = Partial<Record<Exclude<DrawingKind, 'linefill' | 'table'>, number>>;\n\nconst live: { [K in DrawingKind]: Array<DrawingTypes[K]> } = {\n line: [],\n label: [],\n box: [],\n polyline: [],\n linefill: [],\n table: [],\n};\nlet limits: Required<DrawingLimits> = {\n line: DEFAULT_MAX_COUNT,\n label: DEFAULT_MAX_COUNT,\n box: DEFAULT_MAX_COUNT,\n polyline: DEFAULT_MAX_COUNT,\n};\nconst deleted = new WeakSet<object>();\n/** Objects held by a `var` variable, with the number of variables that hold them. */\nlet held = new WeakMap<object, number>();\n/** Bar on which the last `var` variable released an object (linefill rule). */\nlet releasedAt = new WeakMap<object, number>();\n/** Bars during which a released linefill is still skipped by the maximum count. */\nconst LINEFILL_RELEASE_BARS = 5000;\n/** Bar on which a `var` variable got an object: the maximum count skips it from the next bar on. */\nlet heldAt = new WeakMap<object, number>();\n/** Kinds with a maximum count of their own. */\ntype CountedKind = 'line' | 'label' | 'box' | 'polyline';\nconst COUNTED_KINDS: readonly CountedKind[] = ['line', 'label', 'box', 'polyline'];\nconst isCounted = (kind: DrawingKind): kind is CountedKind => (COUNTED_KINDS as readonly DrawingKind[]).includes(kind);\n/** `P` of the module notes: objects deleted by the script (for polylines also by the maximum count). */\nlet pending: Record<CountedKind, number> = { line: 0, label: 0, box: 0, polyline: 0 };\n/** A creation sets `P` to 0 from this value on. */\nconst PENDING_RESET: Record<CountedKind, number> = { line: 5, label: 5, box: 5, polyline: 3 };\n\n/**\n * Marks an object as held by a `var` variable (PineScript `var line l = ...` or `l := line.new(...)` on a `var`\n * variable): the maximum count never deletes it, and it still counts. Returns the object.\n */\nexport function holdDrawing<T extends object>(obj: T): T {\n if (!held.has(obj)) {\n if (currentBar === null) heldAt.delete(obj);\n else heldAt.set(obj, currentBar);\n }\n held.set(obj, (held.get(obj) ?? 0) + 1);\n return obj;\n}\n\n/** The `var` variable no longer refers to the object (it got another object or `na`). */\nexport function releaseDrawing(obj: object | null | undefined): void {\n if (!obj) return;\n const count = held.get(obj) ?? 0;\n if (count > 1) held.set(obj, count - 1);\n else if (held.delete(obj) && currentBar !== null) releasedAt.set(obj, currentBar);\n}\n\n/** Held by a `var` variable since a bar before the current one (or outside a bar loop). */\nfunction heldBefore(obj: object): boolean {\n if (!held.has(obj)) return false;\n const bar = heldAt.get(obj);\n return bar === undefined || currentBar === null || bar < currentBar;\n}\n\n/** Linefill rule: held, or released less than 5,000 bars ago. */\nfunction fillProtected(obj: object): boolean {\n if (held.has(obj)) return true;\n const bar = releasedAt.get(obj);\n return bar !== undefined && currentBar !== null && currentBar - bar < LINEFILL_RELEASE_BARS;\n}\n\n/** A `var` variable of a drawing type: see {@link varDrawing}. */\nexport interface DrawingVariable<T extends object> {\n /** The object of the variable; setting it holds the new object and releases the one before */\n value: T | undefined;\n}\n\n/**\n * A PineScript `var` variable of a drawing type (`var line l = na`). The object it refers to is not deleted by the\n * maximum count; assigning another object (or `undefined` for `na`) releases the one before.\n *\n * @example\n * ```typescript\n * // Pine: var line level = na\n * // level := line.new(bar_index, close, bar_index + 1, close)\n * const level = varDrawing<Line>();\n * level.value = line.new(i, close, i + 1, close);\n * ```\n */\nexport function varDrawing<T extends object>(initial?: T): DrawingVariable<T> {\n let current: T | undefined = initial ? holdDrawing(initial) : undefined;\n return {\n get value() {\n return current;\n },\n set value(next: T | undefined) {\n if (next === current) return;\n releaseDrawing(current);\n current = next ? holdDrawing(next) : undefined;\n },\n };\n}\n\n/** Largest distance, in bars, of a bar index before the current bar (PineScript runtime error RE10026 above it). */\nexport const MAX_DRAWING_BARS_BACK = 10000;\n/** Largest distance, in bars, of a bar index after the last bar of the data (PineScript runtime error RE10020 above it). */\nexport const MAX_DRAWING_BARS_FORWARD = 500;\nlet currentBar: number | null = null;\nlet lastBarIndex: number | null = null;\n\n/** Kinds whose allowance on the last bar is the `P` they had when the bar started. */\ntype AllowanceKind = 'line' | 'label' | 'box';\nconst isAllowanceKind = (kind: DrawingKind): kind is AllowanceKind => kind === 'line' || kind === 'label' || kind === 'box';\n\n/** State of the last bar (see the module notes). */\ninterface LastBar {\n bar: number;\n /** The objects alive when the bar started (the objects of the bars before) */\n old: Set<object>;\n /** `P` of lines, labels and boxes when the bar started: their allowance for the whole bar */\n allowance: Record<AllowanceKind, number>;\n /** `P` of polylines when the bar started */\n carried: number;\n /** A polyline was created on this bar */\n polyline: boolean;\n /** Polylines of the bars before deleted on this bar (by the count or by the script) */\n oldPolylinesGone: number;\n}\nlet lastBar: LastBar | null = null;\n\n/**\n * Tells the drawing functions which bar is being calculated (`bar_index`), so that a bar index more than 10,000\n * bars back throws as in PineScript; `null` turns the check off. `eachBar` of the script API calls it.\n *\n * The bar also dates the objects held by a `var` variable (protected from the next bar on). `last` says that it is\n * the last bar of the data, which has rules of its own for the maximum count. `lastIndex` is the bar index of the\n * last bar of the data (PineScript `last_bar_index`): with it, a bar index more than 500 bars after it throws, also\n * on the bars before the last one (RE10020).\n */\nexport function setDrawingBar(barIndex: number | null, last: boolean = false, lastIndex?: number): void {\n if (lastBar && !(last && barIndex === lastBar.bar)) lastBar = null;\n currentBar = barIndex;\n lastBarIndex = barIndex === null ? null : (lastIndex ?? (last ? barIndex : null));\n if (barIndex !== null && last && !lastBar) {\n const start = (kind: AllowanceKind): number => (pending[kind] >= PENDING_RESET[kind] ? 0 : pending[kind]);\n lastBar = {\n bar: barIndex,\n old: new Set<object>([...live.line, ...live.label, ...live.box, ...live.polyline]),\n allowance: { line: start('line'), label: start('label'), box: start('box') },\n carried: pending.polyline,\n polyline: false,\n oldPolylinesGone: 0,\n };\n }\n}\n\n/**\n * Throws the PineScript runtime error RE10026 when `x` is a bar index more than 10,000 bars before the current bar,\n * and RE10020 when it is more than 500 bars after the last bar of the data (when {@link setDrawingBar} knows it).\n * `method` and `variable` are the names of the PineScript message (\"line.new\", \"x1\").\n *\n * Returns `x`, truncated when it is a bar index: PineScript's x is an int (a box from 5537.94 starts on bar 5537,\n * #176).\n */\nexport function checkBarIndex(method: string, variable: string, x: number, xloc: string | undefined): number {\n if ((xloc ?? 'bar_index') !== 'bar_index') return x;\n x = Math.trunc(x);\n if (currentBar === null) return x;\n if (lastBarIndex !== null && x - lastBarIndex > MAX_DRAWING_BARS_FORWARD) {\n throw new Error(\n `Error on bar ${currentBar}: Objects positioned using xloc.bar_index cannot be drawn further than ` +\n `${MAX_DRAWING_BARS_FORWARD} bars into the future.`\n );\n }\n if (currentBar - x > MAX_DRAWING_BARS_BACK) {\n throw new Error(\n `Error on bar ${currentBar}: Bar index value of the \\`${variable}\\` argument (${x}) in \\`${method}()\\` is too far ` +\n 'from the current bar index. Try using `time` instead.'\n );\n }\n return x;\n}\n\n/** Numeric fields that become NaN when an object is deleted, so that its getters return `na`. */\nconst COORDINATES: { [K in DrawingKind]: Array<keyof DrawingTypes[K]> } = {\n line: ['x1', 'y1', 'x2', 'y2'],\n label: ['x', 'y'],\n box: ['left', 'top', 'right', 'bottom'],\n polyline: [],\n linefill: [],\n table: [],\n};\n\nfunction markDeleted<K extends DrawingKind>(kind: K, obj: DrawingTypes[K], explicit: boolean): void {\n deleted.add(obj);\n for (const field of COORDINATES[kind]) (obj as unknown as Record<string, unknown>)[field as string] = NaN;\n if (kind === 'line' && explicit) {\n for (const fill of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove('linefill', fill);\n }\n}\n\n/** Objects above the maximum that the rule allows for, besides the 5: `P` of the module notes. */\nfunction allowance(kind: DrawingKind): number {\n if (kind === 'polyline') return pending.polyline;\n return lastBar && isAllowanceKind(kind) ? lastBar.allowance[kind] : 0;\n}\n\n/**\n * The maximum count after the creation of `obj`: removes the objects to delete from `list` (the oldest first; the new\n * object and an object held by a `var` variable are skipped and still count) and returns them.\n */\nfunction cutOldest<K extends DrawingKind>(\n kind: K,\n list: Array<DrawingTypes[K]>,\n obj: DrawingTypes[K],\n only?: (old: object) => boolean\n): Array<DrawingTypes[K]> {\n if (kind === 'table') return []; // tables have no maximum count\n const max = limits[kind === 'linefill' ? 'line' : (kind as keyof DrawingLimits)] + allowance(kind);\n if (list.length <= max + SLACK) return [];\n const kept: Array<DrawingTypes[K]> = [];\n const cut: Array<DrawingTypes[K]> = [];\n let excess = list.length - max;\n for (const old of list) {\n if (excess > 0 && old !== obj && (!only || only(old)) && !(kind === 'linefill' ? fillProtected(old) : heldBefore(old))) {\n excess--;\n cut.push(old);\n } else kept.push(old);\n }\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (kind === 'linefill' && kept.length > max + SLACK) cut.push(...kept.splice(0, kept.length - max));\n list.length = 0;\n list.push(...kept);\n return cut;\n}\n\n/** Kinds of the objects created since the last reset (a table counts too), in no order. */\nconst created = new Set<DrawingKind>();\n\n/** The kinds of drawing objects created since the last {@link resetDrawings}, even when none is alive any more. */\nexport function createdDrawingKinds(): DrawingKind[] {\n return [...created];\n}\n\n/** Records a new object and deletes the oldest objects of its kind when the count is too high. */\nexport function register<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n const list = live[kind];\n created.add(kind);\n if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);\n if (isCounted(kind) && pending[kind] >= PENDING_RESET[kind]) pending[kind] = 0;\n list.push(obj);\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline') pending.polyline += cut.length;\n for (const old of cut) markDeleted(kind, old, false);\n return obj;\n}\n\n/** An object created on the last bar (see the module notes). */\nfunction registerLast<K extends DrawingKind>(bar: LastBar, kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n if (kind === 'polyline' && !bar.polyline) {\n bar.polyline = true;\n if (pending.polyline >= PENDING_RESET.polyline) pending.polyline = 0;\n else pending.polyline += bar.carried; // counted twice\n }\n const list = live[kind];\n list.push(obj);\n const isOld = (old: object): boolean => bar.old.has(old);\n if (list.some((old) => old !== obj && isOld(old) && !heldBefore(old))) {\n // the objects of the bars before only; a line takes its linefills with it\n const cut = cutOldest(kind, list, obj, isOld);\n if (kind === 'polyline') {\n pending.polyline += cut.length;\n bar.oldPolylinesGone += cut.length;\n }\n for (const old of cut) markDeleted(kind, old, true);\n } else {\n // the polylines of the bars before deleted on this bar count before the cut (#176)\n if (kind === 'polyline' && pending.polyline < bar.oldPolylinesGone) pending.polyline = bar.oldPolylinesGone;\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline' && cut.length > 0) pending.polyline = bar.oldPolylinesGone;\n for (const old of cut) markDeleted(kind, old, false);\n }\n return obj;\n}\n\n/** Deletes an object (no effect when it is already deleted). */\nexport function remove<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): void {\n const list = live[kind];\n const index = list.indexOf(obj);\n if (index !== -1) {\n list.splice(index, 1);\n if (isCounted(kind)) pending[kind]++;\n if (kind === 'polyline' && lastBar?.old.has(obj)) lastBar.oldPolylinesGone++;\n }\n if (!deleted.has(obj)) markDeleted(kind, obj, true);\n}\n\n/** True when the object was deleted (by `delete` or by the maximum count). */\nexport function isDeleted(obj: unknown): boolean {\n return typeof obj === 'object' && obj !== null && deleted.has(obj);\n}\n\n/** The live objects of a kind, in creation order (a new array). */\nexport function all<K extends DrawingKind>(kind: K): Array<DrawingTypes[K]> {\n return [...live[kind]] as Array<DrawingTypes[K]>;\n}\n\n/** Forgets all objects (without deleting them) and sets the maximum counts (default 50). */\nexport function resetDrawings(newLimits: DrawingLimits = {}): void {\n for (const kind of Object.keys(live) as DrawingKind[]) live[kind].length = 0;\n created.clear();\n held = new WeakMap();\n releasedAt = new WeakMap();\n heldAt = new WeakMap();\n pending = { line: 0, label: 0, box: 0, polyline: 0 };\n currentBar = null;\n lastBarIndex = null;\n lastBar = null;\n limits = {\n line: newLimits.line ?? DEFAULT_MAX_COUNT,\n label: newLimits.label ?? DEFAULT_MAX_COUNT,\n box: newLimits.box ?? DEFAULT_MAX_COUNT,\n polyline: newLimits.polyline ?? DEFAULT_MAX_COUNT,\n };\n}\n\n/** Changes the maximum counts without forgetting the objects (PineScript `indicator(max_*_count)`). */\nexport function setDrawingLimits(newLimits: DrawingLimits): void {\n limits = { ...limits, ...Object.fromEntries(Object.entries(newLimits).filter(([, v]) => v !== undefined)) };\n}\n\n/** The registry state of a run, saved around a nested run (see {@link restoreDrawingState}). */\nexport interface DrawingState {\n live: { [K in DrawingKind]: Array<DrawingTypes[K]> };\n created: DrawingKind[];\n held: WeakMap<object, number>;\n releasedAt: WeakMap<object, number>;\n heldAt: WeakMap<object, number>;\n pending: Record<CountedKind, number>;\n currentBar: number | null;\n lastBarIndex: number | null;\n lastBar: LastBar | null;\n limits: Required<DrawingLimits>;\n}\n\n/** Saves the registry of the current run before a nested run (an intrabar run of a strategy). */\nexport function saveDrawingState(): DrawingState {\n return {\n live: {\n line: [...live.line],\n label: [...live.label],\n box: [...live.box],\n polyline: [...live.polyline],\n linefill: [...live.linefill],\n table: [...live.table],\n },\n created: [...created],\n held,\n releasedAt,\n heldAt,\n pending: { ...pending },\n currentBar,\n lastBarIndex,\n lastBar,\n limits: { ...limits },\n };\n}\n\n/** Puts back the registry saved by {@link saveDrawingState} after the nested run. */\nexport function restoreDrawingState(s: DrawingState): void {\n for (const kind of Object.keys(live) as DrawingKind[]) {\n const list = live[kind] as object[];\n list.length = 0;\n list.push(...(s.live[kind] as object[]));\n }\n created.clear();\n for (const kind of s.created) created.add(kind);\n held = s.held;\n releasedAt = s.releasedAt;\n heldAt = s.heldAt;\n pending = { ...s.pending };\n currentBar = s.currentBar;\n lastBarIndex = s.lastBarIndex;\n lastBar = s.lastBar;\n limits = { ...s.limits };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmEO,MAAM,oBAAoB;AAEjC,MAAM,QAAQ;AAId,MAAM,OAAuD;AAAA,EAC3D,MAAM,CAAC;AAAA,EACP,OAAO,CAAC;AAAA,EACR,KAAK,CAAC;AAAA,EACN,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,OAAO,CAAC;AACV;AACA,IAAI,SAAkC;AAAA,EACpC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AACZ;AACA,MAAM,UAAU,oBAAI,QAAgB;AAEpC,IAAI,OAAO,oBAAI,QAAwB;AAEvC,IAAI,aAAa,oBAAI,QAAwB;AAE7C,MAAM,wBAAwB;AAE9B,IAAI,SAAS,oBA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535
  export declare function seededRandom(seed: int): (min?: float, max?: float) => float;
536
536
  /** Starts every seeded sequence of `math.random` again (called at the start of a script run). */
537
537
  export declare function resetRandom(): void;
538
+ /** The random generators of the current run, saved around a nested run (see {@link restoreRandom}). */
539
+ export declare function saveRandom(): Map<number, (min?: float, max?: float) => float>;
540
+ /** Puts back the random generators saved by {@link saveRandom}. */
541
+ export declare function restoreRandom(saved: Map<number, (min?: float, max?: float) => float>): void;
538
542
  /**
539
543
  * Returns a pseudo-random number.
540
544
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/math/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAI9C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;AAC3C,wBAAgB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC;AAmBzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;AAC5C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC;AAmBxC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;AAC7C,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC;AAmBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC;AAC9D,wBAAgB,KAAK,CAAC,KAA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K,EAAE,GAAG,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC,CAE7E;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC,GAAG,IAAI,CAG3F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,KAAK,CAclE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;AAC5C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC;AAmBxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;AAC1E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;AA2ExE,eAAO,MAAM,EAAE,QAAU,CAAC;AAC1B,eAAO,MAAM,CAAC,QAAS,CAAC;AACxB,eAAO,MAAM,GAAG,oBAAoB,CAAC;AACrC,eAAO,MAAM,IAAI,qBAAqB,CAAC"}
@@ -38,9 +38,11 @@ __export(math_exports, {
38
38
  pow: () => pow,
39
39
  random: () => random,
40
40
  resetRandom: () => resetRandom,
41
+ restoreRandom: () => restoreRandom,
41
42
  round: () => round,
42
43
  round_to_mintick: () => round_to_mintick,
43
44
  rphi: () => rphi,
45
+ saveRandom: () => saveRandom,
44
46
  seededRandom: () => seededRandom,
45
47
  sign: () => sign,
46
48
  sin: () => sin,
@@ -459,6 +461,13 @@ const seeded = /* @__PURE__ */ new Map();
459
461
  function resetRandom() {
460
462
  seeded.clear();
461
463
  }
464
+ function saveRandom() {
465
+ return new Map(seeded);
466
+ }
467
+ function restoreRandom(saved) {
468
+ seeded.clear();
469
+ for (const [k, v] of saved) seeded.set(k, v);
470
+ }
462
471
  function random(min2, max2, seed) {
463
472
  if (seed !== void 0 && seed !== null && !Number.isNaN(seed)) {
464
473
  let gen = seeded.get(seed);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/math/index.ts"],
4
- "sourcesContent": ["/**\n * Math namespace\n * Mirrors PineScript's math.* functions for mathematical operations and calculations.\n *\n * @remarks\n * All math functions in this namespace follow PineScript v6 API specifications.\n * Functions include basic arithmetic, algebraic operations, trigonometry, and combinatorics.\n *\n * Known difference: `log10`, `exp`, `log`, `pow`, `sin`, `cos`, `tan` use JavaScript's `Math`. PineScript uses\n * other algorithms, whose results differ by 1 or 2 units in the last place on part of the inputs (`log10` about 4 %,\n * `exp` about 9 %, `sin` / `cos` / `tan` about 3 %, `log` 0.4 %, `pow` 0.05 % of random inputs). This is visible\n * only when a script amplifies these tiny differences (e.g. `ma > ma[1]` on values of 1e195); `sqrt`, `atan`,\n * `asin`, `acos` are equal. A constant argument (`math.log10(2)`) is computed before the script runs, with other\n * rules: see `constant`.\n *\n * @version 6\n */\n\nimport type { float, int, simple_int, series_float } from '../types/index.js';\nimport { Series } from '../runtime/series.js';\nimport { runningSum, runningSumSeries } from '../ta/running-sum.js';\nimport { checkSumLength } from '../ta/limits.js';\n\n/**\n * Returns the absolute value of a number.\n *\n * @param value - The number or Series\n * @returns The absolute value (always non-negative)\n *\n * @remarks\n * - Returns the distance from zero on the number line\n * - |x| = x if x \u2265 0, -x if x < 0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.abs(5) // Returns: 5\n * math.abs(-5) // Returns: 5\n * math.abs(0) // Returns: 0\n * ```\n */\nexport function abs(value: Series): Series;\nexport function abs(value: float): float;\nexport function abs(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.abs(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.abs(value);\n}\n\n/**\n * Returns the smallest integer greater than or equal to a given number (rounds up).\n *\n * @param value - The number to round up or Series\n * @returns The ceiling value (smallest integer \u2265 value)\n *\n * @remarks\n * - Always rounds towards positive infinity\n * - For positive numbers, rounds away from zero\n * - For negative numbers, rounds towards zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.ceil(4.2) // Returns: 5\n * math.ceil(4.8) // Returns: 5\n * math.ceil(-4.2) // Returns: -4\n * math.ceil(5) // Returns: 5\n * ```\n */\nexport function ceil(value: Series): Series;\nexport function ceil(value: float): int;\nexport function ceil(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.ceil(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.ceil(value);\n}\n\n/**\n * Returns the largest integer less than or equal to a given number (rounds down).\n *\n * @param value - The number to round down or Series\n * @returns The floor value (largest integer \u2264 value)\n *\n * @remarks\n * - Always rounds towards negative infinity\n * - For positive numbers, rounds towards zero\n * - For negative numbers, rounds away from zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.floor(4.2) // Returns: 4\n * math.floor(4.8) // Returns: 4\n * math.floor(-4.2) // Returns: -5\n * math.floor(5) // Returns: 5\n * ```\n */\nexport function floor(value: Series): Series;\nexport function floor(value: float): int;\nexport function floor(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.floor(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.floor(value);\n}\n\n/**\n * Returns the value rounded to the nearest integer or to a specified precision.\n *\n * @param value - The number to round or Series\n * @param precision - Optional number of decimal places (default: 0)\n * @returns The rounded value\n *\n * @remarks\n * - Rounds to nearest integer by default\n * - With precision, rounds to that many decimal places\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * PineScript rules:\n * - ties go away from zero (2.5 -> 3, -2.5 -> -3, -0.5 -> -1)\n * - without a precision, or with a precision <= 0, the result is the integer rounding (1234.5678 @ -2 -> 1235)\n * - a positive precision rounds only the fraction: `int + round(frac * scale) / scale` with\n * `scale = 1 / 10^-precision` (precision above 16 acts as 16); the tie is decided on the exact value of\n * `frac * scale` with a 1e-10 tolerance (1.005 @ 2 -> 1.01, 0.285 @ 2 -> 0.29, -1.45 @ 1 -> -1.5)\n * - an infinite value gives na\n *\n * @example\n * ```typescript\n * math.round(4.2) // Returns: 4\n * math.round(4.5) // Returns: 5\n * math.round(-2.5) // Returns: -3\n * math.round(4.567, 2) // Returns: 4.57\n * math.round(1.005, 2) // Returns: 1.01\n * ```\n */\nexport function round(value: Series, precision?: int): Series;\nexport function round(value: float, precision?: int): float;\nexport function round(value: float | Series, precision?: int): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundValue(valueArray[i] ?? NaN, precision));\n }\n return Series.fromArray(bars, result);\n }\n return roundValue(value, precision);\n}\n\n/** `0.5 - 1e-10` as the exact fraction TIE_HALF / TIE_SCALE: the tie threshold of round / round_to_mintick. */\nconst TIE_SCALE = 10n ** 10n;\nconst TIE_HALF = 5n * 10n ** 9n - 1n;\n/** From 2^52 up every double is an integer. */\nconst INT_LIMIT = 2 ** 52;\n\n/** Exact value of a finite double >= 0 as `[numerator, denominator]`. */\nfunction exactRatio(x: number): [bigint, bigint] {\n const view = new DataView(new ArrayBuffer(8));\n view.setFloat64(0, x);\n const hi = view.getUint32(0);\n const lo = view.getUint32(4);\n const expField = (hi >>> 20) & 0x7ff;\n let mantissa = (BigInt(hi & 0xfffff) << 32n) | BigInt(lo);\n let exp = -1074;\n if (expField !== 0) {\n mantissa |= 1n << 52n;\n exp = expField - 1075;\n }\n return exp >= 0 ? [mantissa << BigInt(exp), 1n] : [mantissa, 1n << BigInt(-exp)];\n}\n\n/** True when `num / den - units` (exact) is >= 0.5 - 1e-10. */\nfunction reachesTie(num: bigint, den: bigint, units: bigint): boolean {\n return (num - units * den) * TIE_SCALE >= TIE_HALF * den;\n}\n\n/** `10^-p`: the exact literal for an integer p (correctly rounded), Math.pow otherwise. */\nfunction tenToMinus(p: number): number {\n return Number.isInteger(p) ? Number(`1e-${p}`) : Math.pow(10, -p);\n}\n\n/** PineScript math.round of one value (see `round`). */\nfunction roundValue(value: number, precision?: number): number {\n if (!Number.isFinite(value)) return NaN;\n const negative = value < 0;\n const magnitude = negative ? -value : value;\n if (precision === undefined || Number.isNaN(precision) || precision <= 0) {\n if (magnitude >= INT_LIMIT) return value;\n let units = Math.floor(magnitude);\n if (magnitude - units >= 0.5) units++;\n return negative ? 0 - units : units;\n }\n const scale = 1 / tenToMinus(Math.min(precision, 16));\n const fraction = magnitude % 1;\n const scaled = fraction * scale;\n let units = Math.floor(scaled);\n const offset = scaled - units - 0.5;\n // Only a near-tie needs the exact product; the window covers the double's own error.\n const slack = 1e-9 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [fn, fd] = exactRatio(fraction);\n const [sn, sd] = exactRatio(scale);\n if (reachesTie(fn * sn, fd * sd, BigInt(units))) units++;\n } else if (offset > 0) {\n units++;\n }\n const result = magnitude - fraction + units / scale;\n return negative ? 0 - result : result;\n}\n\n/** 10^16: a constant keeps 16 decimals. */\nconst CONSTANT_SCALE = 10n ** 16n;\n\n/**\n * Returns the value PineScript gives to a constant float expression (not a PineScript function).\n *\n * @param value - The result of the constant expression, computed in JavaScript (e.g. `1 / 255`)\n * @returns The value of the same expression in a PineScript script\n *\n * @remarks\n * PineScript computes a constant expression (only literals and constants: `1 / 255`, `0.1 * 3`,\n * `math.sqrt(0.1)`) before the script runs, and the value is then rounded. JavaScript cannot tell a constant from a\n * series value, so wrap the constant expressions of a script with this function.\n * - |value| >= 0.001: the exact value of the double is rounded to 16 decimals, ties to even\n * (`1 / 255` -> 0.003921568627451, `1 / 7` -> 0.1428571428571428)\n * - |value| < 0.001, na and infinities: unchanged\n * - the whole expression is computed first, then rounded once (`(1 / 7) * 7` is 1)\n * - math functions of constants use JavaScript's `Math` there: `math.constant(math.sqrt(0.1))` is the PineScript\n * value; `math.log10` of a constant is `math.log(x) / math.log(10)` there:\n * `math.constant(math.log(2) / math.log(10))` -> 0.3010299956639811\n * - the same expression with a series operand (`close / 255`) is not rounded: do not wrap it\n *\n * @example\n * ```typescript\n * // Pine: var const float i_255 = 1 / 255\n * const i_255 = math.constant(1 / 255) // 0.003921568627451 (JavaScript: 0.00392156862745098)\n * math.constant(1 / 7) // 0.1428571428571428 (JavaScript: 0.14285714285714285)\n * math.constant(1 / 3) // 0.3333333333333333 (unchanged)\n * ```\n */\nexport function constant(value: float): float {\n const magnitude = Math.abs(value);\n // from 0.5 up, 16 decimals move a double by less than half its spacing: it stays the same\n if (!(magnitude >= 1e-3 && magnitude < 0.5)) return value;\n const [num, den] = exactRatio(magnitude);\n const scaled = num * CONSTANT_SCALE;\n let units = scaled / den;\n const twiceRest = (scaled - units * den) * 2n;\n if (twiceRest > den || (twiceRest === den && (units & 1n) === 1n)) units++;\n const digits = units.toString().padStart(17, '0');\n const result = Number(`${digits.slice(0, -16)}.${digits.slice(-16)}`);\n return value < 0 ? -result : result;\n}\n\n/**\n * Returns the maximum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The largest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns -Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```typescript\n * math.max(1, 2, 3) // Returns: 3\n * math.max(-1, -5, -2) // Returns: -1\n * math.max(10) // Returns: 10\n * math.max(5, 10, 3, 8) // Returns: 10\n * ```\n */\nexport function max(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.max\n return Math.max(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.max(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the minimum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The smallest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```typescript\n * math.min(1, 2, 3) // Returns: 1\n * math.min(-1, -5, -2) // Returns: -5\n * math.min(10) // Returns: 10\n * math.min(5, 10, 3, 8) // Returns: 3\n * ```\n */\nexport function min(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.min\n return Math.min(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.min(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the average (arithmetic mean) of the arguments.\n *\n * @param values - Variable number of values (numbers or Series)\n * @returns The arithmetic mean\n *\n * @remarks\n * - Calculates sum of all values divided by count\n * - Returns NaN if no arguments provided (division by zero)\n * - If any argument is a Series, returns a Series; otherwise returns a number\n * - PineScript rule: with 1 or 2 values the sum is plain; with 3 values or more it is a Kahan compensated sum whose\n * pending correction is subtracted before the division (math.avg(0.1, 0.2, 0.3) = 0.19999999999999998)\n *\n * @example\n * ```typescript\n * math.avg(1, 2, 3) // Returns: 2\n * math.avg(10, 20) // Returns: 15\n * math.avg(5) // Returns: 5\n * math.avg(1, 2, 3, 4, 5) // Returns: 3\n * ```\n */\nexport function avg(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n\n if (!hasSeries) {\n return avgOf(values as number[]);\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(avgOf(nums));\n }\n\n return Series.fromArray(bars, result);\n}\n\n/** PineScript math.avg of numbers: plain sum up to 2 values, Kahan sum with the correction flushed from 3. */\nfunction avgOf(nums: number[]): number {\n if (nums.length <= 2) {\n let sum = 0;\n for (const n of nums) sum = sum + n;\n return sum / nums.length;\n }\n let sum = 0;\n let c = 0;\n for (const n of nums) {\n const y = n - c;\n const t = sum + y;\n c = t - sum - y;\n sum = t;\n }\n return (sum - c) / nums.length;\n}\n\n/**\n * Returns the sum of values over a sliding window.\n *\n * @param source - Series of values or array\n * @param length - Window length for summation, or one length per bar (a series length: array or Series)\n * @returns Series or array with rolling sum values\n *\n * @remarks\n * - Calculates the sum of the last `length` non-`na` values at each point; an `na` value (also +/-Infinity) is\n * skipped and the bar keeps the previous result (as in PineScript)\n * - Returns NaN until `length` non-`na` values are available\n * - A compensated running sum, as in PineScript, so the result can differ from the exact window sum in the last\n * bits (bit for bit with PineScript)\n * - When passed a Series, returns a Series; when passed an array, returns an array\n * - With a series length, PineScript moves the running sum to the new length when the length changes, with Kahan\n * steps of the raw values: a smaller length removes the values that leave the window (oldest first); a larger\n * length adds back the values from the one before the old window down to the one `length` values back (newest\n * first), then the usual step removes the stored value of the one `length` values back. A bar with an `na` value\n * gives the sum of the last `length` earlier values\n *\n * @example\n * ```typescript\n * math.sum([1, 2, 3, 4, 5], 3) // Returns: [NaN, NaN, 6, 9, 12]\n * // Explanation: [NaN, NaN, 1+2+3, 2+3+4, 3+4+5]\n * ```\n */\nexport function sum(source: Series, length: simple_int | ArrayLike<number> | Series): Series;\nexport function sum(source: series_float, length: simple_int | ArrayLike<number> | Series): series_float;\nexport function sum(\n source: series_float | Series,\n length: simple_int | ArrayLike<number> | Series\n): series_float | Series {\n // Handle Series objects - extract to array first\n const sourceArray = source instanceof Series ? source.toArray() : source;\n if (typeof length === 'number') checkSumLength('math.sum', length, 0);\n // PineScript: the sum of the last `length` non-na values (also +/-Infinity skipped); an na bar keeps the previous\n // result. A compensated running sum, bit for bit as PineScript.\n const result: series_float =\n typeof length === 'number'\n ? runningSum(sourceArray, length)\n : runningSumSeries(sourceArray, length instanceof Series ? length.toArray() : length, 'math.sum');\n\n // If input was a Series, return a Series\n if (source instanceof Series) {\n return Series.fromArray(source.bars, result);\n }\n\n return result;\n}\n\n/**\n * Returns the square root of a number.\n *\n * @param value - The number (must be non-negative) or Series\n * @returns The square root (\u221Avalue)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - \u221Ax \u00D7 \u221Ax = x (for non-negative x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sqrt(9) // Returns: 3\n * math.sqrt(16) // Returns: 4\n * math.sqrt(2) // Returns: 1.414...\n * math.sqrt(0) // Returns: 0\n * ```\n */\nexport function sqrt(value: Series): Series;\nexport function sqrt(value: float): float;\nexport function sqrt(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sqrt(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sqrt(value);\n}\n\n/**\n * Returns base raised to the power of exponent.\n *\n * @param base - The base number or Series\n * @param exponent - The exponent (power) or Series\n * @returns base^exponent\n *\n * @remarks\n * - 0^0 returns 1\n * - Negative base with fractional exponent returns NaN\n * - Any number to the power of 0 equals 1\n * - If any argument is a Series, returns a Series; if all are numbers, returns a number\n *\n * @example\n * ```typescript\n * math.pow(2, 3) // Returns: 8 (2\u00B3)\n * math.pow(10, 2) // Returns: 100\n * math.pow(5, 0) // Returns: 1\n * math.pow(2, -1) // Returns: 0.5\n * ```\n */\nexport function pow(base: Series, exponent: float): Series;\nexport function pow(base: float, exponent: Series): Series;\nexport function pow(base: Series, exponent: Series): Series;\nexport function pow(base: float, exponent: float): float;\nexport function pow(base: float | Series, exponent: float | Series): float | Series {\n const baseIsSeries = base instanceof Series;\n const expIsSeries = exponent instanceof Series;\n \n // Pure scalar case\n if (!baseIsSeries && !expIsSeries) {\n return Math.pow(base as number, exponent as number);\n }\n \n // At least one is a Series - return a Series\n const bars = baseIsSeries ? (base as Series).bars : (exponent as Series).bars;\n const baseArray = baseIsSeries ? (base as Series).toArray() : null;\n const expArray = expIsSeries ? (exponent as Series).toArray() : null;\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const b = baseArray ? baseArray[i] ?? NaN : (base as number);\n const e = expArray ? expArray[i] ?? NaN : (exponent as number);\n result.push(Math.pow(b, e));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns e (Euler's number) raised to the power of value.\n *\n * @param value - The exponent or Series\n * @returns e^value (where e \u2248 2.71828)\n *\n * @remarks\n * - e^0 = 1\n * - e^1 = e \u2248 2.71828\n * - Inverse of ln(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.exp(0) // Returns: 1\n * math.exp(1) // Returns: 2.71828... (e)\n * math.exp(2) // Returns: 7.389...\n * math.exp(-1) // Returns: 0.3678...\n * ```\n */\nexport function exp(value: Series): Series;\nexport function exp(value: float): float;\nexport function exp(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.exp(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.exp(value);\n}\n\n/**\n * Returns the natural logarithm (base e) of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns ln(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - ln(e) = 1\n * - ln(1) = 0\n * - Inverse of exp(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.log(1) // Returns: 0\n * math.log(Math.E) // Returns: 1\n * math.log(10) // Returns: 2.302...\n * math.log(100) // Returns: 4.605...\n * ```\n */\nexport function log(value: Series): Series;\nexport function log(value: float): float;\nexport function log(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log(value);\n}\n\n/**\n * Returns the base-10 logarithm of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns log\u2081\u2080(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - log\u2081\u2080(10) = 1\n * - log\u2081\u2080(100) = 2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.log10(10) // Returns: 1\n * math.log10(100) // Returns: 2\n * math.log10(1000) // Returns: 3\n * math.log10(1) // Returns: 0\n * ```\n */\nexport function log10(value: Series): Series;\nexport function log10(value: float): float;\nexport function log10(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log10(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log10(value);\n}\n\n/**\n * Returns the sine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The sine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - sin(0) = 0\n * - sin(\u03C0/2) = 1\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sin(0) // Returns: 0\n * math.sin(Math.PI / 2) // Returns: 1\n * math.sin(Math.PI) // Returns: 0 (approximately)\n * math.sin(Math.PI / 6) // Returns: 0.5\n * ```\n */\nexport function sin(value: Series): Series;\nexport function sin(value: float): float;\nexport function sin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sin(value);\n}\n\n/**\n * Returns the cosine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The cosine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - cos(0) = 1\n * - cos(\u03C0/2) = 0\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.cos(0) // Returns: 1\n * math.cos(Math.PI / 2) // Returns: 0 (approximately)\n * math.cos(Math.PI) // Returns: -1\n * math.cos(Math.PI / 3) // Returns: 0.5\n * ```\n */\nexport function cos(value: Series): Series;\nexport function cos(value: float): float;\nexport function cos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.cos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.cos(value);\n}\n\n/**\n * Returns the tangent of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The tangent value\n *\n * @remarks\n * - Input is in radians, not degrees\n * - tan(x) = sin(x) / cos(x)\n * - Undefined at \u03C0/2, 3\u03C0/2, etc. (returns very large numbers)\n * - Periodic with period \u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.tan(0) // Returns: 0\n * math.tan(Math.PI / 4) // Returns: 1\n * math.tan(Math.PI / 6) // Returns: 0.577... (1/\u221A3)\n * ```\n */\nexport function tan(value: Series): Series;\nexport function tan(value: float): float;\nexport function tan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.tan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.tan(value);\n}\n\n/**\n * Returns the arcsine (inverse sine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - asin(sin(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - asin(0) = 0\n * - asin(1) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.asin(0) // Returns: 0\n * math.asin(1) // Returns: 1.5707... (\u03C0/2)\n * math.asin(0.5) // Returns: 0.5235... (\u03C0/6)\n * math.asin(-1) // Returns: -1.5707... (-\u03C0/2)\n * ```\n */\nexport function asin(value: Series): Series;\nexport function asin(value: float): float;\nexport function asin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.asin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.asin(value);\n}\n\n/**\n * Returns the arccosine (inverse cosine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [0, \u03C0])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - acos(cos(x)) = x for x in [0, \u03C0]\n * - acos(1) = 0\n * - acos(0) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.acos(1) // Returns: 0\n * math.acos(0) // Returns: 1.5707... (\u03C0/2)\n * math.acos(0.5) // Returns: 1.0471... (\u03C0/3)\n * math.acos(-1) // Returns: 3.1415... (\u03C0)\n * ```\n */\nexport function acos(value: Series): Series;\nexport function acos(value: float): float;\nexport function acos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.acos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.acos(value);\n}\n\n/**\n * Returns the arctangent (inverse tangent) of a number.\n *\n * @param value - The value or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Accepts any number as input\n * - atan(tan(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - atan(0) = 0\n * - atan(1) = \u03C0/4\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.atan(0) // Returns: 0\n * math.atan(1) // Returns: 0.7853... (\u03C0/4)\n * math.atan(-1) // Returns: -0.7853... (-\u03C0/4)\n * math.atan(Infinity) // Returns: 1.5707... (\u03C0/2)\n * ```\n */\nexport function atan(value: Series): Series;\nexport function atan(value: float): float;\nexport function atan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.atan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.atan(value);\n}\n\n/**\n * Converts an angle from degrees to radians.\n *\n * @param degrees - The angle in degrees or Series\n * @returns The angle in radians\n *\n * @remarks\n * - Radians = Degrees \u00D7 (\u03C0 / 180)\n * - One full rotation: 360\u00B0 = 2\u03C0 radians\n * - Common conversions: 90\u00B0 = \u03C0/2, 180\u00B0 = \u03C0, 270\u00B0 = 3\u03C0/2\n * - If degrees is a Series, returns a Series; if degrees is a number, returns a number\n *\n * @example\n * ```typescript\n * math.toradians(0) // Returns: 0\n * math.toradians(90) // Returns: 1.5707... (\u03C0/2)\n * math.toradians(180) // Returns: 3.1415... (\u03C0)\n * math.toradians(360) // Returns: 6.2831... (2\u03C0)\n * ```\n */\nexport function toradians(degrees: Series): Series;\nexport function toradians(degrees: float): float;\nexport function toradians(degrees: float | Series): float | Series {\n if (degrees instanceof Series) {\n const bars = degrees.bars;\n const valueArray = degrees.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (Math.PI / 180));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return degrees * (Math.PI / 180);\n}\n\n/**\n * Converts an angle from radians to degrees.\n *\n * @param radians - The angle in radians or Series\n * @returns The angle in degrees\n *\n * @remarks\n * - Degrees = Radians \u00D7 (180 / \u03C0)\n * - One full rotation: 2\u03C0 radians = 360\u00B0\n * - Common conversions: \u03C0/2 = 90\u00B0, \u03C0 = 180\u00B0, 3\u03C0/2 = 270\u00B0\n * - If radians is a Series, returns a Series; if radians is a number, returns a number\n *\n * @example\n * ```typescript\n * math.todegrees(0) // Returns: 0\n * math.todegrees(Math.PI / 2) // Returns: 90\n * math.todegrees(Math.PI) // Returns: 180\n * math.todegrees(2 * Math.PI) // Returns: 360\n * ```\n */\nexport function todegrees(radians: Series): Series;\nexport function todegrees(radians: float): float;\nexport function todegrees(radians: float | Series): float | Series {\n if (radians instanceof Series) {\n const bars = radians.bars;\n const valueArray = radians.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (180 / Math.PI));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return radians * (180 / Math.PI);\n}\n\n/**\n * PineScript's seeded generator: Java's linear congruential generator (`java.util.Random`), `nextDouble()`.\n * Each generator draws one number per call.\n */\nexport function seededRandom(seed: int): (min?: float, max?: float) => float {\n const mask = (1n << 48n) - 1n;\n let state = (BigInt(Math.trunc(seed)) ^ 0x5deece66dn) & mask;\n const next = (bits: bigint): bigint => {\n state = (0x5deece66dn * state + 11n) & mask;\n return state >> (48n - bits);\n };\n return (min = 0, max = 1) => {\n const hi = next(26n);\n const lo = next(27n);\n const unit = Number((hi << 27n) + lo) / 2 ** 53;\n return min + unit * (max - min);\n };\n}\n\nconst seeded = new Map<number, (min?: float, max?: float) => float>();\n\n/** Starts every seeded sequence of `math.random` again (called at the start of a script run). */\nexport function resetRandom(): void {\n seeded.clear();\n}\n\n/**\n * Returns a pseudo-random number.\n *\n * @param min - Optional minimum value (inclusive), default 0\n * @param max - Optional maximum value (exclusive), default 1\n * @param seed - Optional seed: a repeatable sequence, as PineScript (Java's `java.util.Random`)\n * @returns A random number in the specified range, or [0, 1) if no range specified\n *\n * @remarks\n * - Without a seed: `Math.random()`\n * - With a seed: PineScript's sequence, one number per call (measured: the call on each bar draws the next number\n * of `new java.util.Random(seed).nextDouble()` from the first bar of the history). PineScript keeps one generator\n * per call site; here there is one generator per seed value (started again by `executeScript`): for two call sites\n * with the same seed use `callsite.random(seed)`\n *\n * @example\n * ```typescript\n * math.random() // Returns: value between 0 and 1 (e.g., 0.234...)\n * math.random(0, 10) // Returns: value between 0 and 10 (e.g., 7.45...)\n * math.random(0, 1, 42) // Returns: 0.7275636800328681 on the first call, as PineScript\n * ```\n */\nexport function random(min?: float, max?: float, seed?: int): float {\n if (seed !== undefined && seed !== null && !Number.isNaN(seed)) {\n let gen = seeded.get(seed);\n if (!gen) {\n gen = seededRandom(seed);\n seeded.set(seed, gen);\n }\n return gen(min ?? 0, max ?? 1);\n }\n const rand = Math.random();\n if (min !== undefined && max !== undefined) {\n return min + rand * (max - min);\n }\n return rand;\n}\n\n/**\n * Returns the sign of a number.\n *\n * @param value - The number to check or Series\n * @returns 1 for positive, -1 for negative, 0 for zero, na for na\n *\n * @remarks\n * - Returns 1 if value > 0\n * - Returns -1 if value < 0\n * - Returns 0 if value = 0\n * - Returns na if value is na (as PineScript)\n * - Useful for determining direction or polarity\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sign(5) // Returns: 1\n * math.sign(-3) // Returns: -1\n * math.sign(0) // Returns: 0\n * math.sign(0.001) // Returns: 1\n * math.sign(NaN) // Returns: NaN\n * ```\n */\nexport function sign(value: Series): Series;\nexport function sign(value: float): int;\nexport function sign(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v > 0 ? 1 : v < 0 ? -1 : v === 0 ? 0 : NaN);\n }\n \n return Series.fromArray(bars, result);\n }\n \n return value > 0 ? 1 : value < 0 ? -1 : value === 0 ? 0 : NaN;\n}\n\n/**\n * Rounds a value to the nearest mintick.\n *\n * @param number - The number to round or Series\n * @param mintick - Optional mintick value (defaults to requiring syminfo context)\n * @returns The number rounded to tick precision\n *\n * @remarks\n * - **PineScript v6 signature**: `math.round_to_mintick(number)` - uses implicit syminfo.mintick\n * - **JavaScript signature**: Requires explicit `mintick` OR use `createContext()` with syminfo\n * - Rounds to the nearest value divisible by mintick\n * - Returns NaN for NaN input\n * - If number is a Series, returns a Series; if number is a float, returns a float\n *\n * PineScript rules:\n * - mintick is `minmove / pricescale` (here rebuilt from `mintick`: the smallest power of 10 that makes it an\n * integer); the position on the tick grid is `|number| * pricescale / minmove`\n * - ties go away from zero, decided on the exact value of that product with a 1e-10 tolerance\n * (-1.075 -> -1.08, 1.005 -> 1.01, 2.675 -> 2.68 at mintick 0.01)\n *\n * @example\n * ```typescript\n * // Direct call with explicit mintick\n * const rounded = math.round_to_mintick(1.2345, 0.01); // Returns: 1.23\n * const rounded2 = math.round_to_mintick(1.2367, 0.01); // Returns: 1.24\n *\n * // Or use context API for cleaner syntax\n * const { math } = createContext({ syminfo: { mintick: 0.01 } });\n * const rounded = math.round_to_mintick(1.2345); // Returns: 1.23\n * ```\n */\nexport function round_to_mintick(number: Series, mintick?: float): Series;\nexport function round_to_mintick(number: float, mintick?: float): float;\nexport function round_to_mintick(number: float | Series, mintick?: float): float | Series {\n if (number instanceof Series) {\n const bars = number.bars;\n const valueArray = number.toArray();\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundToTick(valueArray[i] ?? NaN, mintick));\n }\n return Series.fromArray(bars, result);\n }\n\n // Scalar case\n if (isNaN(number)) {\n return NaN;\n }\n\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n return roundToTick(number, mintick);\n}\n\n/** `[minmove, pricescale]` of a mintick: pricescale is the smallest power of 10 (up to 1e15) giving an integer. */\nfunction tickPair(mintick: number): [number, number] | null {\n for (let k = 0; k <= 15; k++) {\n const pricescale = Number(`1e${k}`);\n const scaled = mintick * pricescale;\n const minmove = Math.round(scaled);\n if (minmove >= 1 && Math.abs(scaled - minmove) <= 1e-9 * minmove) return [minmove, pricescale];\n }\n return null;\n}\n\n/** PineScript math.round_to_mintick of one value (see `round_to_mintick`). */\nfunction roundToTick(number: number, mintick: number): number {\n if (!Number.isFinite(number)) return NaN;\n if (mintick === 0) return number;\n const pair = tickPair(mintick);\n const negative = number < 0;\n const magnitude = negative ? -number : number;\n if (pair === null) {\n // A tick that is no decimal fraction: the grid of the double mintick, ties away from zero.\n const scaled = magnitude / mintick;\n let units = Math.trunc(scaled);\n if (scaled - units >= 0.5) units++;\n return (negative ? 0 - units : units) * mintick;\n }\n const [minmove, pricescale] = pair;\n const scaled = (magnitude * pricescale) / minmove;\n let units = Math.trunc(scaled);\n const offset = scaled - units - 0.5;\n const slack = 1e-6 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [n, d] = exactRatio(magnitude);\n const num = n * BigInt(pricescale);\n const den = d * BigInt(minmove);\n const whole = num / den;\n units = Number(whole) + (reachesTie(num, den, whole) ? 1 : 0);\n } else if (offset > 0) {\n units++;\n }\n return ((negative ? 0 - units : units) * minmove) / pricescale;\n}\n\n// Constants\nexport const pi = Math.PI;\nexport const e = Math.E;\nexport const phi = 1.618033988749895; // Golden ratio\nexport const rphi = 0.6180339887498948; // Reciprocal of golden ratio: 1 / phi\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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;AAAA,EAC7D,WAAW,SAAS,GAAG;AACrB;AAAA,EACF;AACA,UAAS,WAAW,IAAI,QAAQ,SAAS,UAAW;AACtD;AAGO,MAAM,KAAK,KAAK;AAChB,MAAM,IAAI,KAAK;AACf,MAAM,MAAM;AACZ,MAAM,OAAO;",
4
+ "sourcesContent": ["/**\n * Math namespace\n * Mirrors PineScript's math.* functions for mathematical operations and calculations.\n *\n * @remarks\n * All math functions in this namespace follow PineScript v6 API specifications.\n * Functions include basic arithmetic, algebraic operations, trigonometry, and combinatorics.\n *\n * Known difference: `log10`, `exp`, `log`, `pow`, `sin`, `cos`, `tan` use JavaScript's `Math`. PineScript uses\n * other algorithms, whose results differ by 1 or 2 units in the last place on part of the inputs (`log10` about 4 %,\n * `exp` about 9 %, `sin` / `cos` / `tan` about 3 %, `log` 0.4 %, `pow` 0.05 % of random inputs). This is visible\n * only when a script amplifies these tiny differences (e.g. `ma > ma[1]` on values of 1e195); `sqrt`, `atan`,\n * `asin`, `acos` are equal. A constant argument (`math.log10(2)`) is computed before the script runs, with other\n * rules: see `constant`.\n *\n * @version 6\n */\n\nimport type { float, int, simple_int, series_float } from '../types/index.js';\nimport { Series } from '../runtime/series.js';\nimport { runningSum, runningSumSeries } from '../ta/running-sum.js';\nimport { checkSumLength } from '../ta/limits.js';\n\n/**\n * Returns the absolute value of a number.\n *\n * @param value - The number or Series\n * @returns The absolute value (always non-negative)\n *\n * @remarks\n * - Returns the distance from zero on the number line\n * - |x| = x if x \u2265 0, -x if x < 0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.abs(5) // Returns: 5\n * math.abs(-5) // Returns: 5\n * math.abs(0) // Returns: 0\n * ```\n */\nexport function abs(value: Series): Series;\nexport function abs(value: float): float;\nexport function abs(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.abs(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.abs(value);\n}\n\n/**\n * Returns the smallest integer greater than or equal to a given number (rounds up).\n *\n * @param value - The number to round up or Series\n * @returns The ceiling value (smallest integer \u2265 value)\n *\n * @remarks\n * - Always rounds towards positive infinity\n * - For positive numbers, rounds away from zero\n * - For negative numbers, rounds towards zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.ceil(4.2) // Returns: 5\n * math.ceil(4.8) // Returns: 5\n * math.ceil(-4.2) // Returns: -4\n * math.ceil(5) // Returns: 5\n * ```\n */\nexport function ceil(value: Series): Series;\nexport function ceil(value: float): int;\nexport function ceil(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.ceil(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.ceil(value);\n}\n\n/**\n * Returns the largest integer less than or equal to a given number (rounds down).\n *\n * @param value - The number to round down or Series\n * @returns The floor value (largest integer \u2264 value)\n *\n * @remarks\n * - Always rounds towards negative infinity\n * - For positive numbers, rounds towards zero\n * - For negative numbers, rounds away from zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.floor(4.2) // Returns: 4\n * math.floor(4.8) // Returns: 4\n * math.floor(-4.2) // Returns: -5\n * math.floor(5) // Returns: 5\n * ```\n */\nexport function floor(value: Series): Series;\nexport function floor(value: float): int;\nexport function floor(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.floor(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.floor(value);\n}\n\n/**\n * Returns the value rounded to the nearest integer or to a specified precision.\n *\n * @param value - The number to round or Series\n * @param precision - Optional number of decimal places (default: 0)\n * @returns The rounded value\n *\n * @remarks\n * - Rounds to nearest integer by default\n * - With precision, rounds to that many decimal places\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * PineScript rules:\n * - ties go away from zero (2.5 -> 3, -2.5 -> -3, -0.5 -> -1)\n * - without a precision, or with a precision <= 0, the result is the integer rounding (1234.5678 @ -2 -> 1235)\n * - a positive precision rounds only the fraction: `int + round(frac * scale) / scale` with\n * `scale = 1 / 10^-precision` (precision above 16 acts as 16); the tie is decided on the exact value of\n * `frac * scale` with a 1e-10 tolerance (1.005 @ 2 -> 1.01, 0.285 @ 2 -> 0.29, -1.45 @ 1 -> -1.5)\n * - an infinite value gives na\n *\n * @example\n * ```typescript\n * math.round(4.2) // Returns: 4\n * math.round(4.5) // Returns: 5\n * math.round(-2.5) // Returns: -3\n * math.round(4.567, 2) // Returns: 4.57\n * math.round(1.005, 2) // Returns: 1.01\n * ```\n */\nexport function round(value: Series, precision?: int): Series;\nexport function round(value: float, precision?: int): float;\nexport function round(value: float | Series, precision?: int): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundValue(valueArray[i] ?? NaN, precision));\n }\n return Series.fromArray(bars, result);\n }\n return roundValue(value, precision);\n}\n\n/** `0.5 - 1e-10` as the exact fraction TIE_HALF / TIE_SCALE: the tie threshold of round / round_to_mintick. */\nconst TIE_SCALE = 10n ** 10n;\nconst TIE_HALF = 5n * 10n ** 9n - 1n;\n/** From 2^52 up every double is an integer. */\nconst INT_LIMIT = 2 ** 52;\n\n/** Exact value of a finite double >= 0 as `[numerator, denominator]`. */\nfunction exactRatio(x: number): [bigint, bigint] {\n const view = new DataView(new ArrayBuffer(8));\n view.setFloat64(0, x);\n const hi = view.getUint32(0);\n const lo = view.getUint32(4);\n const expField = (hi >>> 20) & 0x7ff;\n let mantissa = (BigInt(hi & 0xfffff) << 32n) | BigInt(lo);\n let exp = -1074;\n if (expField !== 0) {\n mantissa |= 1n << 52n;\n exp = expField - 1075;\n }\n return exp >= 0 ? [mantissa << BigInt(exp), 1n] : [mantissa, 1n << BigInt(-exp)];\n}\n\n/** True when `num / den - units` (exact) is >= 0.5 - 1e-10. */\nfunction reachesTie(num: bigint, den: bigint, units: bigint): boolean {\n return (num - units * den) * TIE_SCALE >= TIE_HALF * den;\n}\n\n/** `10^-p`: the exact literal for an integer p (correctly rounded), Math.pow otherwise. */\nfunction tenToMinus(p: number): number {\n return Number.isInteger(p) ? Number(`1e-${p}`) : Math.pow(10, -p);\n}\n\n/** PineScript math.round of one value (see `round`). */\nfunction roundValue(value: number, precision?: number): number {\n if (!Number.isFinite(value)) return NaN;\n const negative = value < 0;\n const magnitude = negative ? -value : value;\n if (precision === undefined || Number.isNaN(precision) || precision <= 0) {\n if (magnitude >= INT_LIMIT) return value;\n let units = Math.floor(magnitude);\n if (magnitude - units >= 0.5) units++;\n return negative ? 0 - units : units;\n }\n const scale = 1 / tenToMinus(Math.min(precision, 16));\n const fraction = magnitude % 1;\n const scaled = fraction * scale;\n let units = Math.floor(scaled);\n const offset = scaled - units - 0.5;\n // Only a near-tie needs the exact product; the window covers the double's own error.\n const slack = 1e-9 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [fn, fd] = exactRatio(fraction);\n const [sn, sd] = exactRatio(scale);\n if (reachesTie(fn * sn, fd * sd, BigInt(units))) units++;\n } else if (offset > 0) {\n units++;\n }\n const result = magnitude - fraction + units / scale;\n return negative ? 0 - result : result;\n}\n\n/** 10^16: a constant keeps 16 decimals. */\nconst CONSTANT_SCALE = 10n ** 16n;\n\n/**\n * Returns the value PineScript gives to a constant float expression (not a PineScript function).\n *\n * @param value - The result of the constant expression, computed in JavaScript (e.g. `1 / 255`)\n * @returns The value of the same expression in a PineScript script\n *\n * @remarks\n * PineScript computes a constant expression (only literals and constants: `1 / 255`, `0.1 * 3`,\n * `math.sqrt(0.1)`) before the script runs, and the value is then rounded. JavaScript cannot tell a constant from a\n * series value, so wrap the constant expressions of a script with this function.\n * - |value| >= 0.001: the exact value of the double is rounded to 16 decimals, ties to even\n * (`1 / 255` -> 0.003921568627451, `1 / 7` -> 0.1428571428571428)\n * - |value| < 0.001, na and infinities: unchanged\n * - the whole expression is computed first, then rounded once (`(1 / 7) * 7` is 1)\n * - math functions of constants use JavaScript's `Math` there: `math.constant(math.sqrt(0.1))` is the PineScript\n * value; `math.log10` of a constant is `math.log(x) / math.log(10)` there:\n * `math.constant(math.log(2) / math.log(10))` -> 0.3010299956639811\n * - the same expression with a series operand (`close / 255`) is not rounded: do not wrap it\n *\n * @example\n * ```typescript\n * // Pine: var const float i_255 = 1 / 255\n * const i_255 = math.constant(1 / 255) // 0.003921568627451 (JavaScript: 0.00392156862745098)\n * math.constant(1 / 7) // 0.1428571428571428 (JavaScript: 0.14285714285714285)\n * math.constant(1 / 3) // 0.3333333333333333 (unchanged)\n * ```\n */\nexport function constant(value: float): float {\n const magnitude = Math.abs(value);\n // from 0.5 up, 16 decimals move a double by less than half its spacing: it stays the same\n if (!(magnitude >= 1e-3 && magnitude < 0.5)) return value;\n const [num, den] = exactRatio(magnitude);\n const scaled = num * CONSTANT_SCALE;\n let units = scaled / den;\n const twiceRest = (scaled - units * den) * 2n;\n if (twiceRest > den || (twiceRest === den && (units & 1n) === 1n)) units++;\n const digits = units.toString().padStart(17, '0');\n const result = Number(`${digits.slice(0, -16)}.${digits.slice(-16)}`);\n return value < 0 ? -result : result;\n}\n\n/**\n * Returns the maximum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The largest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns -Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```typescript\n * math.max(1, 2, 3) // Returns: 3\n * math.max(-1, -5, -2) // Returns: -1\n * math.max(10) // Returns: 10\n * math.max(5, 10, 3, 8) // Returns: 10\n * ```\n */\nexport function max(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.max\n return Math.max(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.max(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the minimum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The smallest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```typescript\n * math.min(1, 2, 3) // Returns: 1\n * math.min(-1, -5, -2) // Returns: -5\n * math.min(10) // Returns: 10\n * math.min(5, 10, 3, 8) // Returns: 3\n * ```\n */\nexport function min(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.min\n return Math.min(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.min(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the average (arithmetic mean) of the arguments.\n *\n * @param values - Variable number of values (numbers or Series)\n * @returns The arithmetic mean\n *\n * @remarks\n * - Calculates sum of all values divided by count\n * - Returns NaN if no arguments provided (division by zero)\n * - If any argument is a Series, returns a Series; otherwise returns a number\n * - PineScript rule: with 1 or 2 values the sum is plain; with 3 values or more it is a Kahan compensated sum whose\n * pending correction is subtracted before the division (math.avg(0.1, 0.2, 0.3) = 0.19999999999999998)\n *\n * @example\n * ```typescript\n * math.avg(1, 2, 3) // Returns: 2\n * math.avg(10, 20) // Returns: 15\n * math.avg(5) // Returns: 5\n * math.avg(1, 2, 3, 4, 5) // Returns: 3\n * ```\n */\nexport function avg(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n\n if (!hasSeries) {\n return avgOf(values as number[]);\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(avgOf(nums));\n }\n\n return Series.fromArray(bars, result);\n}\n\n/** PineScript math.avg of numbers: plain sum up to 2 values, Kahan sum with the correction flushed from 3. */\nfunction avgOf(nums: number[]): number {\n if (nums.length <= 2) {\n let sum = 0;\n for (const n of nums) sum = sum + n;\n return sum / nums.length;\n }\n let sum = 0;\n let c = 0;\n for (const n of nums) {\n const y = n - c;\n const t = sum + y;\n c = t - sum - y;\n sum = t;\n }\n return (sum - c) / nums.length;\n}\n\n/**\n * Returns the sum of values over a sliding window.\n *\n * @param source - Series of values or array\n * @param length - Window length for summation, or one length per bar (a series length: array or Series)\n * @returns Series or array with rolling sum values\n *\n * @remarks\n * - Calculates the sum of the last `length` non-`na` values at each point; an `na` value (also +/-Infinity) is\n * skipped and the bar keeps the previous result (as in PineScript)\n * - Returns NaN until `length` non-`na` values are available\n * - A compensated running sum, as in PineScript, so the result can differ from the exact window sum in the last\n * bits (bit for bit with PineScript)\n * - When passed a Series, returns a Series; when passed an array, returns an array\n * - With a series length, PineScript moves the running sum to the new length when the length changes, with Kahan\n * steps of the raw values: a smaller length removes the values that leave the window (oldest first); a larger\n * length adds back the values from the one before the old window down to the one `length` values back (newest\n * first), then the usual step removes the stored value of the one `length` values back. A bar with an `na` value\n * gives the sum of the last `length` earlier values\n *\n * @example\n * ```typescript\n * math.sum([1, 2, 3, 4, 5], 3) // Returns: [NaN, NaN, 6, 9, 12]\n * // Explanation: [NaN, NaN, 1+2+3, 2+3+4, 3+4+5]\n * ```\n */\nexport function sum(source: Series, length: simple_int | ArrayLike<number> | Series): Series;\nexport function sum(source: series_float, length: simple_int | ArrayLike<number> | Series): series_float;\nexport function sum(\n source: series_float | Series,\n length: simple_int | ArrayLike<number> | Series\n): series_float | Series {\n // Handle Series objects - extract to array first\n const sourceArray = source instanceof Series ? source.toArray() : source;\n if (typeof length === 'number') checkSumLength('math.sum', length, 0);\n // PineScript: the sum of the last `length` non-na values (also +/-Infinity skipped); an na bar keeps the previous\n // result. A compensated running sum, bit for bit as PineScript.\n const result: series_float =\n typeof length === 'number'\n ? runningSum(sourceArray, length)\n : runningSumSeries(sourceArray, length instanceof Series ? length.toArray() : length, 'math.sum');\n\n // If input was a Series, return a Series\n if (source instanceof Series) {\n return Series.fromArray(source.bars, result);\n }\n\n return result;\n}\n\n/**\n * Returns the square root of a number.\n *\n * @param value - The number (must be non-negative) or Series\n * @returns The square root (\u221Avalue)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - \u221Ax \u00D7 \u221Ax = x (for non-negative x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sqrt(9) // Returns: 3\n * math.sqrt(16) // Returns: 4\n * math.sqrt(2) // Returns: 1.414...\n * math.sqrt(0) // Returns: 0\n * ```\n */\nexport function sqrt(value: Series): Series;\nexport function sqrt(value: float): float;\nexport function sqrt(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sqrt(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sqrt(value);\n}\n\n/**\n * Returns base raised to the power of exponent.\n *\n * @param base - The base number or Series\n * @param exponent - The exponent (power) or Series\n * @returns base^exponent\n *\n * @remarks\n * - 0^0 returns 1\n * - Negative base with fractional exponent returns NaN\n * - Any number to the power of 0 equals 1\n * - If any argument is a Series, returns a Series; if all are numbers, returns a number\n *\n * @example\n * ```typescript\n * math.pow(2, 3) // Returns: 8 (2\u00B3)\n * math.pow(10, 2) // Returns: 100\n * math.pow(5, 0) // Returns: 1\n * math.pow(2, -1) // Returns: 0.5\n * ```\n */\nexport function pow(base: Series, exponent: float): Series;\nexport function pow(base: float, exponent: Series): Series;\nexport function pow(base: Series, exponent: Series): Series;\nexport function pow(base: float, exponent: float): float;\nexport function pow(base: float | Series, exponent: float | Series): float | Series {\n const baseIsSeries = base instanceof Series;\n const expIsSeries = exponent instanceof Series;\n \n // Pure scalar case\n if (!baseIsSeries && !expIsSeries) {\n return Math.pow(base as number, exponent as number);\n }\n \n // At least one is a Series - return a Series\n const bars = baseIsSeries ? (base as Series).bars : (exponent as Series).bars;\n const baseArray = baseIsSeries ? (base as Series).toArray() : null;\n const expArray = expIsSeries ? (exponent as Series).toArray() : null;\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const b = baseArray ? baseArray[i] ?? NaN : (base as number);\n const e = expArray ? expArray[i] ?? NaN : (exponent as number);\n result.push(Math.pow(b, e));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns e (Euler's number) raised to the power of value.\n *\n * @param value - The exponent or Series\n * @returns e^value (where e \u2248 2.71828)\n *\n * @remarks\n * - e^0 = 1\n * - e^1 = e \u2248 2.71828\n * - Inverse of ln(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.exp(0) // Returns: 1\n * math.exp(1) // Returns: 2.71828... (e)\n * math.exp(2) // Returns: 7.389...\n * math.exp(-1) // Returns: 0.3678...\n * ```\n */\nexport function exp(value: Series): Series;\nexport function exp(value: float): float;\nexport function exp(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.exp(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.exp(value);\n}\n\n/**\n * Returns the natural logarithm (base e) of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns ln(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - ln(e) = 1\n * - ln(1) = 0\n * - Inverse of exp(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.log(1) // Returns: 0\n * math.log(Math.E) // Returns: 1\n * math.log(10) // Returns: 2.302...\n * math.log(100) // Returns: 4.605...\n * ```\n */\nexport function log(value: Series): Series;\nexport function log(value: float): float;\nexport function log(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log(value);\n}\n\n/**\n * Returns the base-10 logarithm of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns log\u2081\u2080(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - log\u2081\u2080(10) = 1\n * - log\u2081\u2080(100) = 2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.log10(10) // Returns: 1\n * math.log10(100) // Returns: 2\n * math.log10(1000) // Returns: 3\n * math.log10(1) // Returns: 0\n * ```\n */\nexport function log10(value: Series): Series;\nexport function log10(value: float): float;\nexport function log10(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log10(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log10(value);\n}\n\n/**\n * Returns the sine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The sine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - sin(0) = 0\n * - sin(\u03C0/2) = 1\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sin(0) // Returns: 0\n * math.sin(Math.PI / 2) // Returns: 1\n * math.sin(Math.PI) // Returns: 0 (approximately)\n * math.sin(Math.PI / 6) // Returns: 0.5\n * ```\n */\nexport function sin(value: Series): Series;\nexport function sin(value: float): float;\nexport function sin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sin(value);\n}\n\n/**\n * Returns the cosine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The cosine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - cos(0) = 1\n * - cos(\u03C0/2) = 0\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.cos(0) // Returns: 1\n * math.cos(Math.PI / 2) // Returns: 0 (approximately)\n * math.cos(Math.PI) // Returns: -1\n * math.cos(Math.PI / 3) // Returns: 0.5\n * ```\n */\nexport function cos(value: Series): Series;\nexport function cos(value: float): float;\nexport function cos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.cos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.cos(value);\n}\n\n/**\n * Returns the tangent of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The tangent value\n *\n * @remarks\n * - Input is in radians, not degrees\n * - tan(x) = sin(x) / cos(x)\n * - Undefined at \u03C0/2, 3\u03C0/2, etc. (returns very large numbers)\n * - Periodic with period \u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.tan(0) // Returns: 0\n * math.tan(Math.PI / 4) // Returns: 1\n * math.tan(Math.PI / 6) // Returns: 0.577... (1/\u221A3)\n * ```\n */\nexport function tan(value: Series): Series;\nexport function tan(value: float): float;\nexport function tan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.tan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.tan(value);\n}\n\n/**\n * Returns the arcsine (inverse sine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - asin(sin(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - asin(0) = 0\n * - asin(1) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.asin(0) // Returns: 0\n * math.asin(1) // Returns: 1.5707... (\u03C0/2)\n * math.asin(0.5) // Returns: 0.5235... (\u03C0/6)\n * math.asin(-1) // Returns: -1.5707... (-\u03C0/2)\n * ```\n */\nexport function asin(value: Series): Series;\nexport function asin(value: float): float;\nexport function asin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.asin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.asin(value);\n}\n\n/**\n * Returns the arccosine (inverse cosine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [0, \u03C0])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - acos(cos(x)) = x for x in [0, \u03C0]\n * - acos(1) = 0\n * - acos(0) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.acos(1) // Returns: 0\n * math.acos(0) // Returns: 1.5707... (\u03C0/2)\n * math.acos(0.5) // Returns: 1.0471... (\u03C0/3)\n * math.acos(-1) // Returns: 3.1415... (\u03C0)\n * ```\n */\nexport function acos(value: Series): Series;\nexport function acos(value: float): float;\nexport function acos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.acos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.acos(value);\n}\n\n/**\n * Returns the arctangent (inverse tangent) of a number.\n *\n * @param value - The value or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Accepts any number as input\n * - atan(tan(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - atan(0) = 0\n * - atan(1) = \u03C0/4\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.atan(0) // Returns: 0\n * math.atan(1) // Returns: 0.7853... (\u03C0/4)\n * math.atan(-1) // Returns: -0.7853... (-\u03C0/4)\n * math.atan(Infinity) // Returns: 1.5707... (\u03C0/2)\n * ```\n */\nexport function atan(value: Series): Series;\nexport function atan(value: float): float;\nexport function atan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.atan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.atan(value);\n}\n\n/**\n * Converts an angle from degrees to radians.\n *\n * @param degrees - The angle in degrees or Series\n * @returns The angle in radians\n *\n * @remarks\n * - Radians = Degrees \u00D7 (\u03C0 / 180)\n * - One full rotation: 360\u00B0 = 2\u03C0 radians\n * - Common conversions: 90\u00B0 = \u03C0/2, 180\u00B0 = \u03C0, 270\u00B0 = 3\u03C0/2\n * - If degrees is a Series, returns a Series; if degrees is a number, returns a number\n *\n * @example\n * ```typescript\n * math.toradians(0) // Returns: 0\n * math.toradians(90) // Returns: 1.5707... (\u03C0/2)\n * math.toradians(180) // Returns: 3.1415... (\u03C0)\n * math.toradians(360) // Returns: 6.2831... (2\u03C0)\n * ```\n */\nexport function toradians(degrees: Series): Series;\nexport function toradians(degrees: float): float;\nexport function toradians(degrees: float | Series): float | Series {\n if (degrees instanceof Series) {\n const bars = degrees.bars;\n const valueArray = degrees.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (Math.PI / 180));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return degrees * (Math.PI / 180);\n}\n\n/**\n * Converts an angle from radians to degrees.\n *\n * @param radians - The angle in radians or Series\n * @returns The angle in degrees\n *\n * @remarks\n * - Degrees = Radians \u00D7 (180 / \u03C0)\n * - One full rotation: 2\u03C0 radians = 360\u00B0\n * - Common conversions: \u03C0/2 = 90\u00B0, \u03C0 = 180\u00B0, 3\u03C0/2 = 270\u00B0\n * - If radians is a Series, returns a Series; if radians is a number, returns a number\n *\n * @example\n * ```typescript\n * math.todegrees(0) // Returns: 0\n * math.todegrees(Math.PI / 2) // Returns: 90\n * math.todegrees(Math.PI) // Returns: 180\n * math.todegrees(2 * Math.PI) // Returns: 360\n * ```\n */\nexport function todegrees(radians: Series): Series;\nexport function todegrees(radians: float): float;\nexport function todegrees(radians: float | Series): float | Series {\n if (radians instanceof Series) {\n const bars = radians.bars;\n const valueArray = radians.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (180 / Math.PI));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return radians * (180 / Math.PI);\n}\n\n/**\n * PineScript's seeded generator: Java's linear congruential generator (`java.util.Random`), `nextDouble()`.\n * Each generator draws one number per call.\n */\nexport function seededRandom(seed: int): (min?: float, max?: float) => float {\n const mask = (1n << 48n) - 1n;\n let state = (BigInt(Math.trunc(seed)) ^ 0x5deece66dn) & mask;\n const next = (bits: bigint): bigint => {\n state = (0x5deece66dn * state + 11n) & mask;\n return state >> (48n - bits);\n };\n return (min = 0, max = 1) => {\n const hi = next(26n);\n const lo = next(27n);\n const unit = Number((hi << 27n) + lo) / 2 ** 53;\n return min + unit * (max - min);\n };\n}\n\nconst seeded = new Map<number, (min?: float, max?: float) => float>();\n\n/** Starts every seeded sequence of `math.random` again (called at the start of a script run). */\nexport function resetRandom(): void {\n seeded.clear();\n}\n\n/** The random generators of the current run, saved around a nested run (see {@link restoreRandom}). */\nexport function saveRandom(): Map<number, (min?: float, max?: float) => float> {\n return new Map(seeded);\n}\n\n/** Puts back the random generators saved by {@link saveRandom}. */\nexport function restoreRandom(saved: Map<number, (min?: float, max?: float) => float>): void {\n seeded.clear();\n for (const [k, v] of saved) seeded.set(k, v);\n}\n\n/**\n * Returns a pseudo-random number.\n *\n * @param min - Optional minimum value (inclusive), default 0\n * @param max - Optional maximum value (exclusive), default 1\n * @param seed - Optional seed: a repeatable sequence, as PineScript (Java's `java.util.Random`)\n * @returns A random number in the specified range, or [0, 1) if no range specified\n *\n * @remarks\n * - Without a seed: `Math.random()`\n * - With a seed: PineScript's sequence, one number per call (measured: the call on each bar draws the next number\n * of `new java.util.Random(seed).nextDouble()` from the first bar of the history). PineScript keeps one generator\n * per call site; here there is one generator per seed value (started again by `executeScript`): for two call sites\n * with the same seed use `callsite.random(seed)`\n *\n * @example\n * ```typescript\n * math.random() // Returns: value between 0 and 1 (e.g., 0.234...)\n * math.random(0, 10) // Returns: value between 0 and 10 (e.g., 7.45...)\n * math.random(0, 1, 42) // Returns: 0.7275636800328681 on the first call, as PineScript\n * ```\n */\nexport function random(min?: float, max?: float, seed?: int): float {\n if (seed !== undefined && seed !== null && !Number.isNaN(seed)) {\n let gen = seeded.get(seed);\n if (!gen) {\n gen = seededRandom(seed);\n seeded.set(seed, gen);\n }\n return gen(min ?? 0, max ?? 1);\n }\n const rand = Math.random();\n if (min !== undefined && max !== undefined) {\n return min + rand * (max - min);\n }\n return rand;\n}\n\n/**\n * Returns the sign of a number.\n *\n * @param value - The number to check or Series\n * @returns 1 for positive, -1 for negative, 0 for zero, na for na\n *\n * @remarks\n * - Returns 1 if value > 0\n * - Returns -1 if value < 0\n * - Returns 0 if value = 0\n * - Returns na if value is na (as PineScript)\n * - Useful for determining direction or polarity\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sign(5) // Returns: 1\n * math.sign(-3) // Returns: -1\n * math.sign(0) // Returns: 0\n * math.sign(0.001) // Returns: 1\n * math.sign(NaN) // Returns: NaN\n * ```\n */\nexport function sign(value: Series): Series;\nexport function sign(value: float): int;\nexport function sign(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v > 0 ? 1 : v < 0 ? -1 : v === 0 ? 0 : NaN);\n }\n \n return Series.fromArray(bars, result);\n }\n \n return value > 0 ? 1 : value < 0 ? -1 : value === 0 ? 0 : NaN;\n}\n\n/**\n * Rounds a value to the nearest mintick.\n *\n * @param number - The number to round or Series\n * @param mintick - Optional mintick value (defaults to requiring syminfo context)\n * @returns The number rounded to tick precision\n *\n * @remarks\n * - **PineScript v6 signature**: `math.round_to_mintick(number)` - uses implicit syminfo.mintick\n * - **JavaScript signature**: Requires explicit `mintick` OR use `createContext()` with syminfo\n * - Rounds to the nearest value divisible by mintick\n * - Returns NaN for NaN input\n * - If number is a Series, returns a Series; if number is a float, returns a float\n *\n * PineScript rules:\n * - mintick is `minmove / pricescale` (here rebuilt from `mintick`: the smallest power of 10 that makes it an\n * integer); the position on the tick grid is `|number| * pricescale / minmove`\n * - ties go away from zero, decided on the exact value of that product with a 1e-10 tolerance\n * (-1.075 -> -1.08, 1.005 -> 1.01, 2.675 -> 2.68 at mintick 0.01)\n *\n * @example\n * ```typescript\n * // Direct call with explicit mintick\n * const rounded = math.round_to_mintick(1.2345, 0.01); // Returns: 1.23\n * const rounded2 = math.round_to_mintick(1.2367, 0.01); // Returns: 1.24\n *\n * // Or use context API for cleaner syntax\n * const { math } = createContext({ syminfo: { mintick: 0.01 } });\n * const rounded = math.round_to_mintick(1.2345); // Returns: 1.23\n * ```\n */\nexport function round_to_mintick(number: Series, mintick?: float): Series;\nexport function round_to_mintick(number: float, mintick?: float): float;\nexport function round_to_mintick(number: float | Series, mintick?: float): float | Series {\n if (number instanceof Series) {\n const bars = number.bars;\n const valueArray = number.toArray();\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundToTick(valueArray[i] ?? NaN, mintick));\n }\n return Series.fromArray(bars, result);\n }\n\n // Scalar case\n if (isNaN(number)) {\n return NaN;\n }\n\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n return roundToTick(number, mintick);\n}\n\n/** `[minmove, pricescale]` of a mintick: pricescale is the smallest power of 10 (up to 1e15) giving an integer. */\nfunction tickPair(mintick: number): [number, number] | null {\n for (let k = 0; k <= 15; k++) {\n const pricescale = Number(`1e${k}`);\n const scaled = mintick * pricescale;\n const minmove = Math.round(scaled);\n if (minmove >= 1 && Math.abs(scaled - minmove) <= 1e-9 * minmove) return [minmove, pricescale];\n }\n return null;\n}\n\n/** PineScript math.round_to_mintick of one value (see `round_to_mintick`). */\nfunction roundToTick(number: number, mintick: number): number {\n if (!Number.isFinite(number)) return NaN;\n if (mintick === 0) return number;\n const pair = tickPair(mintick);\n const negative = number < 0;\n const magnitude = negative ? -number : number;\n if (pair === null) {\n // A tick that is no decimal fraction: the grid of the double mintick, ties away from zero.\n const scaled = magnitude / mintick;\n let units = Math.trunc(scaled);\n if (scaled - units >= 0.5) units++;\n return (negative ? 0 - units : units) * mintick;\n }\n const [minmove, pricescale] = pair;\n const scaled = (magnitude * pricescale) / minmove;\n let units = Math.trunc(scaled);\n const offset = scaled - units - 0.5;\n const slack = 1e-6 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [n, d] = exactRatio(magnitude);\n const num = n * BigInt(pricescale);\n const den = d * BigInt(minmove);\n const whole = num / den;\n units = Number(whole) + (reachesTie(num, den, whole) ? 1 : 0);\n } else if (offset > 0) {\n units++;\n }\n return ((negative ? 0 - units : units) * minmove) / pricescale;\n}\n\n// Constants\nexport const pi = Math.PI;\nexport const e = Math.E;\nexport const phi = 1.618033988749895; // Golden ratio\nexport const rphi = 0.6180339887498948; // Reciprocal of golden ratio: 1 / phi\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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