oakscriptjs 0.9.3 → 0.9.5

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 (52) hide show
  1. package/dist/cjs/array/index.d.ts +4 -0
  2. package/dist/cjs/array/index.d.ts.map +1 -1
  3. package/dist/cjs/array/index.js +22 -39
  4. package/dist/cjs/array/index.js.map +2 -2
  5. package/dist/cjs/callsite/index.d.ts +62 -3
  6. package/dist/cjs/callsite/index.d.ts.map +1 -1
  7. package/dist/cjs/callsite/index.js +53 -2
  8. package/dist/cjs/callsite/index.js.map +3 -3
  9. package/dist/cjs/index.d.ts +1 -1
  10. package/dist/cjs/index.js +1 -1
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/math/index.d.ts +3 -1
  13. package/dist/cjs/math/index.d.ts.map +1 -1
  14. package/dist/cjs/math/index.js +2 -2
  15. package/dist/cjs/math/index.js.map +2 -2
  16. package/dist/cjs/ta/index.d.ts +12 -6
  17. package/dist/cjs/ta/index.d.ts.map +1 -1
  18. package/dist/cjs/ta/index.js +27 -58
  19. package/dist/cjs/ta/index.js.map +3 -3
  20. package/dist/cjs/ta/running-sum.d.ts +2 -1
  21. package/dist/cjs/ta/running-sum.d.ts.map +1 -1
  22. package/dist/cjs/ta/running-sum.js +7 -2
  23. package/dist/cjs/ta/running-sum.js.map +2 -2
  24. package/dist/esm/array/index.d.ts +4 -0
  25. package/dist/esm/array/index.d.ts.map +1 -1
  26. package/dist/esm/array/index.js +35 -46
  27. package/dist/esm/array/index.js.map +1 -1
  28. package/dist/esm/callsite/index.d.ts +62 -3
  29. package/dist/esm/callsite/index.d.ts.map +1 -1
  30. package/dist/esm/callsite/index.js +117 -6
  31. package/dist/esm/callsite/index.js.map +1 -1
  32. package/dist/esm/index.d.ts +1 -1
  33. package/dist/esm/index.js +1 -1
  34. package/dist/esm/math/index.d.ts +3 -1
  35. package/dist/esm/math/index.d.ts.map +1 -1
  36. package/dist/esm/math/index.js +2 -2
  37. package/dist/esm/math/index.js.map +1 -1
  38. package/dist/esm/ta/index.d.ts +12 -6
  39. package/dist/esm/ta/index.d.ts.map +1 -1
  40. package/dist/esm/ta/index.js +56 -77
  41. package/dist/esm/ta/index.js.map +1 -1
  42. package/dist/esm/ta/running-sum.d.ts +2 -1
  43. package/dist/esm/ta/running-sum.d.ts.map +1 -1
  44. package/dist/esm/ta/running-sum.js +15 -4
  45. package/dist/esm/ta/running-sum.js.map +1 -1
  46. package/package.json +2 -2
  47. package/src/array/index.ts +30 -47
  48. package/src/callsite/index.ts +119 -6
  49. package/src/index.ts +1 -1
  50. package/src/math/index.ts +5 -3
  51. package/src/ta/index.ts +61 -83
  52. package/src/ta/running-sum.ts +16 -4
@@ -465,6 +465,8 @@ export declare function binary_search(id: PineArray<float>, val: float): int;
465
465
  * - Array must be sorted in ascending order
466
466
  * - For duplicate values, returns leftmost occurrence
467
467
  * - When value not found, returns position of next smaller element
468
+ * - PineScript rules: a value below every element gives 0; `na` counts as greater than every number (an array
469
+ * without na gives `size - 1`); the comparison is exact (no 1e-10 tolerance)
468
470
  */
469
471
  export declare function binary_search_leftmost(id: PineArray<float>, val: float): int;
470
472
  /**
@@ -495,6 +497,8 @@ export declare function binary_search_leftmost(id: PineArray<float>, val: float)
495
497
  * - Array must be sorted in ascending order
496
498
  * - For duplicate values, returns rightmost occurrence
497
499
  * - When value not found, returns position of next larger element
500
+ * - PineScript rules: a value above every element gives `size` (the position after the last element); `na` counts
501
+ * as greater than every number (an array without na gives `size`); the comparison is exact (no 1e-10 tolerance)
498
502
  */
499
503
  export declare function binary_search_rightmost(id: PineArray<float>, val: float): int;
500
504
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAA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,aAAa,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAIhF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG"}
@@ -263,48 +263,31 @@ function binary_search(id, val) {
263
263
  return -1;
264
264
  }
265
265
  function binary_search_leftmost(id, val) {
266
- let left = 0;
267
- let right = id.length - 1;
268
- let result = -1;
269
- let found = false;
270
- while (left <= right) {
271
- const mid = Math.floor((left + right) / 2);
272
- if (id[mid] < val) {
273
- if (!found) {
274
- result = mid;
275
- }
276
- left = mid + 1;
277
- } else if (id[mid] === val) {
278
- result = mid;
279
- found = true;
280
- right = mid - 1;
281
- } else {
282
- right = mid - 1;
283
- }
266
+ if (id.length === 0) return -1;
267
+ const at = searchBound(id, val, false);
268
+ return at < id.length && compareSorted(id[at], val) === 0 ? at : Math.max(0, at - 1);
269
+ }
270
+ function compareSorted(a, b) {
271
+ const an = Number.isNaN(a);
272
+ const bn = Number.isNaN(b);
273
+ if (an || bn) return an === bn ? 0 : an ? 1 : -1;
274
+ return a < b ? -1 : a > b ? 1 : 0;
275
+ }
276
+ function searchBound(id, val, after) {
277
+ let lo = 0;
278
+ let hi = id.length;
279
+ while (lo < hi) {
280
+ const mid = lo + hi >>> 1;
281
+ const c = compareSorted(id[mid], val);
282
+ if (c < 0 || after && c === 0) lo = mid + 1;
283
+ else hi = mid;
284
284
  }
285
- return result;
285
+ return lo;
286
286
  }
287
287
  function binary_search_rightmost(id, val) {
288
- let left = 0;
289
- let right = id.length - 1;
290
- let result = -1;
291
- let found = false;
292
- while (left <= right) {
293
- const mid = Math.floor((left + right) / 2);
294
- if (id[mid] <= val) {
295
- if (id[mid] === val) {
296
- result = mid;
297
- found = true;
298
- }
299
- left = mid + 1;
300
- } else {
301
- if (!found) {
302
- result = mid;
303
- }
304
- right = mid - 1;
305
- }
306
- }
307
- return result;
288
+ if (id.length === 0) return -1;
289
+ const at = searchBound(id, val, true);
290
+ return at > 0 && compareSorted(id[at - 1], val) === 0 ? at - 1 : at;
308
291
  }
309
292
  function covariance(id1, id2, biased = true) {
310
293
  if (id1.length === 0 || id2.length === 0) {
@@ -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/**\n * Returns the element at the specified index\n */\nexport function get<T>(id: PineArray<T>, index: simple_int): T {\n return id[index]!;\n}\n\n/**\n * Sets the value of the element at the specified index\n */\nexport function set<T>(id: PineArray<T>, index: simple_int, value: T): void {\n 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 */\nexport function insert<T>(id: PineArray<T>, index: simple_int, value: T): void {\n id.splice(index, 0, value);\n}\n\n/**\n * Removes the element at the specified index\n */\nexport function remove<T>(id: PineArray<T>, index: simple_int): T {\n return id.splice(index, 1)[0]!;\n}\n\n/**\n * Returns true if the array contains the value\n */\nexport function includes<T>(id: PineArray<T>, value: T): bool {\n return id.includes(value);\n}\n\n/**\n * Returns the index of the first occurrence of the value\n */\nexport function indexof<T>(id: PineArray<T>, value: T): int {\n return id.indexOf(value);\n}\n\n/**\n * Returns the index of the last occurrence of the value\n */\nexport function lastindexof<T>(id: PineArray<T>, value: T): int {\n return id.lastIndexOf(value);\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 * Concatenates two arrays\n */\nexport function concat<T>(id1: PineArray<T>, id2: PineArray<T>): PineArray<T> {\n return [...id1, ...id2] as PineArray<T>;\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 a slice of the array\n */\nexport function slice<T>(id: PineArray<T>, index_from: simple_int, index_to?: simple_int): PineArray<T> {\n return id.slice(index_from, index_to) as PineArray<T>;\n}\n\n/**\n * Sorts array elements (numeric)\n */\nexport function sort<T>(id: PineArray<T>, order: 'asc' | 'desc' = 'asc'): void {\n id.sort((a, b) => {\n if (order === 'asc') {\n return (a as any) - (b as any);\n } else {\n return (b as any) - (a as any);\n }\n });\n}\n\n/**\n * Returns the sum of all elements (numeric arrays only)\n */\nexport function sum(id: PineArray<float>): float {\n return id.reduce((acc, val) => acc + val, 0);\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/**\n * The `nth` smallest value (0 = the smallest) of the non-na elements (PineScript `array.min(id, nth)`).\n * An `nth` past the end gives the greatest value; an array without values gives NaN.\n */\nexport function min(id: PineArray<float>, nth: simple_int = 0): float {\n const values = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);\n return values.length ? values[Math.min(nth, values.length - 1)]! : NaN;\n}\n\n/**\n * The `nth` greatest value (0 = the greatest) of the non-na elements (PineScript `array.max(id, nth)`).\n * An `nth` past the end gives the smallest value; an array without values gives NaN.\n */\nexport function max(id: PineArray<float>, nth: simple_int = 0): float {\n const values = id.filter((v) => !Number.isNaN(v)).sort((a, b) => b - a);\n return values.length ? values[Math.min(nth, values.length - 1)]! : NaN;\n}\n\n/**\n * Returns the median value (numeric arrays only)\n */\nexport function median(id: PineArray<float>): float {\n const sorted = [...id].sort((a, b) => a - b);\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 * Returns the mode (most frequent value)\n */\nexport function mode(id: PineArray<float>): float {\n const frequency: Map<float, int> = new Map();\n let maxFreq = 0;\n let mode = id[0]!;\n\n for (const val of id) {\n const freq = (frequency.get(val) || 0) + 1;\n frequency.set(val, freq);\n if (freq > maxFreq) {\n maxFreq = freq;\n mode = val;\n }\n }\n\n return mode;\n}\n\n/**\n * Standard deviation of the non-na elements (PineScript `array.stdev(id, biased)`).\n * `biased` true (default) divides by the count, false by the count - 1.\n */\nexport function stdev(id: PineArray<float>, biased: bool = true): float {\n return Math.sqrt(variance(id, biased));\n}\n\n/**\n * Variance of the non-na elements (PineScript `array.variance(id, biased)`).\n * `biased` true (default) divides by the count, false by the count - 1.\n */\nexport function variance(id: PineArray<float>, biased: bool = true): float {\n const values = id.filter((v) => !Number.isNaN(v));\n if (!values.length) return NaN;\n const mean = values.reduce((a, b) => a + b, 0) / values.length;\n const squares = values.reduce((a, b) => a + (b - mean) * (b - mean), 0);\n return squares / (biased ? values.length : values.length - 1);\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 const end = index_to ?? id.length;\n for (let i = index_from; 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 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 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 */\nexport function binary_search_leftmost(id: PineArray<float>, val: float): int {\n let left = 0;\n let right = id.length - 1;\n let result = -1;\n let found = false;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n\n if (id[mid]! < val) {\n if (!found) {\n result = mid; // Track the last element smaller than val (only if not found)\n }\n left = mid + 1;\n } else if (id[mid]! === val) {\n result = mid;\n found = true;\n // Continue searching to the left for leftmost occurrence\n right = mid - 1;\n } else {\n // id[mid] > val\n right = mid - 1;\n }\n }\n\n return result;\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 */\nexport function binary_search_rightmost(id: PineArray<float>, val: float): int {\n let left = 0;\n let right = id.length - 1;\n let result = -1;\n let found = false;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n\n if (id[mid]! <= val) {\n if (id[mid]! === val) {\n result = mid;\n found = true;\n }\n // Continue searching to the right for rightmost occurrence\n left = mid + 1;\n } else {\n // id[mid] > val\n if (!found) {\n result = mid; // Track the first element greater than val (only if not found)\n }\n right = mid - 1;\n }\n }\n\n return result;\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 */\nexport function covariance(id1: PineArray<float>, id2: PineArray<float>, biased: bool = true): float {\n if (id1.length === 0 || id2.length === 0) {\n return NaN;\n }\n\n if (id1.length !== id2.length) {\n return NaN;\n }\n\n const n = id1.length;\n const mean1 = avg(id1);\n const mean2 = avg(id2);\n\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += (id1[i]! - mean1) * (id2[i]! - mean2);\n }\n\n // Biased: divide by n, Unbiased: divide by n-1\n const divisor = biased ? n : n - 1;\n return sum / divisor;\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 * - position in the sorted array: `percentage / 100 * size - 0.5`, clamped to the first / last value, linear\n * interpolation between the two neighbours\n * - `na` values are sorted after all numbers; with an `na` in the array, a position between two values gives `na`\n */\nexport function percentile_linear_interpolation(id: PineArray<float>, percentage: float): float {\n if (id.length === 0) {\n return NaN;\n }\n const s = sortedNaLast(id);\n const n = s.length;\n const pos = (percentage / 100) * n - 0.5;\n if (pos <= 0) return s[0]!;\n if (pos >= n - 1) return s[n - 1]!;\n const lo = Math.floor(pos);\n const f = pos - lo;\n if (f === 0) return s[lo]!;\n return Number.isNaN(s[n - 1]!) ? NaN : s[lo]! + f * (s[lo + 1]! - s[lo]!);\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/**\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 / 100 * size)` of the sorted array\n * - `na` values are sorted after all numbers (na when that rank holds an `na`)\n */\nexport function percentile_nearest_rank(id: PineArray<float>, percentage: float): float {\n if (id.length === 0) {\n return NaN;\n }\n const s = sortedNaLast(id);\n const rank = Math.min(s.length, Math.max(1, Math.ceil((percentage / 100) * s.length)));\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: 40 (40% of values <= 3)\n * ```\n *\n * @remarks\n * - Returns percentage of elements <= the value at given index\n * - Range: 0 to 100\n * - Returns NaN if array is empty or index out of bounds\n */\nexport function percentrank(id: PineArray<float>, index: int): float {\n if (id.length === 0 || index < 0 || index >= id.length) {\n return NaN;\n }\n\n const value = id[index]!;\n\n if (isNaN(value)) {\n return NaN;\n }\n\n // Count elements less than or equal to the value\n let count = 0;\n for (let i = 0; i < id.length; i++) {\n if (!isNaN(id[i]!) && id[i]! <= value) {\n count++;\n }\n }\n\n // Calculate percentage\n return (count / id.length) * 100;\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 */\nexport function sort_indices(id: PineArray<float>, order: 'asc' | 'desc' = 'asc'): PineArray<int> {\n // Create array of indices\n const indices: PineArray<int> = Array.from({ length: id.length }, (_, i) => i) as PineArray<int>;\n\n // Sort indices based on values in original array\n indices.sort((a, b) => {\n if (order === 'asc') {\n return id[a]! - id[b]!;\n } else {\n return id[b]! - id[a]!;\n }\n });\n\n return indices;\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 * - Returns array of NaN if standard deviation is 0\n * - Useful for comparing values on different scales\n */\nexport function standardize(id: PineArray<float>): PineArray<float> {\n if (id.length === 0) {\n return [] as PineArray<float>;\n }\n\n const mean = avg(id);\n const stdDev = stdev(id);\n\n // If stddev is 0, all values are the same - return array of 0s or NaN\n if (stdDev === 0) {\n return id.map(() => NaN) as PineArray<float>;\n }\n\n // Calculate z-score for each element\n return id.map(value => (value - mean) / stdDev) as PineArray<float>;\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,KA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,YAAY,IAAsB,OAAmB;AACnE,MAAI,GAAG,WAAW,KAAK,QAAQ,KAAK,SAAS,GAAG,QAAQ;AACtD,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,GAAG,KAAK;AAEtB,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ;AACZ,WAAS,IAAI,GAAG,IAAI,GAAG,QAAQ,KAAK;AAClC,QAAI,CAAC,MAAM,GAAG,CAAC,CAAE,KAAK,GAAG,CAAC,KAAM,OAAO;AACrC;AAAA,IACF;AAAA,EACF;AAGA,SAAQ,QAAQ,GAAG,SAAU;AAC/B;AA4BO,SAAS,aAAa,IAAsB,QAAwB,OAAuB;AAEhG,QAAM,UAA0B,MAAM,KAAK,EAAE,QAAQ,GAAG,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC;AAG7E,UAAQ,KAAK,CAAC,GAAG,MAAM;AACrB,QAAI,UAAU,OAAO;AACnB,aAAO,GAAG,CAAC,IAAK,GAAG,CAAC;AAAA,IACtB,OAAO;AACL,aAAO,GAAG,CAAC,IAAK,GAAG,CAAC;AAAA,IACtB;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAyBO,SAAS,YAAY,IAAwC;AAClE,MAAI,GAAG,WAAW,GAAG;AACnB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,OAAO,IAAI,EAAE;AACnB,QAAM,SAAS,MAAM,EAAE;AAGvB,MAAI,WAAW,GAAG;AAChB,WAAO,GAAG,IAAI,MAAM,GAAG;AAAA,EACzB;AAGA,SAAO,GAAG,IAAI,YAAU,QAAQ,QAAQ,MAAM;AAChD;AAyBO,SAAS,QAAWF,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 } 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/**\n * Returns the element at the specified index\n */\nexport function get<T>(id: PineArray<T>, index: simple_int): T {\n return id[index]!;\n}\n\n/**\n * Sets the value of the element at the specified index\n */\nexport function set<T>(id: PineArray<T>, index: simple_int, value: T): void {\n 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 */\nexport function insert<T>(id: PineArray<T>, index: simple_int, value: T): void {\n id.splice(index, 0, value);\n}\n\n/**\n * Removes the element at the specified index\n */\nexport function remove<T>(id: PineArray<T>, index: simple_int): T {\n return id.splice(index, 1)[0]!;\n}\n\n/**\n * Returns true if the array contains the value\n */\nexport function includes<T>(id: PineArray<T>, value: T): bool {\n return id.includes(value);\n}\n\n/**\n * Returns the index of the first occurrence of the value\n */\nexport function indexof<T>(id: PineArray<T>, value: T): int {\n return id.indexOf(value);\n}\n\n/**\n * Returns the index of the last occurrence of the value\n */\nexport function lastindexof<T>(id: PineArray<T>, value: T): int {\n return id.lastIndexOf(value);\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 * Concatenates two arrays\n */\nexport function concat<T>(id1: PineArray<T>, id2: PineArray<T>): PineArray<T> {\n return [...id1, ...id2] as PineArray<T>;\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 a slice of the array\n */\nexport function slice<T>(id: PineArray<T>, index_from: simple_int, index_to?: simple_int): PineArray<T> {\n return id.slice(index_from, index_to) as PineArray<T>;\n}\n\n/**\n * Sorts array elements (numeric)\n */\nexport function sort<T>(id: PineArray<T>, order: 'asc' | 'desc' = 'asc'): void {\n id.sort((a, b) => {\n if (order === 'asc') {\n return (a as any) - (b as any);\n } else {\n return (b as any) - (a as any);\n }\n });\n}\n\n/**\n * Returns the sum of all elements (numeric arrays only)\n */\nexport function sum(id: PineArray<float>): float {\n return id.reduce((acc, val) => acc + val, 0);\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/**\n * The `nth` smallest value (0 = the smallest) of the non-na elements (PineScript `array.min(id, nth)`).\n * An `nth` past the end gives the greatest value; an array without values gives NaN.\n */\nexport function min(id: PineArray<float>, nth: simple_int = 0): float {\n const values = id.filter((v) => !Number.isNaN(v)).sort((a, b) => a - b);\n return values.length ? values[Math.min(nth, values.length - 1)]! : NaN;\n}\n\n/**\n * The `nth` greatest value (0 = the greatest) of the non-na elements (PineScript `array.max(id, nth)`).\n * An `nth` past the end gives the smallest value; an array without values gives NaN.\n */\nexport function max(id: PineArray<float>, nth: simple_int = 0): float {\n const values = id.filter((v) => !Number.isNaN(v)).sort((a, b) => b - a);\n return values.length ? values[Math.min(nth, values.length - 1)]! : NaN;\n}\n\n/**\n * Returns the median value (numeric arrays only)\n */\nexport function median(id: PineArray<float>): float {\n const sorted = [...id].sort((a, b) => a - b);\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 * Returns the mode (most frequent value)\n */\nexport function mode(id: PineArray<float>): float {\n const frequency: Map<float, int> = new Map();\n let maxFreq = 0;\n let mode = id[0]!;\n\n for (const val of id) {\n const freq = (frequency.get(val) || 0) + 1;\n frequency.set(val, freq);\n if (freq > maxFreq) {\n maxFreq = freq;\n mode = val;\n }\n }\n\n return mode;\n}\n\n/**\n * Standard deviation of the non-na elements (PineScript `array.stdev(id, biased)`).\n * `biased` true (default) divides by the count, false by the count - 1.\n */\nexport function stdev(id: PineArray<float>, biased: bool = true): float {\n return Math.sqrt(variance(id, biased));\n}\n\n/**\n * Variance of the non-na elements (PineScript `array.variance(id, biased)`).\n * `biased` true (default) divides by the count, false by the count - 1.\n */\nexport function variance(id: PineArray<float>, biased: bool = true): float {\n const values = id.filter((v) => !Number.isNaN(v));\n if (!values.length) return NaN;\n const mean = values.reduce((a, b) => a + b, 0) / values.length;\n const squares = values.reduce((a, b) => a + (b - mean) * (b - mean), 0);\n return squares / (biased ? values.length : values.length - 1);\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 const end = index_to ?? id.length;\n for (let i = index_from; 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 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 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 */\nexport function covariance(id1: PineArray<float>, id2: PineArray<float>, biased: bool = true): float {\n if (id1.length === 0 || id2.length === 0) {\n return NaN;\n }\n\n if (id1.length !== id2.length) {\n return NaN;\n }\n\n const n = id1.length;\n const mean1 = avg(id1);\n const mean2 = avg(id2);\n\n let sum = 0;\n for (let i = 0; i < n; i++) {\n sum += (id1[i]! - mean1) * (id2[i]! - mean2);\n }\n\n // Biased: divide by n, Unbiased: divide by n-1\n const divisor = biased ? n : n - 1;\n return sum / divisor;\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 * - position in the sorted array: `percentage / 100 * size - 0.5`, clamped to the first / last value, linear\n * interpolation between the two neighbours\n * - `na` values are sorted after all numbers; with an `na` in the array, a position between two values gives `na`\n */\nexport function percentile_linear_interpolation(id: PineArray<float>, percentage: float): float {\n if (id.length === 0) {\n return NaN;\n }\n const s = sortedNaLast(id);\n const n = s.length;\n const pos = (percentage / 100) * n - 0.5;\n if (pos <= 0) return s[0]!;\n if (pos >= n - 1) return s[n - 1]!;\n const lo = Math.floor(pos);\n const f = pos - lo;\n if (f === 0) return s[lo]!;\n return Number.isNaN(s[n - 1]!) ? NaN : s[lo]! + f * (s[lo + 1]! - s[lo]!);\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/**\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 / 100 * size)` of the sorted array\n * - `na` values are sorted after all numbers (na when that rank holds an `na`)\n */\nexport function percentile_nearest_rank(id: PineArray<float>, percentage: float): float {\n if (id.length === 0) {\n return NaN;\n }\n const s = sortedNaLast(id);\n const rank = Math.min(s.length, Math.max(1, Math.ceil((percentage / 100) * s.length)));\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: 40 (40% of values <= 3)\n * ```\n *\n * @remarks\n * - Returns percentage of elements <= the value at given index\n * - Range: 0 to 100\n * - Returns NaN if array is empty or index out of bounds\n */\nexport function percentrank(id: PineArray<float>, index: int): float {\n if (id.length === 0 || index < 0 || index >= id.length) {\n return NaN;\n }\n\n const value = id[index]!;\n\n if (isNaN(value)) {\n return NaN;\n }\n\n // Count elements less than or equal to the value\n let count = 0;\n for (let i = 0; i < id.length; i++) {\n if (!isNaN(id[i]!) && id[i]! <= value) {\n count++;\n }\n }\n\n // Calculate percentage\n return (count / id.length) * 100;\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 */\nexport function sort_indices(id: PineArray<float>, order: 'asc' | 'desc' = 'asc'): PineArray<int> {\n // Create array of indices\n const indices: PineArray<int> = Array.from({ length: id.length }, (_, i) => i) as PineArray<int>;\n\n // Sort indices based on values in original array\n indices.sort((a, b) => {\n if (order === 'asc') {\n return id[a]! - id[b]!;\n } else {\n return id[b]! - id[a]!;\n }\n });\n\n return indices;\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 * - Returns array of NaN if standard deviation is 0\n * - Useful for comparing values on different scales\n */\nexport function standardize(id: PineArray<float>): PineArray<float> {\n if (id.length === 0) {\n return [] as PineArray<float>;\n }\n\n const mean = avg(id);\n const stdDev = stdev(id);\n\n // If stddev is 0, all values are the same - return array of 0s or NaN\n if (stdDev === 0) {\n return id.map(() => NaN) as PineArray<float>;\n }\n\n // Calculate z-score for each element\n return id.map(value => (value - mean) / stdDev) as PineArray<float>;\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;AAKO,SA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AsB,OAAmB;AACnE,MAAI,GAAG,WAAW,KAAK,QAAQ,KAAK,SAAS,GAAG,QAAQ;AACtD,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,GAAG,KAAK;AAEtB,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ;AACZ,WAAS,IAAI,GAAG,IAAI,GAAG,QAAQ,KAAK;AAClC,QAAI,CAAC,MAAM,GAAG,CAAC,CAAE,KAAK,GAAG,CAAC,KAAM,OAAO;AACrC;AAAA,IACF;AAAA,EACF;AAGA,SAAQ,QAAQ,GAAG,SAAU;AAC/B;AA4BO,SAAS,aAAa,IAAsB,QAAwB,OAAuB;AAEhG,QAAM,UAA0B,MAAM,KAAK,EAAE,QAAQ,GAAG,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC;AAG7E,UAAQ,KAAK,CAAC,GAAG,MAAM;AACrB,QAAI,UAAU,OAAO;AACnB,aAAO,GAAG,CAAC,IAAK,GAAG,CAAC;AAAA,IACtB,OAAO;AACL,aAAO,GAAG,CAAC,IAAK,GAAG,CAAC;AAAA,IACtB;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAyBO,SAAS,YAAY,IAAwC;AAClE,MAAI,GAAG,WAAW,GAAG;AACnB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,OAAO,IAAI,EAAE;AACnB,QAAM,SAAS,MAAM,EAAE;AAGvB,MAAI,WAAW,GAAG;AAChB,WAAO,GAAG,IAAI,MAAM,GAAG;AAAA,EACzB;AAGA,SAAO,GAAG,IAAI,YAAU,QAAQ,QAAQ,MAAM;AAChD;AAyBO,SAAS,QAAWF,QAAmB,GAAG,eAAiC;AAGhF,SAAO,UAAaA,OAAM,aAAa;AACzC;",
6
6
  "names": ["size", "mode", "sum"]
7
7
  }
@@ -11,6 +11,8 @@
11
11
  * loops, called only on the bars where the Pine call runs.
12
12
  * - {@link lowest} / {@link highest}: `ta.lowest` / `ta.highest` with a series length (a different length on each
13
13
  * call), which PineScript computes with a state kept between calls.
14
+ * - {@link lowestByBar} / {@link highestByBar} / {@link linreg}: `ta.lowest` / `ta.highest` / `ta.linreg` in a
15
+ * conditional block, whose history is kept by bar (not by call).
14
16
  *
15
17
  * Since PineScript v6, `and` / `or` are lazy: the right operand runs only when the left operand does not decide
16
18
  * the result. A ta.* call in the right operand of `a or b` runs on the bars where `a` is false, in `a and b` on the
@@ -49,16 +51,25 @@ import type { Source } from '../types/index.js';
49
51
  * @param sources - the arguments of the call, one value per chart bar
50
52
  */
51
53
  export declare function whenCalled<T extends number | boolean>(called: ArrayLike<boolean | number>, fn: (...values: number[][]) => ArrayLike<T>, ...sources: Source[]): Array<T | number>;
52
- /** One `ta.crossover(a, b)` call site: false on its first call, as its history is na. */
54
+ /**
55
+ * One `ta.crossover(a, b)` call site: compared with the last call where both arguments were not na; false before
56
+ * such a call.
57
+ */
53
58
  export declare function crossover(): (a: number, b: number) => boolean;
54
- /** One `ta.crossunder(a, b)` call site: false on its first call, as its history is na. */
59
+ /**
60
+ * One `ta.crossunder(a, b)` call site: compared with the last call where both arguments were not na; false before
61
+ * such a call.
62
+ */
55
63
  export declare function crossunder(): (a: number, b: number) => boolean;
56
64
  /**
57
65
  * One `ta.barssince(condition)` call site: the number of calls since the condition was true on a call (0 on that
58
66
  * call), na before the first true condition. An na condition counts as false.
59
67
  */
60
68
  export declare function barssince(): (condition: boolean | number) => number;
61
- /** One `ta.cross(a, b)` call site: false on its first call, as its history is na. */
69
+ /**
70
+ * One `ta.cross(a, b)` call site: compared with the last call where both arguments were not na; false before such
71
+ * a call.
72
+ */
62
73
  export declare function cross(): (a: number, b: number) => boolean;
63
74
  /**
64
75
  * One `ta.lowest(source, length)` call site with a series length (a different length on each call), called with
@@ -85,4 +96,52 @@ export declare function lowest(): (value: number, length: number) => number;
85
96
  * `(value, length)`. Same rules as {@link lowest}.
86
97
  */
87
98
  export declare function highest(): (value: number, length: number) => number;
99
+ /**
100
+ * One `ta.lowest(source, length)` call site in a conditional block whose history is kept by bar (not by call), called
101
+ * with `(barIndex, value, length)` on the bars where the Pine call runs.
102
+ *
103
+ * PineScript rules (measured on a call in a ternary branch, length 6):
104
+ * - the values are kept in a ring of `length + 1` slots indexed by the bar index, filled with 0 at the start and
105
+ * written only on the bars where the call runs: a bar before the first call counts as 0, and a bar without a call
106
+ * holds the value of the call `length + 1` bars earlier (0 if there was none)
107
+ * - on a call, the value replaces the kept extreme when there is none or when it is strictly lower; only otherwise,
108
+ * when the kept extreme is `length` bars old, the last `length` bars are read again from the ring (the oldest bar
109
+ * wins a tie)
110
+ * - na before bar `length - 1` (by bar, not by call)
111
+ *
112
+ * {@link lowest} keeps the history by call instead; both rules were measured, on different scripts.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // Pine: lo = cond ? ta.lowest(low, 6) : na
117
+ * const site = callsite.lowestByBar();
118
+ * const lo = lows.map((v, i) => (cond[i] ? site(i, v, 6) : NaN));
119
+ * ```
120
+ */
121
+ export declare function lowestByBar(): (barIndex: number, value: number, length: number) => number;
122
+ /**
123
+ * One `ta.highest(source, length)` call site in a conditional block whose history is kept by bar, called with
124
+ * `(barIndex, value, length)`. Same rules as {@link lowestByBar} (a value replaces the kept extreme when it is
125
+ * strictly higher).
126
+ */
127
+ export declare function highestByBar(): (barIndex: number, value: number, length: number) => number;
128
+ /**
129
+ * One `ta.linreg(source, length, offset)` call site in a conditional block, called with
130
+ * `(barIndex, value, length, offset)` on the bars where the Pine call runs.
131
+ *
132
+ * PineScript rules (measured): `ta.linreg` keeps the values it receives in a ring of `length + 1` slots indexed by the
133
+ * bar index, filled with 0 at the start and written only on the bars where it is called. The window is read from the
134
+ * ring for the last `length` bars: a bar before the first call counts as 0, and a bar without a call holds the value of
135
+ * the call `length + 1` bars earlier (0 if there was none). The result is na before bar `length - 1`. Called on every
136
+ * bar, it equals `ta.linreg`.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * // Pine: if bar_index >= 20
141
+ * // a := ta.linreg(close, 10, 0)
142
+ * const site = callsite.linreg();
143
+ * const a = closes.map((c, i) => (i >= 20 ? site(i, c, 10, 0) : NaN));
144
+ * ```
145
+ */
146
+ export declare function linreg(): (barIndex: number, value: number, length: number, offset?: number) => number;
88
147
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/callsite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,EACnD,MAAM,EAAE,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC,EACnC,EAAE,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAC3C,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CASnB;AAcD,yFAAyF;AACzF,wBAAgB,SAAS,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE7D;AAED,0FAA0F;AAC1F,wBAAgB,UAAU,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE9D;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,KAAK,MAAM,CAOnE;AAED,qFAAqF;AACrF,wBAAgB,KAAK,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAEzD;AA2CD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAElE;AAED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K,MAAM,CAEnE;AAgCD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAEzF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAE1F;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAUrG"}
@@ -23,10 +23,14 @@ __export(callsite_exports, {
23
23
  crossover: () => crossover,
24
24
  crossunder: () => crossunder,
25
25
  highest: () => highest,
26
+ highestByBar: () => highestByBar,
27
+ linreg: () => linreg,
26
28
  lowest: () => lowest,
29
+ lowestByBar: () => lowestByBar,
27
30
  whenCalled: () => whenCalled
28
31
  });
29
32
  module.exports = __toCommonJS(callsite_exports);
33
+ var import_ta = require("../ta/index.js");
30
34
  function whenCalled(called, fn, ...sources) {
31
35
  const bars = [];
32
36
  for (let i = 0; i < called.length; i++) if (called[i]) bars.push(i);
@@ -42,8 +46,10 @@ function twoSeriesSite(test) {
42
46
  let prevB = NaN;
43
47
  return (a, b) => {
44
48
  const result = test(a, b, prevA, prevB);
45
- prevA = a;
46
- prevB = b;
49
+ if (!Number.isNaN(a) && !Number.isNaN(b)) {
50
+ prevA = a;
51
+ prevB = b;
52
+ }
47
53
  return result;
48
54
  };
49
55
  }
@@ -109,4 +115,49 @@ function lowest() {
109
115
  function highest() {
110
116
  return extremeSite(false);
111
117
  }
118
+ function extremeByBarSite(isLowest) {
119
+ const better = isLowest ? (a, b) => a < b : (a, b) => a > b;
120
+ let ring = [];
121
+ let extreme = NaN;
122
+ let extremeAt = -1;
123
+ return (barIndex, value, length) => {
124
+ const len = Math.floor(length);
125
+ if (ring.length !== len + 1) {
126
+ ring = new Array(len + 1).fill(0);
127
+ extreme = NaN;
128
+ }
129
+ ring[barIndex % (len + 1)] = value;
130
+ if (Number.isNaN(extreme) || better(value, extreme)) {
131
+ extreme = value;
132
+ extremeAt = barIndex;
133
+ } else if (barIndex - extremeAt >= len) {
134
+ extreme = NaN;
135
+ for (let b = barIndex - len + 1; b <= barIndex; b++) {
136
+ const v = ring[b % (len + 1)];
137
+ if (!Number.isNaN(v) && (Number.isNaN(extreme) || better(v, extreme))) {
138
+ extreme = v;
139
+ extremeAt = b;
140
+ }
141
+ }
142
+ }
143
+ return barIndex < len - 1 ? NaN : extreme;
144
+ };
145
+ }
146
+ function lowestByBar() {
147
+ return extremeByBarSite(true);
148
+ }
149
+ function highestByBar() {
150
+ return extremeByBarSite(false);
151
+ }
152
+ function linreg() {
153
+ let ring = [];
154
+ return (barIndex, value, length, offset = 0) => {
155
+ const len = Math.floor(length);
156
+ if (ring.length !== len + 1) ring = new Array(len + 1).fill(0);
157
+ ring[barIndex % (len + 1)] = value;
158
+ if (barIndex < len - 1) return NaN;
159
+ const window = Array.from({ length: len }, (_, k) => ring[(barIndex - len + 1 + k) % (len + 1)]);
160
+ return (0, import_ta.linreg)(window, len, offset)[len - 1];
161
+ };
162
+ }
112
163
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/callsite/index.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview Per-call history of ta.* functions called in a conditional block.\n *\n * In PineScript, every ta.* call keeps its own history of the values it receives. A call inside\n * an `if` block receives values only on the bars where the block runs, so its history skips the\n * other bars: `ta.crossover(a, b)` is false on the first bar the block runs, and `ta.sma(x, 3)`\n * averages the last 3 values it received, not the last 3 bars.\n *\n * - {@link whenCalled}: vectorized, when the bars of the calls are known in advance.\n * - {@link crossover} / {@link crossunder} / {@link cross} / {@link barssince}: one stateful call site for bar\n * loops, called only on the bars where the Pine call runs.\n * - {@link lowest} / {@link highest}: `ta.lowest` / `ta.highest` with a series length (a different length on each\n * call), which PineScript computes with a state kept between calls.\n *\n * Since PineScript v6, `and` / `or` are lazy: the right operand runs only when the left operand does not decide\n * the result. A ta.* call in the right operand of `a or b` runs on the bars where `a` is false, in `a and b` on the\n * bars where `a` is true, so it needs a call site too:\n *\n * ```typescript\n * // Pine: longCond = longUp or (src > sig and ta.barssince(longUp) <= lookback)\n * const since = callsite.whenCalled(longUp.map((u, i) => !u && src[i] > sig[i]), (c) => taCore.barssince(c.map(Boolean)), longUp);\n * // ta.barssince(longUp) only runs where longUp is false: it never sees true and stays na\n * ```\n *\n * ```typescript\n * // Pine: if inRange\n * // buy = ta.crossover(cumRsi, 60)\n * const buy = callsite.whenCalled(inRange, (a) => taCore.crossover(a, a.map(() => 60)), cumRsi);\n *\n * // Same call in a bar loop\n * const buyCross = callsite.crossover();\n * for (let i = 0; i < n; i++) {\n * if (inRange[i]) {\n * const buy = buyCross(cumRsi[i], 60);\n * }\n * }\n * ```\n *\n * @module callsite\n */\n\nimport type { Source } from '../types/index.js';\n\n/**\n * Runs `fn` on the bars where `called` is true only, like a ta.* call inside an `if` block.\n * `fn` receives the values of `sources` on those bars, in order; its results are placed back on\n * the same bars. The other bars get na (NaN).\n *\n * @param called - true (or non-zero) on the bars where the call runs\n * @param fn - the calculation, for example `(x) => taCore.sma(x, 3)`\n * @param sources - the arguments of the call, one value per chart bar\n */\nexport function whenCalled<T extends number | boolean>(\n called: ArrayLike<boolean | number>,\n fn: (...values: number[][]) => ArrayLike<T>,\n ...sources: Source[]\n): Array<T | number> {\n const bars: number[] = [];\n for (let i = 0; i < called.length; i++) if (called[i]) bars.push(i);\n const result = fn(...sources.map(s => bars.map(i => s[i] ?? NaN)));\n const out = new Array<T | number>(called.length).fill(NaN);\n bars.forEach((bar, k) => {\n out[bar] = result[k]!;\n });\n return out;\n}\n\n/** A call site that keeps the two previous arguments (na before the first call). */\nfunction twoSeriesSite(test: (a: number, b: number, prevA: number, prevB: number) => boolean) {\n let prevA = NaN;\n let prevB = NaN;\n return (a: number, b: number): boolean => {\n const result = test(a, b, prevA, prevB);\n prevA = a;\n prevB = b;\n return result;\n };\n}\n\n/** One `ta.crossover(a, b)` call site: false on its first call, as its history is na. */\nexport function crossover(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a > b && pa <= pb);\n}\n\n/** One `ta.crossunder(a, b)` call site: false on its first call, as its history is na. */\nexport function crossunder(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a < b && pa >= pb);\n}\n\n/**\n * One `ta.barssince(condition)` call site: the number of calls since the condition was true on a call (0 on that\n * call), na before the first true condition. An na condition counts as false.\n */\nexport function barssince(): (condition: boolean | number) => number {\n let count = NaN;\n return (condition) => {\n if (condition && !Number.isNaN(condition)) count = 0;\n else if (!Number.isNaN(count)) count++;\n return count;\n };\n}\n\n/** One `ta.cross(a, b)` call site: false on its first call, as its history is na. */\nexport function cross(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => (a > b && pa <= pb) || (a < b && pa >= pb));\n}\n\n/** One `ta.lowest` / `ta.highest` call site with a series length; rules in {@link lowest}. */\nfunction extremeSite(isLowest: boolean): (value: number, length: number) => number {\n const better = isLowest ? (a: number, b: number) => a < b : (a: number, b: number) => a > b;\n const values: number[] = [];\n let extreme = NaN;\n let extremeAt = -1;\n let prevLength = NaN;\n const keep = (v: number, at: number) => {\n extreme = v;\n extremeAt = at;\n };\n const rescan = (i: number, length: number) => {\n extreme = NaN;\n for (let b = i; b > i - length && b >= 0; b--) {\n const v = values[b]!;\n if (!Number.isNaN(v) && (Number.isNaN(extreme) || !better(extreme, v))) keep(v, b);\n }\n };\n return (value, length) => {\n const i = values.length;\n values.push(value);\n if (Number.isNaN(value)) {\n extreme = NaN;\n prevLength = length;\n return NaN;\n }\n if (length > prevLength) {\n const from = Math.max(0, i - length + 1);\n const to = Math.max(0, i - prevLength + 1);\n if (values.slice(from, to).some(Number.isNaN)) keep(value, i);\n else {\n for (let b = from; b < to; b++) if (Number.isNaN(extreme) || better(values[b]!, extreme)) keep(values[b]!, b);\n if (Number.isNaN(extreme) || better(value, extreme)) keep(value, i);\n }\n } else if (length < prevLength || Number.isNaN(extreme) || i - extremeAt >= length) rescan(i, length);\n else if (better(value, extreme)) keep(value, i);\n prevLength = length;\n return i < length - 1 ? NaN : extreme;\n };\n}\n\n/**\n * One `ta.lowest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`.\n *\n * PineScript rules (measured with a length that changes on each bar):\n * - the extreme is kept with its bar; a new value that passes it replaces it; when the kept extreme is `length`\n * calls old, the last `length` values are scanned again (na skipped, the oldest wins a tie)\n * - a length smaller than on the previous call: the last `length` values are scanned again\n * - a length larger than on the previous call: the values that enter the window at its old end are compared with the\n * extreme; when one of them is na, the extreme restarts from the current value (the values in between are not read)\n * - an na value gives na and resets the extreme; na before call `length - 1`\n *\n * @example\n * ```typescript\n * // Pine: lowPrice = ta.lowest(close[1], lookback) // lookback changes per bar\n * const lowPrice = callsite.lowest();\n * const out = closes.map((_, i) => lowPrice(i > 0 ? closes[i - 1]! : NaN, lookback[i]!));\n * ```\n */\nexport function lowest(): (value: number, length: number) => number {\n return extremeSite(true);\n}\n\n/**\n * One `ta.highest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`. Same rules as {@link lowest}.\n */\nexport function highest(): (value: number, length: number) => number {\n return extremeSite(false);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDO,SAAS,WACd,QACA,OACG,SACgB;AACnB,QAAM,OAAiB,CAAC;AACxB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,IAAK,KAAI,OAAO,CAAC,EAAG,MAAK,KAAK,CAAC;AAClE,QAAM,SAAS,G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verview Per-call history of ta.* functions called in a conditional block.\n *\n * In PineScript, every ta.* call keeps its own history of the values it receives. A call inside\n * an `if` block receives values only on the bars where the block runs, so its history skips the\n * other bars: `ta.crossover(a, b)` is false on the first bar the block runs, and `ta.sma(x, 3)`\n * averages the last 3 values it received, not the last 3 bars.\n *\n * - {@link whenCalled}: vectorized, when the bars of the calls are known in advance.\n * - {@link crossover} / {@link crossunder} / {@link cross} / {@link barssince}: one stateful call site for bar\n * loops, called only on the bars where the Pine call runs.\n * - {@link lowest} / {@link highest}: `ta.lowest` / `ta.highest` with a series length (a different length on each\n * call), which PineScript computes with a state kept between calls.\n * - {@link lowestByBar} / {@link highestByBar} / {@link linreg}: `ta.lowest` / `ta.highest` / `ta.linreg` in a\n * conditional block, whose history is kept by bar (not by call).\n *\n * Since PineScript v6, `and` / `or` are lazy: the right operand runs only when the left operand does not decide\n * the result. A ta.* call in the right operand of `a or b` runs on the bars where `a` is false, in `a and b` on the\n * bars where `a` is true, so it needs a call site too:\n *\n * ```typescript\n * // Pine: longCond = longUp or (src > sig and ta.barssince(longUp) <= lookback)\n * const since = callsite.whenCalled(longUp.map((u, i) => !u && src[i] > sig[i]), (c) => taCore.barssince(c.map(Boolean)), longUp);\n * // ta.barssince(longUp) only runs where longUp is false: it never sees true and stays na\n * ```\n *\n * ```typescript\n * // Pine: if inRange\n * // buy = ta.crossover(cumRsi, 60)\n * const buy = callsite.whenCalled(inRange, (a) => taCore.crossover(a, a.map(() => 60)), cumRsi);\n *\n * // Same call in a bar loop\n * const buyCross = callsite.crossover();\n * for (let i = 0; i < n; i++) {\n * if (inRange[i]) {\n * const buy = buyCross(cumRsi[i], 60);\n * }\n * }\n * ```\n *\n * @module callsite\n */\n\nimport type { Source } from '../types/index.js';\nimport { linreg as linregSeries } from '../ta/index.js';\n\n/**\n * Runs `fn` on the bars where `called` is true only, like a ta.* call inside an `if` block.\n * `fn` receives the values of `sources` on those bars, in order; its results are placed back on\n * the same bars. The other bars get na (NaN).\n *\n * @param called - true (or non-zero) on the bars where the call runs\n * @param fn - the calculation, for example `(x) => taCore.sma(x, 3)`\n * @param sources - the arguments of the call, one value per chart bar\n */\nexport function whenCalled<T extends number | boolean>(\n called: ArrayLike<boolean | number>,\n fn: (...values: number[][]) => ArrayLike<T>,\n ...sources: Source[]\n): Array<T | number> {\n const bars: number[] = [];\n for (let i = 0; i < called.length; i++) if (called[i]) bars.push(i);\n const result = fn(...sources.map(s => bars.map(i => s[i] ?? NaN)));\n const out = new Array<T | number>(called.length).fill(NaN);\n bars.forEach((bar, k) => {\n out[bar] = result[k]!;\n });\n return out;\n}\n\n/**\n * A call site that keeps the arguments of the last call where both were not na (na before such a call), as\n * ta.crossover / ta.crossunder / ta.cross.\n */\nfunction twoSeriesSite(test: (a: number, b: number, prevA: number, prevB: number) => boolean) {\n let prevA = NaN;\n let prevB = NaN;\n return (a: number, b: number): boolean => {\n const result = test(a, b, prevA, prevB);\n if (!Number.isNaN(a) && !Number.isNaN(b)) {\n prevA = a;\n prevB = b;\n }\n return result;\n };\n}\n\n/**\n * One `ta.crossover(a, b)` call site: compared with the last call where both arguments were not na; false before\n * such a call.\n */\nexport function crossover(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a > b && pa <= pb);\n}\n\n/**\n * One `ta.crossunder(a, b)` call site: compared with the last call where both arguments were not na; false before\n * such a call.\n */\nexport function crossunder(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a < b && pa >= pb);\n}\n\n/**\n * One `ta.barssince(condition)` call site: the number of calls since the condition was true on a call (0 on that\n * call), na before the first true condition. An na condition counts as false.\n */\nexport function barssince(): (condition: boolean | number) => number {\n let count = NaN;\n return (condition) => {\n if (condition && !Number.isNaN(condition)) count = 0;\n else if (!Number.isNaN(count)) count++;\n return count;\n };\n}\n\n/**\n * One `ta.cross(a, b)` call site: compared with the last call where both arguments were not na; false before such\n * a call.\n */\nexport function cross(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => (a > b && pa <= pb) || (a < b && pa >= pb));\n}\n\n/** One `ta.lowest` / `ta.highest` call site with a series length; rules in {@link lowest}. */\nfunction extremeSite(isLowest: boolean): (value: number, length: number) => number {\n const better = isLowest ? (a: number, b: number) => a < b : (a: number, b: number) => a > b;\n const values: number[] = [];\n let extreme = NaN;\n let extremeAt = -1;\n let prevLength = NaN;\n const keep = (v: number, at: number) => {\n extreme = v;\n extremeAt = at;\n };\n const rescan = (i: number, length: number) => {\n extreme = NaN;\n for (let b = i; b > i - length && b >= 0; b--) {\n const v = values[b]!;\n if (!Number.isNaN(v) && (Number.isNaN(extreme) || !better(extreme, v))) keep(v, b);\n }\n };\n return (value, length) => {\n const i = values.length;\n values.push(value);\n if (Number.isNaN(value)) {\n extreme = NaN;\n prevLength = length;\n return NaN;\n }\n if (length > prevLength) {\n const from = Math.max(0, i - length + 1);\n const to = Math.max(0, i - prevLength + 1);\n if (values.slice(from, to).some(Number.isNaN)) keep(value, i);\n else {\n for (let b = from; b < to; b++) if (Number.isNaN(extreme) || better(values[b]!, extreme)) keep(values[b]!, b);\n if (Number.isNaN(extreme) || better(value, extreme)) keep(value, i);\n }\n } else if (length < prevLength || Number.isNaN(extreme) || i - extremeAt >= length) rescan(i, length);\n else if (better(value, extreme)) keep(value, i);\n prevLength = length;\n return i < length - 1 ? NaN : extreme;\n };\n}\n\n/**\n * One `ta.lowest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`.\n *\n * PineScript rules (measured with a length that changes on each bar):\n * - the extreme is kept with its bar; a new value that passes it replaces it; when the kept extreme is `length`\n * calls old, the last `length` values are scanned again (na skipped, the oldest wins a tie)\n * - a length smaller than on the previous call: the last `length` values are scanned again\n * - a length larger than on the previous call: the values that enter the window at its old end are compared with the\n * extreme; when one of them is na, the extreme restarts from the current value (the values in between are not read)\n * - an na value gives na and resets the extreme; na before call `length - 1`\n *\n * @example\n * ```typescript\n * // Pine: lowPrice = ta.lowest(close[1], lookback) // lookback changes per bar\n * const lowPrice = callsite.lowest();\n * const out = closes.map((_, i) => lowPrice(i > 0 ? closes[i - 1]! : NaN, lookback[i]!));\n * ```\n */\nexport function lowest(): (value: number, length: number) => number {\n return extremeSite(true);\n}\n\n/**\n * One `ta.highest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`. Same rules as {@link lowest}.\n */\nexport function highest(): (value: number, length: number) => number {\n return extremeSite(false);\n}\n\n/** One `ta.lowest` / `ta.highest` call site whose history is kept by bar; rules in {@link lowestByBar}. */\nfunction extremeByBarSite(isLowest: boolean): (barIndex: number, value: number, length: number) => number {\n const better = isLowest ? (a: number, b: number) => a < b : (a: number, b: number) => a > b;\n let ring: number[] = [];\n let extreme = NaN;\n let extremeAt = -1;\n return (barIndex, value, length) => {\n const len = Math.floor(length);\n if (ring.length !== len + 1) {\n ring = new Array<number>(len + 1).fill(0);\n extreme = NaN;\n }\n ring[barIndex % (len + 1)] = value;\n if (Number.isNaN(extreme) || better(value, extreme)) {\n extreme = value;\n extremeAt = barIndex;\n } else if (barIndex - extremeAt >= len) {\n extreme = NaN;\n for (let b = barIndex - len + 1; b <= barIndex; b++) {\n const v = ring[b % (len + 1)]!;\n if (!Number.isNaN(v) && (Number.isNaN(extreme) || better(v, extreme))) {\n extreme = v;\n extremeAt = b;\n }\n }\n }\n return barIndex < len - 1 ? NaN : extreme;\n };\n}\n\n/**\n * One `ta.lowest(source, length)` call site in a conditional block whose history is kept by bar (not by call), called\n * with `(barIndex, value, length)` on the bars where the Pine call runs.\n *\n * PineScript rules (measured on a call in a ternary branch, length 6):\n * - the values are kept in a ring of `length + 1` slots indexed by the bar index, filled with 0 at the start and\n * written only on the bars where the call runs: a bar before the first call counts as 0, and a bar without a call\n * holds the value of the call `length + 1` bars earlier (0 if there was none)\n * - on a call, the value replaces the kept extreme when there is none or when it is strictly lower; only otherwise,\n * when the kept extreme is `length` bars old, the last `length` bars are read again from the ring (the oldest bar\n * wins a tie)\n * - na before bar `length - 1` (by bar, not by call)\n *\n * {@link lowest} keeps the history by call instead; both rules were measured, on different scripts.\n *\n * @example\n * ```typescript\n * // Pine: lo = cond ? ta.lowest(low, 6) : na\n * const site = callsite.lowestByBar();\n * const lo = lows.map((v, i) => (cond[i] ? site(i, v, 6) : NaN));\n * ```\n */\nexport function lowestByBar(): (barIndex: number, value: number, length: number) => number {\n return extremeByBarSite(true);\n}\n\n/**\n * One `ta.highest(source, length)` call site in a conditional block whose history is kept by bar, called with\n * `(barIndex, value, length)`. Same rules as {@link lowestByBar} (a value replaces the kept extreme when it is\n * strictly higher).\n */\nexport function highestByBar(): (barIndex: number, value: number, length: number) => number {\n return extremeByBarSite(false);\n}\n\n/**\n * One `ta.linreg(source, length, offset)` call site in a conditional block, called with\n * `(barIndex, value, length, offset)` on the bars where the Pine call runs.\n *\n * PineScript rules (measured): `ta.linreg` keeps the values it receives in a ring of `length + 1` slots indexed by the\n * bar index, filled with 0 at the start and written only on the bars where it is called. The window is read from the\n * ring for the last `length` bars: a bar before the first call counts as 0, and a bar without a call holds the value of\n * the call `length + 1` bars earlier (0 if there was none). The result is na before bar `length - 1`. Called on every\n * bar, it equals `ta.linreg`.\n *\n * @example\n * ```typescript\n * // Pine: if bar_index >= 20\n * // a := ta.linreg(close, 10, 0)\n * const site = callsite.linreg();\n * const a = closes.map((c, i) => (i >= 20 ? site(i, c, 10, 0) : NaN));\n * ```\n */\nexport function linreg(): (barIndex: number, value: number, length: number, offset?: number) => number {\n let ring: number[] = [];\n return (barIndex, value, length, offset = 0) => {\n const len = Math.floor(length);\n if (ring.length !== len + 1) ring = new Array<number>(len + 1).fill(0);\n ring[barIndex % (len + 1)] = value;\n if (barIndex < len - 1) return NaN;\n const window = Array.from({ length: len }, (_, k) => ring[(barIndex - len + 1 + k) % (len + 1)]!);\n return linregSeries(window, len, offset)[len - 1]!;\n };\n}\n\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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ACtB,SAAO,CAAC,UAAU,OAAO,QAAQ,SAAS,MAAM;AAC9C,UAAM,MAAM,KAAK,MAAM,MAAM;AAC7B,QAAI,KAAK,WAAW,MAAM,EAAG,QAAO,IAAI,MAAc,MAAM,CAAC,EAAE,KAAK,CAAC;AACrE,SAAK,YAAY,MAAM,EAAE,IAAI;AAC7B,QAAI,WAAW,MAAM,EAAG,QAAO;AAC/B,UAAM,SAAS,MAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,CAAC,GAAG,MAAM,MAAM,WAAW,MAAM,IAAI,MAAM,MAAM,EAAE,CAAE;AAChG,eAAO,UAAAA,QAAa,QAAQ,KAAK,MAAM,EAAE,MAAM,CAAC;AAAA,EAClD;AACF;",
6
+ "names": ["linregSeries"]
7
7
  }
@@ -54,7 +54,7 @@ export type * from './strategy/index.js';
54
54
  export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
55
55
  export type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';
56
56
  export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
57
- export declare const VERSION = "0.9.3";
57
+ export declare const VERSION = "0.9.5";
58
58
  /**
59
59
  * Library information
60
60
  */
package/dist/cjs/index.js CHANGED
@@ -160,7 +160,7 @@ var import_inputs = require("./runtime/inputs.js");
160
160
  var import_strategy = require("./strategy/index.js");
161
161
  var import_LightweightChartsAdapter = require("./runtime/adapters/LightweightChartsAdapter.js");
162
162
  var import_SimpleInputAdapter = require("./runtime/adapters/SimpleInputAdapter.js");
163
- const VERSION = "0.9.3";
163
+ const VERSION = "0.9.5";
164
164
  const info = {
165
165
  name: "OakScriptJS",
166
166
  version: VERSION,