oakscriptjs 0.9.6 → 0.10.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 (140) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/array/index.d.ts +9 -23
  3. package/dist/cjs/array/index.d.ts.map +1 -1
  4. package/dist/cjs/array/index.js +4 -0
  5. package/dist/cjs/array/index.js.map +2 -2
  6. package/dist/cjs/drawing/bar-time.d.ts +24 -0
  7. package/dist/cjs/drawing/bar-time.d.ts.map +1 -0
  8. package/dist/cjs/drawing/bar-time.js +47 -0
  9. package/dist/cjs/drawing/bar-time.js.map +7 -0
  10. package/dist/cjs/drawing/output.d.ts +32 -0
  11. package/dist/cjs/drawing/output.d.ts.map +1 -0
  12. package/dist/cjs/drawing/output.js +184 -0
  13. package/dist/cjs/drawing/output.js.map +7 -0
  14. package/dist/cjs/drawing/registry.d.ts +5 -4
  15. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  16. package/dist/cjs/drawing/registry.js +11 -2
  17. package/dist/cjs/drawing/registry.js.map +2 -2
  18. package/dist/cjs/index.d.ts +7 -3
  19. package/dist/cjs/index.d.ts.map +1 -1
  20. package/dist/cjs/index.js +11 -2
  21. package/dist/cjs/index.js.map +2 -2
  22. package/dist/cjs/polyline/index.d.ts +3 -5
  23. package/dist/cjs/polyline/index.d.ts.map +1 -1
  24. package/dist/cjs/polyline/index.js +0 -5
  25. package/dist/cjs/polyline/index.js.map +2 -2
  26. package/dist/cjs/runtime/index.d.ts +2 -1
  27. package/dist/cjs/runtime/index.d.ts.map +1 -1
  28. package/dist/cjs/runtime/index.js +2 -0
  29. package/dist/cjs/runtime/index.js.map +2 -2
  30. package/dist/cjs/runtime/input-active.d.ts +27 -0
  31. package/dist/cjs/runtime/input-active.d.ts.map +1 -0
  32. package/dist/cjs/runtime/input-active.js +44 -0
  33. package/dist/cjs/runtime/input-active.js.map +7 -0
  34. package/dist/cjs/runtime/types.d.ts +51 -2
  35. package/dist/cjs/runtime/types.d.ts.map +1 -1
  36. package/dist/cjs/runtime/types.js.map +1 -1
  37. package/dist/cjs/script/index.d.ts +104 -8
  38. package/dist/cjs/script/index.d.ts.map +1 -1
  39. package/dist/cjs/script/index.js +163 -28
  40. package/dist/cjs/script/index.js.map +3 -3
  41. package/dist/cjs/str/index.d.ts +9 -3
  42. package/dist/cjs/str/index.d.ts.map +1 -1
  43. package/dist/cjs/str/index.js +11 -6
  44. package/dist/cjs/str/index.js.map +2 -2
  45. package/dist/cjs/str/numberformat.d.ts +6 -0
  46. package/dist/cjs/str/numberformat.d.ts.map +1 -1
  47. package/dist/cjs/str/numberformat.js +9 -1
  48. package/dist/cjs/str/numberformat.js.map +2 -2
  49. package/dist/cjs/table/index.d.ts +87 -0
  50. package/dist/cjs/table/index.d.ts.map +1 -0
  51. package/dist/cjs/table/index.js +150 -0
  52. package/dist/cjs/table/index.js.map +7 -0
  53. package/dist/cjs/text/index.d.ts +17 -2
  54. package/dist/cjs/text/index.d.ts.map +1 -1
  55. package/dist/cjs/text/index.js +15 -1
  56. package/dist/cjs/text/index.js.map +2 -2
  57. package/dist/cjs/types/index.d.ts +30 -1
  58. package/dist/cjs/types/index.d.ts.map +1 -1
  59. package/dist/cjs/types/index.js +12 -0
  60. package/dist/cjs/types/index.js.map +2 -2
  61. package/dist/cjs/types/metadata.d.ts +258 -26
  62. package/dist/cjs/types/metadata.d.ts.map +1 -1
  63. package/dist/cjs/types/metadata.js.map +1 -1
  64. package/dist/esm/array/index.d.ts +9 -23
  65. package/dist/esm/array/index.d.ts.map +1 -1
  66. package/dist/esm/array/index.js +10 -22
  67. package/dist/esm/array/index.js.map +1 -1
  68. package/dist/esm/drawing/bar-time.d.ts +24 -0
  69. package/dist/esm/drawing/bar-time.d.ts.map +1 -0
  70. package/dist/esm/drawing/bar-time.js +44 -0
  71. package/dist/esm/drawing/bar-time.js.map +1 -0
  72. package/dist/esm/drawing/output.d.ts +32 -0
  73. package/dist/esm/drawing/output.d.ts.map +1 -0
  74. package/dist/esm/drawing/output.js +190 -0
  75. package/dist/esm/drawing/output.js.map +1 -0
  76. package/dist/esm/drawing/registry.d.ts +5 -4
  77. package/dist/esm/drawing/registry.d.ts.map +1 -1
  78. package/dist/esm/drawing/registry.js +12 -2
  79. package/dist/esm/drawing/registry.js.map +1 -1
  80. package/dist/esm/index.d.ts +7 -3
  81. package/dist/esm/index.d.ts.map +1 -1
  82. package/dist/esm/index.js +8 -3
  83. package/dist/esm/index.js.map +1 -1
  84. package/dist/esm/polyline/index.d.ts +3 -5
  85. package/dist/esm/polyline/index.d.ts.map +1 -1
  86. package/dist/esm/polyline/index.js +3 -9
  87. package/dist/esm/polyline/index.js.map +1 -1
  88. package/dist/esm/runtime/index.d.ts +2 -1
  89. package/dist/esm/runtime/index.d.ts.map +1 -1
  90. package/dist/esm/runtime/index.js +1 -0
  91. package/dist/esm/runtime/index.js.map +1 -1
  92. package/dist/esm/runtime/input-active.d.ts +27 -0
  93. package/dist/esm/runtime/input-active.d.ts.map +1 -0
  94. package/dist/esm/runtime/input-active.js +54 -0
  95. package/dist/esm/runtime/input-active.js.map +1 -0
  96. package/dist/esm/runtime/types.d.ts +51 -2
  97. package/dist/esm/runtime/types.d.ts.map +1 -1
  98. package/dist/esm/script/index.d.ts +104 -8
  99. package/dist/esm/script/index.d.ts.map +1 -1
  100. package/dist/esm/script/index.js +194 -24
  101. package/dist/esm/script/index.js.map +1 -1
  102. package/dist/esm/str/index.d.ts +9 -3
  103. package/dist/esm/str/index.d.ts.map +1 -1
  104. package/dist/esm/str/index.js +25 -10
  105. package/dist/esm/str/index.js.map +1 -1
  106. package/dist/esm/str/numberformat.d.ts +6 -0
  107. package/dist/esm/str/numberformat.d.ts.map +1 -1
  108. package/dist/esm/str/numberformat.js +12 -0
  109. package/dist/esm/str/numberformat.js.map +1 -1
  110. package/dist/esm/table/index.d.ts +87 -0
  111. package/dist/esm/table/index.d.ts.map +1 -0
  112. package/dist/esm/table/index.js +169 -0
  113. package/dist/esm/table/index.js.map +1 -0
  114. package/dist/esm/text/index.d.ts +17 -2
  115. package/dist/esm/text/index.d.ts.map +1 -1
  116. package/dist/esm/text/index.js +17 -2
  117. package/dist/esm/text/index.js.map +1 -1
  118. package/dist/esm/types/index.d.ts +30 -1
  119. package/dist/esm/types/index.d.ts.map +1 -1
  120. package/dist/esm/types/index.js +14 -0
  121. package/dist/esm/types/index.js.map +1 -1
  122. package/dist/esm/types/metadata.d.ts +258 -26
  123. package/dist/esm/types/metadata.d.ts.map +1 -1
  124. package/package.json +1 -1
  125. package/src/array/index.ts +12 -23
  126. package/src/drawing/bar-time.ts +42 -0
  127. package/src/drawing/output.ts +214 -0
  128. package/src/drawing/registry.ts +16 -6
  129. package/src/index.ts +11 -3
  130. package/src/polyline/index.ts +3 -12
  131. package/src/runtime/index.ts +3 -0
  132. package/src/runtime/input-active.ts +50 -0
  133. package/src/runtime/types.ts +48 -2
  134. package/src/script/index.ts +301 -30
  135. package/src/str/index.ts +23 -10
  136. package/src/str/numberformat.ts +13 -0
  137. package/src/table/index.ts +221 -0
  138. package/src/text/index.ts +18 -2
  139. package/src/types/index.ts +32 -1
  140. package/src/types/metadata.ts +325 -26
package/README.md CHANGED
@@ -62,7 +62,7 @@ function body() {
62
62
 
63
63
  // The host runs the body over bars and collects everything it declared.
64
64
  const run = executeScript(body, bars);
65
- // run.result.plots / markers / bgcolors, run.inputConfig, run.plotConfig, ...
65
+ // run.result.plots / markers / bgColors / labels / lines / tables, run.inputConfig, run.plotConfig, ...
66
66
  ```
67
67
 
68
68
  For stateful logic PineScript writes with `var`/`:=`/loops, use `eachBar` inside the script body. The values are plain numbers, so JS operators and `if`/`for` work. For PineScript comparison rules (1e-10 tolerance, `na` compares false), use `compare.gt(a, b)`, `compare.eq(a, b)`... from `oakscriptjs`.
@@ -2,7 +2,7 @@
2
2
  * Array namespace
3
3
  * Mirrors PineScript's array.* functions
4
4
  */
5
- import type { PineArray, int, float, bool, simple_int, color, Line, Box, Label, Linefill } from '../types/index.js';
5
+ import type { PineArray, int, float, bool, simple_int, color, Line, Box, Label, Linefill, Table } from '../types/index.js';
6
6
  /**
7
7
  * Creates a new array with initial size and default value
8
8
  */
@@ -421,6 +421,14 @@ export declare function new_label(size?: simple_int, initial_value?: Label): Pin
421
421
  * Enables dynamic color changes across multiple channels.
422
422
  */
423
423
  export declare function new_linefill(size?: simple_int, initial_value?: Linefill): PineArray<Linefill>;
424
+ /**
425
+ * Creates a new array of tables (PineScript `array.new_table`).
426
+ *
427
+ * @param size - Initial size of array (default: 0)
428
+ * @param initial_value - Initial value for all elements (default: undefined)
429
+ * @returns New table array
430
+ */
431
+ export declare function new_table(size?: simple_int, initial_value?: Table): PineArray<Table>;
424
432
  /**
425
433
  * Absolute value of array elements
426
434
  *
@@ -737,26 +745,4 @@ export declare function standardize(id: PineArray<float>): PineArray<float>;
737
745
  * - See PineScript documentation for UDT usage patterns
738
746
  */
739
747
  export declare function newtype<T>(size?: simple_int, initial_value?: T): PineArray<T>;
740
- /**
741
- * ⚠️ RENDERING FUNCTIONS NOT IMPLEMENTED
742
- *
743
- * The following array constructor functions are intentionally excluded
744
- * because they create arrays for rendering objects, which are outside
745
- * the scope of this calculation-focused library:
746
- *
747
- * - `new_box()` - Creates arrays of box drawing objects
748
- * - `new_label()` - Creates arrays of label objects
749
- * - `new_line()` - Creates arrays of line drawing objects
750
- * - `new_linefill()` - Creates arrays of line fill objects
751
- * - `new_table()` - Creates arrays of table layout objects
752
- *
753
- * **Design Constraint**: This library focuses on calculation and indicator
754
- * functions only. Rendering, visualization, and UI functions require a
755
- * rendering engine and are not included.
756
- *
757
- * If you need these functions, consider:
758
- * 1. Using PineScript directly
759
- * 2. Implementing a rendering layer separately
760
- * 3. Using this library for calculations and another library for visualization
761
- */
762
748
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;GAGG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K,CAStF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,CAoBnE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,GAAE,SAAiB,GAAG,SAAS,CAAC,GAAG,CAAC,CAE1F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAYlE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,GAAE,UAAc,EAAE,aAAa,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAIhF"}
@@ -52,6 +52,7 @@ __export(array_exports, {
52
52
  new_line: () => new_line,
53
53
  new_linefill: () => new_linefill,
54
54
  new_string: () => new_string,
55
+ new_table: () => new_table,
55
56
  newtype: () => newtype,
56
57
  percentile_linear_interpolation: () => percentile_linear_interpolation,
57
58
  percentile_nearest_rank: () => percentile_nearest_rank,
@@ -374,6 +375,9 @@ function new_label(size2 = 0, initial_value) {
374
375
  function new_linefill(size2 = 0, initial_value) {
375
376
  return new_array(size2, initial_value);
376
377
  }
378
+ function new_table(size2 = 0, initial_value) {
379
+ return new_array(size2, initial_value);
380
+ }
377
381
  function abs(id) {
378
382
  return id.map((x) => Math.abs(x));
379
383
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/array/index.ts"],
4
- "sourcesContent": ["/**\n * Array namespace\n * Mirrors PineScript's array.* functions\n */\n\nimport type { PineArray, int, float, bool, simple_int, color, Line, Box, Label, Linefill } from '../types/index.js';\n\n/**\n * Creates a new array with initial size and default value\n */\nexport function new_array<T>(size: simple_int = 0, initial_value?: T): PineArray<T> {\n const arr: PineArray<T> = [];\n for (let i = 0; i < size; i++) {\n arr.push(initial_value as T);\n }\n return arr;\n}\n\n/**\n * Returns the number of elements in an array\n */\nexport function size<T>(id: PineArray<T>): int {\n return id.length;\n}\n\n/** True for a PineScript `na` element: NaN, null or undefined. */\nfunction isNa(v: unknown): boolean {\n return v === undefined || v === null || (typeof v === 'number' && Number.isNaN(v));\n}\n\n/** The `na` of the array's element type: NaN for a numeric (or empty) array, undefined otherwise. */\nfunction naOf<T>(id: PineArray<T>): T {\n return (id.length === 0 || typeof id[0] === 'number' ? NaN : undefined) as T;\n}\n\n/**\n * Position addressed by a PineScript index: truncated, a negative index counts from the end. An index outside\n * `-size .. size - 1 + extra` is a runtime error.\n */\nfunction position(name: string, id: PineArray<unknown>, index: number, extra = 0): number {\n const i = Math.trunc(index);\n const n = id.length;\n if (i < -n || i >= n + extra) {\n throw new Error(`array.${name}: index ${i} is out of bounds, array size is ${n}`);\n }\n return i < 0 ? i + n : i;\n}\n\n/**\n * Returns the element at the specified index.\n *\n * PineScript rules: a negative index counts from the end (`get(a, -1)` is the last element); an index outside\n * `-size .. size - 1` is a runtime error (throws); an `na` index gives `na`.\n */\nexport function get<T>(id: PineArray<T>, index: simple_int): T {\n if (Number.isNaN(index)) return naOf(id);\n return id[position('get', id, index)]!;\n}\n\n/**\n * Sets the value of the element at the specified index.\n *\n * PineScript rules: a negative index counts from the end; an index outside `-size .. size - 1` is a runtime error\n * (throws); an `na` index does nothing.\n */\nexport function set<T>(id: PineArray<T>, index: simple_int, value: T): void {\n if (Number.isNaN(index)) return;\n id[position('set', id, index)] = value;\n}\n\n/**\n * Appends a value to the end of the array\n */\nexport function push<T>(id: PineArray<T>, value: T): void {\n id.push(value);\n}\n\n/**\n * Removes and returns the last element of the array\n */\nexport function pop<T>(id: PineArray<T>): T {\n return id.pop() as T;\n}\n\n/**\n * Inserts a value at the beginning of the array\n */\nexport function unshift<T>(id: PineArray<T>, value: T): void {\n id.unshift(value);\n}\n\n/**\n * Removes and returns the first element of the array\n */\nexport function shift<T>(id: PineArray<T>): T {\n return id.shift() as T;\n}\n\n/**\n * Removes all elements from the array\n */\nexport function clear<T>(id: PineArray<T>): void {\n id.length = 0;\n}\n\n/**\n * Inserts a value at the specified index.\n *\n * PineScript rules: a negative index counts from the end and `size` appends, so `-size .. size` is valid; any other\n * index is a runtime error (throws); an `na` index appends.\n */\nexport function insert<T>(id: PineArray<T>, index: simple_int, value: T): void {\n if (Number.isNaN(index)) {\n id.push(value);\n return;\n }\n id.splice(position('insert', id, index, 1), 0, value);\n}\n\n/**\n * Removes the element at the specified index and returns it.\n *\n * PineScript rules: a negative index counts from the end; an index outside `-size .. size - 1` is a runtime error\n * (throws); an `na` index removes nothing and gives `na`.\n */\nexport function remove<T>(id: PineArray<T>, index: simple_int): T {\n if (Number.isNaN(index)) return naOf(id);\n return id.splice(position('remove', id, index), 1)[0]!;\n}\n\n/** PineScript `==` of two elements: numbers are equal when |a - b| <= 1e-10; `na` never equals anything. */\nfunction pineEqual(a: unknown, b: unknown): boolean {\n if (isNa(a) || isNa(b)) return false;\n if (a === b) return true;\n if (typeof a === 'number' && typeof b === 'number') {\n const d = a - b;\n return -1e-10 <= d && d <= 1e-10;\n }\n return false;\n}\n\n/**\n * Returns true if the array contains the value.\n *\n * PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.\n */\nexport function includes<T>(id: PineArray<T>, value: T): bool {\n return indexof(id, value) >= 0;\n}\n\n/**\n * Returns the index of the first occurrence of the value, -1 when not found.\n *\n * PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.\n */\nexport function indexof<T>(id: PineArray<T>, value: T): int {\n for (let i = 0; i < id.length; i++) {\n if (pineEqual(id[i], value)) return i;\n }\n return -1;\n}\n\n/**\n * Returns the index of the last occurrence of the value, -1 when not found.\n *\n * PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.\n */\nexport function lastindexof<T>(id: PineArray<T>, value: T): int {\n for (let i = id.length - 1; i >= 0; i--) {\n if (pineEqual(id[i], value)) return i;\n }\n return -1;\n}\n\n/**\n * Returns a shallow copy of the array\n */\nexport function copy<T>(id: PineArray<T>): PineArray<T> {\n return [...id] as PineArray<T>;\n}\n\n/**\n * Appends the elements of `id2` to `id1` and returns `id1` (PineScript `array.concat` changes `id1`).\n */\nexport function concat<T>(id1: PineArray<T>, id2: PineArray<T>): PineArray<T> {\n for (const v of Array.from(id2)) id1.push(v);\n return id1;\n}\n\n/**\n * Joins all elements into a string\n */\nexport function join(id: PineArray<any>, separator: string = ','): string {\n return id.join(separator);\n}\n\n/**\n * Reverses the array in place\n */\nexport function reverse<T>(id: PineArray<T>): void {\n id.reverse();\n}\n\n/**\n * Returns the elements from `index_from` (included) to `index_to` (excluded, default: the size) as a live view of\n * the array (PineScript `array.slice`).\n *\n * PineScript rules:\n * - the slice shares the elements of the original array: a change of an element of the slice changes the original\n * array, and adding / removing elements of the slice adds / removes them in the original array, inside the slice\n * bounds (a push to the slice inserts at the end of the slice)\n * - `index_from` must address an element (`0 .. size - 1`) and `index_to` may be `size`; other bounds, or\n * `index_from > index_to`, are a runtime error (throws); an `na` bound means the start / the end of the array\n */\nexport function slice<T>(id: PineArray<T>, index_from: simple_int, index_to?: simple_int): PineArray<T> {\n const n = id.length;\n const start = Number.isNaN(index_from) ? 0 : Math.trunc(index_from);\n const stop = index_to === undefined || Number.isNaN(index_to) ? n : Math.trunc(index_to);\n if (start < 0 || start >= n) throw new Error(`array.slice: index ${start} is out of bounds, array size is ${n}`);\n if (stop < 0 || stop > n) throw new Error(`array.slice: index ${stop} is out of bounds, array size is ${n}`);\n if (start > stop) throw new Error(`array.slice: index_from ${start} is greater than index_to ${stop}`);\n return sliceView(id, start, stop - start);\n}\n\n/** Index of a property key that is an array index, -1 otherwise. */\nfunction indexKey(p: string | symbol): number {\n if (typeof p !== 'string') return -1;\n const i = Number(p);\n return Number.isInteger(i) && i >= 0 && String(i) === p ? i : -1;\n}\n\n/**\n * Live view of `size` elements of `parent` from `start`: an array (a Proxy) whose element reads and writes go to\n * `parent`, and whose size changes insert / remove elements in `parent` at the end of the view.\n */\nfunction sliceView<T>(parent: PineArray<T>, start: number, size: number): PineArray<T> {\n const resize = (target: number): void => {\n if (target > size) parent.splice(start + size, 0, ...Array<T>(target - size).fill(undefined as T));\n else if (target < size) parent.splice(start + target, size - target);\n size = target;\n };\n return new Proxy<T[]>([], {\n get(target, p, receiver) {\n const i = indexKey(p);\n if (i >= 0) return i < size ? parent[start + i] : undefined;\n if (p === 'length') return size;\n return Reflect.get(target, p, receiver);\n },\n set(target, p, value, receiver) {\n const i = indexKey(p);\n if (i >= 0) {\n if (i >= size) resize(i + 1);\n parent[start + i] = value;\n return true;\n }\n if (p === 'length') {\n resize(Number(value));\n return true;\n }\n return Reflect.set(target, p, value, receiver);\n },\n has(target, p) {\n const i = indexKey(p);\n return i >= 0 ? i < size : Reflect.has(target, p);\n },\n // Array methods delete the slots past the new end before they set the length, which does the removal.\n deleteProperty(target, p) {\n return indexKey(p) >= 0 ? true : Reflect.deleteProperty(target, p);\n },\n ownKeys(target) {\n return [...Array.from({ length: size }, (_, i) => String(i)), ...Reflect.ownKeys(target)];\n },\n getOwnPropertyDescriptor(target, p) {\n const i = indexKey(p);\n if (i >= 0) {\n return i < size ? { value: parent[start + i], writable: true, enumerable: true, configurable: true } : undefined;\n }\n if (p === 'length') return { value: size, writable: true, enumerable: false, configurable: false };\n return Reflect.getOwnPropertyDescriptor(target, p);\n },\n });\n}\n\n/** Sort order of array.sort / array.sort_indices (PineScript `order.ascending` / `order.descending`). */\nexport type SortOrder = 'asc' | 'desc' | 'ascending' | 'descending';\n\n/**\n * Positions of the elements in PineScript sorted order: ascending values, `na` after the numbers (before the\n * strings of a string array), stable; descending is the ascending result reversed.\n */\nfunction sortedPositions<T>(id: PineArray<T>, order: SortOrder): number[] {\n const values: number[] = [];\n const nas: number[] = [];\n for (let i = 0; i < id.length; i++) (isNa(id[i]) ? nas : values).push(i);\n values.sort((a, b) => {\n const x = id[a] as unknown as number;\n const y = id[b] as unknown as number;\n return x < y ? -1 : x > y ? 1 : 0;\n });\n const naFirst = values.length > 0 && typeof id[values[0]!] === 'string';\n const positions = naFirst ? [...nas, ...values] : [...values, ...nas];\n if (order === 'desc' || order === 'descending') positions.reverse();\n return positions;\n}\n\n/**\n * Sorts the array in place.\n *\n * PineScript rules: `na` goes after the numbers in ascending order and before them in descending order (the\n * ascending result reversed); in a string array `na` goes first in ascending order.\n */\nexport function sort<T>(id: PineArray<T>, order: SortOrder = 'asc'): void {\n const sorted = sortedPositions(id, order).map((p) => id[p]!);\n for (let i = 0; i < sorted.length; i++) id[i] = sorted[i]!;\n}\n\n/**\n * Sum of the non-na elements (PineScript `array.sum(id)`), added from left to right; an array without values gives NaN.\n * As PineScript, the running sum is set to 0 after a step when its absolute value is <= 1e-10.\n */\nexport function sum(id: PineArray<float>): float {\n let total = 0;\n let count = 0;\n for (const v of id) {\n if (Number.isNaN(v)) continue;\n count++;\n total += v;\n if (Math.abs(total) <= 1e-10) total = 0;\n }\n return count ? total : NaN;\n}\n\n/**\n * Average of the non-na elements (PineScript `array.avg(id)`); an array without values gives NaN.\n */\nexport function avg(id: PineArray<float>): float {\n const values = id.filter((v) => !Number.isNaN(v));\n return values.length ? values.reduce((a, b) => a + b, 0) / values.length : NaN;\n}\n\n/** The `nth` value of the non-na elements sorted with `compare` (array.min / array.max). */\nfunction nthValue(name: string, id: PineArray<float>, nth: number, compare: (a: number, b: number) => number): float {\n const rank = Number.isNaN(nth) ? 0 : Math.trunc(nth);\n const values = id.filter((v) => !Number.isNaN(v));\n if (!values.length) return NaN;\n if (rank < 0 || rank >= id.length) {\n throw new Error(`array.${name}: nth ${rank} is out of bounds, array size is ${id.length}`);\n }\n values.sort(compare);\n return values[Math.min(rank, values.length - 1)]!;\n}\n\n/**\n * The `nth` smallest value (0 = the smallest) of the non-na elements (PineScript `array.min(id, nth)`).\n *\n * PineScript rules: an `nth` past the non-na values but inside the array size gives the greatest value; an `nth`\n * outside `0 .. size - 1` is a runtime error (throws); an `na` nth counts as 0; an array without values gives NaN.\n */\nexport function min(id: PineArray<float>, nth: simple_int = 0): float {\n return nthValue('min', id, nth, (a, b) => a - b);\n}\n\n/**\n * The `nth` greatest value (0 = the greatest) of the non-na elements (PineScript `array.max(id, nth)`).\n *\n * PineScript rules: an `nth` past the non-na values but inside the array size gives the smallest value; an `nth`\n * outside `0 .. size - 1` is a runtime error (throws); an `na` nth counts as 0; an array without values gives NaN.\n */\nexport function max(id: PineArray<float>, nth: simple_int = 0): float {\n return nthValue('max', id, nth, (a, b) => b - a);\n}\n\n/**\n * Median of the non-na elements (PineScript `array.median(id)`): the middle value, or the mean of the two middle\n * values for an even count; an array without values gives NaN.\n */\nexport function median(id: PineArray<float>): float {\n const sorted = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);\n if (!sorted.length) return NaN;\n const mid = Math.floor(sorted.length / 2);\n return sorted.length % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!;\n}\n\n/**\n * Most frequent non-na element (PineScript `array.mode(id)`), compared exactly.\n *\n * PineScript rules: with several values of the same frequency, the smallest one; an array without values gives NaN.\n */\nexport function mode(id: PineArray<float>): float {\n const frequency = new Map<float, int>();\n for (const v of id) {\n if (!Number.isNaN(v)) frequency.set(v, (frequency.get(v) ?? 0) + 1);\n }\n let best = NaN;\n let bestCount = 0;\n for (const [v, count] of frequency) {\n if (count > bestCount || (count === bestCount && v < best)) {\n best = v;\n bestCount = count;\n }\n }\n return best;\n}\n\n/**\n * Standard deviation of the non-na elements (PineScript `array.stdev(id, biased)`): the square root of\n * `array.variance(id, biased)`.\n */\nexport function stdev(id: PineArray<float>, biased: bool = true): float {\n return Math.sqrt(variance(id, biased));\n}\n\n/** Sum of the values and sum of their squares, both added from the first to the last value. */\nfunction moments(values: number[]): [number, number] {\n let p = 0;\n let q = 0;\n for (const v of values) p += v;\n for (const v of values) q += v * v;\n return [p, q];\n}\n\n/**\n * Variance of the non-na elements (PineScript `array.variance(id, biased)`).\n *\n * PineScript rule (moment form): with `p` the sum of the values, `q` the sum of their squares, `n` the count and\n * `m = p / n`: biased (default) `max(0, q / n - m * m)`, unbiased `max(0, q / (n - 1) - (p / (n - 1)) * m)`.\n * One value gives 0 biased and NaN unbiased; an array without values gives NaN.\n */\nexport function variance(id: PineArray<float>, biased: bool = true): float {\n const values = id.filter((v) => !Number.isNaN(v));\n const n = values.length;\n if (!n) return NaN;\n if (n < 2) return biased ? 0 : NaN;\n const [p, q] = moments(values);\n const mean = p / n;\n return biased ? Math.max(0, q / n - mean * mean) : Math.max(0, q / (n - 1) - (p / (n - 1)) * mean);\n}\n\n/**\n * Fills the array with the specified value\n */\nexport function fill<T>(id: PineArray<T>, value: T, index_from: simple_int = 0, index_to?: simple_int): void {\n // PineScript: an na bound is the start / the end; a bound past the end is a runtime error\n const start = index_from === undefined || index_from === null || Number.isNaN(index_from) ? 0 : index_from;\n const end = index_to === undefined || index_to === null || Number.isNaN(index_to) ? id.length : index_to;\n for (const i of [start, end]) {\n if (i < 0 || i > id.length) throw new Error(`array.fill: index ${i} is out of bounds, array size is ${id.length}`);\n }\n for (let i = start; i < end; i++) {\n id[i] = value;\n }\n}\n\n/**\n * Creates an array from its arguments (PineScript `array.from(arg0, arg1, ...)`).\n * `na` values are kept.\n *\n * @example\n * ```typescript\n * array.from(0.236, 0.382, 0.5, 0.618); // [0.236, 0.382, 0.5, 0.618]\n * ```\n */\nexport function from<T>(...values: T[]): PineArray<T> {\n return [...values];\n}\n\n/**\n * Returns the first element of the array\n *\n * @param id - The array\n * @returns The first element, or undefined if array is empty\n *\n * @remarks\n * - Equivalent to `array.get(id, 0)`\n * - Returns undefined for empty arrays\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const firstElement = array.first(arr); // Returns: 1\n * ```\n */\nexport function first<T>(id: PineArray<T>): T {\n // PineScript: a runtime error on an empty array\n if (id.length === 0) throw new Error('Cannot call array.first() if array is empty');\n return id[0]!;\n}\n\n/**\n * Returns the last element of the array\n *\n * @param id - The array\n * @returns The last element, or undefined if array is empty\n *\n * @remarks\n * - Equivalent to `array.get(id, array.size(id) - 1)`\n * - Returns undefined for empty arrays\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const lastElement = array.last(arr); // Returns: 5\n * ```\n */\nexport function last<T>(id: PineArray<T>): T {\n // PineScript: a runtime error on an empty array (as array.first)\n if (id.length === 0) throw new Error('Cannot call array.last() if array is empty');\n return id[id.length - 1]!;\n}\n\n/**\n * True when at least one element of a bool array is true (PineScript `array.some(id)`).\n * An empty array gives false.\n */\nexport function some(id: PineArray<bool>): bool {\n return id.some((v) => v === true);\n}\n\n/**\n * True when every element of a bool array is true (PineScript `array.every(id)`).\n * An empty array gives false, as in PineScript.\n */\nexport function every(id: PineArray<bool>): bool {\n return id.length > 0 && id.every((v) => v === true);\n}\n\n/**\n * Create new boolean array\n *\n * Creates a new array object of bool type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: false)\n * @returns New boolean array\n *\n * @example\n * ```typescript\n * const arr = array.new_bool(5, true);\n * // Creates: [true, true, true, true, true]\n * ```\n */\nexport function new_bool(size: simple_int = 0, initial_value: bool = false): PineArray<bool> {\n return new_array<bool>(size, initial_value);\n}\n\n/**\n * Create new float array\n *\n * Creates a new array object of float type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: NaN)\n * @returns New float array\n *\n * @example\n * ```typescript\n * const arr = array.new_float(5, 0.0);\n * // Creates: [0.0, 0.0, 0.0, 0.0, 0.0]\n * ```\n */\nexport function new_float(size: simple_int = 0, initial_value: float = NaN): PineArray<float> {\n return new_array<float>(size, initial_value);\n}\n\n/**\n * Create new integer array\n *\n * Creates a new array object of int type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: NaN)\n * @returns New integer array\n *\n * @example\n * ```typescript\n * const arr = array.new_int(5, 0);\n * // Creates: [0, 0, 0, 0, 0]\n * ```\n */\nexport function new_int(size: simple_int = 0, initial_value: int = NaN): PineArray<int> {\n return new_array<int>(size, initial_value);\n}\n\n/**\n * Create new string array\n *\n * Creates a new array object of string type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New string array\n *\n * @example\n * ```typescript\n * const arr = array.new_string(5, \"text\");\n * // Creates: [\"text\", \"text\", \"text\", \"text\", \"text\"]\n * ```\n */\nexport function new_string(size: simple_int = 0, initial_value?: string): PineArray<string> {\n return new_array<string>(size, initial_value);\n}\n\n/**\n * Create new color array\n *\n * Creates a new array object of color type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New color array\n *\n * @example\n * ```typescript\n * const arr = array.new_color(5, \"#FF0000\");\n * // Creates: [\"#FF0000\", \"#FF0000\", \"#FF0000\", \"#FF0000\", \"#FF0000\"]\n * ```\n */\nexport function new_color(size: simple_int = 0, initial_value?: color): PineArray<color> {\n return new_array<color>(size, initial_value);\n}\n\n/**\n * Create new line array\n *\n * Creates a new array object of line type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New line array\n *\n * @example\n * ```typescript\n * import { array, line } from 'oakscriptjs';\n *\n * // Create array to store last 15 lines\n * const lines = array.new_line();\n * const trendLine = line.new(0, 100, 50, 150);\n * array.push(lines, trendLine);\n *\n * // Manage line count\n * if (array.size(lines) > 15) {\n * const oldLine = array.shift(lines);\n * }\n * ```\n *\n * @remarks\n * Useful for managing collections of trend lines, support/resistance levels, or channel lines.\n * In PineScript, this is typically used with line.delete() to manage chart object limits.\n */\nexport function new_line(size: simple_int = 0, initial_value?: Line): PineArray<Line> {\n return new_array<Line>(size, initial_value);\n}\n\n/**\n * Create new box array\n *\n * Creates a new array object of box type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New box array\n *\n * @example\n * ```typescript\n * import { array, box } from 'oakscriptjs';\n *\n * // Create array to store gap boxes\n * const gaps = array.new_box();\n * const gapBox = box.new(10, 120, 15, 110);\n * array.push(gaps, gapBox);\n *\n * // Track multiple gaps\n * for (let i = 0; i < array.size(gaps); i++) {\n * const gap = array.get(gaps, i);\n * const gapTop = box.get_top(gap);\n * const gapBottom = box.get_bottom(gap);\n * // Check if gap filled...\n * }\n * ```\n *\n * @remarks\n * Useful for tracking ranges, gaps, consolidation zones, or rectangle patterns.\n * Enables systematic analysis of multiple box objects.\n */\nexport function new_box(size: simple_int = 0, initial_value?: Box): PineArray<Box> {\n return new_array<Box>(size, initial_value);\n}\n\n/**\n * Create new label array\n *\n * Creates a new array object of label type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New label array\n *\n * @example\n * ```typescript\n * import { array, label } from 'oakscriptjs';\n *\n * // Create array to store pivot labels\n * const pivotLabels = array.new_label();\n *\n * // Add labels for pivot highs\n * const pivotLabel = label.new(50, 155.5, 'PH', 'bar_index', 'abovebar');\n * array.push(pivotLabels, pivotLabel);\n *\n * // Limit number of labels shown\n * const maxLabels = 50;\n * if (array.size(pivotLabels) > maxLabels) {\n * array.shift(pivotLabels);\n * }\n * ```\n *\n * @remarks\n * Useful for managing collections of annotations, pivot markers, or signal labels.\n * Helps limit the number of labels displayed by removing old ones.\n */\nexport function new_label(size: simple_int = 0, initial_value?: Label): PineArray<Label> {\n return new_array<Label>(size, initial_value);\n}\n\n/**\n * Create new linefill array\n *\n * Creates a new array object of linefill type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New linefill array\n *\n * @example\n * ```typescript\n * import { array, line, linefill } from 'oakscriptjs';\n *\n * // Create array to store channel fills\n * const channels = array.new_linefill();\n *\n * // Create channel\n * const upperLine = line.new(0, 120, 50, 130);\n * const lowerLine = line.new(0, 100, 50, 110);\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF15');\n *\n * array.push(channels, channelFill);\n * ```\n *\n * @remarks\n * Useful for managing collections of channel fills, Bollinger Band fills, or regression channel fills.\n * Enables dynamic color changes across multiple channels.\n */\nexport function new_linefill(size: simple_int = 0, initial_value?: Linefill): PineArray<Linefill> {\n return new_array<Linefill>(size, initial_value);\n}\n\n/**\n * Absolute value of array elements\n *\n * Returns an array containing the absolute value of each element in the original array.\n *\n * @param id - Array of numeric values\n * @returns New array with absolute values\n *\n * @example\n * ```typescript\n * const arr = [-1, -2, 3, -4, 5];\n * const result = array.abs(arr);\n * // Returns: [1, 2, 3, 4, 5]\n * ```\n */\nexport function abs(id: PineArray<float>): PineArray<float> {\n return id.map(x => Math.abs(x)) as PineArray<float>;\n}\n\n/**\n * Range of array values\n *\n * Returns the difference between the maximum and minimum values in the array.\n *\n * @param id - Array of numeric values\n * @returns Difference between max and min (range)\n *\n * @example\n * ```typescript\n * const arr = [1, 5, 3, 9, 2];\n * const result = array.range(arr);\n * // Returns: 8 (9 - 1)\n * ```\n *\n * @remarks\n * Returns NaN if the array is empty.\n */\nexport function range(id: PineArray<float>): float {\n if (id.length === 0) {\n return NaN;\n }\n return max(id) - min(id);\n}\n\n/**\n * Binary Search\n *\n * Searches for a value in a sorted array using binary search algorithm.\n * Returns the index of the value if found, or -1 if not found.\n *\n * @param id - Sorted array (ascending order)\n * @param val - Value to search for\n * @returns Index of the value, or -1 if not found\n *\n * @example\n * ```typescript\n * const arr = [-2, 0, 1, 5, 9]; // Must be sorted\n * const index = array.binary_search(arr, 5);\n * // Returns: 3\n * ```\n *\n * @remarks\n * - Array must be sorted in ascending order\n * - Uses standard binary search algorithm\n * - Time complexity: O(log n)\n */\nexport function binary_search(id: PineArray<float>, val: float): int {\n let left = 0;\n let right = id.length - 1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n\n if (id[mid]! === val) {\n return mid;\n }\n\n if (id[mid]! < val) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n\n return -1; // Not found\n}\n\n/**\n * Binary Search Leftmost\n *\n * Returns the index of the value if found. When not found, returns the index\n * of the next smallest element to the left of where the value would be.\n *\n * @param id - Sorted array (ascending order)\n * @param val - Value to search for\n * @returns Index of value or insertion point to the left\n *\n * @example\n * ```typescript\n * const arr = [-2, 0, 1, 5, 9];\n * const index = array.binary_search_leftmost(arr, 3);\n * // Returns: 2 (index of 1, which is left of where 3 would be)\n * ```\n *\n * @example\n * ```typescript\n * const arr = [4, 5, 5, 5];\n * const index = array.binary_search_leftmost(arr, 5);\n * // Returns: 1 (index of first instance of 5)\n * ```\n *\n * @remarks\n * - Array must be sorted in ascending order\n * - For duplicate values, returns leftmost occurrence\n * - When value not found, returns position of next smaller element\n * - PineScript rules: a value below every element gives 0; `na` counts as greater than every number (an array\n * without na gives `size - 1`); the comparison is exact (no 1e-10 tolerance)\n */\nexport function binary_search_leftmost(id: PineArray<float>, val: float): int {\n if (id.length === 0) return -1;\n const at = searchBound(id, val, false);\n return at < id.length && compareSorted(id[at]!, val) === 0 ? at : Math.max(0, at - 1);\n}\n\n/**\n * Order of the PineScript binary searches: numbers in ascending order, na above every number (equal to na).\n */\nfunction compareSorted(a: float, b: float): number {\n const an = Number.isNaN(a);\n const bn = Number.isNaN(b);\n if (an || bn) return an === bn ? 0 : an ? 1 : -1;\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\n/** First index whose element is >= `val` (`after` false) or > `val` (`after` true); `id.length` when none. */\nfunction searchBound(id: PineArray<float>, val: float, after: boolean): int {\n let lo = 0;\n let hi = id.length;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n const c = compareSorted(id[mid]!, val);\n if (c < 0 || (after && c === 0)) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n}\n\n/**\n * Binary Search Rightmost\n *\n * Returns the index of the value if found. When not found, returns the index\n * of the element to the right of where the value would be.\n *\n * @param id - Sorted array (ascending order)\n * @param val - Value to search for\n * @returns Index of value or insertion point to the right\n *\n * @example\n * ```typescript\n * const arr = [-2, 0, 1, 5, 9];\n * const index = array.binary_search_rightmost(arr, 3);\n * // Returns: 3 (index of 5, which is right of where 3 would be)\n * ```\n *\n * @example\n * ```typescript\n * const arr = [4, 5, 5, 5];\n * const index = array.binary_search_rightmost(arr, 5);\n * // Returns: 3 (index of last instance of 5)\n * ```\n *\n * @remarks\n * - Array must be sorted in ascending order\n * - For duplicate values, returns rightmost occurrence\n * - When value not found, returns position of next larger element\n * - PineScript rules: a value above every element gives `size` (the position after the last element); `na` counts\n * as greater than every number (an array without na gives `size`); the comparison is exact (no 1e-10 tolerance)\n */\nexport function binary_search_rightmost(id: PineArray<float>, val: float): int {\n if (id.length === 0) return -1;\n const at = searchBound(id, val, true);\n return at > 0 && compareSorted(id[at - 1]!, val) === 0 ? at - 1 : at;\n}\n\n/**\n * Covariance\n *\n * Returns the covariance between two arrays.\n *\n * @param id1 - First array\n * @param id2 - Second array\n * @param biased - If true, uses biased estimate (population). If false, uses unbiased estimate (sample). Default: true\n * @returns Covariance between the two arrays\n *\n * @example\n * ```typescript\n * const prices = [100, 102, 98, 105, 103];\n * const volume = [1000, 1200, 950, 1300, 1100];\n * const cov = array.covariance(prices, volume);\n * // Returns covariance between price and volume\n * ```\n *\n * @remarks\n * - Biased (true): divides by n (population covariance)\n * - Unbiased (false): divides by n-1 (sample covariance)\n * - Returns NaN if arrays are empty or have different lengths\n * - Formula: Cov(X,Y) = E[(X - \u03BCX)(Y - \u03BCY)]\n *\n * PineScript rules: a pair where either value is `na` is skipped and the count is the number of pairs kept; both\n * means first, then the sum of the products from the first to the last pair. One pair gives 0 biased, NaN unbiased.\n */\nexport function covariance(id1: PineArray<float>, id2: PineArray<float>, biased: bool = true): float {\n if (id1.length !== id2.length) {\n return NaN;\n }\n const xs: number[] = [];\n const ys: number[] = [];\n for (let i = 0; i < id1.length; i++) {\n if (Number.isNaN(id1[i]!) || Number.isNaN(id2[i]!)) continue;\n xs.push(id1[i]!);\n ys.push(id2[i]!);\n }\n const n = xs.length;\n if (!n || (!biased && n < 2)) return NaN;\n let mean1 = 0;\n let mean2 = 0;\n for (let i = 0; i < n; i++) {\n mean1 += xs[i]!;\n mean2 += ys[i]!;\n }\n mean1 /= n;\n mean2 /= n;\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += (xs[i]! - mean1) * (ys[i]! - mean2);\n }\n return sum / (biased ? n : n - 1);\n}\n\n/**\n * Percentile Linear Interpolation\n *\n * Returns the value for which the specified percentage of array values are\n * less than or equal to it, using linear interpolation.\n *\n * @param id - Array of numeric values\n * @param percentage - Percentage (0-100)\n * @returns Percentile value using linear interpolation\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const p50 = array.percentile_linear_interpolation(arr, 50);\n * // Returns: 3 (median)\n * ```\n *\n * @remarks\n * - Uses linear interpolation between adjacent values\n * - Result may not be a member of the array\n * - Returns NaN if array is empty\n *\n * PineScript rules:\n * - 1-based position in the sorted array: `size * percentage / 100 + 0.5` (snapped to an integer within 1e-9),\n * clamped to the first / last value; between two values `lo * (1 - frac) + hi * frac`\n * - `na` values are sorted after all numbers; with an `na` in the array, a position between two values gives `na`\n * - an `na` percentage gives `na`; a percentage outside 0 .. 100 is a runtime error (throws)\n */\nexport function percentile_linear_interpolation(id: PineArray<float>, percentage: float): float {\n if (id.length === 0 || Number.isNaN(percentage)) {\n return NaN;\n }\n checkPercentage('percentile_linear_interpolation', percentage);\n const s = sortedNaLast(id);\n const n = s.length;\n let pos = (n * percentage) / 100 + 0.5;\n const nearest = Math.round(pos);\n if (Math.abs(pos - nearest) < 1e-9) pos = nearest;\n if (pos <= 1) return s[0]!;\n if (pos >= n) return s[n - 1]!;\n const lower = Math.floor(pos);\n const frac = pos - lower;\n if (frac === 0) return s[lower - 1]!;\n if (Number.isNaN(s[n - 1]!)) return NaN;\n return s[lower - 1]! * (1 - frac) + s[lower]! * frac;\n}\n\n/** Array values sorted ascending, `na` values after the numbers (array.percentile_*). */\nfunction sortedNaLast(id: PineArray<float>): number[] {\n const numbers = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);\n return [...numbers, ...Array<number>(id.length - numbers.length).fill(NaN)];\n}\n\n/** A percentage outside 0 .. 100 is a PineScript runtime error. */\nfunction checkPercentage(name: string, percentage: number): void {\n if (!(percentage >= 0 && percentage <= 100)) {\n throw new Error(`array.${name}: percentage ${percentage} must be between 0 and 100`);\n }\n}\n\n/**\n * Percentile Nearest Rank\n *\n * Returns the value for which the specified percentage of array values are\n * less than or equal to it, using the nearest-rank method.\n *\n * @param id - Array of numeric values\n * @param percentage - Percentage (0-100)\n * @returns Percentile value using nearest rank\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const p50 = array.percentile_nearest_rank(arr, 50);\n * // Returns: 3 (median, always a member of array)\n * ```\n *\n * @remarks\n * - Result is always a member of the array\n * - Uses nearest-rank method (no interpolation)\n * - Returns NaN if array is empty\n *\n * PineScript rules:\n * - the value at rank `ceil(percentage * size / 100)` (clamped to 1 .. size) of the sorted array\n * - `na` values are sorted after all numbers (na when that rank holds an `na`)\n * - an `na` percentage counts as 0; a percentage outside 0 .. 100 is a runtime error (throws)\n */\nexport function percentile_nearest_rank(id: PineArray<float>, percentage: float): float {\n if (id.length === 0) {\n return NaN;\n }\n const pct = Number.isNaN(percentage) ? 0 : percentage;\n checkPercentage('percentile_nearest_rank', pct);\n const s = sortedNaLast(id);\n const rank = Math.min(s.length, Math.max(1, Math.ceil((pct * s.length) / 100)));\n return s[rank - 1]!;\n}\n\n/**\n * Percent Rank\n *\n * Returns the percentile rank of the element at the specified index.\n * The percentile rank is the percentage of elements that are less than\n * or equal to the reference value.\n *\n * @param id - Array of numeric values\n * @param index - Index of element to rank\n * @returns Percentile rank (0-100)\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const rank = array.percentrank(arr, 2); // Value at index 2 is 3\n * // Returns: 50 ((3 - 1) * 100 / (5 - 1))\n * ```\n *\n * @remarks\n * - Range: 0 to 100\n *\n * PineScript rules:\n * - `(count - 1) * 100 / (size - 1)`, with `count` the number of non-na elements <= the element (exact\n * comparison, no 1e-10 tolerance); `na` elements count in the size\n * - an `na` element, a one-element array or an empty array gives NaN\n * - an `na` index counts as 0; an index outside `0 .. size - 1` is a runtime error (throws)\n */\nexport function percentrank(id: PineArray<float>, index: int): float {\n const i = Number.isNaN(index) ? 0 : Math.trunc(index);\n if (id.length === 0) {\n return NaN;\n }\n if (i < 0 || i >= id.length) {\n throw new Error(`array.percentrank: index ${i} is out of bounds, array size is ${id.length}`);\n }\n if (id.length === 1) {\n return NaN;\n }\n const value = id[i]!;\n if (Number.isNaN(value)) {\n return NaN;\n }\n let count = 0;\n for (const v of id) {\n if (v <= value) count++;\n }\n return ((count - 1) * 100) / (id.length - 1);\n}\n\n/**\n * Sort Indices\n *\n * Returns an array of indices which, when used to index the original array,\n * will access its elements in their sorted order. Does not modify the original array.\n *\n * @param id - Array to get sorted indices from\n * @param order - Sort order: 'asc' or 'desc' (default: 'asc')\n * @returns Array of indices in sorted order\n *\n * @example\n * ```typescript\n * const arr = [5, -2, 0, 9, 1];\n * const indices = array.sort_indices(arr); // [1, 2, 4, 0, 3]\n * // arr[1] = -2 (smallest)\n * // arr[2] = 0\n * // arr[4] = 1\n * // arr[0] = 5\n * // arr[3] = 9 (largest)\n * ```\n *\n * @remarks\n * - Original array is not modified\n * - Returns indices that would sort the array\n * - Useful for maintaining correspondence with other arrays\n * - PineScript rule: the indices of `na` elements go where `array.sort` puts them (after the numbers in ascending\n * order, in their original order: `sort_indices([na, na, 5, 1])` is `[3, 2, 0, 1]`)\n */\nexport function sort_indices<T>(id: PineArray<T>, order: SortOrder = 'asc'): PineArray<int> {\n return sortedPositions(id, order);\n}\n\n/**\n * Standardize\n *\n * Returns an array of standardized elements (z-score normalization).\n * Each element is transformed to (value - mean) / stddev.\n *\n * @param id - Array of numeric values\n * @returns Array of standardized values (z-scores)\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const standardized = array.standardize(arr);\n * // Mean = 3, StdDev \u2248 1.414\n * // Result \u2248 [-1.414, -0.707, 0, 0.707, 1.414]\n * ```\n *\n * @remarks\n * - Formula: z = (x - \u03BC) / \u03C3\n * - Result has mean of 0 and standard deviation of 1\n * - Useful for comparing values on different scales\n *\n * PineScript rules:\n * - \u03BC and \u03C3 are the population mean and standard deviation of the non-na elements, as `array.variance` (moment\n * form); `na` elements stay `na`\n * - when \u03C3 is 0 (all values equal) every non-na element gives 1\n */\nexport function standardize(id: PineArray<float>): PineArray<float> {\n const values = id.filter((v) => !Number.isNaN(v));\n if (!values.length) {\n return id.map(() => NaN);\n }\n const [p, q] = moments(values);\n const mean = p / values.length;\n const stdDev = Math.sqrt(Math.max(0, q / values.length - mean * mean));\n if (stdDev === 0) {\n return id.map((v) => (Number.isNaN(v) ? NaN : 1));\n }\n return id.map((v) => (Number.isNaN(v) ? NaN : (v - mean) / stdDev));\n}\n\n/**\n * New Type (User-Defined Type Array)\n *\n * Creates a new array of user-defined type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements\n * @returns New array of user-defined type\n *\n * @example\n * ```typescript\n * // NOTE: User-defined types (UDTs) are not fully supported yet\n * // This is a placeholder for future implementation\n * const arr = array.newtype<MyType>(5);\n * ```\n *\n * @remarks\n * - **\u26A0\uFE0F LIMITED SUPPORT**: User-defined types (UDTs) require a type system\n * that is not yet fully implemented in this library\n * - This function currently works like `new_array<T>()` for basic types\n * - Full UDT support will be added in a future version\n * - See PineScript documentation for UDT usage patterns\n */\nexport function newtype<T>(size: simple_int = 0, initial_value?: T): PineArray<T> {\n // For now, this is just an alias for new_array\n // Full UDT support requires implementing the type system\n return new_array<T>(size, initial_value);\n}\n\n/**\n * \u26A0\uFE0F RENDERING FUNCTIONS NOT IMPLEMENTED\n *\n * The following array constructor functions are intentionally excluded\n * because they create arrays for rendering objects, which are outside\n * the scope of this calculation-focused library:\n *\n * - `new_box()` - Creates arrays of box drawing objects\n * - `new_label()` - Creates arrays of label objects\n * - `new_line()` - Creates arrays of line drawing objects\n * - `new_linefill()` - Creates arrays of line fill objects\n * - `new_table()` - Creates arrays of table layout objects\n *\n * **Design Constraint**: This library focuses on calculation and indicator\n * functions only. Rendering, visualization, and UI functions require a\n * rendering engine and are not included.\n *\n * If you need these functions, consider:\n * 1. Using PineScript directly\n * 2. Implementing a rendering layer separately\n * 3. Using this library for calculations and another library for visualization\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,UAAaA,QAAmB,GAAG,eAAiC;AAClF,QAAM,MAAoB,CAAC;AAC3B,WAAS,IAAI,GAAG,IAAIA,OAAM,KAAK;AAC7B,QAAI,KAAK,aAAkB;AAAA,EAC7B;AACA,SAAO;AACT;AAKO,SAAS,KAAQ,IAAuB;AAC7C,SAAO,GAAG;AACZ;AAGA,SAAS,KAAK,GAAqB;AACjC,SAAO,MAAM,UAAa,MAAM,QAAS,OAAO,MAAM,YAAY,OAAO,MAAM,CAAC;AAClF;AAGA,SAAS,KAAQ,IAAqB;AACpC,SAAQ,GAAG,WAAW,KAAK,OAAO,GAAG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,WAAO;AAAA,EACT;AACA,MAAI,QAAQ;AACZ,aAAW,KAAK,IAAI;AAClB,QAAI,KAAK,MAAO;AAAA,EAClB;AACA,UAAS,QAAQ,KAAK,OAAQ,GAAG,SAAS;AAC5C;AA8BO,SAAS,aAAgB,IAAkB,QAAmB,OAAuB;AAC1F,SAAO,gBAAgB,IAAI,KAAK;AAClC;AA6BO,SAAS,YAAY,IAAwC;AAClE,QAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,MAAM,CAAC,CAAC;AAChD,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO,GAAG,IAAI,MAAM,GAAG;AAAA,EACzB;AACA,QAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,MAAM;AAC7B,QAAM,OAAO,IAAI,OAAO;AACxB,QAAM,SAAS,KAAK,KAAK,KAAK,IAAI,GAAG,IAAI,OAAO,SAAS,OAAO,IAAI,CAAC;AACrE,MAAI,WAAW,GAAG;AAChB,WAAO,GAAG,IAAI,CAAC,MAAO,OAAO,MAAM,CAAC,IAAI,MAAM,CAAE;AAAA,EAClD;AACA,SAAO,GAAG,IAAI,CAAC,MAAO,OAAO,MAAM,CAAC,IAAI,OAAO,IAAI,QAAQ,MAAO;AACpE;AAyBO,SAAS,QAAWD,QAAmB,GAAG,eAAiC;AAGhF,SAAO,UAAaA,OAAM,aAAa;AACzC;",
4
+ "sourcesContent": ["/**\n * Array namespace\n * Mirrors PineScript's array.* functions\n */\n\nimport type { PineArray, int, float, bool, simple_int, color, Line, Box, Label, Linefill, Table } from '../types/index.js';\n\n/**\n * Creates a new array with initial size and default value\n */\nexport function new_array<T>(size: simple_int = 0, initial_value?: T): PineArray<T> {\n const arr: PineArray<T> = [];\n for (let i = 0; i < size; i++) {\n arr.push(initial_value as T);\n }\n return arr;\n}\n\n/**\n * Returns the number of elements in an array\n */\nexport function size<T>(id: PineArray<T>): int {\n return id.length;\n}\n\n/** True for a PineScript `na` element: NaN, null or undefined. */\nfunction isNa(v: unknown): boolean {\n return v === undefined || v === null || (typeof v === 'number' && Number.isNaN(v));\n}\n\n/** The `na` of the array's element type: NaN for a numeric (or empty) array, undefined otherwise. */\nfunction naOf<T>(id: PineArray<T>): T {\n return (id.length === 0 || typeof id[0] === 'number' ? NaN : undefined) as T;\n}\n\n/**\n * Position addressed by a PineScript index: truncated, a negative index counts from the end. An index outside\n * `-size .. size - 1 + extra` is a runtime error.\n */\nfunction position(name: string, id: PineArray<unknown>, index: number, extra = 0): number {\n const i = Math.trunc(index);\n const n = id.length;\n if (i < -n || i >= n + extra) {\n throw new Error(`array.${name}: index ${i} is out of bounds, array size is ${n}`);\n }\n return i < 0 ? i + n : i;\n}\n\n/**\n * Returns the element at the specified index.\n *\n * PineScript rules: a negative index counts from the end (`get(a, -1)` is the last element); an index outside\n * `-size .. size - 1` is a runtime error (throws); an `na` index gives `na`.\n */\nexport function get<T>(id: PineArray<T>, index: simple_int): T {\n if (Number.isNaN(index)) return naOf(id);\n return id[position('get', id, index)]!;\n}\n\n/**\n * Sets the value of the element at the specified index.\n *\n * PineScript rules: a negative index counts from the end; an index outside `-size .. size - 1` is a runtime error\n * (throws); an `na` index does nothing.\n */\nexport function set<T>(id: PineArray<T>, index: simple_int, value: T): void {\n if (Number.isNaN(index)) return;\n id[position('set', id, index)] = value;\n}\n\n/**\n * Appends a value to the end of the array\n */\nexport function push<T>(id: PineArray<T>, value: T): void {\n id.push(value);\n}\n\n/**\n * Removes and returns the last element of the array\n */\nexport function pop<T>(id: PineArray<T>): T {\n return id.pop() as T;\n}\n\n/**\n * Inserts a value at the beginning of the array\n */\nexport function unshift<T>(id: PineArray<T>, value: T): void {\n id.unshift(value);\n}\n\n/**\n * Removes and returns the first element of the array\n */\nexport function shift<T>(id: PineArray<T>): T {\n return id.shift() as T;\n}\n\n/**\n * Removes all elements from the array\n */\nexport function clear<T>(id: PineArray<T>): void {\n id.length = 0;\n}\n\n/**\n * Inserts a value at the specified index.\n *\n * PineScript rules: a negative index counts from the end and `size` appends, so `-size .. size` is valid; any other\n * index is a runtime error (throws); an `na` index appends.\n */\nexport function insert<T>(id: PineArray<T>, index: simple_int, value: T): void {\n if (Number.isNaN(index)) {\n id.push(value);\n return;\n }\n id.splice(position('insert', id, index, 1), 0, value);\n}\n\n/**\n * Removes the element at the specified index and returns it.\n *\n * PineScript rules: a negative index counts from the end; an index outside `-size .. size - 1` is a runtime error\n * (throws); an `na` index removes nothing and gives `na`.\n */\nexport function remove<T>(id: PineArray<T>, index: simple_int): T {\n if (Number.isNaN(index)) return naOf(id);\n return id.splice(position('remove', id, index), 1)[0]!;\n}\n\n/** PineScript `==` of two elements: numbers are equal when |a - b| <= 1e-10; `na` never equals anything. */\nfunction pineEqual(a: unknown, b: unknown): boolean {\n if (isNa(a) || isNa(b)) return false;\n if (a === b) return true;\n if (typeof a === 'number' && typeof b === 'number') {\n const d = a - b;\n return -1e-10 <= d && d <= 1e-10;\n }\n return false;\n}\n\n/**\n * Returns true if the array contains the value.\n *\n * PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.\n */\nexport function includes<T>(id: PineArray<T>, value: T): bool {\n return indexof(id, value) >= 0;\n}\n\n/**\n * Returns the index of the first occurrence of the value, -1 when not found.\n *\n * PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.\n */\nexport function indexof<T>(id: PineArray<T>, value: T): int {\n for (let i = 0; i < id.length; i++) {\n if (pineEqual(id[i], value)) return i;\n }\n return -1;\n}\n\n/**\n * Returns the index of the last occurrence of the value, -1 when not found.\n *\n * PineScript rules: numbers are compared with a 1e-10 tolerance (|a - b| <= 1e-10); `na` is never found.\n */\nexport function lastindexof<T>(id: PineArray<T>, value: T): int {\n for (let i = id.length - 1; i >= 0; i--) {\n if (pineEqual(id[i], value)) return i;\n }\n return -1;\n}\n\n/**\n * Returns a shallow copy of the array\n */\nexport function copy<T>(id: PineArray<T>): PineArray<T> {\n return [...id] as PineArray<T>;\n}\n\n/**\n * Appends the elements of `id2` to `id1` and returns `id1` (PineScript `array.concat` changes `id1`).\n */\nexport function concat<T>(id1: PineArray<T>, id2: PineArray<T>): PineArray<T> {\n for (const v of Array.from(id2)) id1.push(v);\n return id1;\n}\n\n/**\n * Joins all elements into a string\n */\nexport function join(id: PineArray<any>, separator: string = ','): string {\n return id.join(separator);\n}\n\n/**\n * Reverses the array in place\n */\nexport function reverse<T>(id: PineArray<T>): void {\n id.reverse();\n}\n\n/**\n * Returns the elements from `index_from` (included) to `index_to` (excluded, default: the size) as a live view of\n * the array (PineScript `array.slice`).\n *\n * PineScript rules:\n * - the slice shares the elements of the original array: a change of an element of the slice changes the original\n * array, and adding / removing elements of the slice adds / removes them in the original array, inside the slice\n * bounds (a push to the slice inserts at the end of the slice)\n * - `index_from` must address an element (`0 .. size - 1`) and `index_to` may be `size`; other bounds, or\n * `index_from > index_to`, are a runtime error (throws); an `na` bound means the start / the end of the array\n */\nexport function slice<T>(id: PineArray<T>, index_from: simple_int, index_to?: simple_int): PineArray<T> {\n const n = id.length;\n const start = Number.isNaN(index_from) ? 0 : Math.trunc(index_from);\n const stop = index_to === undefined || Number.isNaN(index_to) ? n : Math.trunc(index_to);\n if (start < 0 || start >= n) throw new Error(`array.slice: index ${start} is out of bounds, array size is ${n}`);\n if (stop < 0 || stop > n) throw new Error(`array.slice: index ${stop} is out of bounds, array size is ${n}`);\n if (start > stop) throw new Error(`array.slice: index_from ${start} is greater than index_to ${stop}`);\n return sliceView(id, start, stop - start);\n}\n\n/** Index of a property key that is an array index, -1 otherwise. */\nfunction indexKey(p: string | symbol): number {\n if (typeof p !== 'string') return -1;\n const i = Number(p);\n return Number.isInteger(i) && i >= 0 && String(i) === p ? i : -1;\n}\n\n/**\n * Live view of `size` elements of `parent` from `start`: an array (a Proxy) whose element reads and writes go to\n * `parent`, and whose size changes insert / remove elements in `parent` at the end of the view.\n */\nfunction sliceView<T>(parent: PineArray<T>, start: number, size: number): PineArray<T> {\n const resize = (target: number): void => {\n if (target > size) parent.splice(start + size, 0, ...Array<T>(target - size).fill(undefined as T));\n else if (target < size) parent.splice(start + target, size - target);\n size = target;\n };\n return new Proxy<T[]>([], {\n get(target, p, receiver) {\n const i = indexKey(p);\n if (i >= 0) return i < size ? parent[start + i] : undefined;\n if (p === 'length') return size;\n return Reflect.get(target, p, receiver);\n },\n set(target, p, value, receiver) {\n const i = indexKey(p);\n if (i >= 0) {\n if (i >= size) resize(i + 1);\n parent[start + i] = value;\n return true;\n }\n if (p === 'length') {\n resize(Number(value));\n return true;\n }\n return Reflect.set(target, p, value, receiver);\n },\n has(target, p) {\n const i = indexKey(p);\n return i >= 0 ? i < size : Reflect.has(target, p);\n },\n // Array methods delete the slots past the new end before they set the length, which does the removal.\n deleteProperty(target, p) {\n return indexKey(p) >= 0 ? true : Reflect.deleteProperty(target, p);\n },\n ownKeys(target) {\n return [...Array.from({ length: size }, (_, i) => String(i)), ...Reflect.ownKeys(target)];\n },\n getOwnPropertyDescriptor(target, p) {\n const i = indexKey(p);\n if (i >= 0) {\n return i < size ? { value: parent[start + i], writable: true, enumerable: true, configurable: true } : undefined;\n }\n if (p === 'length') return { value: size, writable: true, enumerable: false, configurable: false };\n return Reflect.getOwnPropertyDescriptor(target, p);\n },\n });\n}\n\n/** Sort order of array.sort / array.sort_indices (PineScript `order.ascending` / `order.descending`). */\nexport type SortOrder = 'asc' | 'desc' | 'ascending' | 'descending';\n\n/**\n * Positions of the elements in PineScript sorted order: ascending values, `na` after the numbers (before the\n * strings of a string array), stable; descending is the ascending result reversed.\n */\nfunction sortedPositions<T>(id: PineArray<T>, order: SortOrder): number[] {\n const values: number[] = [];\n const nas: number[] = [];\n for (let i = 0; i < id.length; i++) (isNa(id[i]) ? nas : values).push(i);\n values.sort((a, b) => {\n const x = id[a] as unknown as number;\n const y = id[b] as unknown as number;\n return x < y ? -1 : x > y ? 1 : 0;\n });\n const naFirst = values.length > 0 && typeof id[values[0]!] === 'string';\n const positions = naFirst ? [...nas, ...values] : [...values, ...nas];\n if (order === 'desc' || order === 'descending') positions.reverse();\n return positions;\n}\n\n/**\n * Sorts the array in place.\n *\n * PineScript rules: `na` goes after the numbers in ascending order and before them in descending order (the\n * ascending result reversed); in a string array `na` goes first in ascending order.\n */\nexport function sort<T>(id: PineArray<T>, order: SortOrder = 'asc'): void {\n const sorted = sortedPositions(id, order).map((p) => id[p]!);\n for (let i = 0; i < sorted.length; i++) id[i] = sorted[i]!;\n}\n\n/**\n * Sum of the non-na elements (PineScript `array.sum(id)`), added from left to right; an array without values gives NaN.\n * As PineScript, the running sum is set to 0 after a step when its absolute value is <= 1e-10.\n */\nexport function sum(id: PineArray<float>): float {\n let total = 0;\n let count = 0;\n for (const v of id) {\n if (Number.isNaN(v)) continue;\n count++;\n total += v;\n if (Math.abs(total) <= 1e-10) total = 0;\n }\n return count ? total : NaN;\n}\n\n/**\n * Average of the non-na elements (PineScript `array.avg(id)`); an array without values gives NaN.\n */\nexport function avg(id: PineArray<float>): float {\n const values = id.filter((v) => !Number.isNaN(v));\n return values.length ? values.reduce((a, b) => a + b, 0) / values.length : NaN;\n}\n\n/** The `nth` value of the non-na elements sorted with `compare` (array.min / array.max). */\nfunction nthValue(name: string, id: PineArray<float>, nth: number, compare: (a: number, b: number) => number): float {\n const rank = Number.isNaN(nth) ? 0 : Math.trunc(nth);\n const values = id.filter((v) => !Number.isNaN(v));\n if (!values.length) return NaN;\n if (rank < 0 || rank >= id.length) {\n throw new Error(`array.${name}: nth ${rank} is out of bounds, array size is ${id.length}`);\n }\n values.sort(compare);\n return values[Math.min(rank, values.length - 1)]!;\n}\n\n/**\n * The `nth` smallest value (0 = the smallest) of the non-na elements (PineScript `array.min(id, nth)`).\n *\n * PineScript rules: an `nth` past the non-na values but inside the array size gives the greatest value; an `nth`\n * outside `0 .. size - 1` is a runtime error (throws); an `na` nth counts as 0; an array without values gives NaN.\n */\nexport function min(id: PineArray<float>, nth: simple_int = 0): float {\n return nthValue('min', id, nth, (a, b) => a - b);\n}\n\n/**\n * The `nth` greatest value (0 = the greatest) of the non-na elements (PineScript `array.max(id, nth)`).\n *\n * PineScript rules: an `nth` past the non-na values but inside the array size gives the smallest value; an `nth`\n * outside `0 .. size - 1` is a runtime error (throws); an `na` nth counts as 0; an array without values gives NaN.\n */\nexport function max(id: PineArray<float>, nth: simple_int = 0): float {\n return nthValue('max', id, nth, (a, b) => b - a);\n}\n\n/**\n * Median of the non-na elements (PineScript `array.median(id)`): the middle value, or the mean of the two middle\n * values for an even count; an array without values gives NaN.\n */\nexport function median(id: PineArray<float>): float {\n const sorted = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);\n if (!sorted.length) return NaN;\n const mid = Math.floor(sorted.length / 2);\n return sorted.length % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!;\n}\n\n/**\n * Most frequent non-na element (PineScript `array.mode(id)`), compared exactly.\n *\n * PineScript rules: with several values of the same frequency, the smallest one; an array without values gives NaN.\n */\nexport function mode(id: PineArray<float>): float {\n const frequency = new Map<float, int>();\n for (const v of id) {\n if (!Number.isNaN(v)) frequency.set(v, (frequency.get(v) ?? 0) + 1);\n }\n let best = NaN;\n let bestCount = 0;\n for (const [v, count] of frequency) {\n if (count > bestCount || (count === bestCount && v < best)) {\n best = v;\n bestCount = count;\n }\n }\n return best;\n}\n\n/**\n * Standard deviation of the non-na elements (PineScript `array.stdev(id, biased)`): the square root of\n * `array.variance(id, biased)`.\n */\nexport function stdev(id: PineArray<float>, biased: bool = true): float {\n return Math.sqrt(variance(id, biased));\n}\n\n/** Sum of the values and sum of their squares, both added from the first to the last value. */\nfunction moments(values: number[]): [number, number] {\n let p = 0;\n let q = 0;\n for (const v of values) p += v;\n for (const v of values) q += v * v;\n return [p, q];\n}\n\n/**\n * Variance of the non-na elements (PineScript `array.variance(id, biased)`).\n *\n * PineScript rule (moment form): with `p` the sum of the values, `q` the sum of their squares, `n` the count and\n * `m = p / n`: biased (default) `max(0, q / n - m * m)`, unbiased `max(0, q / (n - 1) - (p / (n - 1)) * m)`.\n * One value gives 0 biased and NaN unbiased; an array without values gives NaN.\n */\nexport function variance(id: PineArray<float>, biased: bool = true): float {\n const values = id.filter((v) => !Number.isNaN(v));\n const n = values.length;\n if (!n) return NaN;\n if (n < 2) return biased ? 0 : NaN;\n const [p, q] = moments(values);\n const mean = p / n;\n return biased ? Math.max(0, q / n - mean * mean) : Math.max(0, q / (n - 1) - (p / (n - 1)) * mean);\n}\n\n/**\n * Fills the array with the specified value\n */\nexport function fill<T>(id: PineArray<T>, value: T, index_from: simple_int = 0, index_to?: simple_int): void {\n // PineScript: an na bound is the start / the end; a bound past the end is a runtime error\n const start = index_from === undefined || index_from === null || Number.isNaN(index_from) ? 0 : index_from;\n const end = index_to === undefined || index_to === null || Number.isNaN(index_to) ? id.length : index_to;\n for (const i of [start, end]) {\n if (i < 0 || i > id.length) throw new Error(`array.fill: index ${i} is out of bounds, array size is ${id.length}`);\n }\n for (let i = start; i < end; i++) {\n id[i] = value;\n }\n}\n\n/**\n * Creates an array from its arguments (PineScript `array.from(arg0, arg1, ...)`).\n * `na` values are kept.\n *\n * @example\n * ```typescript\n * array.from(0.236, 0.382, 0.5, 0.618); // [0.236, 0.382, 0.5, 0.618]\n * ```\n */\nexport function from<T>(...values: T[]): PineArray<T> {\n return [...values];\n}\n\n/**\n * Returns the first element of the array\n *\n * @param id - The array\n * @returns The first element, or undefined if array is empty\n *\n * @remarks\n * - Equivalent to `array.get(id, 0)`\n * - Returns undefined for empty arrays\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const firstElement = array.first(arr); // Returns: 1\n * ```\n */\nexport function first<T>(id: PineArray<T>): T {\n // PineScript: a runtime error on an empty array\n if (id.length === 0) throw new Error('Cannot call array.first() if array is empty');\n return id[0]!;\n}\n\n/**\n * Returns the last element of the array\n *\n * @param id - The array\n * @returns The last element, or undefined if array is empty\n *\n * @remarks\n * - Equivalent to `array.get(id, array.size(id) - 1)`\n * - Returns undefined for empty arrays\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const lastElement = array.last(arr); // Returns: 5\n * ```\n */\nexport function last<T>(id: PineArray<T>): T {\n // PineScript: a runtime error on an empty array (as array.first)\n if (id.length === 0) throw new Error('Cannot call array.last() if array is empty');\n return id[id.length - 1]!;\n}\n\n/**\n * True when at least one element of a bool array is true (PineScript `array.some(id)`).\n * An empty array gives false.\n */\nexport function some(id: PineArray<bool>): bool {\n return id.some((v) => v === true);\n}\n\n/**\n * True when every element of a bool array is true (PineScript `array.every(id)`).\n * An empty array gives false, as in PineScript.\n */\nexport function every(id: PineArray<bool>): bool {\n return id.length > 0 && id.every((v) => v === true);\n}\n\n/**\n * Create new boolean array\n *\n * Creates a new array object of bool type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: false)\n * @returns New boolean array\n *\n * @example\n * ```typescript\n * const arr = array.new_bool(5, true);\n * // Creates: [true, true, true, true, true]\n * ```\n */\nexport function new_bool(size: simple_int = 0, initial_value: bool = false): PineArray<bool> {\n return new_array<bool>(size, initial_value);\n}\n\n/**\n * Create new float array\n *\n * Creates a new array object of float type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: NaN)\n * @returns New float array\n *\n * @example\n * ```typescript\n * const arr = array.new_float(5, 0.0);\n * // Creates: [0.0, 0.0, 0.0, 0.0, 0.0]\n * ```\n */\nexport function new_float(size: simple_int = 0, initial_value: float = NaN): PineArray<float> {\n return new_array<float>(size, initial_value);\n}\n\n/**\n * Create new integer array\n *\n * Creates a new array object of int type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: NaN)\n * @returns New integer array\n *\n * @example\n * ```typescript\n * const arr = array.new_int(5, 0);\n * // Creates: [0, 0, 0, 0, 0]\n * ```\n */\nexport function new_int(size: simple_int = 0, initial_value: int = NaN): PineArray<int> {\n return new_array<int>(size, initial_value);\n}\n\n/**\n * Create new string array\n *\n * Creates a new array object of string type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New string array\n *\n * @example\n * ```typescript\n * const arr = array.new_string(5, \"text\");\n * // Creates: [\"text\", \"text\", \"text\", \"text\", \"text\"]\n * ```\n */\nexport function new_string(size: simple_int = 0, initial_value?: string): PineArray<string> {\n return new_array<string>(size, initial_value);\n}\n\n/**\n * Create new color array\n *\n * Creates a new array object of color type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New color array\n *\n * @example\n * ```typescript\n * const arr = array.new_color(5, \"#FF0000\");\n * // Creates: [\"#FF0000\", \"#FF0000\", \"#FF0000\", \"#FF0000\", \"#FF0000\"]\n * ```\n */\nexport function new_color(size: simple_int = 0, initial_value?: color): PineArray<color> {\n return new_array<color>(size, initial_value);\n}\n\n/**\n * Create new line array\n *\n * Creates a new array object of line type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New line array\n *\n * @example\n * ```typescript\n * import { array, line } from 'oakscriptjs';\n *\n * // Create array to store last 15 lines\n * const lines = array.new_line();\n * const trendLine = line.new(0, 100, 50, 150);\n * array.push(lines, trendLine);\n *\n * // Manage line count\n * if (array.size(lines) > 15) {\n * const oldLine = array.shift(lines);\n * }\n * ```\n *\n * @remarks\n * Useful for managing collections of trend lines, support/resistance levels, or channel lines.\n * In PineScript, this is typically used with line.delete() to manage chart object limits.\n */\nexport function new_line(size: simple_int = 0, initial_value?: Line): PineArray<Line> {\n return new_array<Line>(size, initial_value);\n}\n\n/**\n * Create new box array\n *\n * Creates a new array object of box type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New box array\n *\n * @example\n * ```typescript\n * import { array, box } from 'oakscriptjs';\n *\n * // Create array to store gap boxes\n * const gaps = array.new_box();\n * const gapBox = box.new(10, 120, 15, 110);\n * array.push(gaps, gapBox);\n *\n * // Track multiple gaps\n * for (let i = 0; i < array.size(gaps); i++) {\n * const gap = array.get(gaps, i);\n * const gapTop = box.get_top(gap);\n * const gapBottom = box.get_bottom(gap);\n * // Check if gap filled...\n * }\n * ```\n *\n * @remarks\n * Useful for tracking ranges, gaps, consolidation zones, or rectangle patterns.\n * Enables systematic analysis of multiple box objects.\n */\nexport function new_box(size: simple_int = 0, initial_value?: Box): PineArray<Box> {\n return new_array<Box>(size, initial_value);\n}\n\n/**\n * Create new label array\n *\n * Creates a new array object of label type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New label array\n *\n * @example\n * ```typescript\n * import { array, label } from 'oakscriptjs';\n *\n * // Create array to store pivot labels\n * const pivotLabels = array.new_label();\n *\n * // Add labels for pivot highs\n * const pivotLabel = label.new(50, 155.5, 'PH', 'bar_index', 'abovebar');\n * array.push(pivotLabels, pivotLabel);\n *\n * // Limit number of labels shown\n * const maxLabels = 50;\n * if (array.size(pivotLabels) > maxLabels) {\n * array.shift(pivotLabels);\n * }\n * ```\n *\n * @remarks\n * Useful for managing collections of annotations, pivot markers, or signal labels.\n * Helps limit the number of labels displayed by removing old ones.\n */\nexport function new_label(size: simple_int = 0, initial_value?: Label): PineArray<Label> {\n return new_array<Label>(size, initial_value);\n}\n\n/**\n * Create new linefill array\n *\n * Creates a new array object of linefill type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New linefill array\n *\n * @example\n * ```typescript\n * import { array, line, linefill } from 'oakscriptjs';\n *\n * // Create array to store channel fills\n * const channels = array.new_linefill();\n *\n * // Create channel\n * const upperLine = line.new(0, 120, 50, 130);\n * const lowerLine = line.new(0, 100, 50, 110);\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF15');\n *\n * array.push(channels, channelFill);\n * ```\n *\n * @remarks\n * Useful for managing collections of channel fills, Bollinger Band fills, or regression channel fills.\n * Enables dynamic color changes across multiple channels.\n */\nexport function new_linefill(size: simple_int = 0, initial_value?: Linefill): PineArray<Linefill> {\n return new_array<Linefill>(size, initial_value);\n}\n\n/**\n * Creates a new array of tables (PineScript `array.new_table`).\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements (default: undefined)\n * @returns New table array\n */\nexport function new_table(size: simple_int = 0, initial_value?: Table): PineArray<Table> {\n return new_array<Table>(size, initial_value);\n}\n\n/**\n * Absolute value of array elements\n *\n * Returns an array containing the absolute value of each element in the original array.\n *\n * @param id - Array of numeric values\n * @returns New array with absolute values\n *\n * @example\n * ```typescript\n * const arr = [-1, -2, 3, -4, 5];\n * const result = array.abs(arr);\n * // Returns: [1, 2, 3, 4, 5]\n * ```\n */\nexport function abs(id: PineArray<float>): PineArray<float> {\n return id.map(x => Math.abs(x)) as PineArray<float>;\n}\n\n/**\n * Range of array values\n *\n * Returns the difference between the maximum and minimum values in the array.\n *\n * @param id - Array of numeric values\n * @returns Difference between max and min (range)\n *\n * @example\n * ```typescript\n * const arr = [1, 5, 3, 9, 2];\n * const result = array.range(arr);\n * // Returns: 8 (9 - 1)\n * ```\n *\n * @remarks\n * Returns NaN if the array is empty.\n */\nexport function range(id: PineArray<float>): float {\n if (id.length === 0) {\n return NaN;\n }\n return max(id) - min(id);\n}\n\n/**\n * Binary Search\n *\n * Searches for a value in a sorted array using binary search algorithm.\n * Returns the index of the value if found, or -1 if not found.\n *\n * @param id - Sorted array (ascending order)\n * @param val - Value to search for\n * @returns Index of the value, or -1 if not found\n *\n * @example\n * ```typescript\n * const arr = [-2, 0, 1, 5, 9]; // Must be sorted\n * const index = array.binary_search(arr, 5);\n * // Returns: 3\n * ```\n *\n * @remarks\n * - Array must be sorted in ascending order\n * - Uses standard binary search algorithm\n * - Time complexity: O(log n)\n */\nexport function binary_search(id: PineArray<float>, val: float): int {\n let left = 0;\n let right = id.length - 1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n\n if (id[mid]! === val) {\n return mid;\n }\n\n if (id[mid]! < val) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n\n return -1; // Not found\n}\n\n/**\n * Binary Search Leftmost\n *\n * Returns the index of the value if found. When not found, returns the index\n * of the next smallest element to the left of where the value would be.\n *\n * @param id - Sorted array (ascending order)\n * @param val - Value to search for\n * @returns Index of value or insertion point to the left\n *\n * @example\n * ```typescript\n * const arr = [-2, 0, 1, 5, 9];\n * const index = array.binary_search_leftmost(arr, 3);\n * // Returns: 2 (index of 1, which is left of where 3 would be)\n * ```\n *\n * @example\n * ```typescript\n * const arr = [4, 5, 5, 5];\n * const index = array.binary_search_leftmost(arr, 5);\n * // Returns: 1 (index of first instance of 5)\n * ```\n *\n * @remarks\n * - Array must be sorted in ascending order\n * - For duplicate values, returns leftmost occurrence\n * - When value not found, returns position of next smaller element\n * - PineScript rules: a value below every element gives 0; `na` counts as greater than every number (an array\n * without na gives `size - 1`); the comparison is exact (no 1e-10 tolerance)\n */\nexport function binary_search_leftmost(id: PineArray<float>, val: float): int {\n if (id.length === 0) return -1;\n const at = searchBound(id, val, false);\n return at < id.length && compareSorted(id[at]!, val) === 0 ? at : Math.max(0, at - 1);\n}\n\n/**\n * Order of the PineScript binary searches: numbers in ascending order, na above every number (equal to na).\n */\nfunction compareSorted(a: float, b: float): number {\n const an = Number.isNaN(a);\n const bn = Number.isNaN(b);\n if (an || bn) return an === bn ? 0 : an ? 1 : -1;\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\n/** First index whose element is >= `val` (`after` false) or > `val` (`after` true); `id.length` when none. */\nfunction searchBound(id: PineArray<float>, val: float, after: boolean): int {\n let lo = 0;\n let hi = id.length;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n const c = compareSorted(id[mid]!, val);\n if (c < 0 || (after && c === 0)) lo = mid + 1;\n else hi = mid;\n }\n return lo;\n}\n\n/**\n * Binary Search Rightmost\n *\n * Returns the index of the value if found. When not found, returns the index\n * of the element to the right of where the value would be.\n *\n * @param id - Sorted array (ascending order)\n * @param val - Value to search for\n * @returns Index of value or insertion point to the right\n *\n * @example\n * ```typescript\n * const arr = [-2, 0, 1, 5, 9];\n * const index = array.binary_search_rightmost(arr, 3);\n * // Returns: 3 (index of 5, which is right of where 3 would be)\n * ```\n *\n * @example\n * ```typescript\n * const arr = [4, 5, 5, 5];\n * const index = array.binary_search_rightmost(arr, 5);\n * // Returns: 3 (index of last instance of 5)\n * ```\n *\n * @remarks\n * - Array must be sorted in ascending order\n * - For duplicate values, returns rightmost occurrence\n * - When value not found, returns position of next larger element\n * - PineScript rules: a value above every element gives `size` (the position after the last element); `na` counts\n * as greater than every number (an array without na gives `size`); the comparison is exact (no 1e-10 tolerance)\n */\nexport function binary_search_rightmost(id: PineArray<float>, val: float): int {\n if (id.length === 0) return -1;\n const at = searchBound(id, val, true);\n return at > 0 && compareSorted(id[at - 1]!, val) === 0 ? at - 1 : at;\n}\n\n/**\n * Covariance\n *\n * Returns the covariance between two arrays.\n *\n * @param id1 - First array\n * @param id2 - Second array\n * @param biased - If true, uses biased estimate (population). If false, uses unbiased estimate (sample). Default: true\n * @returns Covariance between the two arrays\n *\n * @example\n * ```typescript\n * const prices = [100, 102, 98, 105, 103];\n * const volume = [1000, 1200, 950, 1300, 1100];\n * const cov = array.covariance(prices, volume);\n * // Returns covariance between price and volume\n * ```\n *\n * @remarks\n * - Biased (true): divides by n (population covariance)\n * - Unbiased (false): divides by n-1 (sample covariance)\n * - Returns NaN if arrays are empty or have different lengths\n * - Formula: Cov(X,Y) = E[(X - \u03BCX)(Y - \u03BCY)]\n *\n * PineScript rules: a pair where either value is `na` is skipped and the count is the number of pairs kept; both\n * means first, then the sum of the products from the first to the last pair. One pair gives 0 biased, NaN unbiased.\n */\nexport function covariance(id1: PineArray<float>, id2: PineArray<float>, biased: bool = true): float {\n if (id1.length !== id2.length) {\n return NaN;\n }\n const xs: number[] = [];\n const ys: number[] = [];\n for (let i = 0; i < id1.length; i++) {\n if (Number.isNaN(id1[i]!) || Number.isNaN(id2[i]!)) continue;\n xs.push(id1[i]!);\n ys.push(id2[i]!);\n }\n const n = xs.length;\n if (!n || (!biased && n < 2)) return NaN;\n let mean1 = 0;\n let mean2 = 0;\n for (let i = 0; i < n; i++) {\n mean1 += xs[i]!;\n mean2 += ys[i]!;\n }\n mean1 /= n;\n mean2 /= n;\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += (xs[i]! - mean1) * (ys[i]! - mean2);\n }\n return sum / (biased ? n : n - 1);\n}\n\n/**\n * Percentile Linear Interpolation\n *\n * Returns the value for which the specified percentage of array values are\n * less than or equal to it, using linear interpolation.\n *\n * @param id - Array of numeric values\n * @param percentage - Percentage (0-100)\n * @returns Percentile value using linear interpolation\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const p50 = array.percentile_linear_interpolation(arr, 50);\n * // Returns: 3 (median)\n * ```\n *\n * @remarks\n * - Uses linear interpolation between adjacent values\n * - Result may not be a member of the array\n * - Returns NaN if array is empty\n *\n * PineScript rules:\n * - 1-based position in the sorted array: `size * percentage / 100 + 0.5` (snapped to an integer within 1e-9),\n * clamped to the first / last value; between two values `lo * (1 - frac) + hi * frac`\n * - `na` values are sorted after all numbers; with an `na` in the array, a position between two values gives `na`\n * - an `na` percentage gives `na`; a percentage outside 0 .. 100 is a runtime error (throws)\n */\nexport function percentile_linear_interpolation(id: PineArray<float>, percentage: float): float {\n if (id.length === 0 || Number.isNaN(percentage)) {\n return NaN;\n }\n checkPercentage('percentile_linear_interpolation', percentage);\n const s = sortedNaLast(id);\n const n = s.length;\n let pos = (n * percentage) / 100 + 0.5;\n const nearest = Math.round(pos);\n if (Math.abs(pos - nearest) < 1e-9) pos = nearest;\n if (pos <= 1) return s[0]!;\n if (pos >= n) return s[n - 1]!;\n const lower = Math.floor(pos);\n const frac = pos - lower;\n if (frac === 0) return s[lower - 1]!;\n if (Number.isNaN(s[n - 1]!)) return NaN;\n return s[lower - 1]! * (1 - frac) + s[lower]! * frac;\n}\n\n/** Array values sorted ascending, `na` values after the numbers (array.percentile_*). */\nfunction sortedNaLast(id: PineArray<float>): number[] {\n const numbers = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);\n return [...numbers, ...Array<number>(id.length - numbers.length).fill(NaN)];\n}\n\n/** A percentage outside 0 .. 100 is a PineScript runtime error. */\nfunction checkPercentage(name: string, percentage: number): void {\n if (!(percentage >= 0 && percentage <= 100)) {\n throw new Error(`array.${name}: percentage ${percentage} must be between 0 and 100`);\n }\n}\n\n/**\n * Percentile Nearest Rank\n *\n * Returns the value for which the specified percentage of array values are\n * less than or equal to it, using the nearest-rank method.\n *\n * @param id - Array of numeric values\n * @param percentage - Percentage (0-100)\n * @returns Percentile value using nearest rank\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const p50 = array.percentile_nearest_rank(arr, 50);\n * // Returns: 3 (median, always a member of array)\n * ```\n *\n * @remarks\n * - Result is always a member of the array\n * - Uses nearest-rank method (no interpolation)\n * - Returns NaN if array is empty\n *\n * PineScript rules:\n * - the value at rank `ceil(percentage * size / 100)` (clamped to 1 .. size) of the sorted array\n * - `na` values are sorted after all numbers (na when that rank holds an `na`)\n * - an `na` percentage counts as 0; a percentage outside 0 .. 100 is a runtime error (throws)\n */\nexport function percentile_nearest_rank(id: PineArray<float>, percentage: float): float {\n if (id.length === 0) {\n return NaN;\n }\n const pct = Number.isNaN(percentage) ? 0 : percentage;\n checkPercentage('percentile_nearest_rank', pct);\n const s = sortedNaLast(id);\n const rank = Math.min(s.length, Math.max(1, Math.ceil((pct * s.length) / 100)));\n return s[rank - 1]!;\n}\n\n/**\n * Percent Rank\n *\n * Returns the percentile rank of the element at the specified index.\n * The percentile rank is the percentage of elements that are less than\n * or equal to the reference value.\n *\n * @param id - Array of numeric values\n * @param index - Index of element to rank\n * @returns Percentile rank (0-100)\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const rank = array.percentrank(arr, 2); // Value at index 2 is 3\n * // Returns: 50 ((3 - 1) * 100 / (5 - 1))\n * ```\n *\n * @remarks\n * - Range: 0 to 100\n *\n * PineScript rules:\n * - `(count - 1) * 100 / (size - 1)`, with `count` the number of non-na elements <= the element (exact\n * comparison, no 1e-10 tolerance); `na` elements count in the size\n * - an `na` element, a one-element array or an empty array gives NaN\n * - an `na` index counts as 0; an index outside `0 .. size - 1` is a runtime error (throws)\n */\nexport function percentrank(id: PineArray<float>, index: int): float {\n const i = Number.isNaN(index) ? 0 : Math.trunc(index);\n if (id.length === 0) {\n return NaN;\n }\n if (i < 0 || i >= id.length) {\n throw new Error(`array.percentrank: index ${i} is out of bounds, array size is ${id.length}`);\n }\n if (id.length === 1) {\n return NaN;\n }\n const value = id[i]!;\n if (Number.isNaN(value)) {\n return NaN;\n }\n let count = 0;\n for (const v of id) {\n if (v <= value) count++;\n }\n return ((count - 1) * 100) / (id.length - 1);\n}\n\n/**\n * Sort Indices\n *\n * Returns an array of indices which, when used to index the original array,\n * will access its elements in their sorted order. Does not modify the original array.\n *\n * @param id - Array to get sorted indices from\n * @param order - Sort order: 'asc' or 'desc' (default: 'asc')\n * @returns Array of indices in sorted order\n *\n * @example\n * ```typescript\n * const arr = [5, -2, 0, 9, 1];\n * const indices = array.sort_indices(arr); // [1, 2, 4, 0, 3]\n * // arr[1] = -2 (smallest)\n * // arr[2] = 0\n * // arr[4] = 1\n * // arr[0] = 5\n * // arr[3] = 9 (largest)\n * ```\n *\n * @remarks\n * - Original array is not modified\n * - Returns indices that would sort the array\n * - Useful for maintaining correspondence with other arrays\n * - PineScript rule: the indices of `na` elements go where `array.sort` puts them (after the numbers in ascending\n * order, in their original order: `sort_indices([na, na, 5, 1])` is `[3, 2, 0, 1]`)\n */\nexport function sort_indices<T>(id: PineArray<T>, order: SortOrder = 'asc'): PineArray<int> {\n return sortedPositions(id, order);\n}\n\n/**\n * Standardize\n *\n * Returns an array of standardized elements (z-score normalization).\n * Each element is transformed to (value - mean) / stddev.\n *\n * @param id - Array of numeric values\n * @returns Array of standardized values (z-scores)\n *\n * @example\n * ```typescript\n * const arr = [1, 2, 3, 4, 5];\n * const standardized = array.standardize(arr);\n * // Mean = 3, StdDev \u2248 1.414\n * // Result \u2248 [-1.414, -0.707, 0, 0.707, 1.414]\n * ```\n *\n * @remarks\n * - Formula: z = (x - \u03BC) / \u03C3\n * - Result has mean of 0 and standard deviation of 1\n * - Useful for comparing values on different scales\n *\n * PineScript rules:\n * - \u03BC and \u03C3 are the population mean and standard deviation of the non-na elements, as `array.variance` (moment\n * form); `na` elements stay `na`\n * - when \u03C3 is 0 (all values equal) every non-na element gives 1\n */\nexport function standardize(id: PineArray<float>): PineArray<float> {\n const values = id.filter((v) => !Number.isNaN(v));\n if (!values.length) {\n return id.map(() => NaN);\n }\n const [p, q] = moments(values);\n const mean = p / values.length;\n const stdDev = Math.sqrt(Math.max(0, q / values.length - mean * mean));\n if (stdDev === 0) {\n return id.map((v) => (Number.isNaN(v) ? NaN : 1));\n }\n return id.map((v) => (Number.isNaN(v) ? NaN : (v - mean) / stdDev));\n}\n\n/**\n * New Type (User-Defined Type Array)\n *\n * Creates a new array of user-defined type elements.\n *\n * @param size - Initial size of array (default: 0)\n * @param initial_value - Initial value for all elements\n * @returns New array of user-defined type\n *\n * @example\n * ```typescript\n * // NOTE: User-defined types (UDTs) are not fully supported yet\n * // This is a placeholder for future implementation\n * const arr = array.newtype<MyType>(5);\n * ```\n *\n * @remarks\n * - **\u26A0\uFE0F LIMITED SUPPORT**: User-defined types (UDTs) require a type system\n * that is not yet fully implemented in this library\n * - This function currently works like `new_array<T>()` for basic types\n * - Full UDT support will be added in a future version\n * - See PineScript documentation for UDT usage patterns\n */\nexport function newtype<T>(size: simple_int = 0, initial_value?: T): PineArray<T> {\n // For now, this is just an alias for new_array\n // Full UDT support requires implementing the type system\n return new_array<T>(size, initial_value);\n}\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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I,QAAQ,MAAM;AAC7B,QAAM,OAAO,IAAI,OAAO;AACxB,QAAM,SAAS,KAAK,KAAK,KAAK,IAAI,GAAG,IAAI,OAAO,SAAS,OAAO,IAAI,CAAC;AACrE,MAAI,WAAW,GAAG;AAChB,WAAO,GAAG,IAAI,CAAC,MAAO,OAAO,MAAM,CAAC,IAAI,MAAM,CAAE;AAAA,EAClD;AACA,SAAO,GAAG,IAAI,CAAC,MAAO,OAAO,MAAM,CAAC,IAAI,OAAO,IAAI,QAAQ,MAAO;AACpE;AAyBO,SAAS,QAAWD,QAAmB,GAAG,eAAiC;AAGhF,SAAO,UAAaA,OAAM,aAAa;AACzC;",
6
6
  "names": ["size", "sum"]
7
7
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Times of bars after the last bar.
3
+ *
4
+ * PineScript draws on future bars: `line.new(..., bar_index + 15, ...)`, box edges after the last bar,
5
+ * `plot(..., offset = k)`. These points get the time of the future bar: the last bar time plus k times the bar
6
+ * interval. The bar interval is the most frequent gap between two consecutive bars (1 day on daily bars even with
7
+ * weekends and holidays). A renderer that adds the same future bar slots to the chart draws a point at
8
+ * `barTime(bars, n - 1 + k)` k bars after the last bar.
9
+ *
10
+ * @module drawing/bar-time
11
+ */
12
+ /** Most frequent positive gap between consecutive bar times (in the unit of the bar times); 0 with fewer than 2 bars. */
13
+ export declare function barInterval(bars: ReadonlyArray<{
14
+ time: number;
15
+ }>): number;
16
+ /**
17
+ * Time of bar `index`: the bar time for 0 <= index < bars.length, the time of a future bar for
18
+ * index >= bars.length (last bar time + (index - last index) * barInterval(bars)). NaN for a negative or non-integer
19
+ * index, or no bar. `interval` can be passed to avoid recomputing it.
20
+ */
21
+ export declare function barTime(bars: ReadonlyArray<{
22
+ time: number;
23
+ }>, index: number, interval?: number): number;
24
+ //# sourceMappingURL=bar-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bar-time.d.ts","sourceRoot":"","sources":["../../../src/drawing/bar-time.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,yHAAyH;AACzH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAgBzE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAKvG"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var bar_time_exports = {};
20
+ __export(bar_time_exports, {
21
+ barInterval: () => barInterval,
22
+ barTime: () => barTime
23
+ });
24
+ module.exports = __toCommonJS(bar_time_exports);
25
+ function barInterval(bars) {
26
+ const counts = /* @__PURE__ */ new Map();
27
+ let best = 0;
28
+ let bestCount = 0;
29
+ for (let i = 1; i < bars.length; i++) {
30
+ const d = bars[i].time - bars[i - 1].time;
31
+ if (!(d > 0)) continue;
32
+ const c = (counts.get(d) ?? 0) + 1;
33
+ counts.set(d, c);
34
+ if (c > bestCount || c === bestCount && d < best) {
35
+ best = d;
36
+ bestCount = c;
37
+ }
38
+ }
39
+ return best;
40
+ }
41
+ function barTime(bars, index, interval) {
42
+ const n = bars.length;
43
+ if (n === 0 || index < 0 || !Number.isInteger(index)) return NaN;
44
+ if (index < n) return bars[index].time;
45
+ return bars[n - 1].time + (index - (n - 1)) * (interval ?? barInterval(bars));
46
+ }
47
+ //# sourceMappingURL=bar-time.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/drawing/bar-time.ts"],
4
+ "sourcesContent": ["/**\n * Times of bars after the last bar.\n *\n * PineScript draws on future bars: `line.new(..., bar_index + 15, ...)`, box edges after the last bar,\n * `plot(..., offset = k)`. These points get the time of the future bar: the last bar time plus k times the bar\n * interval. The bar interval is the most frequent gap between two consecutive bars (1 day on daily bars even with\n * weekends and holidays). A renderer that adds the same future bar slots to the chart draws a point at\n * `barTime(bars, n - 1 + k)` k bars after the last bar.\n *\n * @module drawing/bar-time\n */\n\n/** Most frequent positive gap between consecutive bar times (in the unit of the bar times); 0 with fewer than 2 bars. */\nexport function barInterval(bars: ReadonlyArray<{ time: number }>): number {\n const counts = new Map<number, number>();\n let best = 0;\n let bestCount = 0;\n for (let i = 1; i < bars.length; i++) {\n const d = bars[i]!.time - bars[i - 1]!.time;\n if (!(d > 0)) continue;\n const c = (counts.get(d) ?? 0) + 1;\n counts.set(d, c);\n // ties: the smaller gap\n if (c > bestCount || (c === bestCount && d < best)) {\n best = d;\n bestCount = c;\n }\n }\n return best;\n}\n\n/**\n * Time of bar `index`: the bar time for 0 <= index < bars.length, the time of a future bar for\n * index >= bars.length (last bar time + (index - last index) * barInterval(bars)). NaN for a negative or non-integer\n * index, or no bar. `interval` can be passed to avoid recomputing it.\n */\nexport function barTime(bars: ReadonlyArray<{ time: number }>, index: number, interval?: number): number {\n const n = bars.length;\n if (n === 0 || index < 0 || !Number.isInteger(index)) return NaN;\n if (index < n) return bars[index]!.time;\n return bars[n - 1]!.time + (index - (n - 1)) * (interval ?? barInterval(bars));\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,SAAS,YAAY,MAA+C;AACzE,QAAM,SAAS,oBAAI,IAAoB;AACvC,MAAI,OAAO;AACX,MAAI,YAAY;AAChB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,IAAI,KAAK,CAAC,EAAG,OAAO,KAAK,IAAI,CAAC,EAAG;AACvC,QAAI,EAAE,IAAI,GAAI;AACd,UAAM,KAAK,OAAO,IAAI,CAAC,KAAK,KAAK;AACjC,WAAO,IAAI,GAAG,CAAC;AAEf,QAAI,IAAI,aAAc,MAAM,aAAa,IAAI,MAAO;AAClD,aAAO;AACP,kBAAY;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,QAAQ,MAAuC,OAAe,UAA2B;AACvG,QAAM,IAAI,KAAK;AACf,MAAI,MAAM,KAAK,QAAQ,KAAK,CAAC,OAAO,UAAU,KAAK,EAAG,QAAO;AAC7D,MAAI,QAAQ,EAAG,QAAO,KAAK,KAAK,EAAG;AACnC,SAAO,KAAK,IAAI,CAAC,EAAG,QAAQ,SAAS,IAAI,OAAO,YAAY,YAAY,IAAI;AAC9E;",
6
+ "names": []
7
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Renderable form of the live drawing objects (labels, lines, boxes, linefills, polylines, tables): the
3
+ * `IndicatorResult` fields `labels`, `lines`, `boxes`, `linefills`, `polylines` and `tables`.
4
+ *
5
+ * Conversion rules:
6
+ * - x coordinates become bar times: a `bar_index` x is the time of that bar, or of a future bar after the last bar
7
+ * (see {@link barTime}); a `bar_time` x (UNIX ms, as PineScript) is converted to the unit of the bar times
8
+ * - an object with an `na` coordinate (or a bar index before the first bar) is not drawn, as in PineScript
9
+ * - a property the script did not set is omitted (the renderer uses the PineScript default); a colour set to `na`
10
+ * is 'transparent'
11
+ * - `force_overlay` is kept only when true
12
+ *
13
+ * @module drawing/output
14
+ */
15
+ import type { BoxData, LabelData, LineDrawingData, LinefillData, PolylineData, TableData } from '../types/metadata.js';
16
+ /** Drawing fields of an IndicatorResult; a kind without live objects is undefined. */
17
+ export interface DrawingOutputs {
18
+ labels?: LabelData[];
19
+ lines?: LineDrawingData[];
20
+ boxes?: BoxData[];
21
+ linefills?: LinefillData[];
22
+ polylines?: PolylineData[];
23
+ tables?: TableData[];
24
+ }
25
+ /**
26
+ * Converts the live drawing objects of the registry. `bars` are the chart bars (their `time` in `timeUnit`, 's' by
27
+ * default as lightweight-charts); they give the time of a bar index.
28
+ */
29
+ export declare function drawingOutputs(bars: ReadonlyArray<{
30
+ time: number;
31
+ }>, timeUnit?: 's' | 'ms'): DrawingOutputs;
32
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/drawing/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,KAAK,EACV,OAAO,EACP,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EAEZ,SAAS,EACV,MAAM,sBAAsB,CAAC;AAE9B,sFAAsF;AACtF,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;CACtB;AAiBD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,QAAQ,GAAE,GAAG,GAAG,IAAU,GAAG,cAAc,CA4JhH"}