oakscriptjs 0.9.1 → 0.9.3
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/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/math/index.d.ts +6 -0
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js.map +2 -2
- package/dist/cjs/ta/index.d.ts +2 -0
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +13 -17
- package/dist/cjs/ta/index.js.map +2 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/math/index.d.ts +6 -0
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +6 -0
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/ta/index.d.ts +2 -0
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +23 -26
- package/dist/esm/ta/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/math/index.ts +6 -0
- package/src/ta/index.ts +23 -29
package/dist/cjs/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export type * from './strategy/index.js';
|
|
|
54
54
|
export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
55
55
|
export type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
56
56
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
57
|
-
export declare const VERSION = "0.9.
|
|
57
|
+
export declare const VERSION = "0.9.3";
|
|
58
58
|
/**
|
|
59
59
|
* Library information
|
|
60
60
|
*/
|
package/dist/cjs/index.js
CHANGED
|
@@ -160,7 +160,7 @@ var import_inputs = require("./runtime/inputs.js");
|
|
|
160
160
|
var import_strategy = require("./strategy/index.js");
|
|
161
161
|
var import_LightweightChartsAdapter = require("./runtime/adapters/LightweightChartsAdapter.js");
|
|
162
162
|
var import_SimpleInputAdapter = require("./runtime/adapters/SimpleInputAdapter.js");
|
|
163
|
-
const VERSION = "0.9.
|
|
163
|
+
const VERSION = "0.9.3";
|
|
164
164
|
const info = {
|
|
165
165
|
name: "OakScriptJS",
|
|
166
166
|
version: VERSION,
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * OakScriptJS - Simplified PineScript-like library for JavaScript\n *\n * This library provides Series-based lazy evaluation and technical analysis functions\n * for building trading indicators. The PineScript-style script API is in `oakscriptjs/script`.\n *\n * Key features:\n * - Series class for lazy evaluation and method chaining\n * - Core TA functions (array-based)\n * - TA-Series wrappers (Series-based)\n *\n * @packageDocumentation\n */\n\n// Export all types\nexport * from './types/index.js';\nexport * from './types/metadata.js';\n\n// Export core namespaces (array-based functions)\nimport * as taCore from './ta/index.js';\nimport * as math from './math/index.js';\nimport * as array from './array/index.js';\nimport * as map from './map/index.js';\nimport * as str from './str/index.js';\nimport * as color from './color/index.js';\nimport * as time from './time/index.js';\nimport * as timeframe from './timeframe/index.js';\nimport * as matrix from './matrix/index.js';\nimport * as line from './line/index.js';\nimport * as box from './box/index.js';\nimport * as label from './label/index.js';\nimport * as linefill from './linefill/index.js';\nimport * as chartPoint from './chartpoint/index.js';\nimport * as polyline from './polyline/index.js';\nimport * as text from './text/index.js';\nimport * as compare from './compare/index.js';\nimport * as callsite from './callsite/index.js';\n\nexport { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, text, compare, callsite };\n\n// Export Series class (self-contained, no context)\nexport { Series, BarData } from './runtime/series.js';\nexport type { SeriesExtractor } from './runtime/series.js';\n\n// Export TA-Series namespace (Series-based wrappers)\nimport * as ta from './ta-series.js';\nexport { ta };\n\n// Export metadata types for indicator return values\nexport type {\n PlotOptions,\n HLineOptions,\n FillOptions,\n InputMetadata,\n PlotMetadata,\n IndicatorMetadata,\n TimeValue,\n PlotData,\n HLineData,\n FillData,\n FillGradient,\n IndicatorResult,\n IndicatorFactory,\n PlotStyle,\n LineStyle,\n PlotDisplay,\n InputType\n} from './types/metadata.js';\n\n// Re-export commonly used functions for convenience\nexport { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr, cum, vwap } from './ta-series.js';\nexport { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math/index.js';\nexport { rgb, from_hex as color_from_hex, new_color } from './color/index.js';\n\n// Export chart data utilities\nexport { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';\n\n// Export libraries (ZigZag, etc.)\nexport * from './lib/index.js';\n\n// Export helper functions for generated indicators (PineScript compatibility)\nexport {isNA as na, nz, fixnan} from './utils/index.js';\n\n// Export indicator infrastructure\nexport {\n indicator,\n type IndicatorMetadataConfig,\n type InputDefinition,\n type IndicatorContext,\n type IndicatorInstance,\n type IndicatorConstructor,\n} from './indicator.js';\n\nexport {\n input,\n type InputValue,\n type IntInputOptions,\n type FloatInputOptions,\n type SourceInputOptions,\n type BoolInputOptions,\n type StringInputOptions,\n type TimeInputOptions,\n type SourceType,\n} from './input.js';\n\nexport {\n plot as plotHelper,\n createPlot,\n type Time,\n type TimeValuePair,\n type PlotOptions as PlotHelperOptions,\n type PlotResult,\n} from './plot.js';\n\n// Runtime exports - global context runtime (setContext, plot, hline) drawing through a ChartAdapter\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n} from './runtime/runtime.js';\n\nexport {\n input_int,\n input_float,\n input_bool,\n input_string,\n input_source,\n input_timeframe,\n input_session,\n input_time,\n} from './runtime/inputs.js';\n\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputOptions,\n OhlcvData,\n PlotConfig,\n HLineConfig,\n FillConfig,\n ArrowConfig,\n} from './runtime/types.js';\n\n// Strategy types and constants (the script API forwards strategy.* calls to a host engine)\nexport {\n STRATEGY_CONSTANTS,\n STRATEGY_DEFAULTS,\n STRATEGY_NUMBER_VARIABLES,\n STRATEGY_TEXT_VARIABLES,\n} from './strategy/index.js';\nexport type * from './strategy/index.js';\n\nexport { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';\n\n// Version\nexport const VERSION = '0.9.
|
|
4
|
+
"sourcesContent": ["/**\n * OakScriptJS - Simplified PineScript-like library for JavaScript\n *\n * This library provides Series-based lazy evaluation and technical analysis functions\n * for building trading indicators. The PineScript-style script API is in `oakscriptjs/script`.\n *\n * Key features:\n * - Series class for lazy evaluation and method chaining\n * - Core TA functions (array-based)\n * - TA-Series wrappers (Series-based)\n *\n * @packageDocumentation\n */\n\n// Export all types\nexport * from './types/index.js';\nexport * from './types/metadata.js';\n\n// Export core namespaces (array-based functions)\nimport * as taCore from './ta/index.js';\nimport * as math from './math/index.js';\nimport * as array from './array/index.js';\nimport * as map from './map/index.js';\nimport * as str from './str/index.js';\nimport * as color from './color/index.js';\nimport * as time from './time/index.js';\nimport * as timeframe from './timeframe/index.js';\nimport * as matrix from './matrix/index.js';\nimport * as line from './line/index.js';\nimport * as box from './box/index.js';\nimport * as label from './label/index.js';\nimport * as linefill from './linefill/index.js';\nimport * as chartPoint from './chartpoint/index.js';\nimport * as polyline from './polyline/index.js';\nimport * as text from './text/index.js';\nimport * as compare from './compare/index.js';\nimport * as callsite from './callsite/index.js';\n\nexport { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, text, compare, callsite };\n\n// Export Series class (self-contained, no context)\nexport { Series, BarData } from './runtime/series.js';\nexport type { SeriesExtractor } from './runtime/series.js';\n\n// Export TA-Series namespace (Series-based wrappers)\nimport * as ta from './ta-series.js';\nexport { ta };\n\n// Export metadata types for indicator return values\nexport type {\n PlotOptions,\n HLineOptions,\n FillOptions,\n InputMetadata,\n PlotMetadata,\n IndicatorMetadata,\n TimeValue,\n PlotData,\n HLineData,\n FillData,\n FillGradient,\n IndicatorResult,\n IndicatorFactory,\n PlotStyle,\n LineStyle,\n PlotDisplay,\n InputType\n} from './types/metadata.js';\n\n// Re-export commonly used functions for convenience\nexport { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr, cum, vwap } from './ta-series.js';\nexport { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math/index.js';\nexport { rgb, from_hex as color_from_hex, new_color } from './color/index.js';\n\n// Export chart data utilities\nexport { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';\n\n// Export libraries (ZigZag, etc.)\nexport * from './lib/index.js';\n\n// Export helper functions for generated indicators (PineScript compatibility)\nexport {isNA as na, nz, fixnan} from './utils/index.js';\n\n// Export indicator infrastructure\nexport {\n indicator,\n type IndicatorMetadataConfig,\n type InputDefinition,\n type IndicatorContext,\n type IndicatorInstance,\n type IndicatorConstructor,\n} from './indicator.js';\n\nexport {\n input,\n type InputValue,\n type IntInputOptions,\n type FloatInputOptions,\n type SourceInputOptions,\n type BoolInputOptions,\n type StringInputOptions,\n type TimeInputOptions,\n type SourceType,\n} from './input.js';\n\nexport {\n plot as plotHelper,\n createPlot,\n type Time,\n type TimeValuePair,\n type PlotOptions as PlotHelperOptions,\n type PlotResult,\n} from './plot.js';\n\n// Runtime exports - global context runtime (setContext, plot, hline) drawing through a ChartAdapter\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n} from './runtime/runtime.js';\n\nexport {\n input_int,\n input_float,\n input_bool,\n input_string,\n input_source,\n input_timeframe,\n input_session,\n input_time,\n} from './runtime/inputs.js';\n\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputOptions,\n OhlcvData,\n PlotConfig,\n HLineConfig,\n FillConfig,\n ArrowConfig,\n} from './runtime/types.js';\n\n// Strategy types and constants (the script API forwards strategy.* calls to a host engine)\nexport {\n STRATEGY_CONSTANTS,\n STRATEGY_DEFAULTS,\n STRATEGY_NUMBER_VARIABLES,\n STRATEGY_TEXT_VARIABLES,\n} from './strategy/index.js';\nexport type * from './strategy/index.js';\n\nexport { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';\n\n// Version\nexport const VERSION = '0.9.3';\n\n/**\n * Library information\n */\nexport const info = {\n name: 'OakScriptJS',\n version: VERSION,\n description: 'Simplified PineScript-like library - Series + TA functions',\n features: {\n series: 'Lazy evaluation with Series class',\n ta: 'Technical analysis functions (Series and array-based)',\n script: 'PineScript-style script API (oakscriptjs/script): indicator, strategy, inputs, plots, request.security',\n runtime: 'Global context runtime drawing through a ChartAdapter',\n indicator: 'Indicator function with automatic pane management'\n },\n namespaces: {\n core: ['ta', 'math', 'array', 'map', 'str', 'color', 'time', 'timeframe', 'matrix'],\n drawing: ['line', 'box', 'label', 'linefill', 'chartPoint', 'polyline', 'text'],\n runtime: ['setContext', 'plot', 'hline', 'input_*'],\n indicator: ['indicator', 'input', 'plotHelper', 'createPlot']\n }\n};\n\n// PineScript compatibility stubs - functions that have no runtime effect\n// These are no-ops so that PineScript-style code runs without modification\n\n/**\n * alertcondition() - Stub for PineScript alert configuration\n * In PineScript, this registers an alert condition. In oakscriptjs, it's a no-op\n * since alert configuration is handled by the host application.\n */\nexport function alertcondition(_condition: unknown, _title?: string, _message?: string): void {\n // No-op: Alert conditions are handled by the host application\n}\n"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M;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,UAAU;AAAA,IACR,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,YAAY;AAAA,IACV,MAAM,CAAC,MAAM,QAAQ,SAAS,OAAO,OAAO,SAAS,QAAQ,aAAa,QAAQ;AAAA,IAClF,SAAS,CAAC,QAAQ,OAAO,SAAS,YAAY,cAAc,YAAY,MAAM;AAAA,IAC9E,SAAS,CAAC,cAAc,QAAQ,SAAS,SAAS;AAAA,IAClD,WAAW,CAAC,aAAa,SAAS,cAAc,YAAY;AAAA,EAC9D;AACF;AAUO,SAAS,eAAe,YAAqB,QAAiB,UAAyB;AAE9F;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
package/dist/cjs/math/index.d.ts
CHANGED
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
* All math functions in this namespace follow PineScript v6 API specifications.
|
|
7
7
|
* Functions include basic arithmetic, algebraic operations, trigonometry, and combinatorics.
|
|
8
8
|
*
|
|
9
|
+
* Known difference: `log10`, `exp`, `log`, `pow`, `sin`, `cos`, `tan` use JavaScript's `Math`. PineScript uses
|
|
10
|
+
* other algorithms, whose results differ by 1 or 2 units in the last place on part of the inputs (`log10` about 4 %,
|
|
11
|
+
* `exp` about 9 %, `sin` / `cos` / `tan` about 3 %, `log` 0.4 %, `pow` 0.05 % of random inputs). A constant argument
|
|
12
|
+
* (`math.log10(2)`) can differ by up to 3 units in the last place. This is visible only when a script amplifies
|
|
13
|
+
* these tiny differences (e.g. `ma > ma[1]` on values of 1e195); `sqrt`, `atan`, `asin`, `acos` are equal.
|
|
14
|
+
*
|
|
9
15
|
* @version 6
|
|
10
16
|
*/
|
|
11
17
|
import type { float, int, simple_int, series_float } from '../types/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/math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ACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AACnD,wBAAgB,SAAS,CAAC,OAAO,EAAE,KAAK,GAAG,KAAK,CAAC;AAmBjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;AACnD,wBAAgB,SAAS,CAAC,OAAO,EAAE,KAAK,GAAG,KAAK,CAAC;AAmBjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,KAAK,CAQnE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;AAC5C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC;AAmBxC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;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;AAuDxE,eAAO,MAAM,EAAE,QAAU,CAAC;AAC1B,eAAO,MAAM,CAAC,QAAS,CAAC;AACxB,eAAO,MAAM,GAAG,oBAAoB,CAAC;AACrC,eAAO,MAAM,IAAI,oBAAoB,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 * @version 6\n */\n\nimport type { float, int, simple_int, series_float } from '../types/index.js';\nimport { Series } from '../runtime/series.js';\nimport { runningSum } from '../ta/running-sum.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 * - Uses \"round half up\" strategy (0.5 rounds to 1)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.round(4.2) // Returns: 4\n * math.round(4.5) // Returns: 5\n * math.round(4.8) // Returns: 5\n * math.round(4.567, 2) // Returns: 4.57\n * math.round(4.567, 1) // Returns: 4.6\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 length = bars.length;\n \n const result: number[] = [];\n if (precision === undefined) {\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.round(v));\n }\n } else {\n const multiplier = Math.pow(10, precision);\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.round(v * multiplier) / multiplier);\n }\n }\n \n return Series.fromArray(bars, result);\n }\n \n if (precision === undefined) {\n return Math.round(value);\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\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 *\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 // All scalars - calculate simple average\n return (values as number[]).reduce((a, b) => a + b, 0) / values.length;\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 const sum = nums.reduce((a, b) => a + b, 0);\n result.push(sum / nums.length);\n }\n \n return Series.fromArray(bars, result);\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\n * @returns Series or array with rolling sum values\n *\n * @remarks\n * - Calculates the sum of the last `length` non-`na` values at each point; an `na` value (also +/-Infinity) is\n * skipped and the bar keeps the previous result (as in PineScript)\n * - Returns NaN until `length` non-`na` values are available\n * - A compensated running sum, as in PineScript, so the result can differ from the exact window sum in the last\n * bits (bit for bit with PineScript)\n * - When passed a Series, returns a Series; when passed an array, returns an array\n *\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): Series;\nexport function sum(source: series_float, length: simple_int): series_float;\nexport function sum(source: series_float | Series, length: simple_int): series_float | Series {\n // Handle Series objects - extract to array first\n const sourceArray = source instanceof Series ? source.toArray() : source;\n // PineScript: the sum of the last `length` non-na values (also +/-Infinity skipped); an na bar keeps the previous\n // result. A compensated running sum, bit for bit as PineScript.\n const result: series_float = runningSum(sourceArray, length);\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 * Returns a pseudo-random number.\n *\n * @param min - Optional minimum value (inclusive)\n * @param max - Optional maximum value (exclusive)\n * @param seed - Optional seed for deterministic random\n * @returns A random number in the specified range, or [0, 1) if no range specified\n *\n * @remarks\n * - Without arguments: returns value in [0, 1)\n * - With min and max: returns value in [min, max)\n * - **WARNING**: The seed parameter is accepted for API compatibility but NOT currently implemented\n * - This implementation always generates non-deterministic random values\n * - PineScript's version supports deterministic seeding for repeatable sequences\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(5, 15) // Returns: value between 5 and 15 (e.g., 11.82...)\n * ```\n */\nexport function random(min?: float, max?: float, _seed?: int): float {\n // TODO: Implement deterministic seeding to match PineScript behavior\n // Currently _seed parameter is ignored\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\n *\n * @remarks\n * - Returns 1 if value > 0\n * - Returns -1 if value < 0\n * - Returns 0 if value = 0\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 * ```\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 : 0);\n }\n \n return Series.fromArray(bars, result);\n }\n \n return value > 0 ? 1 : value < 0 ? -1 : 0;\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 * - Ties round up (0.5 -> 1)\n * - If number is a Series, returns a Series; if number is a float, returns a float\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 const length = bars.length;\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 \n const result: number[] = [];\n if (mintick === 0) {\n // No rounding needed\n for (let i = 0; i < length; i++) {\n result.push(valueArray[i] ?? NaN);\n }\n } else {\n for (let i = 0; i < length; i++) {\n const v = valueArray[i];\n if (v === undefined || isNaN(v)) {\n result.push(NaN);\n } else {\n result.push(Math.round(v / mintick) * mintick);\n }\n }\n }\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\n if (mintick === 0) {\n return number;\n }\n\n // Round to nearest tick\n return Math.round(number / mintick) * mintick;\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.618033988749895; // Reciprocal of golden ratio\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;
|
|
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). A constant argument\n * (`math.log10(2)`) can differ by up to 3 units in the last place. This is visible only when a script amplifies\n * these tiny differences (e.g. `ma > ma[1]` on values of 1e195); `sqrt`, `atan`, `asin`, `acos` are equal.\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 } from '../ta/running-sum.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 * - Uses \"round half up\" strategy (0.5 rounds to 1)\n * - If value is a Series, returns a Series; if value is a number, returns a number\n *\n * @example\n * ```typescript\n * math.round(4.2) // Returns: 4\n * math.round(4.5) // Returns: 5\n * math.round(4.8) // Returns: 5\n * math.round(4.567, 2) // Returns: 4.57\n * math.round(4.567, 1) // Returns: 4.6\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 length = bars.length;\n \n const result: number[] = [];\n if (precision === undefined) {\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.round(v));\n }\n } else {\n const multiplier = Math.pow(10, precision);\n for (let i = 0; i < length; i++) {\n const v = valueArray[i] ?? NaN;\n result.push(Math.round(v * multiplier) / multiplier);\n }\n }\n \n return Series.fromArray(bars, result);\n }\n \n if (precision === undefined) {\n return Math.round(value);\n }\n const multiplier = Math.pow(10, precision);\n return Math.round(value * multiplier) / multiplier;\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 *\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 // All scalars - calculate simple average\n return (values as number[]).reduce((a, b) => a + b, 0) / values.length;\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 const sum = nums.reduce((a, b) => a + b, 0);\n result.push(sum / nums.length);\n }\n \n return Series.fromArray(bars, result);\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\n * @returns Series or array with rolling sum values\n *\n * @remarks\n * - Calculates the sum of the last `length` non-`na` values at each point; an `na` value (also +/-Infinity) is\n * skipped and the bar keeps the previous result (as in PineScript)\n * - Returns NaN until `length` non-`na` values are available\n * - A compensated running sum, as in PineScript, so the result can differ from the exact window sum in the last\n * bits (bit for bit with PineScript)\n * - When passed a Series, returns a Series; when passed an array, returns an array\n *\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): Series;\nexport function sum(source: series_float, length: simple_int): series_float;\nexport function sum(source: series_float | Series, length: simple_int): series_float | Series {\n // Handle Series objects - extract to array first\n const sourceArray = source instanceof Series ? source.toArray() : source;\n // PineScript: the sum of the last `length` non-na values (also +/-Infinity skipped); an na bar keeps the previous\n // result. A compensated running sum, bit for bit as PineScript.\n const result: series_float = runningSum(sourceArray, length);\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 * Returns a pseudo-random number.\n *\n * @param min - Optional minimum value (inclusive)\n * @param max - Optional maximum value (exclusive)\n * @param seed - Optional seed for deterministic random\n * @returns A random number in the specified range, or [0, 1) if no range specified\n *\n * @remarks\n * - Without arguments: returns value in [0, 1)\n * - With min and max: returns value in [min, max)\n * - **WARNING**: The seed parameter is accepted for API compatibility but NOT currently implemented\n * - This implementation always generates non-deterministic random values\n * - PineScript's version supports deterministic seeding for repeatable sequences\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(5, 15) // Returns: value between 5 and 15 (e.g., 11.82...)\n * ```\n */\nexport function random(min?: float, max?: float, _seed?: int): float {\n // TODO: Implement deterministic seeding to match PineScript behavior\n // Currently _seed parameter is ignored\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\n *\n * @remarks\n * - Returns 1 if value > 0\n * - Returns -1 if value < 0\n * - Returns 0 if value = 0\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 * ```\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 : 0);\n }\n \n return Series.fromArray(bars, result);\n }\n \n return value > 0 ? 1 : value < 0 ? -1 : 0;\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 * - Ties round up (0.5 -> 1)\n * - If number is a Series, returns a Series; if number is a float, returns a float\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 const length = bars.length;\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 \n const result: number[] = [];\n if (mintick === 0) {\n // No rounding needed\n for (let i = 0; i < length; i++) {\n result.push(valueArray[i] ?? NaN);\n }\n } else {\n for (let i = 0; i < length; i++) {\n const v = valueArray[i];\n if (v === undefined || isNaN(v)) {\n result.push(NaN);\n } else {\n result.push(Math.round(v / mintick) * mintick);\n }\n }\n }\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\n if (mintick === 0) {\n return number;\n }\n\n // Round to nearest tick\n return Math.round(number / mintick) * mintick;\n}\n\n// Constants\nexport const pi = Math.PI;\nexport const e = Math.E;\n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MAAI,YAAY,QAAW;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,MAAI,YAAY,GAAG;AACjB,WAAO;AAAA,EACT;AAGA,SAAO,KAAK,MAAM,SAAS,OAAO,IAAI;AACxC;AAGO,MAAM,KAAK,KAAK;AAChB,MAAM,IAAI,KAAK;AACf,MAAM,MAAM;AACZ,MAAM,OAAO;",
|
|
6
6
|
"names": ["multiplier", "sum", "e", "min", "max"]
|
|
7
7
|
}
|
package/dist/cjs/ta/index.d.ts
CHANGED
|
@@ -264,6 +264,7 @@ export declare function atr(length: simple_int, high?: Source, low?: Source, clo
|
|
|
264
264
|
* - Direction: 1 = downtrend (red), -1 = uptrend (green)
|
|
265
265
|
* - Uses hl2 (average of high and low) as the source
|
|
266
266
|
* - SuperTrend helps identify the current market trend and potential reversal points
|
|
267
|
+
* - As in PineScript (`nz` of the previous bands): 0 on bar 0, na on the next bars while the ATR is na
|
|
267
268
|
*
|
|
268
269
|
* @example
|
|
269
270
|
* ```typescript
|
|
@@ -929,6 +930,7 @@ export declare function tsi(source: Source, shortLength: simple_int, longLength:
|
|
|
929
930
|
* - CMO > +50: overbought conditions
|
|
930
931
|
* - CMO < -50: oversold conditions
|
|
931
932
|
* - Unlike RSI, CMO uses sum of gains/losses instead of averages
|
|
933
|
+
* - na on a flat window (every change 0), as in PineScript
|
|
932
934
|
* - More volatile than RSI
|
|
933
935
|
*
|
|
934
936
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ta/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAO,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAInI;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EA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MAAM,EAAE,MAAM,GAAG,YAAY,CAE/D;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAE/D"}
|
package/dist/cjs/ta/index.js
CHANGED
|
@@ -333,28 +333,24 @@ function supertrend(factor, atrPeriod, high, low, close, wicks = false) {
|
|
|
333
333
|
source.push((high[i] + low[i]) / 2);
|
|
334
334
|
}
|
|
335
335
|
const atrValues = atr(atrPeriod, high, low, close);
|
|
336
|
-
|
|
337
|
-
let
|
|
336
|
+
const nz = (v) => isNaN(v) ? 0 : v;
|
|
337
|
+
let lastLowerBand = NaN;
|
|
338
|
+
let lastUpperBand = NaN;
|
|
338
339
|
let prevSuperTrend = NaN;
|
|
339
340
|
for (let i = 0; i < source.length; i++) {
|
|
340
341
|
const atrValue = atrValues[i] * factor;
|
|
341
|
-
if (isNaN(atrValue)) {
|
|
342
|
-
supertrendValues.push(NaN);
|
|
343
|
-
directions.push(1);
|
|
344
|
-
continue;
|
|
345
|
-
}
|
|
346
342
|
let upperBand = source[i] + atrValue;
|
|
347
343
|
let lowerBand = source[i] - atrValue;
|
|
344
|
+
const prevLowerBand = nz(lastLowerBand);
|
|
345
|
+
const prevUpperBand = nz(lastUpperBand);
|
|
348
346
|
const highPrice = wicks ? high[i] : close[i];
|
|
349
347
|
const lowPrice = wicks ? low[i] : close[i];
|
|
350
|
-
const prevLowPrice = i > 0 ? wicks ? low[i - 1] : close[i - 1] :
|
|
351
|
-
const prevHighPrice = i > 0 ? wicks ? high[i - 1] : close[i - 1] :
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
upperBand = upperBand < prevUpperBand || prevHighPrice > prevUpperBand ? upperBand : prevUpperBand;
|
|
355
|
-
}
|
|
348
|
+
const prevLowPrice = i > 0 ? wicks ? low[i - 1] : close[i - 1] : NaN;
|
|
349
|
+
const prevHighPrice = i > 0 ? wicks ? high[i - 1] : close[i - 1] : NaN;
|
|
350
|
+
lowerBand = lowerBand > prevLowerBand || prevLowPrice < prevLowerBand ? lowerBand : prevLowerBand;
|
|
351
|
+
upperBand = upperBand < prevUpperBand || prevHighPrice > prevUpperBand ? upperBand : prevUpperBand;
|
|
356
352
|
let currentDirection;
|
|
357
|
-
if (isNaN(
|
|
353
|
+
if (i === 0 || isNaN(atrValues[i - 1])) {
|
|
358
354
|
currentDirection = 1;
|
|
359
355
|
} else if (prevSuperTrend === prevUpperBand) {
|
|
360
356
|
currentDirection = highPrice > upperBand ? -1 : 1;
|
|
@@ -364,8 +360,8 @@ function supertrend(factor, atrPeriod, high, low, close, wicks = false) {
|
|
|
364
360
|
const superTrendValue = currentDirection === -1 ? lowerBand : upperBand;
|
|
365
361
|
supertrendValues.push(superTrendValue);
|
|
366
362
|
directions.push(currentDirection);
|
|
367
|
-
|
|
368
|
-
|
|
363
|
+
lastLowerBand = lowerBand;
|
|
364
|
+
lastUpperBand = upperBand;
|
|
369
365
|
prevSuperTrend = superTrendValue;
|
|
370
366
|
}
|
|
371
367
|
return [supertrendValues, directions];
|
|
@@ -994,7 +990,7 @@ function cmo(source, length) {
|
|
|
994
990
|
}
|
|
995
991
|
const totalMovement = sumGains + sumLosses;
|
|
996
992
|
if (totalMovement === 0) {
|
|
997
|
-
result.push(
|
|
993
|
+
result.push(NaN);
|
|
998
994
|
} else {
|
|
999
995
|
const cmoValue = (sumGains - sumLosses) / totalMovement * 100;
|
|
1000
996
|
result.push(cmoValue);
|