oakscriptjs 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/bin/oakscript.mjs +10 -3
- package/dist/cjs/box/index.d.ts +348 -289
- package/dist/cjs/box/index.d.ts.map +1 -1
- package/dist/cjs/box/index.js.map +2 -2
- package/dist/cjs/check/node.d.ts.map +1 -1
- package/dist/cjs/check/node.js +1 -0
- package/dist/cjs/check/node.js.map +2 -2
- package/dist/cjs/check/preview.d.ts +31 -0
- package/dist/cjs/check/preview.d.ts.map +1 -0
- package/dist/cjs/check/preview.js +303 -0
- package/dist/cjs/check/preview.js.map +7 -0
- package/dist/cjs/color/index.d.ts +11 -11
- package/dist/cjs/color/index.js.map +1 -1
- package/dist/cjs/color/parse.d.ts +2 -0
- package/dist/cjs/color/parse.d.ts.map +1 -1
- package/dist/cjs/color/parse.js +6 -0
- package/dist/cjs/color/parse.js.map +2 -2
- package/dist/cjs/compare/index.d.ts +76 -12
- package/dist/cjs/compare/index.d.ts.map +1 -1
- package/dist/cjs/compare/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +28 -5
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +14 -0
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/label/index.d.ts +265 -187
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +1 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/line/index.d.ts +247 -207
- package/dist/cjs/line/index.d.ts.map +1 -1
- package/dist/cjs/line/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts +61 -89
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +49 -40
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts +57 -78
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/input-active.d.ts +2 -2
- package/dist/cjs/runtime/input-active.js.map +1 -1
- package/dist/cjs/runtime/series.d.ts +241 -161
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +223 -127
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/api/alert.d.ts +37 -0
- package/dist/cjs/script/api/alert.d.ts.map +1 -0
- package/dist/cjs/script/api/alert.js +17 -0
- package/dist/cjs/script/api/alert.js.map +7 -0
- package/dist/cjs/script/api/calc.d.ts +232 -0
- package/dist/cjs/script/api/calc.d.ts.map +1 -0
- package/dist/cjs/script/api/calc.js +17 -0
- package/dist/cjs/script/api/calc.js.map +7 -0
- package/dist/cjs/script/api/color.d.ts +213 -0
- package/dist/cjs/script/api/color.d.ts.map +1 -0
- package/dist/cjs/script/api/color.js +17 -0
- package/dist/cjs/script/api/color.js.map +7 -0
- package/dist/cjs/script/api/context.d.ts +764 -0
- package/dist/cjs/script/api/context.d.ts.map +1 -0
- package/dist/cjs/script/api/context.js +17 -0
- package/dist/cjs/script/api/context.js.map +7 -0
- package/dist/cjs/script/api/log.d.ts +58 -0
- package/dist/cjs/script/api/log.d.ts.map +1 -0
- package/dist/cjs/script/api/log.js +17 -0
- package/dist/cjs/script/api/log.js.map +7 -0
- package/dist/cjs/script/api/strategy.d.ts +391 -0
- package/dist/cjs/script/api/strategy.d.ts.map +1 -0
- package/dist/cjs/script/api/strategy.js +17 -0
- package/dist/cjs/script/api/strategy.js.map +7 -0
- package/dist/cjs/script/api/ta.d.ts +1012 -0
- package/dist/cjs/script/api/ta.d.ts.map +1 -0
- package/dist/cjs/script/api/ta.js +17 -0
- package/dist/cjs/script/api/ta.js.map +7 -0
- package/dist/cjs/script/api/table.d.ts +479 -0
- package/dist/cjs/script/api/table.d.ts.map +1 -0
- package/dist/cjs/script/api/table.js +17 -0
- package/dist/cjs/script/api/table.js.map +7 -0
- package/dist/cjs/script/constants.d.ts +228 -83
- package/dist/cjs/script/constants.d.ts.map +1 -1
- package/dist/cjs/script/constants.js +87 -0
- package/dist/cjs/script/constants.js.map +2 -2
- package/dist/cjs/script/define.d.ts +94 -0
- package/dist/cjs/script/define.d.ts.map +1 -0
- package/dist/cjs/script/define.js +127 -0
- package/dist/cjs/script/define.js.map +7 -0
- package/dist/cjs/script/drawing-args.d.ts.map +1 -1
- package/dist/cjs/script/drawing-args.js +1 -1
- package/dist/cjs/script/drawing-args.js.map +2 -2
- package/dist/cjs/script/formula.d.ts +53 -0
- package/dist/cjs/script/formula.d.ts.map +1 -0
- package/dist/cjs/script/formula.js +402 -0
- package/dist/cjs/script/formula.js.map +7 -0
- package/dist/cjs/script/globals.d.ts +10 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/index.d.ts +1065 -1006
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +530 -60
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/script/json.d.ts +117 -0
- package/dist/cjs/script/json.d.ts.map +1 -0
- package/dist/cjs/script/json.js +321 -0
- package/dist/cjs/script/json.js.map +7 -0
- package/dist/cjs/str/index.d.ts +50 -75
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +2 -2
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/strategy/index.d.ts +102 -1
- package/dist/cjs/strategy/index.d.ts.map +1 -1
- package/dist/cjs/strategy/index.js.map +2 -2
- package/dist/cjs/table/index.d.ts +330 -49
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +55 -27
- package/dist/cjs/table/index.js.map +2 -2
- package/dist/cjs/text/index.d.ts +12 -14
- package/dist/cjs/text/index.d.ts.map +1 -1
- package/dist/cjs/text/index.js.map +2 -2
- package/dist/cjs/types/index.d.ts +15 -8
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +12 -3
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/esm/box/index.d.ts +348 -289
- package/dist/esm/box/index.d.ts.map +1 -1
- package/dist/esm/box/index.js +276 -276
- package/dist/esm/box/index.js.map +1 -1
- package/dist/esm/check/node.d.ts.map +1 -1
- package/dist/esm/check/node.js +1 -0
- package/dist/esm/check/node.js.map +1 -1
- package/dist/esm/check/preview.d.ts +31 -0
- package/dist/esm/check/preview.d.ts.map +1 -0
- package/dist/esm/check/preview.js +296 -0
- package/dist/esm/check/preview.js.map +1 -0
- package/dist/esm/color/index.d.ts +11 -11
- package/dist/esm/color/index.js +11 -11
- package/dist/esm/color/parse.d.ts +2 -0
- package/dist/esm/color/parse.d.ts.map +1 -1
- package/dist/esm/color/parse.js +7 -0
- package/dist/esm/color/parse.js.map +1 -1
- package/dist/esm/compare/index.d.ts +76 -12
- package/dist/esm/compare/index.d.ts.map +1 -1
- package/dist/esm/compare/index.js +76 -12
- package/dist/esm/compare/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +28 -5
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +39 -3
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/label/index.d.ts +265 -187
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +207 -177
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/line/index.d.ts +247 -207
- package/dist/esm/line/index.d.ts.map +1 -1
- package/dist/esm/line/index.js +202 -194
- package/dist/esm/line/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts +61 -89
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +61 -89
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +49 -40
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +22 -9
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts +57 -78
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +57 -78
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/input-active.d.ts +2 -2
- package/dist/esm/runtime/input-active.js +2 -2
- package/dist/esm/runtime/series.d.ts +241 -161
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +241 -161
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/api/alert.d.ts +37 -0
- package/dist/esm/script/api/alert.d.ts.map +1 -0
- package/dist/esm/script/api/alert.js +7 -0
- package/dist/esm/script/api/alert.js.map +1 -0
- package/dist/esm/script/api/calc.d.ts +232 -0
- package/dist/esm/script/api/calc.d.ts.map +1 -0
- package/dist/esm/script/api/calc.js +6 -0
- package/dist/esm/script/api/calc.js.map +1 -0
- package/dist/esm/script/api/color.d.ts +213 -0
- package/dist/esm/script/api/color.d.ts.map +1 -0
- package/dist/esm/script/api/color.js +6 -0
- package/dist/esm/script/api/color.js.map +1 -0
- package/dist/esm/script/api/context.d.ts +764 -0
- package/dist/esm/script/api/context.d.ts.map +1 -0
- package/dist/esm/script/api/context.js +7 -0
- package/dist/esm/script/api/context.js.map +1 -0
- package/dist/esm/script/api/log.d.ts +58 -0
- package/dist/esm/script/api/log.d.ts.map +1 -0
- package/dist/esm/script/api/log.js +6 -0
- package/dist/esm/script/api/log.js.map +1 -0
- package/dist/esm/script/api/strategy.d.ts +391 -0
- package/dist/esm/script/api/strategy.d.ts.map +1 -0
- package/dist/esm/script/api/strategy.js +7 -0
- package/dist/esm/script/api/strategy.js.map +1 -0
- package/dist/esm/script/api/ta.d.ts +1012 -0
- package/dist/esm/script/api/ta.d.ts.map +1 -0
- package/dist/esm/script/api/ta.js +6 -0
- package/dist/esm/script/api/ta.js.map +1 -0
- package/dist/esm/script/api/table.d.ts +479 -0
- package/dist/esm/script/api/table.d.ts.map +1 -0
- package/dist/esm/script/api/table.js +7 -0
- package/dist/esm/script/api/table.js.map +1 -0
- package/dist/esm/script/constants.d.ts +228 -83
- package/dist/esm/script/constants.d.ts.map +1 -1
- package/dist/esm/script/constants.js +110 -24
- package/dist/esm/script/constants.js.map +1 -1
- package/dist/esm/script/define.d.ts +94 -0
- package/dist/esm/script/define.d.ts.map +1 -0
- package/dist/esm/script/define.js +136 -0
- package/dist/esm/script/define.js.map +1 -0
- package/dist/esm/script/drawing-args.d.ts.map +1 -1
- package/dist/esm/script/drawing-args.js +2 -1
- package/dist/esm/script/drawing-args.js.map +1 -1
- package/dist/esm/script/formula.d.ts +53 -0
- package/dist/esm/script/formula.d.ts.map +1 -0
- package/dist/esm/script/formula.js +408 -0
- package/dist/esm/script/formula.js.map +1 -0
- package/dist/esm/script/globals.d.ts +10 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/index.d.ts +1065 -1006
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +1096 -151
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/script/json.d.ts +117 -0
- package/dist/esm/script/json.d.ts.map +1 -0
- package/dist/esm/script/json.js +375 -0
- package/dist/esm/script/json.js.map +1 -0
- package/dist/esm/str/index.d.ts +50 -75
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +51 -76
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/strategy/index.d.ts +102 -1
- package/dist/esm/strategy/index.d.ts.map +1 -1
- package/dist/esm/strategy/index.js +1 -1
- package/dist/esm/strategy/index.js.map +1 -1
- package/dist/esm/table/index.d.ts +330 -49
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +372 -61
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/text/index.d.ts +12 -14
- package/dist/esm/text/index.d.ts.map +1 -1
- package/dist/esm/text/index.js +12 -14
- package/dist/esm/text/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +15 -8
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +15 -8
- package/dist/esm/types/index.js.map +1 -1
- package/docs/first-indicator.md +152 -0
- package/docs/guide.md +1185 -0
- package/docs/inventory.md +772 -0
- package/docs/no-code.md +207 -0
- package/docs/recipes.md +202 -0
- package/package.json +2 -1
- package/skills/oakscript/SKILL.md +8 -0
- package/skills/oakscript/reference/errors.md +3 -2
- package/src/box/index.ts +348 -289
- package/src/check/node.ts +1 -0
- package/src/check/preview.ts +307 -0
- package/src/color/index.ts +11 -11
- package/src/color/parse.ts +7 -0
- package/src/compare/index.ts +76 -12
- package/src/drawing/registry.ts +44 -5
- package/src/index.ts +1 -1
- package/src/label/index.ts +267 -189
- package/src/line/index.ts +248 -208
- package/src/linefill/index.ts +61 -89
- package/src/math/index.ts +51 -42
- package/src/polyline/index.ts +57 -78
- package/src/runtime/input-active.ts +2 -2
- package/src/runtime/series.ts +243 -163
- package/src/script/api/alert.ts +43 -0
- package/src/script/api/calc.ts +250 -0
- package/src/script/api/color.ts +245 -0
- package/src/script/api/context.ts +944 -0
- package/src/script/api/log.ts +60 -0
- package/src/script/api/strategy.ts +410 -0
- package/src/script/api/ta.ts +1115 -0
- package/src/script/api/table.ts +538 -0
- package/src/script/constants.ts +229 -25
- package/src/script/define.ts +221 -0
- package/src/script/drawing-args.ts +2 -1
- package/src/script/formula.ts +438 -0
- package/src/script/globals.ts +10 -0
- package/src/script/index.ts +1517 -239
- package/src/script/json.ts +457 -0
- package/src/str/index.ts +51 -76
- package/src/strategy/index.ts +102 -1
- package/src/table/index.ts +388 -62
- package/src/text/index.ts +12 -14
- package/src/types/index.ts +15 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":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K,KAAK,CAAC,CAE7E;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC,GAAG,IAAI,CAG3F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,KAAK,CAclE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;AAC5C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC;AAmBxC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;AAC1E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;AA2ExE,oFAAoF;AACpF,eAAO,MAAM,EAAE,QAAU,CAAC;AAC1B,wFAAwF;AACxF,eAAO,MAAM,CAAC,QAAS,CAAC;AACxB,2CAA2C;AAC3C,eAAO,MAAM,GAAG,oBAAoB,CAAC;AACrC,wEAAwE;AACxE,eAAO,MAAM,IAAI,qBAAqB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/math/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Math namespace\n * Mirrors PineScript's math.* functions for mathematical operations and calculations.\n *\n * @remarks\n * All math functions in this namespace follow PineScript v6 API specifications.\n * Functions include basic arithmetic, algebraic operations, trigonometry, and combinatorics.\n *\n * Known difference: `log10`, `exp`, `log`, `pow`, `sin`, `cos`, `tan` use JavaScript's `Math`. PineScript uses\n * other algorithms, whose results differ by 1 or 2 units in the last place on part of the inputs (`log10` about 4 %,\n * `exp` about 9 %, `sin` / `cos` / `tan` about 3 %, `log` 0.4 %, `pow` 0.05 % of random inputs). This is visible\n * only when a script amplifies these tiny differences (e.g. `ma > ma[1]` on values of 1e195); `sqrt`, `atan`,\n * `asin`, `acos` are equal. A constant argument (`math.log10(2)`) is computed before the script runs, with other\n * rules: see `constant`.\n *\n * @version 6\n */\n\nimport type { float, int, simple_int, series_float } from '../types/index.js';\nimport { Series } from '../runtime/series.js';\nimport { runningSum, runningSumSeries } from '../ta/running-sum.js';\nimport { checkSumLength } from '../ta/limits.js';\n\n/**\n * Returns the absolute value of a number.\n *\n * @param value - The number or Series\n * @returns The absolute value (always non-negative)\n *\n * @remarks\n * - Returns the distance from zero on the number line\n * - |x| = x if x \u2265 0, -x if x < 0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.abs(5) // Returns: 5\n * math.abs(-5) // Returns: 5\n * math.abs(0) // Returns: 0\n * ```\n */\nexport function abs(value: Series): Series;\nexport function abs(value: float): float;\nexport function abs(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.abs(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.abs(value);\n}\n\n/**\n * Returns the smallest integer greater than or equal to a given number (rounds up).\n *\n * @param value - The number to round up or Series\n * @returns The ceiling value (smallest integer \u2265 value)\n *\n * @remarks\n * - Always rounds towards positive infinity\n * - For positive numbers, rounds away from zero\n * - For negative numbers, rounds towards zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.ceil(4.2) // Returns: 5\n * math.ceil(4.8) // Returns: 5\n * math.ceil(-4.2) // Returns: -4\n * math.ceil(5) // Returns: 5\n * ```\n */\nexport function ceil(value: Series): Series;\nexport function ceil(value: float): int;\nexport function ceil(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.ceil(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.ceil(value);\n}\n\n/**\n * Returns the largest integer less than or equal to a given number (rounds down).\n *\n * @param value - The number to round down or Series\n * @returns The floor value (largest integer \u2264 value)\n *\n * @remarks\n * - Always rounds towards negative infinity\n * - For positive numbers, rounds towards zero\n * - For negative numbers, rounds away from zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.floor(4.2) // Returns: 4\n * math.floor(4.8) // Returns: 4\n * math.floor(-4.2) // Returns: -5\n * math.floor(5) // Returns: 5\n * ```\n */\nexport function floor(value: Series): Series;\nexport function floor(value: float): int;\nexport function floor(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.floor(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.floor(value);\n}\n\n/**\n * Returns the value rounded to the nearest integer or to a specified precision.\n *\n * @param value - The number to round or Series\n * @param precision - Optional number of decimal places (default: 0)\n * @returns The rounded value\n *\n * @remarks\n * - Rounds to nearest integer by default\n * - With precision, rounds to that many decimal places\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * PineScript rules:\n * - ties go away from zero (2.5 -> 3, -2.5 -> -3, -0.5 -> -1)\n * - without a precision, or with a precision <= 0, the result is the integer rounding (1234.5678 @ -2 -> 1235)\n * - a positive precision rounds only the fraction: `int + round(frac * scale) / scale` with\n * `scale = 1 / 10^-precision` (precision above 16 acts as 16); the tie is decided on the exact value of\n * `frac * scale` with a 1e-10 tolerance (1.005 @ 2 -> 1.01, 0.285 @ 2 -> 0.29, -1.45 @ 1 -> -1.5)\n * - an infinite value gives na\n *\n * @example\n * ```typescript\n * math.round(4.2) // Returns: 4\n * math.round(4.5) // Returns: 5\n * math.round(-2.5) // Returns: -3\n * math.round(4.567, 2) // Returns: 4.57\n * math.round(1.005, 2) // Returns: 1.01\n * ```\n */\nexport function round(value: Series, precision?: int): Series;\nexport function round(value: float, precision?: int): float;\nexport function round(value: float | Series, precision?: int): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundValue(valueArray[i] ?? NaN, precision));\n }\n return Series.fromArray(bars, result);\n }\n return roundValue(value, precision);\n}\n\n/** `0.5 - 1e-10` as the exact fraction TIE_HALF / TIE_SCALE: the tie threshold of round / round_to_mintick. */\nconst TIE_SCALE = 10n ** 10n;\nconst TIE_HALF = 5n * 10n ** 9n - 1n;\n/** From 2^52 up every double is an integer. */\nconst INT_LIMIT = 2 ** 52;\n\n/** Exact value of a finite double >= 0 as `[numerator, denominator]`. */\nfunction exactRatio(x: number): [bigint, bigint] {\n const view = new DataView(new ArrayBuffer(8));\n view.setFloat64(0, x);\n const hi = view.getUint32(0);\n const lo = view.getUint32(4);\n const expField = (hi >>> 20) & 0x7ff;\n let mantissa = (BigInt(hi & 0xfffff) << 32n) | BigInt(lo);\n let exp = -1074;\n if (expField !== 0) {\n mantissa |= 1n << 52n;\n exp = expField - 1075;\n }\n return exp >= 0 ? [mantissa << BigInt(exp), 1n] : [mantissa, 1n << BigInt(-exp)];\n}\n\n/** True when `num / den - units` (exact) is >= 0.5 - 1e-10. */\nfunction reachesTie(num: bigint, den: bigint, units: bigint): boolean {\n return (num - units * den) * TIE_SCALE >= TIE_HALF * den;\n}\n\n/** `10^-p`: the exact literal for an integer p (correctly rounded), Math.pow otherwise. */\nfunction tenToMinus(p: number): number {\n return Number.isInteger(p) ? Number(`1e-${p}`) : Math.pow(10, -p);\n}\n\n/** PineScript math.round of one value (see `round`). */\nfunction roundValue(value: number, precision?: number): number {\n if (!Number.isFinite(value)) return NaN;\n const negative = value < 0;\n const magnitude = negative ? -value : value;\n if (precision === undefined || Number.isNaN(precision) || precision <= 0) {\n if (magnitude >= INT_LIMIT) return value;\n let units = Math.floor(magnitude);\n if (magnitude - units >= 0.5) units++;\n return negative ? 0 - units : units;\n }\n const scale = 1 / tenToMinus(Math.min(precision, 16));\n const fraction = magnitude % 1;\n const scaled = fraction * scale;\n let units = Math.floor(scaled);\n const offset = scaled - units - 0.5;\n // Only a near-tie needs the exact product; the window covers the double's own error.\n const slack = 1e-9 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [fn, fd] = exactRatio(fraction);\n const [sn, sd] = exactRatio(scale);\n if (reachesTie(fn * sn, fd * sd, BigInt(units))) units++;\n } else if (offset > 0) {\n units++;\n }\n const result = magnitude - fraction + units / scale;\n return negative ? 0 - result : result;\n}\n\n/** 10^16: a constant keeps 16 decimals. */\nconst CONSTANT_SCALE = 10n ** 16n;\n\n/**\n * Returns the value PineScript gives to a constant float expression (not a PineScript function).\n *\n * @param value - The result of the constant expression, computed in JavaScript (e.g. `1 / 255`)\n * @returns The value of the same expression in a PineScript script\n *\n * @remarks\n * PineScript computes a constant expression (only literals and constants: `1 / 255`, `0.1 * 3`,\n * `math.sqrt(0.1)`) before the script runs, and the value is then rounded. JavaScript cannot tell a constant from a\n * series value, so wrap the constant expressions of a script with this function.\n * - |value| >= 0.001: the exact value of the double is rounded to 16 decimals, ties to even\n * (`1 / 255` -> 0.003921568627451, `1 / 7` -> 0.1428571428571428)\n * - |value| < 0.001, na and infinities: unchanged\n * - the whole expression is computed first, then rounded once (`(1 / 7) * 7` is 1)\n * - math functions of constants use JavaScript's `Math` there: `math.constant(math.sqrt(0.1))` is the PineScript\n * value; `math.log10` of a constant is `math.log(x) / math.log(10)` there:\n * `math.constant(math.log(2) / math.log(10))` -> 0.3010299956639811\n * - the same expression with a series operand (`close / 255`) is not rounded: do not wrap it\n *\n * @example\n * ```typescript\n * // Pine: var const float i_255 = 1 / 255\n * const i_255 = math.constant(1 / 255) // 0.003921568627451 (JavaScript: 0.00392156862745098)\n * math.constant(1 / 7) // 0.1428571428571428 (JavaScript: 0.14285714285714285)\n * math.constant(1 / 3) // 0.3333333333333333 (unchanged)\n * ```\n */\nexport function constant(value: float): float {\n const magnitude = Math.abs(value);\n // from 0.5 up, 16 decimals move a double by less than half its spacing: it stays the same\n if (!(magnitude >= 1e-3 && magnitude < 0.5)) return value;\n const [num, den] = exactRatio(magnitude);\n const scaled = num * CONSTANT_SCALE;\n let units = scaled / den;\n const twiceRest = (scaled - units * den) * 2n;\n if (twiceRest > den || (twiceRest === den && (units & 1n) === 1n)) units++;\n const digits = units.toString().padStart(17, '0');\n const result = Number(`${digits.slice(0, -16)}.${digits.slice(-16)}`);\n return value < 0 ? -result : result;\n}\n\n/**\n * Returns the maximum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The largest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns -Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```typescript\n * math.max(1, 2, 3) // Returns: 3\n * math.max(-1, -5, -2) // Returns: -1\n * math.max(10) // Returns: 10\n * math.max(5, 10, 3, 8) // Returns: 10\n * ```\n */\nexport function max(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.max\n return Math.max(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.max(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the minimum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The smallest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```typescript\n * math.min(1, 2, 3) // Returns: 1\n * math.min(-1, -5, -2) // Returns: -5\n * math.min(10) // Returns: 10\n * math.min(5, 10, 3, 8) // Returns: 3\n * ```\n */\nexport function min(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.min\n return Math.min(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.min(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the average (arithmetic mean) of the arguments.\n *\n * @param values - Variable number of values (numbers or Series)\n * @returns The arithmetic mean\n *\n * @remarks\n * - Calculates sum of all values divided by count\n * - Returns NaN if no arguments provided (division by zero)\n * - If any argument is a Series, returns a Series; otherwise returns a number\n * - PineScript rule: with 1 or 2 values the sum is plain; with 3 values or more it is a Kahan compensated sum whose\n * pending correction is subtracted before the division (math.avg(0.1, 0.2, 0.3) = 0.19999999999999998)\n *\n * @example\n * ```typescript\n * math.avg(1, 2, 3) // Returns: 2\n * math.avg(10, 20) // Returns: 15\n * math.avg(5) // Returns: 5\n * math.avg(1, 2, 3, 4, 5) // Returns: 3\n * ```\n */\nexport function avg(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n\n if (!hasSeries) {\n return avgOf(values as number[]);\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(avgOf(nums));\n }\n\n return Series.fromArray(bars, result);\n}\n\n/** PineScript math.avg of numbers: plain sum up to 2 values, Kahan sum with the correction flushed from 3. */\nfunction avgOf(nums: number[]): number {\n if (nums.length <= 2) {\n let sum = 0;\n for (const n of nums) sum = sum + n;\n return sum / nums.length;\n }\n let sum = 0;\n let c = 0;\n for (const n of nums) {\n const y = n - c;\n const t = sum + y;\n c = t - sum - y;\n sum = t;\n }\n return (sum - c) / nums.length;\n}\n\n/**\n * Returns the sum of values over a sliding window.\n *\n * @param source - Series of values or array\n * @param length - Window length for summation, or one length per bar (a series length: array or Series)\n * @returns Series or array with rolling sum values\n *\n * @remarks\n * - Calculates the sum of the last `length` non-`na` values at each point; an `na` value (also +/-Infinity) is\n * skipped and the bar keeps the previous result (as in PineScript)\n * - Returns NaN until `length` non-`na` values are available\n * - The correctly rounded sum of the window values (the exact sum, rounded once), as PineScript (#188)\n * - When passed a Series, returns a Series; when passed an array, returns an array\n * - With a series length, the window is the last `length` values of each bar. A bar with an `na` value\n * gives the sum of the last `length` earlier values\n *\n * @example\n * ```typescript\n * math.sum([1, 2, 3, 4, 5], 3) // Returns: [NaN, NaN, 6, 9, 12]\n * // Explanation: [NaN, NaN, 1+2+3, 2+3+4, 3+4+5]\n * ```\n */\nexport function sum(source: Series, length: simple_int | ArrayLike<number> | Series): Series;\nexport function sum(source: series_float, length: simple_int | ArrayLike<number> | Series): series_float;\nexport function sum(\n source: series_float | Series,\n length: simple_int | ArrayLike<number> | Series\n): series_float | Series {\n // Handle Series objects - extract to array first\n const sourceArray = source instanceof Series ? source.toArray() : source;\n if (typeof length === 'number') checkSumLength('math.sum', length, 0);\n // PineScript: the sum of the last `length` non-na values (also +/-Infinity skipped); an na bar keeps the previous\n // result. The correctly rounded window sum, bit for bit as PineScript (#188).\n const result: series_float =\n typeof length === 'number'\n ? runningSum(sourceArray, length)\n : runningSumSeries(sourceArray, length instanceof Series ? length.toArray() : length, 'math.sum');\n\n // If input was a Series, return a Series\n if (source instanceof Series) {\n return Series.fromArray(source.bars, result);\n }\n\n return result;\n}\n\n/**\n * Returns the square root of a number.\n *\n * @param value - The number (must be non-negative) or Series\n * @returns The square root (\u221Avalue)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - \u221Ax \u00D7 \u221Ax = x (for non-negative x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sqrt(9) // Returns: 3\n * math.sqrt(16) // Returns: 4\n * math.sqrt(2) // Returns: 1.414...\n * math.sqrt(0) // Returns: 0\n * ```\n */\nexport function sqrt(value: Series): Series;\nexport function sqrt(value: float): float;\nexport function sqrt(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sqrt(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sqrt(value);\n}\n\n/**\n * Returns base raised to the power of exponent.\n *\n * @param base - The base number or Series\n * @param exponent - The exponent (power) or Series\n * @returns base^exponent\n *\n * @remarks\n * - 0^0 returns 1\n * - Negative base with fractional exponent returns NaN\n * - Any number to the power of 0 equals 1\n * - If any argument is a Series, returns a Series; if all are numbers, returns a number\n *\n * @example\n * ```typescript\n * math.pow(2, 3) // Returns: 8 (2\u00B3)\n * math.pow(10, 2) // Returns: 100\n * math.pow(5, 0) // Returns: 1\n * math.pow(2, -1) // Returns: 0.5\n * ```\n */\nexport function pow(base: Series, exponent: float): Series;\nexport function pow(base: float, exponent: Series): Series;\nexport function pow(base: Series, exponent: Series): Series;\nexport function pow(base: float, exponent: float): float;\nexport function pow(base: float | Series, exponent: float | Series): float | Series {\n const baseIsSeries = base instanceof Series;\n const expIsSeries = exponent instanceof Series;\n \n // Pure scalar case\n if (!baseIsSeries && !expIsSeries) {\n return Math.pow(base as number, exponent as number);\n }\n \n // At least one is a Series - return a Series\n const bars = baseIsSeries ? (base as Series).bars : (exponent as Series).bars;\n const baseArray = baseIsSeries ? (base as Series).toArray() : null;\n const expArray = expIsSeries ? (exponent as Series).toArray() : null;\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const b = baseArray ? baseArray[i] ?? NaN : (base as number);\n const e = expArray ? expArray[i] ?? NaN : (exponent as number);\n result.push(Math.pow(b, e));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns e (Euler's number) raised to the power of value.\n *\n * @param value - The exponent or Series\n * @returns e^value (where e \u2248 2.71828)\n *\n * @remarks\n * - e^0 = 1\n * - e^1 = e \u2248 2.71828\n * - Inverse of ln(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.exp(0) // Returns: 1\n * math.exp(1) // Returns: 2.71828... (e)\n * math.exp(2) // Returns: 7.389...\n * math.exp(-1) // Returns: 0.3678...\n * ```\n */\nexport function exp(value: Series): Series;\nexport function exp(value: float): float;\nexport function exp(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.exp(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.exp(value);\n}\n\n/**\n * Returns the natural logarithm (base e) of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns ln(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - ln(e) = 1\n * - ln(1) = 0\n * - Inverse of exp(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.log(1) // Returns: 0\n * math.log(Math.E) // Returns: 1\n * math.log(10) // Returns: 2.302...\n * math.log(100) // Returns: 4.605...\n * ```\n */\nexport function log(value: Series): Series;\nexport function log(value: float): float;\nexport function log(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log(value);\n}\n\n/**\n * Returns the base-10 logarithm of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns log\u2081\u2080(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - log\u2081\u2080(10) = 1\n * - log\u2081\u2080(100) = 2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.log10(10) // Returns: 1\n * math.log10(100) // Returns: 2\n * math.log10(1000) // Returns: 3\n * math.log10(1) // Returns: 0\n * ```\n */\nexport function log10(value: Series): Series;\nexport function log10(value: float): float;\nexport function log10(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log10(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log10(value);\n}\n\n/**\n * Returns the sine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The sine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - sin(0) = 0\n * - sin(\u03C0/2) = 1\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sin(0) // Returns: 0\n * math.sin(Math.PI / 2) // Returns: 1\n * math.sin(Math.PI) // Returns: 0 (approximately)\n * math.sin(Math.PI / 6) // Returns: 0.5\n * ```\n */\nexport function sin(value: Series): Series;\nexport function sin(value: float): float;\nexport function sin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sin(value);\n}\n\n/**\n * Returns the cosine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The cosine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - cos(0) = 1\n * - cos(\u03C0/2) = 0\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.cos(0) // Returns: 1\n * math.cos(Math.PI / 2) // Returns: 0 (approximately)\n * math.cos(Math.PI) // Returns: -1\n * math.cos(Math.PI / 3) // Returns: 0.5\n * ```\n */\nexport function cos(value: Series): Series;\nexport function cos(value: float): float;\nexport function cos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.cos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.cos(value);\n}\n\n/**\n * Returns the tangent of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The tangent value\n *\n * @remarks\n * - Input is in radians, not degrees\n * - tan(x) = sin(x) / cos(x)\n * - Undefined at \u03C0/2, 3\u03C0/2, etc. (returns very large numbers)\n * - Periodic with period \u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.tan(0) // Returns: 0\n * math.tan(Math.PI / 4) // Returns: 1\n * math.tan(Math.PI / 6) // Returns: 0.577... (1/\u221A3)\n * ```\n */\nexport function tan(value: Series): Series;\nexport function tan(value: float): float;\nexport function tan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.tan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.tan(value);\n}\n\n/**\n * Returns the arcsine (inverse sine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - asin(sin(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - asin(0) = 0\n * - asin(1) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.asin(0) // Returns: 0\n * math.asin(1) // Returns: 1.5707... (\u03C0/2)\n * math.asin(0.5) // Returns: 0.5235... (\u03C0/6)\n * math.asin(-1) // Returns: -1.5707... (-\u03C0/2)\n * ```\n */\nexport function asin(value: Series): Series;\nexport function asin(value: float): float;\nexport function asin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.asin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.asin(value);\n}\n\n/**\n * Returns the arccosine (inverse cosine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [0, \u03C0])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - acos(cos(x)) = x for x in [0, \u03C0]\n * - acos(1) = 0\n * - acos(0) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.acos(1) // Returns: 0\n * math.acos(0) // Returns: 1.5707... (\u03C0/2)\n * math.acos(0.5) // Returns: 1.0471... (\u03C0/3)\n * math.acos(-1) // Returns: 3.1415... (\u03C0)\n * ```\n */\nexport function acos(value: Series): Series;\nexport function acos(value: float): float;\nexport function acos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.acos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.acos(value);\n}\n\n/**\n * Returns the arctangent (inverse tangent) of a number.\n *\n * @param value - The value or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Accepts any number as input\n * - atan(tan(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - atan(0) = 0\n * - atan(1) = \u03C0/4\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.atan(0) // Returns: 0\n * math.atan(1) // Returns: 0.7853... (\u03C0/4)\n * math.atan(-1) // Returns: -0.7853... (-\u03C0/4)\n * math.atan(Infinity) // Returns: 1.5707... (\u03C0/2)\n * ```\n */\nexport function atan(value: Series): Series;\nexport function atan(value: float): float;\nexport function atan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.atan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.atan(value);\n}\n\n/**\n * Converts an angle from degrees to radians.\n *\n * @param degrees - The angle in degrees or Series\n * @returns The angle in radians\n *\n * @remarks\n * - Radians = Degrees \u00D7 (\u03C0 / 180)\n * - One full rotation: 360\u00B0 = 2\u03C0 radians\n * - Common conversions: 90\u00B0 = \u03C0/2, 180\u00B0 = \u03C0, 270\u00B0 = 3\u03C0/2\n * - If degrees is a Series, returns a Series; if degrees is a number, returns a number\n *\n * @example\n * ```typescript\n * math.toradians(0) // Returns: 0\n * math.toradians(90) // Returns: 1.5707... (\u03C0/2)\n * math.toradians(180) // Returns: 3.1415... (\u03C0)\n * math.toradians(360) // Returns: 6.2831... (2\u03C0)\n * ```\n */\nexport function toradians(degrees: Series): Series;\nexport function toradians(degrees: float): float;\nexport function toradians(degrees: float | Series): float | Series {\n if (degrees instanceof Series) {\n const bars = degrees.bars;\n const valueArray = degrees.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (Math.PI / 180));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return degrees * (Math.PI / 180);\n}\n\n/**\n * Converts an angle from radians to degrees.\n *\n * @param radians - The angle in radians or Series\n * @returns The angle in degrees\n *\n * @remarks\n * - Degrees = Radians \u00D7 (180 / \u03C0)\n * - One full rotation: 2\u03C0 radians = 360\u00B0\n * - Common conversions: \u03C0/2 = 90\u00B0, \u03C0 = 180\u00B0, 3\u03C0/2 = 270\u00B0\n * - If radians is a Series, returns a Series; if radians is a number, returns a number\n *\n * @example\n * ```typescript\n * math.todegrees(0) // Returns: 0\n * math.todegrees(Math.PI / 2) // Returns: 90\n * math.todegrees(Math.PI) // Returns: 180\n * math.todegrees(2 * Math.PI) // Returns: 360\n * ```\n */\nexport function todegrees(radians: Series): Series;\nexport function todegrees(radians: float): float;\nexport function todegrees(radians: float | Series): float | Series {\n if (radians instanceof Series) {\n const bars = radians.bars;\n const valueArray = radians.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (180 / Math.PI));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return radians * (180 / Math.PI);\n}\n\n/**\n * PineScript's seeded generator: Java's linear congruential generator (`java.util.Random`), `nextDouble()`.\n * Each generator draws one number per call.\n */\nexport function seededRandom(seed: int): (min?: float, max?: float) => float {\n const mask = (1n << 48n) - 1n;\n let state = (BigInt(Math.trunc(seed)) ^ 0x5deece66dn) & mask;\n const next = (bits: bigint): bigint => {\n state = (0x5deece66dn * state + 11n) & mask;\n return state >> (48n - bits);\n };\n return (min = 0, max = 1) => {\n const hi = next(26n);\n const lo = next(27n);\n const unit = Number((hi << 27n) + lo) / 2 ** 53;\n return min + unit * (max - min);\n };\n}\n\nconst seeded = new Map<number, (min?: float, max?: float) => float>();\n\n/** Starts every seeded sequence of `math.random` again (called at the start of a script run). */\nexport function resetRandom(): void {\n seeded.clear();\n}\n\n/** The random generators of the current run, saved around a nested run (see {@link restoreRandom}). */\nexport function saveRandom(): Map<number, (min?: float, max?: float) => float> {\n return new Map(seeded);\n}\n\n/** Puts back the random generators saved by {@link saveRandom}. */\nexport function restoreRandom(saved: Map<number, (min?: float, max?: float) => float>): void {\n seeded.clear();\n for (const [k, v] of saved) seeded.set(k, v);\n}\n\n/**\n * Returns a pseudo-random number.\n *\n * @param min - Optional minimum value (inclusive), default 0\n * @param max - Optional maximum value (exclusive), default 1\n * @param seed - Optional seed: a repeatable sequence, as PineScript (Java's `java.util.Random`)\n * @returns A random number in the specified range, or [0, 1) if no range specified\n *\n * @remarks\n * - Without a seed: `Math.random()`\n * - With a seed: PineScript's sequence, one number per call (measured: the call on each bar draws the next number\n * of `new java.util.Random(seed).nextDouble()` from the first bar of the history). PineScript keeps one generator\n * per call site; here there is one generator per seed value (started again by `executeScript`): for two call sites\n * with the same seed use `callsite.random(seed)`\n *\n * @example\n * ```typescript\n * math.random() // Returns: value between 0 and 1 (e.g., 0.234...)\n * math.random(0, 10) // Returns: value between 0 and 10 (e.g., 7.45...)\n * math.random(0, 1, 42) // Returns: 0.7275636800328681 on the first call, as PineScript\n * ```\n */\nexport function random(min?: float, max?: float, seed?: int): float {\n if (seed !== undefined && seed !== null && !Number.isNaN(seed)) {\n let gen = seeded.get(seed);\n if (!gen) {\n gen = seededRandom(seed);\n seeded.set(seed, gen);\n }\n return gen(min ?? 0, max ?? 1);\n }\n const rand = Math.random();\n if (min !== undefined && max !== undefined) {\n return min + rand * (max - min);\n }\n return rand;\n}\n\n/**\n * Returns the sign of a number.\n *\n * @param value - The number to check or Series\n * @returns 1 for positive, -1 for negative, 0 for zero, na for na\n *\n * @remarks\n * - Returns 1 if value > 0\n * - Returns -1 if value < 0\n * - Returns 0 if value = 0\n * - Returns na if value is na (as PineScript)\n * - Useful for determining direction or polarity\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.sign(5) // Returns: 1\n * math.sign(-3) // Returns: -1\n * math.sign(0) // Returns: 0\n * math.sign(0.001) // Returns: 1\n * math.sign(NaN) // Returns: NaN\n * ```\n */\nexport function sign(value: Series): Series;\nexport function sign(value: float): int;\nexport function sign(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v > 0 ? 1 : v < 0 ? -1 : v === 0 ? 0 : NaN);\n }\n \n return Series.fromArray(bars, result);\n }\n \n return value > 0 ? 1 : value < 0 ? -1 : value === 0 ? 0 : NaN;\n}\n\n/**\n * Rounds a value to the nearest mintick.\n *\n * @param number - The number to round or Series\n * @param mintick - Optional mintick value (defaults to requiring syminfo context)\n * @returns The number rounded to tick precision\n *\n * @remarks\n * - **PineScript v6 signature**: `math.round_to_mintick(number)` - uses implicit syminfo.mintick\n * - **JavaScript signature**: Requires explicit `mintick` OR use `createContext()` with syminfo\n * - Rounds to the nearest value divisible by mintick\n * - Returns NaN for NaN input\n * - If number is a Series, returns a Series; if number is a float, returns a float\n *\n * PineScript rules:\n * - mintick is `minmove / pricescale` (here rebuilt from `mintick`: the smallest power of 10 that makes it an\n * integer); the position on the tick grid is `|number| * pricescale / minmove`\n * - ties go away from zero, decided on the exact value of that product with a 1e-10 tolerance\n * (-1.075 -> -1.08, 1.005 -> 1.01, 2.675 -> 2.68 at mintick 0.01)\n *\n * @example\n * ```typescript\n * // Direct call with explicit mintick\n * const rounded = math.round_to_mintick(1.2345, 0.01); // Returns: 1.23\n * const rounded2 = math.round_to_mintick(1.2367, 0.01); // Returns: 1.24\n *\n * // Or use context API for cleaner syntax\n * const { math } = createContext({ syminfo: { mintick: 0.01 } });\n * const rounded = math.round_to_mintick(1.2345); // Returns: 1.23\n * ```\n */\nexport function round_to_mintick(number: Series, mintick?: float): Series;\nexport function round_to_mintick(number: float, mintick?: float): float;\nexport function round_to_mintick(number: float | Series, mintick?: float): float | Series {\n if (number instanceof Series) {\n const bars = number.bars;\n const valueArray = number.toArray();\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundToTick(valueArray[i] ?? NaN, mintick));\n }\n return Series.fromArray(bars, result);\n }\n\n // Scalar case\n if (isNaN(number)) {\n return NaN;\n }\n\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n return roundToTick(number, mintick);\n}\n\n/** `[minmove, pricescale]` of a mintick: pricescale is the smallest power of 10 (up to 1e15) giving an integer. */\nfunction tickPair(mintick: number): [number, number] | null {\n for (let k = 0; k <= 15; k++) {\n const pricescale = Number(`1e${k}`);\n const scaled = mintick * pricescale;\n const minmove = Math.round(scaled);\n if (minmove >= 1 && Math.abs(scaled - minmove) <= 1e-9 * minmove) return [minmove, pricescale];\n }\n return null;\n}\n\n/** PineScript math.round_to_mintick of one value (see `round_to_mintick`). */\nfunction roundToTick(number: number, mintick: number): number {\n if (!Number.isFinite(number)) return NaN;\n if (mintick === 0) return number;\n const pair = tickPair(mintick);\n const negative = number < 0;\n const magnitude = negative ? -number : number;\n if (pair === null) {\n // A tick that is no decimal fraction: the grid of the double mintick, ties away from zero.\n const scaled = magnitude / mintick;\n let units = Math.trunc(scaled);\n if (scaled - units >= 0.5) units++;\n return (negative ? 0 - units : units) * mintick;\n }\n const [minmove, pricescale] = pair;\n const scaled = (magnitude * pricescale) / minmove;\n let units = Math.trunc(scaled);\n const offset = scaled - units - 0.5;\n const slack = 1e-6 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [n, d] = exactRatio(magnitude);\n const num = n * BigInt(pricescale);\n const den = d * BigInt(minmove);\n const whole = num / den;\n units = Number(whole) + (reachesTie(num, den, whole) ? 1 : 0);\n } else if (offset > 0) {\n units++;\n }\n return ((negative ? 0 - units : units) * minmove) / pricescale;\n}\n\n// Constants\nexport const pi = Math.PI;\nexport const e = Math.E;\nexport const phi = 1.618033988749895; // Golden ratio\nexport const rphi = 0.6180339887498948; // Reciprocal of golden ratio: 1 / phi\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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;AAmBA,oBAAuB;AACvB,yBAA6C;AAC7C,oBAA+B;AAsBxB,SAAS,IAAI,OAAuC;AACzD,MAAI,iBAAiB,sBAAQ;AAC3B,UAAM,OAAO,MAAM;AACnB,UAAM,aAAa,MAAM,QAAQ;AACjC,UAAM,SAAS,KAAK;AAEpB,UAAM,SAAmB,CAAC;AAC1B,aAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,YAAM,IAAI,WAAW,CAA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/**\n * Math namespace\n * Mirrors PineScript's math.* functions for mathematical operations and calculations.\n *\n * @remarks\n * All math functions in this namespace follow PineScript v6 API specifications.\n * Functions include basic arithmetic, algebraic operations, trigonometry, and combinatorics.\n *\n * Known difference: `log10`, `exp`, `log`, `pow`, `sin`, `cos`, `tan` use JavaScript's `Math`. PineScript uses\n * other algorithms, whose results differ by 1 or 2 units in the last place on part of the inputs (`log10` about 4 %,\n * `exp` about 9 %, `sin` / `cos` / `tan` about 3 %, `log` 0.4 %, `pow` 0.05 % of random inputs). This is visible\n * only when a script amplifies these tiny differences (e.g. `ma > ma[1]` on values of 1e195); `sqrt`, `atan`,\n * `asin`, `acos` are equal. A constant argument (`math.log10(2)`) is computed before the script runs, with other\n * rules: see `constant`.\n *\n * @version 6\n */\n\nimport type { float, int, simple_int, series_float } from '../types/index.js';\nimport { Series } from '../runtime/series.js';\nimport { runningSum, runningSumSeries } from '../ta/running-sum.js';\nimport { checkSumLength } from '../ta/limits.js';\n\n/**\n * Returns the absolute value of a number.\n *\n * @param value - The number or Series\n * @returns The absolute value (always non-negative)\n *\n * @remarks\n * - Returns the distance from zero on the number line\n * - |x| = x if x \u2265 0, -x if x < 0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.abs(5) // Returns: 5\n * math.abs(-5) // Returns: 5\n * math.abs(0) // Returns: 0\n * ```\n */\nexport function abs(value: Series): Series;\nexport function abs(value: float): float;\nexport function abs(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.abs(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.abs(value);\n}\n\n/**\n * Returns the smallest integer greater than or equal to a given number (rounds up).\n *\n * @param value - The number to round up or Series\n * @returns The ceiling value (smallest integer \u2265 value)\n *\n * @remarks\n * - Always rounds towards positive infinity\n * - For positive numbers, rounds away from zero\n * - For negative numbers, rounds towards zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.ceil(4.2) // Returns: 5\n * math.ceil(4.8) // Returns: 5\n * math.ceil(-4.2) // Returns: -4\n * math.ceil(5) // Returns: 5\n * ```\n */\nexport function ceil(value: Series): Series;\nexport function ceil(value: float): int;\nexport function ceil(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.ceil(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.ceil(value);\n}\n\n/**\n * Returns the largest integer less than or equal to a given number (rounds down).\n *\n * @param value - The number to round down or Series\n * @returns The floor value (largest integer \u2264 value)\n *\n * @remarks\n * - Always rounds towards negative infinity\n * - For positive numbers, rounds towards zero\n * - For negative numbers, rounds away from zero\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.floor(4.2) // Returns: 4\n * math.floor(4.8) // Returns: 4\n * math.floor(-4.2) // Returns: -5\n * math.floor(5) // Returns: 5\n * ```\n */\nexport function floor(value: Series): Series;\nexport function floor(value: float): int;\nexport function floor(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.floor(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.floor(value);\n}\n\n/**\n * Returns the value rounded to the nearest integer or to a specified precision.\n *\n * @param value - The number to round or Series\n * @param precision - Optional number of decimal places (default: 0)\n * @returns The rounded value\n *\n * @remarks\n * - Rounds to nearest integer by default\n * - With precision, rounds to that many decimal places\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * PineScript rules:\n * - ties go away from zero (2.5 -> 3, -2.5 -> -3, -0.5 -> -1)\n * - without a precision, or with a precision <= 0, the result is the integer rounding (1234.5678 @ -2 -> 1235)\n * - a positive precision rounds only the fraction: `int + round(frac * scale) / scale` with\n * `scale = 1 / 10^-precision` (precision above 16 acts as 16); the tie is decided on the exact value of\n * `frac * scale` with a 1e-10 tolerance (1.005 @ 2 -> 1.01, 0.285 @ 2 -> 0.29, -1.45 @ 1 -> -1.5)\n * - an infinite value gives na\n *\n * @example\n * ```js\n * math.round(4.2) // Returns: 4\n * math.round(4.5) // Returns: 5\n * math.round(-2.5) // Returns: -3\n * math.round(4.567, 2) // Returns: 4.57\n * math.round(1.005, 2) // Returns: 1.01\n * ```\n */\nexport function round(value: Series, precision?: int): Series;\nexport function round(value: float, precision?: int): float;\nexport function round(value: float | Series, precision?: int): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundValue(valueArray[i] ?? NaN, precision));\n }\n return Series.fromArray(bars, result);\n }\n return roundValue(value, precision);\n}\n\n/** `0.5 - 1e-10` as the exact fraction TIE_HALF / TIE_SCALE: the tie threshold of round / round_to_mintick. */\nconst TIE_SCALE = 10n ** 10n;\nconst TIE_HALF = 5n * 10n ** 9n - 1n;\n/** From 2^52 up every double is an integer. */\nconst INT_LIMIT = 2 ** 52;\n\n/** Exact value of a finite double >= 0 as `[numerator, denominator]`. */\nfunction exactRatio(x: number): [bigint, bigint] {\n const view = new DataView(new ArrayBuffer(8));\n view.setFloat64(0, x);\n const hi = view.getUint32(0);\n const lo = view.getUint32(4);\n const expField = (hi >>> 20) & 0x7ff;\n let mantissa = (BigInt(hi & 0xfffff) << 32n) | BigInt(lo);\n let exp = -1074;\n if (expField !== 0) {\n mantissa |= 1n << 52n;\n exp = expField - 1075;\n }\n return exp >= 0 ? [mantissa << BigInt(exp), 1n] : [mantissa, 1n << BigInt(-exp)];\n}\n\n/** True when `num / den - units` (exact) is >= 0.5 - 1e-10. */\nfunction reachesTie(num: bigint, den: bigint, units: bigint): boolean {\n return (num - units * den) * TIE_SCALE >= TIE_HALF * den;\n}\n\n/** `10^-p`: the exact literal for an integer p (correctly rounded), Math.pow otherwise. */\nfunction tenToMinus(p: number): number {\n return Number.isInteger(p) ? Number(`1e-${p}`) : Math.pow(10, -p);\n}\n\n/** PineScript math.round of one value (see `round`). */\nfunction roundValue(value: number, precision?: number): number {\n if (!Number.isFinite(value)) return NaN;\n const negative = value < 0;\n const magnitude = negative ? -value : value;\n if (precision === undefined || Number.isNaN(precision) || precision <= 0) {\n if (magnitude >= INT_LIMIT) return value;\n let units = Math.floor(magnitude);\n if (magnitude - units >= 0.5) units++;\n return negative ? 0 - units : units;\n }\n const scale = 1 / tenToMinus(Math.min(precision, 16));\n const fraction = magnitude % 1;\n const scaled = fraction * scale;\n let units = Math.floor(scaled);\n const offset = scaled - units - 0.5;\n // Only a near-tie needs the exact product; the window covers the double's own error.\n const slack = 1e-9 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [fn, fd] = exactRatio(fraction);\n const [sn, sd] = exactRatio(scale);\n if (reachesTie(fn * sn, fd * sd, BigInt(units))) units++;\n } else if (offset > 0) {\n units++;\n }\n const result = magnitude - fraction + units / scale;\n return negative ? 0 - result : result;\n}\n\n/** 10^16: a constant keeps 16 decimals. */\nconst CONSTANT_SCALE = 10n ** 16n;\n\n/**\n * Returns the value PineScript gives to a constant float expression (not a PineScript function).\n *\n * @param value - The result of the constant expression, computed in JavaScript (e.g. `1 / 255`)\n * @returns The value of the same expression in a PineScript script\n *\n * @remarks\n * PineScript computes a constant expression (only literals and constants: `1 / 255`, `0.1 * 3`,\n * `math.sqrt(0.1)`) before the script runs, and the value is then rounded. JavaScript cannot tell a constant from a\n * series value, so wrap the constant expressions of a script with this function.\n * - |value| >= 0.001: the exact value of the double is rounded to 16 decimals, ties to even\n * (`1 / 255` -> 0.003921568627451, `1 / 7` -> 0.1428571428571428)\n * - |value| < 0.001, na and infinities: unchanged\n * - the whole expression is computed first, then rounded once (`(1 / 7) * 7` is 1)\n * - math functions of constants use JavaScript's `Math` there: `math.constant(math.sqrt(0.1))` is the PineScript\n * value; `math.log10` of a constant is `math.log(x) / math.log(10)` there:\n * `math.constant(math.log(2) / math.log(10))` -> 0.3010299956639811\n * - the same expression with a series operand (`close / 255`) is not rounded: do not wrap it\n *\n * @example\n * ```js\n * // Pine: var const float i_255 = 1 / 255\n * const i_255 = math.constant(1 / 255) // 0.003921568627451 (JavaScript: 0.00392156862745098)\n * math.constant(1 / 7) // 0.1428571428571428 (JavaScript: 0.14285714285714285)\n * math.constant(1 / 3) // 0.3333333333333333 (unchanged)\n * ```\n */\nexport function constant(value: float): float {\n const magnitude = Math.abs(value);\n // from 0.5 up, 16 decimals move a double by less than half its spacing: it stays the same\n if (!(magnitude >= 1e-3 && magnitude < 0.5)) return value;\n const [num, den] = exactRatio(magnitude);\n const scaled = num * CONSTANT_SCALE;\n let units = scaled / den;\n const twiceRest = (scaled - units * den) * 2n;\n if (twiceRest > den || (twiceRest === den && (units & 1n) === 1n)) units++;\n const digits = units.toString().padStart(17, '0');\n const result = Number(`${digits.slice(0, -16)}.${digits.slice(-16)}`);\n return value < 0 ? -result : result;\n}\n\n/**\n * Returns the maximum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The largest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns -Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```js\n * math.max(1, 2, 3) // Returns: 3\n * math.max(-1, -5, -2) // Returns: -1\n * math.max(10) // Returns: 10\n * math.max(5, 10, 3, 8) // Returns: 10\n * ```\n */\nexport function max(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.max\n return Math.max(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.max(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the minimum value from the arguments.\n *\n * @param values - Variable number of values to compare (numbers or Series)\n * @returns The smallest value\n *\n * @remarks\n * - Accepts any number of arguments\n * - Returns Infinity if no arguments provided\n * - Returns NaN if any argument is NaN\n * - If any argument is a Series, returns a Series; otherwise returns a number\n *\n * @example\n * ```js\n * math.min(1, 2, 3) // Returns: 1\n * math.min(-1, -5, -2) // Returns: -5\n * math.min(10) // Returns: 10\n * math.min(5, 10, 3, 8) // Returns: 3\n * ```\n */\nexport function min(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n \n if (!hasSeries) {\n // All scalars - use native Math.min\n return Math.min(...(values as number[]));\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(Math.min(...nums));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns the average (arithmetic mean) of the arguments.\n *\n * @param values - Variable number of values (numbers or Series)\n * @returns The arithmetic mean\n *\n * @remarks\n * - Calculates sum of all values divided by count\n * - Returns NaN if no arguments provided (division by zero)\n * - If any argument is a Series, returns a Series; otherwise returns a number\n * - PineScript rule: with 1 or 2 values the sum is plain; with 3 values or more it is a Kahan compensated sum whose\n * pending correction is subtracted before the division (math.avg(0.1, 0.2, 0.3) = 0.19999999999999998)\n *\n * @example\n * ```js\n * math.avg(1, 2, 3) // Returns: 2\n * math.avg(10, 20) // Returns: 15\n * math.avg(5) // Returns: 5\n * math.avg(1, 2, 3, 4, 5) // Returns: 3\n * ```\n */\nexport function avg(...values: (float | Series)[]): float | Series {\n // Check if any value is a Series\n const hasSeries = values.some(v => v instanceof Series);\n\n if (!hasSeries) {\n return avgOf(values as number[]);\n }\n \n // At least one Series - return a Series\n const firstSeries = values.find(v => v instanceof Series) as Series;\n const bars = firstSeries.bars;\n const length = bars.length;\n \n // Convert all values to arrays (scalars become constant arrays)\n const valueArrays = values.map(v => \n v instanceof Series ? v.toArray() : null\n );\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const nums = values.map((v, idx) => \n valueArrays[idx] ? valueArrays[idx]![i] ?? NaN : (v as number)\n );\n result.push(avgOf(nums));\n }\n\n return Series.fromArray(bars, result);\n}\n\n/** PineScript math.avg of numbers: plain sum up to 2 values, Kahan sum with the correction flushed from 3. */\nfunction avgOf(nums: number[]): number {\n if (nums.length <= 2) {\n let sum = 0;\n for (const n of nums) sum = sum + n;\n return sum / nums.length;\n }\n let sum = 0;\n let c = 0;\n for (const n of nums) {\n const y = n - c;\n const t = sum + y;\n c = t - sum - y;\n sum = t;\n }\n return (sum - c) / nums.length;\n}\n\n/**\n * Returns the sum of values over a sliding window.\n *\n * @param source - Series of values or array\n * @param length - Window length for summation, or one length per bar (a series length: array or Series)\n * @returns Series or array with rolling sum values\n *\n * @remarks\n * - Calculates the sum of the last `length` non-`na` values at each point; an `na` value (also +/-Infinity) is\n * skipped and the bar keeps the previous result (as in PineScript)\n * - Returns NaN until `length` non-`na` values are available\n * - The correctly rounded sum of the window values (the exact sum, rounded once), as PineScript (#188)\n * - When passed a Series, returns a Series; when passed an array, returns an array\n * - With a series length, the window is the last `length` values of each bar. A bar with an `na` value\n * gives the sum of the last `length` earlier values\n *\n * @example\n * ```js\n * math.sum([1, 2, 3, 4, 5], 3) // Returns: [NaN, NaN, 6, 9, 12]\n * // Explanation: [NaN, NaN, 1+2+3, 2+3+4, 3+4+5]\n * ```\n */\nexport function sum(source: Series, length: simple_int | ArrayLike<number> | Series): Series;\nexport function sum(source: series_float, length: simple_int | ArrayLike<number> | Series): series_float;\nexport function sum(\n source: series_float | Series,\n length: simple_int | ArrayLike<number> | Series\n): series_float | Series {\n // Handle Series objects - extract to array first\n const sourceArray = source instanceof Series ? source.toArray() : source;\n if (typeof length === 'number') checkSumLength('math.sum', length, 0);\n // PineScript: the sum of the last `length` non-na values (also +/-Infinity skipped); an na bar keeps the previous\n // result. The correctly rounded window sum, bit for bit as PineScript (#188).\n const result: series_float =\n typeof length === 'number'\n ? runningSum(sourceArray, length)\n : runningSumSeries(sourceArray, length instanceof Series ? length.toArray() : length, 'math.sum');\n\n // If input was a Series, return a Series\n if (source instanceof Series) {\n return Series.fromArray(source.bars, result);\n }\n\n return result;\n}\n\n/**\n * Returns the square root of a number.\n *\n * @param value - The number (must be non-negative) or Series\n * @returns The square root (\u221Avalue)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - \u221Ax \u00D7 \u221Ax = x (for non-negative x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.sqrt(9) // Returns: 3\n * math.sqrt(16) // Returns: 4\n * math.sqrt(2) // Returns: 1.414...\n * math.sqrt(0) // Returns: 0\n * ```\n */\nexport function sqrt(value: Series): Series;\nexport function sqrt(value: float): float;\nexport function sqrt(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sqrt(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sqrt(value);\n}\n\n/**\n * Returns base raised to the power of exponent.\n *\n * @param base - The base number or Series\n * @param exponent - The exponent (power) or Series\n * @returns base^exponent\n *\n * @remarks\n * - 0^0 returns 1\n * - Negative base with fractional exponent returns NaN\n * - Any number to the power of 0 equals 1\n * - If any argument is a Series, returns a Series; if all are numbers, returns a number\n *\n * @example\n * ```js\n * math.pow(2, 3) // Returns: 8 (2\u00B3)\n * math.pow(10, 2) // Returns: 100\n * math.pow(5, 0) // Returns: 1\n * math.pow(2, -1) // Returns: 0.5\n * ```\n */\nexport function pow(base: Series, exponent: float): Series;\nexport function pow(base: float, exponent: Series): Series;\nexport function pow(base: Series, exponent: Series): Series;\nexport function pow(base: float, exponent: float): float;\nexport function pow(base: float | Series, exponent: float | Series): float | Series {\n const baseIsSeries = base instanceof Series;\n const expIsSeries = exponent instanceof Series;\n \n // Pure scalar case\n if (!baseIsSeries && !expIsSeries) {\n return Math.pow(base as number, exponent as number);\n }\n \n // At least one is a Series - return a Series\n const bars = baseIsSeries ? (base as Series).bars : (exponent as Series).bars;\n const baseArray = baseIsSeries ? (base as Series).toArray() : null;\n const expArray = expIsSeries ? (exponent as Series).toArray() : null;\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const b = baseArray ? baseArray[i] ?? NaN : (base as number);\n const e = expArray ? expArray[i] ?? NaN : (exponent as number);\n result.push(Math.pow(b, e));\n }\n \n return Series.fromArray(bars, result);\n}\n\n/**\n * Returns e (Euler's number) raised to the power of value.\n *\n * @param value - The exponent or Series\n * @returns e^value (where e \u2248 2.71828)\n *\n * @remarks\n * - e^0 = 1\n * - e^1 = e \u2248 2.71828\n * - Inverse of ln(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.exp(0) // Returns: 1\n * math.exp(1) // Returns: 2.71828... (e)\n * math.exp(2) // Returns: 7.389...\n * math.exp(-1) // Returns: 0.3678...\n * ```\n */\nexport function exp(value: Series): Series;\nexport function exp(value: float): float;\nexport function exp(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.exp(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.exp(value);\n}\n\n/**\n * Returns the natural logarithm (base e) of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns ln(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - ln(e) = 1\n * - ln(1) = 0\n * - Inverse of exp(x)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.log(1) // Returns: 0\n * math.log(Math.E) // Returns: 1\n * math.log(10) // Returns: 2.302...\n * math.log(100) // Returns: 4.605...\n * ```\n */\nexport function log(value: Series): Series;\nexport function log(value: float): float;\nexport function log(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log(value);\n}\n\n/**\n * Returns the base-10 logarithm of a number.\n *\n * @param value - The number (must be positive) or Series\n * @returns log\u2081\u2080(value)\n *\n * @remarks\n * - Returns NaN for negative numbers\n * - Returns -Infinity for 0\n * - log\u2081\u2080(10) = 1\n * - log\u2081\u2080(100) = 2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.log10(10) // Returns: 1\n * math.log10(100) // Returns: 2\n * math.log10(1000) // Returns: 3\n * math.log10(1) // Returns: 0\n * ```\n */\nexport function log10(value: Series): Series;\nexport function log10(value: float): float;\nexport function log10(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.log10(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.log10(value);\n}\n\n/**\n * Returns the sine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The sine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - sin(0) = 0\n * - sin(\u03C0/2) = 1\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.sin(0) // Returns: 0\n * math.sin(Math.PI / 2) // Returns: 1\n * math.sin(Math.PI) // Returns: 0 (approximately)\n * math.sin(Math.PI / 6) // Returns: 0.5\n * ```\n */\nexport function sin(value: Series): Series;\nexport function sin(value: float): float;\nexport function sin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.sin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.sin(value);\n}\n\n/**\n * Returns the cosine of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The cosine value (range: [-1, 1])\n *\n * @remarks\n * - Input is in radians, not degrees\n * - cos(0) = 1\n * - cos(\u03C0/2) = 0\n * - Periodic with period 2\u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.cos(0) // Returns: 1\n * math.cos(Math.PI / 2) // Returns: 0 (approximately)\n * math.cos(Math.PI) // Returns: -1\n * math.cos(Math.PI / 3) // Returns: 0.5\n * ```\n */\nexport function cos(value: Series): Series;\nexport function cos(value: float): float;\nexport function cos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.cos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.cos(value);\n}\n\n/**\n * Returns the tangent of an angle in radians.\n *\n * @param value - The angle in radians or Series\n * @returns The tangent value\n *\n * @remarks\n * - Input is in radians, not degrees\n * - tan(x) = sin(x) / cos(x)\n * - Undefined at \u03C0/2, 3\u03C0/2, etc. (returns very large numbers)\n * - Periodic with period \u03C0\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.tan(0) // Returns: 0\n * math.tan(Math.PI / 4) // Returns: 1\n * math.tan(Math.PI / 6) // Returns: 0.577... (1/\u221A3)\n * ```\n */\nexport function tan(value: Series): Series;\nexport function tan(value: float): float;\nexport function tan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.tan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.tan(value);\n}\n\n/**\n * Returns the arcsine (inverse sine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - asin(sin(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - asin(0) = 0\n * - asin(1) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.asin(0) // Returns: 0\n * math.asin(1) // Returns: 1.5707... (\u03C0/2)\n * math.asin(0.5) // Returns: 0.5235... (\u03C0/6)\n * math.asin(-1) // Returns: -1.5707... (-\u03C0/2)\n * ```\n */\nexport function asin(value: Series): Series;\nexport function asin(value: float): float;\nexport function asin(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.asin(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.asin(value);\n}\n\n/**\n * Returns the arccosine (inverse cosine) of a number.\n *\n * @param value - The value (must be in range [-1, 1]) or Series\n * @returns The angle in radians (range: [0, \u03C0])\n *\n * @remarks\n * - Returns NaN for values outside [-1, 1]\n * - acos(cos(x)) = x for x in [0, \u03C0]\n * - acos(1) = 0\n * - acos(0) = \u03C0/2\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.acos(1) // Returns: 0\n * math.acos(0) // Returns: 1.5707... (\u03C0/2)\n * math.acos(0.5) // Returns: 1.0471... (\u03C0/3)\n * math.acos(-1) // Returns: 3.1415... (\u03C0)\n * ```\n */\nexport function acos(value: Series): Series;\nexport function acos(value: float): float;\nexport function acos(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.acos(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.acos(value);\n}\n\n/**\n * Returns the arctangent (inverse tangent) of a number.\n *\n * @param value - The value or Series\n * @returns The angle in radians (range: [-\u03C0/2, \u03C0/2])\n *\n * @remarks\n * - Accepts any number as input\n * - atan(tan(x)) = x for x in [-\u03C0/2, \u03C0/2]\n * - atan(0) = 0\n * - atan(1) = \u03C0/4\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.atan(0) // Returns: 0\n * math.atan(1) // Returns: 0.7853... (\u03C0/4)\n * math.atan(-1) // Returns: -0.7853... (-\u03C0/4)\n * math.atan(Infinity) // Returns: 1.5707... (\u03C0/2)\n * ```\n */\nexport function atan(value: Series): Series;\nexport function atan(value: float): float;\nexport function atan(value: float | Series): float | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.atan(v));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return Math.atan(value);\n}\n\n/**\n * Converts an angle from degrees to radians.\n *\n * @param degrees - The angle in degrees or Series\n * @returns The angle in radians\n *\n * @remarks\n * - Radians = Degrees \u00D7 (\u03C0 / 180)\n * - One full rotation: 360\u00B0 = 2\u03C0 radians\n * - Common conversions: 90\u00B0 = \u03C0/2, 180\u00B0 = \u03C0, 270\u00B0 = 3\u03C0/2\n * - If degrees is a Series, returns a Series; if degrees is a number, returns a number\n *\n * @example\n * ```js\n * math.toradians(0) // Returns: 0\n * math.toradians(90) // Returns: 1.5707... (\u03C0/2)\n * math.toradians(180) // Returns: 3.1415... (\u03C0)\n * math.toradians(360) // Returns: 6.2831... (2\u03C0)\n * ```\n */\nexport function toradians(degrees: Series): Series;\nexport function toradians(degrees: float): float;\nexport function toradians(degrees: float | Series): float | Series {\n if (degrees instanceof Series) {\n const bars = degrees.bars;\n const valueArray = degrees.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (Math.PI / 180));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return degrees * (Math.PI / 180);\n}\n\n/**\n * Converts an angle from radians to degrees.\n *\n * @param radians - The angle in radians or Series\n * @returns The angle in degrees\n *\n * @remarks\n * - Degrees = Radians \u00D7 (180 / \u03C0)\n * - One full rotation: 2\u03C0 radians = 360\u00B0\n * - Common conversions: \u03C0/2 = 90\u00B0, \u03C0 = 180\u00B0, 3\u03C0/2 = 270\u00B0\n * - If radians is a Series, returns a Series; if radians is a number, returns a number\n *\n * @example\n * ```js\n * math.todegrees(0) // Returns: 0\n * math.todegrees(Math.PI / 2) // Returns: 90\n * math.todegrees(Math.PI) // Returns: 180\n * math.todegrees(2 * Math.PI) // Returns: 360\n * ```\n */\nexport function todegrees(radians: Series): Series;\nexport function todegrees(radians: float): float;\nexport function todegrees(radians: float | Series): float | Series {\n if (radians instanceof Series) {\n const bars = radians.bars;\n const valueArray = radians.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v * (180 / Math.PI));\n }\n \n return Series.fromArray(bars, result);\n }\n \n return radians * (180 / Math.PI);\n}\n\n/**\n * Makes a repeatable random number generator: the same seed always gives the same sequence of numbers (the\n * sequence of `math.random(min, max, seed)`). Each call of the generator draws the next number. In a script, prefer\n * `math.random(min, max, seed)`.\n * @param seed - Whole number that picks the sequence.\n * @returns A function `(min?, max?)` that gives the next number, from `min` (included, default 0) to `max`\n * (excluded, default 1).\n * @example\n * ```js\n * const draw = math.seededRandom(42);\n * const first = draw(0, 100);\n * ```\n */\nexport function seededRandom(seed: int): (min?: float, max?: float) => float {\n const mask = (1n << 48n) - 1n;\n let state = (BigInt(Math.trunc(seed)) ^ 0x5deece66dn) & mask;\n const next = (bits: bigint): bigint => {\n state = (0x5deece66dn * state + 11n) & mask;\n return state >> (48n - bits);\n };\n return (min = 0, max = 1) => {\n const hi = next(26n);\n const lo = next(27n);\n const unit = Number((hi << 27n) + lo) / 2 ** 53;\n return min + unit * (max - min);\n };\n}\n\nconst seeded = new Map<number, (min?: float, max?: float) => float>();\n\n/** Starts every seeded sequence of `math.random` again (called at the start of a script run). */\nexport function resetRandom(): void {\n seeded.clear();\n}\n\n/** The random generators of the current run, saved around a nested run (see {@link restoreRandom}). */\nexport function saveRandom(): Map<number, (min?: float, max?: float) => float> {\n return new Map(seeded);\n}\n\n/** Puts back the random generators saved by {@link saveRandom}. */\nexport function restoreRandom(saved: Map<number, (min?: float, max?: float) => float>): void {\n seeded.clear();\n for (const [k, v] of saved) seeded.set(k, v);\n}\n\n/**\n * Returns a pseudo-random number.\n *\n * @param min - Optional minimum value (inclusive), default 0\n * @param max - Optional maximum value (exclusive), default 1\n * @param seed - Optional seed: a repeatable sequence, as PineScript (Java's `java.util.Random`)\n * @returns A random number in the specified range, or [0, 1) if no range specified\n *\n * @remarks\n * - Without a seed: `Math.random()`\n * - With a seed: PineScript's sequence, one number per call (measured: the call on each bar draws the next number\n * of `new java.util.Random(seed).nextDouble()` from the first bar of the history). PineScript keeps one generator\n * per call site; here there is one generator per seed value (started again by `executeScript`): for two call sites\n * with the same seed use `callsite.random(seed)`\n *\n * @example\n * ```js\n * math.random() // Returns: value between 0 and 1 (e.g., 0.234...)\n * math.random(0, 10) // Returns: value between 0 and 10 (e.g., 7.45...)\n * math.random(0, 1, 42) // Returns: 0.7275636800328681 on the first call, as PineScript\n * ```\n */\nexport function random(min?: float, max?: float, seed?: int): float {\n if (seed !== undefined && seed !== null && !Number.isNaN(seed)) {\n let gen = seeded.get(seed);\n if (!gen) {\n gen = seededRandom(seed);\n seeded.set(seed, gen);\n }\n return gen(min ?? 0, max ?? 1);\n }\n const rand = Math.random();\n if (min !== undefined && max !== undefined) {\n return min + rand * (max - min);\n }\n return rand;\n}\n\n/**\n * Returns the sign of a number.\n *\n * @param value - The number to check or Series\n * @returns 1 for positive, -1 for negative, 0 for zero, na for na\n *\n * @remarks\n * - Returns 1 if value > 0\n * - Returns -1 if value < 0\n * - Returns 0 if value = 0\n * - Returns na if value is na (as PineScript)\n * - Useful for determining direction or polarity\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```js\n * math.sign(5) // Returns: 1\n * math.sign(-3) // Returns: -1\n * math.sign(0) // Returns: 0\n * math.sign(0.001) // Returns: 1\n * math.sign(NaN) // Returns: NaN\n * ```\n */\nexport function sign(value: Series): Series;\nexport function sign(value: float): int;\nexport function sign(value: float | Series): int | Series {\n if (value instanceof Series) {\n const bars = value.bars;\n const valueArray = value.toArray();\n const length = bars.length;\n \n const result: number[] = [];\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(v > 0 ? 1 : v < 0 ? -1 : v === 0 ? 0 : NaN);\n }\n \n return Series.fromArray(bars, result);\n }\n \n return value > 0 ? 1 : value < 0 ? -1 : value === 0 ? 0 : NaN;\n}\n\n/**\n * Rounds a price to the nearest tick, the smallest price step of the symbol (`syminfo.mintick`). Use it for levels\n * that must be real prices (a stop, a target).\n *\n * @param number - The price to round: a number or a Series\n * @param mintick - The tick size, e.g. 0.01. Default in a script: the chart symbol's tick (`syminfo.mintick`);\n * called outside a script it is required (it throws without it)\n * @returns The value rounded to the tick: a Series for a Series, a number for a number\n *\n * @remarks\n * - Rounds to the nearest value divisible by mintick\n * - Returns NaN for NaN input\n * - If number is a Series, returns a Series; if number is a float, returns a float\n *\n * PineScript rules:\n * - mintick is `minmove / pricescale` (here rebuilt from `mintick`: the smallest power of 10 that makes it an\n * integer); the position on the tick grid is `|number| * pricescale / minmove`\n * - ties go away from zero, decided on the exact value of that product with a 1e-10 tolerance\n * (-1.075 -> -1.08, 1.005 -> 1.01, 2.675 -> 2.68 at mintick 0.01)\n *\n * @example\n * ```js\n * const stop = math.round_to_mintick(low.mul(0.98));\n * plot(stop, \"Stop\");\n * math.round_to_mintick(1.2345, 0.01) // Returns: 1.23\n * ```\n */\nexport function round_to_mintick(number: Series, mintick?: float): Series;\nexport function round_to_mintick(number: float, mintick?: float): float;\nexport function round_to_mintick(number: float | Series, mintick?: float): float | Series {\n if (number instanceof Series) {\n const bars = number.bars;\n const valueArray = number.toArray();\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n const result: number[] = [];\n for (let i = 0; i < bars.length; i++) {\n result.push(roundToTick(valueArray[i] ?? NaN, mintick));\n }\n return Series.fromArray(bars, result);\n }\n\n // Scalar case\n if (isNaN(number)) {\n return NaN;\n }\n\n if (mintick === undefined) {\n throw new Error(\n 'math.round_to_mintick() requires mintick value. ' +\n 'Either pass it explicitly or use createContext({ syminfo: { mintick } }) for implicit data.'\n );\n }\n return roundToTick(number, mintick);\n}\n\n/** `[minmove, pricescale]` of a mintick: pricescale is the smallest power of 10 (up to 1e15) giving an integer. */\nfunction tickPair(mintick: number): [number, number] | null {\n for (let k = 0; k <= 15; k++) {\n const pricescale = Number(`1e${k}`);\n const scaled = mintick * pricescale;\n const minmove = Math.round(scaled);\n if (minmove >= 1 && Math.abs(scaled - minmove) <= 1e-9 * minmove) return [minmove, pricescale];\n }\n return null;\n}\n\n/** PineScript math.round_to_mintick of one value (see `round_to_mintick`). */\nfunction roundToTick(number: number, mintick: number): number {\n if (!Number.isFinite(number)) return NaN;\n if (mintick === 0) return number;\n const pair = tickPair(mintick);\n const negative = number < 0;\n const magnitude = negative ? -number : number;\n if (pair === null) {\n // A tick that is no decimal fraction: the grid of the double mintick, ties away from zero.\n const scaled = magnitude / mintick;\n let units = Math.trunc(scaled);\n if (scaled - units >= 0.5) units++;\n return (negative ? 0 - units : units) * mintick;\n }\n const [minmove, pricescale] = pair;\n const scaled = (magnitude * pricescale) / minmove;\n let units = Math.trunc(scaled);\n const offset = scaled - units - 0.5;\n const slack = 1e-6 + scaled * 1.8e-15;\n if (-slack < offset && offset < slack) {\n const [n, d] = exactRatio(magnitude);\n const num = n * BigInt(pricescale);\n const den = d * BigInt(minmove);\n const whole = num / den;\n units = Number(whole) + (reachesTie(num, den, whole) ? 1 : 0);\n } else if (offset > 0) {\n units++;\n }\n return ((negative ? 0 - units : units) * minmove) / pricescale;\n}\n\n// Constants\n/** Pi, the ratio of a circle's circumference to its diameter: 3.141592653589793. */\nexport const pi = Math.PI;\n/** Euler's number e, the base of natural logarithms (`math.log`): 2.718281828459045. */\nexport const e = Math.E;\n/** The golden ratio: 1.618033988749895. */\nexport const phi = 1.618033988749895;\n/** The reciprocal of the golden ratio (1 / phi): 0.6180339887498948. */\nexport const rphi = 0.6180339887498948;\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;A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,QAAQ,MAAM;AACpB,YAAQ,OAAO,KAAK,KAAK,WAAW,KAAK,KAAK,KAAK,IAAI,IAAI;AAAA,EAC7D,WAAW,SAAS,GAAG;AACrB;AAAA,EACF;AACA,UAAS,WAAW,IAAI,QAAQ,SAAS,UAAW;AACtD;AAIO,MAAM,KAAK,KAAK;AAEhB,MAAM,IAAI,KAAK;AAEf,MAAM,MAAM;AAEZ,MAAM,OAAO;",
|
|
6
6
|
"names": ["exp", "units", "sum", "e", "min", "max", "scaled"]
|
|
7
7
|
}
|
|
@@ -1,111 +1,90 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Polyline namespace
|
|
3
|
-
* Functions for creating and manipulating polyline drawing objects.
|
|
2
|
+
* Polyline namespace: functions that draw shapes through many points (`polyline.*`).
|
|
4
3
|
*
|
|
5
4
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* A polyline joins a list of chart points with straight or curved segments, open or closed, and can fill the closed
|
|
6
|
+
* shape: channels, patterns, zig-zags, curves. The `curved` flag goes to the renderer (`result.polylines` of the
|
|
7
|
+
* script API), which draws the curve.
|
|
9
8
|
*
|
|
10
9
|
* @version 6
|
|
11
10
|
*/
|
|
12
11
|
import type { ChartPoint, Polyline, color } from '../types/index.js';
|
|
13
12
|
export type { Polyline };
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
14
|
+
* Draws a shape through a list of chart points and returns its handle, to delete it later. The points are copied:
|
|
15
|
+
* changing the array afterwards does not move the polyline. With `xloc.bar_index` the x of a point is its `index`,
|
|
16
|
+
* with `xloc.bar_time` its `time`. The arguments after `points` can also be given by name in an object. Polylines
|
|
17
|
+
* above `max_polylines_count` (default 50) are deleted oldest first.
|
|
18
|
+
* @param points - The points, in drawing order (`chart.point.from_index(...)`, `chart.point.now()`...).
|
|
19
|
+
* @param curved - When true, the segments are curves through the points instead of straight lines. Default: false.
|
|
20
|
+
* @param closed - When true, the last point is joined back to the first one. Default: false.
|
|
21
|
+
* @param xloc - What the x coordinates of the points are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`.
|
|
22
|
+
* Default: `xloc.bar_index`.
|
|
23
|
+
* @param line_color - Colour of the segments. Default: blue (#2196F3).
|
|
24
|
+
* @param fill_color - Colour that fills the inside of the shape. Default: none.
|
|
25
|
+
* @param line_style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`. Default: `line.style_solid`.
|
|
26
|
+
* @param line_width - Width of the segments in pixels; a width under 1 is drawn as 1. Default: 1.
|
|
27
|
+
* @param force_overlay - When true, the polyline is drawn on the price pane even if the script has its own pane.
|
|
28
|
+
* Default: false.
|
|
29
|
+
* @returns The new polyline.
|
|
32
30
|
* @example
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* chartPoint.from_index(10, 120),
|
|
40
|
-
* chartPoint.from_index(20, 110)
|
|
41
|
-
* ];
|
|
42
|
-
*
|
|
43
|
-
* // Create a basic polyline
|
|
44
|
-
* const myPolyline = polyline.new(points);
|
|
45
|
-
*
|
|
46
|
-
* // Create a closed polygon with fill
|
|
47
|
-
* const polygon = polyline.new(
|
|
48
|
-
* points,
|
|
49
|
-
* false, // curved
|
|
50
|
-
* true, // closed
|
|
51
|
-
* 'bar_index', // xloc
|
|
52
|
-
* '#FF5722', // line_color
|
|
53
|
-
* 'rgba(255, 87, 34, 0.3)' // fill_color
|
|
54
|
-
* );
|
|
31
|
+
* ```js
|
|
32
|
+
* eachBar((c) => {
|
|
33
|
+
* if (c.i !== c.n - 1) return;
|
|
34
|
+
* const points = [0, 1, 2, 3, 4].map((k) => chart.point.from_index(c.i - k * 5, c.get(close, k * 5)));
|
|
35
|
+
* polyline.new(points, { curved: true, line_color: color.orange, line_width: 2 });
|
|
36
|
+
* });
|
|
55
37
|
* ```
|
|
56
38
|
*/
|
|
57
39
|
export declare function new_polyline(points: ChartPoint[], curved?: boolean, closed?: boolean, xloc?: 'bar_index' | 'bar_time' | 'pane', line_color?: color, fill_color?: color | null, line_style?: 'solid' | 'dotted' | 'dashed', line_width?: number, force_overlay?: boolean): Polyline;
|
|
58
40
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @param id - Polyline object to delete
|
|
62
|
-
*
|
|
63
|
-
* @remarks
|
|
64
|
-
* Removes the polyline from `polyline.all()` (the drawing registry, see drawing/registry).
|
|
65
|
-
*
|
|
41
|
+
* Removes the polyline from the chart and from `polyline.all`. Deleting it again does nothing.
|
|
42
|
+
* @param id - The polyline to delete.
|
|
66
43
|
* @example
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* polyline.
|
|
44
|
+
* ```js
|
|
45
|
+
* eachBar((c) => {
|
|
46
|
+
* const p = polyline.new([chart.point.from_index(c.i - 5, c.get(low, 5)), chart.point.now(c.high)]);
|
|
47
|
+
* if (c.i < c.n - 1) polyline.delete(p); // keep only the polyline of the last bar
|
|
48
|
+
* });
|
|
70
49
|
* ```
|
|
71
50
|
*/
|
|
72
51
|
export declare function delete_polyline(id: Polyline): void;
|
|
73
52
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @returns Array of all active polylines
|
|
77
|
-
*
|
|
78
|
-
* @remarks
|
|
79
|
-
* Returns a copy of the internal polylines array to prevent external modification.
|
|
80
|
-
*
|
|
53
|
+
* Returns the polylines that are still on the chart, oldest first, as `polyline.all` does. The array is a copy.
|
|
54
|
+
* @returns The live polylines in creation order.
|
|
81
55
|
* @example
|
|
82
|
-
* ```
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* console.log('Polyline ID:', p.id, 'Points:', p.points.length);
|
|
87
|
-
* }
|
|
56
|
+
* ```js
|
|
57
|
+
* eachBar((c) => {
|
|
58
|
+
* if (c.i === c.n - 1 && polyline.get_all().length > 10) polyline.delete(polyline.get_all()[0]);
|
|
59
|
+
* });
|
|
88
60
|
* ```
|
|
89
61
|
*/
|
|
90
62
|
export declare function get_all(): readonly Polyline[];
|
|
91
63
|
/**
|
|
92
|
-
*
|
|
64
|
+
* Returns the polylines that are still on the chart, oldest first. The array is a copy.
|
|
65
|
+
* (In a script, `polyline.all` is read as a value, without a call.)
|
|
66
|
+
* @returns The live polylines in creation order.
|
|
67
|
+
* @example
|
|
68
|
+
* ```js
|
|
69
|
+
* eachBar((c) => {
|
|
70
|
+
* if (c.i === c.n - 1) for (const p of polyline.all) polyline.delete(p);
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
93
73
|
*/
|
|
94
74
|
export declare function all(): Polyline[];
|
|
95
75
|
/**
|
|
96
|
-
* Deletes
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
76
|
+
* Deletes every live polyline at once.
|
|
77
|
+
* @example
|
|
78
|
+
* ```js
|
|
79
|
+
* eachBar((c) => {
|
|
80
|
+
* if (c.i === c.n - 1) polyline.clear_all();
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
101
83
|
*/
|
|
102
84
|
export declare function clear_all(): void;
|
|
103
85
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* @remarks
|
|
107
|
-
* This is useful for resetting state, especially in tests.
|
|
108
|
-
* Not part of the PineScript API.
|
|
86
|
+
* Starts the numbering of the polyline ids again from 1 (the `id` of the next polyline is "polyline_1"). Meant for
|
|
87
|
+
* tests; a script has no use for it.
|
|
109
88
|
*/
|
|
110
89
|
export declare function reset_id_counter(): void;
|
|
111
90
|
export { new_polyline as new };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/polyline/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/polyline/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAIrE,YAAY,EAAE,QAAQ,EAAE,CAAC;AAYzB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,UAAU,EAAE,EACpB,MAAM,GAAE,OAAe,EACvB,MAAM,GAAE,OAAe,EACvB,IAAI,GAAE,WAAW,GAAG,UAAU,GAAG,MAAoB,EACrD,UAAU,GAAE,KAAiB,EAC7B,UAAU,GAAE,KAAK,GAAG,IAAW,EAC/B,UAAU,GAAE,OAAO,GAAG,QAAQ,GAAG,QAAkB,EACnD,UAAU,GAAE,MAAU,EACtB,aAAa,GAAE,OAAe,GAC7B,QAAQ,CAuBV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAElD;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,IAAI,SAAS,QAAQ,EAAE,CAE7C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,IAAI,QAAQ,EAAE,CAEhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAGD,OAAO,EAAE,YAAY,IAAI,GAAG,EAAE,CAAC;AAC/B,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/polyline/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Polyline namespace
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Polyline namespace: functions that draw shapes through many points (`polyline.*`).\n *\n * @remarks\n * A polyline joins a list of chart points with straight or curved segments, open or closed, and can fill the closed\n * shape: channels, patterns, zig-zags, curves. The `curved` flag goes to the renderer (`result.polylines` of the\n * script API), which draws the curve.\n *\n * @version 6\n */\n\nimport type { ChartPoint, Polyline, color } from '../types/index.js';\nimport { all as allDrawings, checkBarIndex, register, remove } from '../drawing/registry.js';\n\n// Re-export the Polyline type for convenience\nexport type { Polyline };\n\n// Internal counter for generating unique IDs\nlet polylineIdCounter = 0;\n\n/**\n * Generates a unique ID for a polyline\n */\nfunction generateId(): string {\n return `polyline_${++polylineIdCounter}`;\n}\n\n/**\n * Draws a shape through a list of chart points and returns its handle, to delete it later. The points are copied:\n * changing the array afterwards does not move the polyline. With `xloc.bar_index` the x of a point is its `index`,\n * with `xloc.bar_time` its `time`. The arguments after `points` can also be given by name in an object. Polylines\n * above `max_polylines_count` (default 50) are deleted oldest first.\n * @param points - The points, in drawing order (`chart.point.from_index(...)`, `chart.point.now()`...).\n * @param curved - When true, the segments are curves through the points instead of straight lines. Default: false.\n * @param closed - When true, the last point is joined back to the first one. Default: false.\n * @param xloc - What the x coordinates of the points are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`.\n * Default: `xloc.bar_index`.\n * @param line_color - Colour of the segments. Default: blue (#2196F3).\n * @param fill_color - Colour that fills the inside of the shape. Default: none.\n * @param line_style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`. Default: `line.style_solid`.\n * @param line_width - Width of the segments in pixels; a width under 1 is drawn as 1. Default: 1.\n * @param force_overlay - When true, the polyline is drawn on the price pane even if the script has its own pane.\n * Default: false.\n * @returns The new polyline.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i !== c.n - 1) return;\n * const points = [0, 1, 2, 3, 4].map((k) => chart.point.from_index(c.i - k * 5, c.get(close, k * 5)));\n * polyline.new(points, { curved: true, line_color: color.orange, line_width: 2 });\n * });\n * ```\n */\nexport function new_polyline(\n points: ChartPoint[],\n curved: boolean = false,\n closed: boolean = false,\n xloc: 'bar_index' | 'bar_time' | 'pane' = 'bar_index',\n line_color: color = '#2196F3',\n fill_color: color | null = null,\n line_style: 'solid' | 'dotted' | 'dashed' = 'solid',\n line_width: number = 1,\n force_overlay: boolean = false\n): Polyline {\n // Validate line_width is positive\n if (line_width < 1) {\n console.warn('polyline.new(): line_width must be at least 1. Using 1.');\n line_width = 1;\n }\n\n if (xloc === 'bar_index') for (const point of points) if (point.index !== null) checkBarIndex('polyline.new', 'points', point.index, xloc);\n\n const polyline: Polyline = {\n id: generateId(),\n points: [...points], // Create a copy of the points array\n curved,\n closed,\n xloc,\n line_color,\n fill_color,\n line_style,\n line_width,\n force_overlay,\n };\n\n return register('polyline', polyline);\n}\n\n/**\n * Removes the polyline from the chart and from `polyline.all`. Deleting it again does nothing.\n * @param id - The polyline to delete.\n * @example\n * ```js\n * eachBar((c) => {\n * const p = polyline.new([chart.point.from_index(c.i - 5, c.get(low, 5)), chart.point.now(c.high)]);\n * if (c.i < c.n - 1) polyline.delete(p); // keep only the polyline of the last bar\n * });\n * ```\n */\nexport function delete_polyline(id: Polyline): void {\n remove('polyline', id);\n}\n\n/**\n * Returns the polylines that are still on the chart, oldest first, as `polyline.all` does. The array is a copy.\n * @returns The live polylines in creation order.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1 && polyline.get_all().length > 10) polyline.delete(polyline.get_all()[0]);\n * });\n * ```\n */\nexport function get_all(): readonly Polyline[] {\n return allDrawings('polyline');\n}\n\n/**\n * Returns the polylines that are still on the chart, oldest first. The array is a copy.\n * (In a script, `polyline.all` is read as a value, without a call.)\n * @returns The live polylines in creation order.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) for (const p of polyline.all) polyline.delete(p);\n * });\n * ```\n */\nexport function all(): Polyline[] {\n return allDrawings('polyline');\n}\n\n/**\n * Deletes every live polyline at once.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) polyline.clear_all();\n * });\n * ```\n */\nexport function clear_all(): void {\n for (const p of allDrawings('polyline')) remove('polyline', p);\n}\n\n/**\n * Starts the numbering of the polyline ids again from 1 (the `id` of the next polyline is \"polyline_1\"). Meant for\n * tests; a script has no use for it.\n */\nexport function reset_id_counter(): void {\n polylineIdCounter = 0;\n}\n\n// Aliases to match PineScript API\nexport { new_polyline as new };\nexport { delete_polyline as delete };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAoE;AAMpE,IAAI,oBAAoB;AAKxB,SAAS,aAAqB;AAC5B,SAAO,YAAY,EAAE,iBAAiB;AACxC;AA4BO,SAAS,aACd,QACA,SAAkB,OAClB,SAAkB,OAClB,OAA0C,aAC1C,aAAoB,WACpB,aAA2B,MAC3B,aAA4C,SAC5C,aAAqB,GACrB,gBAAyB,OACf;AAEV,MAAI,aAAa,GAAG;AAClB,YAAQ,KAAK,yDAAyD;AACtE,iBAAa;AAAA,EACf;AAEA,MAAI,SAAS;AAAa,eAAW,SAAS,OAAQ,KAAI,MAAM,UAAU,KAAM,oCAAc,gBAAgB,UAAU,MAAM,OAAO,IAAI;AAAA;AAEzI,QAAM,WAAqB;AAAA,IACzB,IAAI,WAAW;AAAA,IACf,QAAQ,CAAC,GAAG,MAAM;AAAA;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,aAAO,0BAAS,YAAY,QAAQ;AACtC;AAaO,SAAS,gBAAgB,IAAoB;AAClD,8BAAO,YAAY,EAAE;AACvB;AAYO,SAAS,UAA+B;AAC7C,aAAO,gBAAAA,KAAY,UAAU;AAC/B;AAaO,SAAS,MAAkB;AAChC,aAAO,gBAAAA,KAAY,UAAU;AAC/B;AAWO,SAAS,YAAkB;AAChC,aAAW,SAAK,gBAAAA,KAAY,UAAU,EAAG,6BAAO,YAAY,CAAC;AAC/D;AAMO,SAAS,mBAAyB;AACvC,sBAAoB;AACtB;",
|
|
6
6
|
"names": ["allDrawings"]
|
|
7
7
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { InputConfig } from './types.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* cannot be edited. It still gives its value to the script.
|
|
7
|
+
* Host-side: whether an input is active (its `active` option): an inactive input is shown greyed out in the settings
|
|
8
|
+
* and cannot be edited. It still gives its value to the script.
|
|
9
9
|
*
|
|
10
10
|
* @param config - The input
|
|
11
11
|
* @param inputs - Current input values by id
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/runtime/input-active.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview PineScript `active` of an input: whether the settings dialog lets the user edit it\n * @module runtime/input-active\n */\n\nimport type { InputConfig, InputCondition } from './types.js';\n\n/** Current value of an input: the host value, else the default of its config. */\nfunction inputValue(id: string, inputs: Record<string, unknown>, configs?: readonly InputConfig[]): unknown {\n const value = inputs[id];\n if (value !== undefined) return value;\n return configs?.find((c) => c.id === id)?.defval;\n}\n\nfunction holds(condition: InputCondition, inputs: Record<string, unknown>, configs?: readonly InputConfig[]): boolean {\n if (typeof condition === 'string') return inputValue(condition, inputs, configs) === true;\n if ('not' in condition) return !holds(condition.not, inputs, configs);\n if ('any' in condition) return condition.any.some((c) => holds(c, inputs, configs));\n if ('all' in condition) return condition.all.every((c) => holds(c, inputs, configs));\n const value = inputValue(condition.input, inputs, configs);\n if (!('eq' in condition) && !('ne' in condition)) return value === true;\n return (!('eq' in condition) || value === condition.eq) && (!('ne' in condition) || value !== condition.ne);\n}\n\n/**\n *
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview PineScript `active` of an input: whether the settings dialog lets the user edit it\n * @module runtime/input-active\n */\n\nimport type { InputConfig, InputCondition } from './types.js';\n\n/** Current value of an input: the host value, else the default of its config. */\nfunction inputValue(id: string, inputs: Record<string, unknown>, configs?: readonly InputConfig[]): unknown {\n const value = inputs[id];\n if (value !== undefined) return value;\n return configs?.find((c) => c.id === id)?.defval;\n}\n\nfunction holds(condition: InputCondition, inputs: Record<string, unknown>, configs?: readonly InputConfig[]): boolean {\n if (typeof condition === 'string') return inputValue(condition, inputs, configs) === true;\n if ('not' in condition) return !holds(condition.not, inputs, configs);\n if ('any' in condition) return condition.any.some((c) => holds(c, inputs, configs));\n if ('all' in condition) return condition.all.every((c) => holds(c, inputs, configs));\n const value = inputValue(condition.input, inputs, configs);\n if (!('eq' in condition) && !('ne' in condition)) return value === true;\n return (!('eq' in condition) || value === condition.eq) && (!('ne' in condition) || value !== condition.ne);\n}\n\n/**\n * Host-side: whether an input is active (its `active` option): an inactive input is shown greyed out in the settings\n * and cannot be edited. It still gives its value to the script.\n *\n * @param config - The input\n * @param inputs - Current input values by id\n * @param configs - All the inputs of the indicator: gives the default of an input that has no value in `inputs`\n * @returns true when `config.active` is not set, is true, or is a condition that holds\n *\n * @example\n * ```typescript\n * const configs: InputConfig[] = [\n * { id: 'showMa1', type: 'bool', defval: true, title: 'MA #1' },\n * { id: 'ma1Length', type: 'int', defval: 20, active: 'showMa1' },\n * { id: 'bbMult', type: 'float', defval: 2, active: { input: 'maType', eq: 'SMA + Bollinger Bands' } },\n * ];\n * isInputActive(configs[1], { showMa1: false }) // false\n * isInputActive(configs[1], {}, configs) // true: the default of showMa1\n * ```\n */\nexport function isInputActive(config: InputConfig, inputs: Record<string, unknown> = {}, configs?: readonly InputConfig[]): boolean {\n const { active } = config;\n if (active === undefined) return true;\n if (typeof active === 'boolean') return active;\n return holds(active, inputs, configs);\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAS,WAAW,IAAY,QAAiC,SAA2C;AAC1G,QAAM,QAAQ,OAAO,EAAE;AACvB,MAAI,UAAU,OAAW,QAAO;AAChC,SAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG;AAC5C;AAEA,SAAS,MAAM,WAA2B,QAAiC,SAA2C;AACpH,MAAI,OAAO,cAAc,SAAU,QAAO,WAAW,WAAW,QAAQ,OAAO,MAAM;AACrF,MAAI,SAAS,UAAW,QAAO,CAAC,MAAM,UAAU,KAAK,QAAQ,OAAO;AACpE,MAAI,SAAS,UAAW,QAAO,UAAU,IAAI,KAAK,CAAC,MAAM,MAAM,GAAG,QAAQ,OAAO,CAAC;AAClF,MAAI,SAAS,UAAW,QAAO,UAAU,IAAI,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,OAAO,CAAC;AACnF,QAAM,QAAQ,WAAW,UAAU,OAAO,QAAQ,OAAO;AACzD,MAAI,EAAE,QAAQ,cAAc,EAAE,QAAQ,WAAY,QAAO,UAAU;AACnE,UAAQ,EAAE,QAAQ,cAAc,UAAU,UAAU,QAAQ,EAAE,QAAQ,cAAc,UAAU,UAAU;AAC1G;AAsBO,SAAS,cAAc,QAAqB,SAAkC,CAAC,GAAG,SAA2C;AAClI,QAAM,EAAE,OAAO,IAAI;AACnB,MAAI,WAAW,OAAW,QAAO;AACjC,MAAI,OAAO,WAAW,UAAW,QAAO;AACxC,SAAO,MAAM,QAAQ,QAAQ,OAAO;AACtC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|