oakscriptjs 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/array/index.d.ts +8 -2
- package/dist/cjs/array/index.d.ts.map +1 -1
- package/dist/cjs/array/index.js +2 -1
- package/dist/cjs/array/index.js.map +2 -2
- package/dist/cjs/box/index.d.ts.map +1 -1
- package/dist/cjs/box/index.js +7 -1
- package/dist/cjs/box/index.js.map +2 -2
- package/dist/cjs/callsite/index.d.ts +73 -32
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +69 -65
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +84 -0
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +153 -6
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +8 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +33 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/input.d.ts +9 -1
- package/dist/cjs/input.d.ts.map +1 -1
- package/dist/cjs/input.js +16 -0
- package/dist/cjs/input.js.map +2 -2
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +3 -0
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/line/index.d.ts +10 -27
- package/dist/cjs/line/index.d.ts.map +1 -1
- package/dist/cjs/line/index.js +11 -22
- package/dist/cjs/line/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts +3 -0
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js +15 -1
- package/dist/cjs/linefill/index.js.map +3 -3
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js +2 -0
- package/dist/cjs/math/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js +3 -0
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/adapters/SimpleInputAdapter.js +1 -1
- package/dist/cjs/runtime/adapters/SimpleInputAdapter.js.map +2 -2
- package/dist/cjs/runtime/index.d.ts +1 -1
- package/dist/cjs/runtime/index.d.ts.map +1 -1
- package/dist/cjs/runtime/index.js +1 -0
- package/dist/cjs/runtime/index.js.map +2 -2
- package/dist/cjs/runtime/inputs.d.ts +9 -0
- package/dist/cjs/runtime/inputs.d.ts.map +1 -1
- package/dist/cjs/runtime/inputs.js +8 -0
- package/dist/cjs/runtime/inputs.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +1 -1
- package/dist/cjs/runtime/types.d.ts.map +1 -1
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/script/index.d.ts +91 -21
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +207 -19
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/security/other.d.ts +92 -0
- package/dist/cjs/security/other.d.ts.map +1 -0
- package/dist/cjs/security/other.js +164 -0
- package/dist/cjs/security/other.js.map +7 -0
- package/dist/cjs/session/bars.d.ts +24 -1
- package/dist/cjs/session/bars.d.ts.map +1 -1
- package/dist/cjs/session/bars.js +56 -7
- package/dist/cjs/session/bars.js.map +3 -3
- package/dist/cjs/session/calendar.d.ts +13 -2
- package/dist/cjs/session/calendar.d.ts.map +1 -1
- package/dist/cjs/session/calendar.js +39 -9
- package/dist/cjs/session/calendar.js.map +2 -2
- package/dist/cjs/session/context.d.ts +76 -0
- package/dist/cjs/session/context.d.ts.map +1 -0
- package/dist/cjs/session/context.js +114 -0
- package/dist/cjs/session/context.js.map +7 -0
- package/dist/cjs/str/floatingdecimal.d.ts +31 -0
- package/dist/cjs/str/floatingdecimal.d.ts.map +1 -0
- package/dist/cjs/str/floatingdecimal.js +298 -0
- package/dist/cjs/str/floatingdecimal.js.map +7 -0
- package/dist/cjs/str/index.d.ts +4 -1
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +2 -1
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/str/numberformat.d.ts +7 -3
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +4 -3
- package/dist/cjs/str/numberformat.js.map +2 -2
- package/dist/cjs/ta/index.d.ts +67 -34
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +202 -145
- package/dist/cjs/ta/index.js.map +2 -2
- package/dist/cjs/ta/limits.d.ts +35 -0
- package/dist/cjs/ta/limits.d.ts.map +1 -0
- package/dist/cjs/ta/limits.js +64 -0
- package/dist/cjs/ta/limits.js.map +7 -0
- package/dist/cjs/ta/running-sum.d.ts +0 -16
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +2 -0
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta-series.d.ts +8 -8
- package/dist/cjs/ta-series.d.ts.map +1 -1
- package/dist/cjs/ta-series.js +10 -8
- package/dist/cjs/ta-series.js.map +2 -2
- package/dist/cjs/table/index.d.ts +3 -1
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +1 -0
- package/dist/cjs/table/index.js.map +3 -3
- package/dist/cjs/time/index.d.ts +5 -2
- package/dist/cjs/time/index.d.ts.map +1 -1
- package/dist/cjs/time/index.js +2 -2
- package/dist/cjs/time/index.js.map +2 -2
- package/dist/cjs/time/session.d.ts +26 -1
- package/dist/cjs/time/session.d.ts.map +1 -1
- package/dist/cjs/time/session.js +94 -12
- package/dist/cjs/time/session.js.map +3 -3
- package/dist/cjs/time/timezone.d.ts +6 -1
- package/dist/cjs/time/timezone.d.ts.map +1 -1
- package/dist/cjs/time/timezone.js +2 -2
- package/dist/cjs/time/timezone.js.map +2 -2
- package/dist/cjs/types/metadata.d.ts +28 -4
- package/dist/cjs/types/metadata.d.ts.map +1 -1
- package/dist/cjs/types/metadata.js.map +1 -1
- package/dist/esm/array/index.d.ts +8 -2
- package/dist/esm/array/index.d.ts.map +1 -1
- package/dist/esm/array/index.js +12 -3
- package/dist/esm/array/index.js.map +1 -1
- package/dist/esm/box/index.d.ts.map +1 -1
- package/dist/esm/box/index.js +8 -2
- package/dist/esm/box/index.js.map +1 -1
- package/dist/esm/callsite/index.d.ts +73 -32
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +143 -106
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +84 -0
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +260 -6
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +8 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +13 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/input.d.ts +9 -1
- package/dist/esm/input.d.ts.map +1 -1
- package/dist/esm/input.js +16 -0
- package/dist/esm/input.js.map +1 -1
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +4 -1
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/line/index.d.ts +10 -27
- package/dist/esm/line/index.d.ts.map +1 -1
- package/dist/esm/line/index.js +22 -60
- package/dist/esm/line/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts +3 -0
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +20 -1
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +3 -0
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +5 -1
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/adapters/SimpleInputAdapter.js +1 -1
- package/dist/esm/runtime/adapters/SimpleInputAdapter.js.map +1 -1
- package/dist/esm/runtime/index.d.ts +1 -1
- package/dist/esm/runtime/index.d.ts.map +1 -1
- package/dist/esm/runtime/index.js +1 -1
- package/dist/esm/runtime/index.js.map +1 -1
- package/dist/esm/runtime/inputs.d.ts +9 -0
- package/dist/esm/runtime/inputs.d.ts.map +1 -1
- package/dist/esm/runtime/inputs.js +15 -0
- package/dist/esm/runtime/inputs.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +1 -1
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/index.d.ts +91 -21
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +259 -28
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/security/other.d.ts +92 -0
- package/dist/esm/security/other.d.ts.map +1 -0
- package/dist/esm/security/other.js +211 -0
- package/dist/esm/security/other.js.map +1 -0
- package/dist/esm/session/bars.d.ts +24 -1
- package/dist/esm/session/bars.d.ts.map +1 -1
- package/dist/esm/session/bars.js +75 -6
- package/dist/esm/session/bars.js.map +1 -1
- package/dist/esm/session/calendar.d.ts +13 -2
- package/dist/esm/session/calendar.d.ts.map +1 -1
- package/dist/esm/session/calendar.js +54 -10
- package/dist/esm/session/calendar.js.map +1 -1
- package/dist/esm/session/context.d.ts +76 -0
- package/dist/esm/session/context.d.ts.map +1 -0
- package/dist/esm/session/context.js +124 -0
- package/dist/esm/session/context.js.map +1 -0
- package/dist/esm/str/floatingdecimal.d.ts +31 -0
- package/dist/esm/str/floatingdecimal.d.ts.map +1 -0
- package/dist/esm/str/floatingdecimal.js +272 -0
- package/dist/esm/str/floatingdecimal.js.map +1 -0
- package/dist/esm/str/index.d.ts +4 -1
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +9 -2
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts +7 -3
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +11 -5
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/ta/index.d.ts +67 -34
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +284 -240
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/ta/limits.d.ts +35 -0
- package/dist/esm/ta/limits.d.ts.map +1 -0
- package/dist/esm/ta/limits.js +67 -0
- package/dist/esm/ta/limits.js.map +1 -0
- package/dist/esm/ta/running-sum.d.ts +0 -16
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +2 -0
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta-series.d.ts +8 -8
- package/dist/esm/ta-series.d.ts.map +1 -1
- package/dist/esm/ta-series.js +11 -8
- package/dist/esm/ta-series.js.map +1 -1
- package/dist/esm/table/index.d.ts +3 -1
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +6 -1
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/time/index.d.ts +5 -2
- package/dist/esm/time/index.d.ts.map +1 -1
- package/dist/esm/time/index.js +6 -3
- package/dist/esm/time/index.js.map +1 -1
- package/dist/esm/time/session.d.ts +26 -1
- package/dist/esm/time/session.d.ts.map +1 -1
- package/dist/esm/time/session.js +141 -16
- package/dist/esm/time/session.js.map +1 -1
- package/dist/esm/time/timezone.d.ts +6 -1
- package/dist/esm/time/timezone.d.ts.map +1 -1
- package/dist/esm/time/timezone.js +8 -2
- package/dist/esm/time/timezone.js.map +1 -1
- package/dist/esm/types/metadata.d.ts +28 -4
- package/dist/esm/types/metadata.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/array/index.ts +11 -3
- package/src/box/index.ts +8 -2
- package/src/callsite/index.ts +150 -100
- package/src/drawing/registry.ts +278 -5
- package/src/index.ts +44 -1
- package/src/input.ts +18 -1
- package/src/label/index.ts +4 -1
- package/src/line/index.ts +22 -64
- package/src/linefill/index.ts +20 -1
- package/src/math/index.ts +2 -0
- package/src/polyline/index.ts +3 -1
- package/src/runtime/adapters/SimpleInputAdapter.ts +1 -1
- package/src/runtime/index.ts +1 -0
- package/src/runtime/inputs.ts +16 -0
- package/src/runtime/types.ts +1 -1
- package/src/script/index.ts +355 -34
- package/src/security/other.ts +269 -0
- package/src/session/bars.ts +70 -6
- package/src/session/calendar.ts +60 -10
- package/src/session/context.ts +162 -0
- package/src/str/floatingdecimal.ts +268 -0
- package/src/str/index.ts +8 -2
- package/src/str/numberformat.ts +13 -6
- package/src/ta/index.ts +304 -248
- package/src/ta/limits.ts +74 -0
- package/src/ta/running-sum.ts +2 -0
- package/src/ta-series.ts +19 -16
- package/src/table/index.ts +4 -1
- package/src/time/index.ts +6 -3
- package/src/time/session.ts +137 -15
- package/src/time/timezone.ts +9 -2
- package/src/types/metadata.ts +28 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* History limits of the window functions.
|
|
3
|
+
*
|
|
4
|
+
* PineScript stops a script when `ta.highest` / `ta.lowest` / `ta.highestbars` / `ta.lowestbars` ask for more than
|
|
5
|
+
* 15,000 bars (runtime error RE10004): with a constant length on the first bar, with a length that changes on the
|
|
6
|
+
* bar where it passes the limit. `math.sum`, `ta.sma`, `ta.variance`, `ta.stdev` and `ta.bb` have the same error
|
|
7
|
+
* above 5,000 bars; the message names the function that keeps the window ('stdev'->'variance', 'bb'->'sma').
|
|
8
|
+
*/
|
|
9
|
+
/** Largest length of `ta.highest` / `ta.lowest` / `ta.highestbars` / `ta.lowestbars`. */
|
|
10
|
+
export declare const MAX_WINDOW_LENGTH = 15000;
|
|
11
|
+
/** Largest length of `math.sum` / `ta.sma` / `ta.variance` / `ta.stdev` / `ta.bb`. */
|
|
12
|
+
export declare const MAX_SUM_LENGTH = 5000;
|
|
13
|
+
/** Names of the PineScript message for the functions with the 5,000 limit ("a->b": a calls b). */
|
|
14
|
+
export declare const SUM_FUNCTIONS: Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* PineScript's runtime error RE10004 text; `bar` is the bar index of the call when it is known. `name` is the
|
|
17
|
+
* function, or a call path "stdev->variance" (printed 'stdev'->'variance').
|
|
18
|
+
*/
|
|
19
|
+
export declare function windowError(name: string, length: number, bar?: number, max?: number): string;
|
|
20
|
+
/** Throws RE10004 when the (truncated) length of a window function is above the limit. */
|
|
21
|
+
export declare function checkWindowLength(name: string, length: number, bar?: number, max?: number): void;
|
|
22
|
+
/** Throws RE10004 for a function of {@link SUM_FUNCTIONS} ("ta.sma", ...) with a length above 5,000. */
|
|
23
|
+
export declare function checkSumLength(name: string, length: number, bar?: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* PineScript's runtime error RE10001 text for a length that is 0 or negative. `name` is the function, or a call path
|
|
26
|
+
* "atr->rma" (printed 'atr'->'rma'); the value prints as a float ("0.0", "-1.0").
|
|
27
|
+
*/
|
|
28
|
+
export declare function lengthError(name: string, value: number, bar?: number, arg?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Throws RE10001 when the (truncated) length is 0 or negative, as PineScript does for every window function on the
|
|
31
|
+
* bar of the call (#175): `ta.sma(close, 0)` stops on bar 0, a series length that becomes 0 on the bar where it
|
|
32
|
+
* does. `ta.hma(src, 1)` stops in its inner `wma(src, 0)`. An na length is not checked here.
|
|
33
|
+
*/
|
|
34
|
+
export declare function checkPositiveLength(name: string, length: number, bar?: number, arg?: string): void;
|
|
35
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../../src/ta/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yFAAyF;AACzF,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC,sFAAsF;AACtF,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,kGAAkG;AAClG,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMhD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,SAAoB,GAAG,MAAM,CAMvG;AAED,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,SAAoB,GAAG,IAAI,CAI3G;AAED,wGAAwG;AACxG,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAM/E;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,SAAW,GAAG,MAAM,CAO7F;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,SAAW,GAAG,IAAI,CAGpG"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var limits_exports = {};
|
|
20
|
+
__export(limits_exports, {
|
|
21
|
+
MAX_SUM_LENGTH: () => MAX_SUM_LENGTH,
|
|
22
|
+
MAX_WINDOW_LENGTH: () => MAX_WINDOW_LENGTH,
|
|
23
|
+
SUM_FUNCTIONS: () => SUM_FUNCTIONS,
|
|
24
|
+
checkPositiveLength: () => checkPositiveLength,
|
|
25
|
+
checkSumLength: () => checkSumLength,
|
|
26
|
+
checkWindowLength: () => checkWindowLength,
|
|
27
|
+
lengthError: () => lengthError,
|
|
28
|
+
windowError: () => windowError
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(limits_exports);
|
|
31
|
+
const MAX_WINDOW_LENGTH = 15e3;
|
|
32
|
+
const MAX_SUM_LENGTH = 5e3;
|
|
33
|
+
const SUM_FUNCTIONS = {
|
|
34
|
+
"math.sum": "sum",
|
|
35
|
+
"ta.sma": "sma",
|
|
36
|
+
"ta.variance": "variance",
|
|
37
|
+
"ta.stdev": "stdev->variance",
|
|
38
|
+
"ta.bb": "bb->sma"
|
|
39
|
+
};
|
|
40
|
+
function windowError(name, length, bar, max = MAX_WINDOW_LENGTH) {
|
|
41
|
+
const fn = name.split("->").map((part) => `'${part}'`).join("->");
|
|
42
|
+
return (bar === void 0 ? "" : `Error on bar ${bar}: `) + `The ${fn} function references too many historical candles (${length}), the limit is ${max}.`;
|
|
43
|
+
}
|
|
44
|
+
function checkWindowLength(name, length, bar, max = MAX_WINDOW_LENGTH) {
|
|
45
|
+
const len = Math.trunc(length);
|
|
46
|
+
if (len <= 0) throw new Error(lengthError(name, len, bar));
|
|
47
|
+
if (len > max) throw new Error(windowError(name, len, bar, max));
|
|
48
|
+
}
|
|
49
|
+
function checkSumLength(name, length, bar) {
|
|
50
|
+
const fn = SUM_FUNCTIONS[name];
|
|
51
|
+
if (fn === void 0) return;
|
|
52
|
+
checkPositiveLength(name === "ta.bb" ? "bb" : fn, length, bar);
|
|
53
|
+
checkWindowLength(fn, length, bar, MAX_SUM_LENGTH);
|
|
54
|
+
}
|
|
55
|
+
function lengthError(name, value, bar, arg = "length") {
|
|
56
|
+
const fn = name.split("->").map((part) => `'${part}'`).join("->");
|
|
57
|
+
const text = Number.isInteger(value) ? value.toFixed(1) : String(value);
|
|
58
|
+
return (bar === void 0 ? "" : `Error on bar ${bar}: `) + `Invalid value of the '${arg}' argument (${text}) in the ${fn} function. It must be > 0.`;
|
|
59
|
+
}
|
|
60
|
+
function checkPositiveLength(name, length, bar, arg = "length") {
|
|
61
|
+
const len = Math.trunc(length);
|
|
62
|
+
if (len <= 0) throw new Error(lengthError(name, len, bar, arg));
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/ta/limits.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * History limits of the window functions.\n *\n * PineScript stops a script when `ta.highest` / `ta.lowest` / `ta.highestbars` / `ta.lowestbars` ask for more than\n * 15,000 bars (runtime error RE10004): with a constant length on the first bar, with a length that changes on the\n * bar where it passes the limit. `math.sum`, `ta.sma`, `ta.variance`, `ta.stdev` and `ta.bb` have the same error\n * above 5,000 bars; the message names the function that keeps the window ('stdev'->'variance', 'bb'->'sma').\n */\n\n/** Largest length of `ta.highest` / `ta.lowest` / `ta.highestbars` / `ta.lowestbars`. */\nexport const MAX_WINDOW_LENGTH = 15000;\n\n/** Largest length of `math.sum` / `ta.sma` / `ta.variance` / `ta.stdev` / `ta.bb`. */\nexport const MAX_SUM_LENGTH = 5000;\n\n/** Names of the PineScript message for the functions with the 5,000 limit (\"a->b\": a calls b). */\nexport const SUM_FUNCTIONS: Record<string, string> = {\n 'math.sum': 'sum',\n 'ta.sma': 'sma',\n 'ta.variance': 'variance',\n 'ta.stdev': 'stdev->variance',\n 'ta.bb': 'bb->sma',\n};\n\n/**\n * PineScript's runtime error RE10004 text; `bar` is the bar index of the call when it is known. `name` is the\n * function, or a call path \"stdev->variance\" (printed 'stdev'->'variance').\n */\nexport function windowError(name: string, length: number, bar?: number, max = MAX_WINDOW_LENGTH): string {\n const fn = name.split('->').map((part) => `'${part}'`).join('->');\n return (\n (bar === undefined ? '' : `Error on bar ${bar}: `) +\n `The ${fn} function references too many historical candles (${length}), the limit is ${max}.`\n );\n}\n\n/** Throws RE10004 when the (truncated) length of a window function is above the limit. */\nexport function checkWindowLength(name: string, length: number, bar?: number, max = MAX_WINDOW_LENGTH): void {\n const len = Math.trunc(length);\n if (len <= 0) throw new Error(lengthError(name, len, bar));\n if (len > max) throw new Error(windowError(name, len, bar, max));\n}\n\n/** Throws RE10004 for a function of {@link SUM_FUNCTIONS} (\"ta.sma\", ...) with a length above 5,000. */\nexport function checkSumLength(name: string, length: number, bar?: number): void {\n const fn = SUM_FUNCTIONS[name];\n if (fn === undefined) return;\n // RE10001 names 'bb' itself, RE10004 its inner 'sma'\n checkPositiveLength(name === 'ta.bb' ? 'bb' : fn, length, bar);\n checkWindowLength(fn, length, bar, MAX_SUM_LENGTH);\n}\n\n/**\n * PineScript's runtime error RE10001 text for a length that is 0 or negative. `name` is the function, or a call path\n * \"atr->rma\" (printed 'atr'->'rma'); the value prints as a float (\"0.0\", \"-1.0\").\n */\nexport function lengthError(name: string, value: number, bar?: number, arg = 'length'): string {\n const fn = name.split('->').map((part) => `'${part}'`).join('->');\n const text = Number.isInteger(value) ? value.toFixed(1) : String(value);\n return (\n (bar === undefined ? '' : `Error on bar ${bar}: `) +\n `Invalid value of the '${arg}' argument (${text}) in the ${fn} function. It must be > 0.`\n );\n}\n\n/**\n * Throws RE10001 when the (truncated) length is 0 or negative, as PineScript does for every window function on the\n * bar of the call (#175): `ta.sma(close, 0)` stops on bar 0, a series length that becomes 0 on the bar where it\n * does. `ta.hma(src, 1)` stops in its inner `wma(src, 0)`. An na length is not checked here.\n */\nexport function checkPositiveLength(name: string, length: number, bar?: number, arg = 'length'): void {\n const len = Math.trunc(length);\n if (len <= 0) throw new Error(lengthError(name, len, bar, arg));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,MAAM,oBAAoB;AAG1B,MAAM,iBAAiB;AAGvB,MAAM,gBAAwC;AAAA,EACnD,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,SAAS;AACX;AAMO,SAAS,YAAY,MAAc,QAAgB,KAAc,MAAM,mBAA2B;AACvG,QAAM,KAAK,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG,EAAE,KAAK,IAAI;AAChE,UACG,QAAQ,SAAY,KAAK,gBAAgB,GAAG,QAC7C,OAAO,EAAE,qDAAqD,MAAM,mBAAmB,GAAG;AAE9F;AAGO,SAAS,kBAAkB,MAAc,QAAgB,KAAc,MAAM,mBAAyB;AAC3G,QAAM,MAAM,KAAK,MAAM,MAAM;AAC7B,MAAI,OAAO,EAAG,OAAM,IAAI,MAAM,YAAY,MAAM,KAAK,GAAG,CAAC;AACzD,MAAI,MAAM,IAAK,OAAM,IAAI,MAAM,YAAY,MAAM,KAAK,KAAK,GAAG,CAAC;AACjE;AAGO,SAAS,eAAe,MAAc,QAAgB,KAAoB;AAC/E,QAAM,KAAK,cAAc,IAAI;AAC7B,MAAI,OAAO,OAAW;AAEtB,sBAAoB,SAAS,UAAU,OAAO,IAAI,QAAQ,GAAG;AAC7D,oBAAkB,IAAI,QAAQ,KAAK,cAAc;AACnD;AAMO,SAAS,YAAY,MAAc,OAAe,KAAc,MAAM,UAAkB;AAC7F,QAAM,KAAK,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG,EAAE,KAAK,IAAI;AAChE,QAAM,OAAO,OAAO,UAAU,KAAK,IAAI,MAAM,QAAQ,CAAC,IAAI,OAAO,KAAK;AACtE,UACG,QAAQ,SAAY,KAAK,gBAAgB,GAAG,QAC7C,yBAAyB,GAAG,eAAe,IAAI,YAAY,EAAE;AAEjE;AAOO,SAAS,oBAAoB,MAAc,QAAgB,KAAc,MAAM,UAAgB;AACpG,QAAM,MAAM,KAAK,MAAM,MAAM;AAC7B,MAAI,OAAO,EAAG,OAAM,IAAI,MAAM,YAAY,MAAM,KAAK,KAAK,GAAG,CAAC;AAChE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Running window sum with the floating-point behaviour of PineScript `math.sum` / `ta.sma` / `ta.stdev` /
|
|
3
|
-
* `ta.variance` (bit for bit).
|
|
4
|
-
*
|
|
5
|
-
* PineScript does not sum the window again on each bar. It keeps a compensated (Kahan) running sum:
|
|
6
|
-
* - each bar first removes, with a Kahan step, the compensated value that was added for the value that leaves the
|
|
7
|
-
* window, then adds the new value with a Kahan step and keeps its compensated value;
|
|
8
|
-
* - when the compensation of the previous step would be lost when applied to the new value, the sum is computed
|
|
9
|
-
* again from the window values (newest first) and the compensation is reset. The test moves the new value toward
|
|
10
|
-
* +infinity by the size of the compensation, in floating point (#136, #142).
|
|
11
|
-
*
|
|
12
|
-
* So the result can differ from the exact window sum in the last bits (e.g. a small residue on a window of zeros),
|
|
13
|
-
* as in PineScript.
|
|
14
|
-
*
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
1
|
/** A value PineScript treats as na in window functions (also +/-Infinity). */
|
|
18
2
|
export declare function isNa(v: number | null | undefined): boolean;
|
|
19
3
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"running-sum.d.ts","sourceRoot":"","sources":["../../../src/ta/running-sum.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"running-sum.d.ts","sourceR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ACd,MAAM,EAAE,OAAO,GACd,MAAM,EAAE,CAGV;AAED,4FAA4F;AAC5F,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,MAAM,EAAE,OAAO,EACf,IAAI,SAAgB,GACnB,MAAM,EAAE,CAGV"}
|
|
@@ -26,6 +26,7 @@ __export(running_sum_exports, {
|
|
|
26
26
|
runningVarianceSeries: () => runningVarianceSeries
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(running_sum_exports);
|
|
29
|
+
var import_limits = require("./limits.js");
|
|
29
30
|
function compensationLost(x, c) {
|
|
30
31
|
if (c === 0 || x === 0) return false;
|
|
31
32
|
const size = Math.abs(c);
|
|
@@ -151,6 +152,7 @@ function seriesLengths(lengths, count, name) {
|
|
|
151
152
|
}
|
|
152
153
|
return Array.from({ length: count }, (_, i) => {
|
|
153
154
|
const len = Math.floor(lengths[i]);
|
|
155
|
+
(0, import_limits.checkSumLength)(name, len, i);
|
|
154
156
|
if (!(len >= 1)) throw new Error(`${name}: length must be at least 1 (bar ${i}: ${lengths[i]})`);
|
|
155
157
|
return len;
|
|
156
158
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ta/running-sum.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Running window sum with the floating-point behaviour of PineScript `math.sum` / `ta.sma` / `ta.stdev` /\n * `ta.variance` (bit for bit).\n *\n * PineScript does not sum the window again on each bar. It keeps a compensated (Kahan) running sum:\n * - each bar first removes, with a Kahan step, the compensated value that was added for the value that leaves the\n * window, then adds the new value with a Kahan step and keeps its compensated value;\n * - when the compensation of the previous step would be lost when applied to the new value, the sum is computed\n * again from the window values (newest first) and the compensation is reset. The test moves the new value toward\n * +infinity by the size of the compensation, in floating point (#136, #142).\n *\n * So the result can differ from the exact window sum in the last bits (e.g. a small residue on a window of zeros),\n * as in PineScript.\n *\n * @internal\n */\n\n/**\n * Whether the compensation `c` is (partly) lost when it is applied to `x`: `x + |c|` in floating point moves `x` by\n * less than `|c|`. Moving toward +infinity uses the grid above `x` (the coarser binade just below a power of two, the\n * finer binade for a negative power of two), as PineScript (measured bit for bit, #142).\n */\nfunction compensationLost(x: number, c: number): boolean {\n if (c === 0 || x === 0) return false;\n const size = Math.abs(c);\n return Math.abs(x + size - x) < size;\n}\n\n/** A value PineScript treats as na in window functions (also +/-Infinity). */\nexport function isNa(v: number | null | undefined): boolean {\n return v === undefined || v === null || !Number.isFinite(v);\n}\n\n/**\n * Running sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without\n * changing it; {@link commit} keeps the last step. So several candidate values can be tried on one bar and only the\n * last one kept (a ta.* call in a loop).\n *\n * The length can change from one step to the next (a series length). PineScript then first moves the kept sum to the\n * new length with Kahan steps of the raw values (not the stored compensated values): a smaller length removes the\n * values that leave the window, oldest first; a larger length adds back the values from the one before the old window\n * down to the one `length` values back, newest first (one more than the window needs). Then the usual step runs with\n * the new length: it removes the stored value of the one `length` values back and adds the new value.\n */\nexport class RunningSum {\n private readonly values: number[] = [];\n private readonly stored: number[] = [];\n private keptLength = NaN;\n private s = 0;\n private c = 0;\n private stepLength = NaN;\n private stepX = NaN;\n private stepY = NaN;\n private stepS = 0;\n private stepC = 0;\n\n /** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */\n private resize(len: number): void {\n const values = this.values;\n const n = values.length;\n const kept = this.keptLength;\n let s = this.s;\n let c = this.c;\n const add = (v: number) => {\n const y = v - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n };\n if (len < kept) {\n for (let k = Math.max(0, n - kept); k <= n - len - 1; k++) add(-values[k]!);\n } else if (len > kept) {\n for (let k = n - kept - 1; k >= Math.max(0, n - len); k--) add(values[k]!);\n }\n this.stepS = s;\n this.stepC = c;\n }\n\n /**\n * The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is\n * unchanged until {@link commit}.\n *\n * @returns The sum, or NaN while fewer than `length` values exist (with `x`)\n */\n step(x: number, length: number): number {\n const len = length;\n const values = this.values;\n this.resize(len);\n let s = this.stepS;\n let c = this.stepC;\n const c0 = c;\n const n = values.length;\n if (n >= len) {\n const y = -this.stored[n - len]! - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n }\n if (compensationLost(x, c0)) {\n let fresh = x;\n for (let k = n - 1; k >= Math.max(0, n + 1 - len); k--) fresh += values[k]!;\n s = fresh;\n c = 0;\n this.stepY = x;\n } else {\n const y = x - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n this.stepY = y;\n }\n this.stepLength = len;\n this.stepX = x;\n this.stepS = s;\n this.stepC = c;\n return n + 1 >= len ? s : NaN;\n }\n\n /**\n * The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the\n * state is unchanged until {@link commit}. With an unchanged length, it is the previous result.\n *\n * @returns The sum, or NaN while fewer than `length` values exist\n */\n stepNa(length: number): number {\n this.resize(length);\n this.stepLength = length;\n this.stepX = NaN;\n const n = this.values.length;\n return n > 0 && n >= length ? this.stepS : NaN;\n }\n\n /** Keeps the state of the last {@link step} or {@link stepNa}. */\n commit(): void {\n if (!Number.isNaN(this.stepX)) {\n this.values.push(this.stepX);\n this.stored.push(this.stepY);\n }\n this.keptLength = this.stepLength;\n this.s = this.stepS;\n this.c = this.stepC;\n }\n}\n\n/** The running sums of `source` with the length `lengthAt(i)` on bar `i`. */\nfunction sumWindows(source: ArrayLike<number | null | undefined>, lengthAt: (i: number) => number): number[] {\n const out: number[] = new Array<number>(source.length);\n const sum = new RunningSum();\n for (let i = 0; i < source.length; i++) {\n const v = source[i];\n const len = lengthAt(i);\n out[i] = isNa(v) ? sum.stepNa(len) : sum.step(v as number, len);\n sum.commit();\n }\n return out;\n}\n\n/**\n * The sum of the last `length` non-na values on each bar, as PineScript computes it.\n *\n * @param source - Values (na: NaN, null, undefined or +/-Infinity, skipped)\n * @param length - Number of non-na values in the window\n * @returns The running sum per bar: NaN until `length` non-na values exist; a bar with an na value keeps the\n * previous result\n */\nexport function runningSum(source: ArrayLike<number | null | undefined>, length: number): number[] {\n const len = Math.floor(length);\n if (!(len >= 1)) return new Array<number>(source.length).fill(NaN);\n return sumWindows(source, () => len);\n}\n\n/** The values of a series length, floored, checked to be at least 1 on every bar. */\nfunction seriesLengths(lengths: ArrayLike<number>, count: number, name: string): number[] {\n if (lengths.length < count) {\n throw new Error(`${name}: the length series has ${lengths.length} values for ${count} bars`);\n }\n return Array.from({ length: count }, (_, i) => {\n const len = Math.floor(lengths[i]!);\n if (!(len >= 1)) throw new Error(`${name}: length must be at least 1 (bar ${i}: ${lengths[i]})`);\n return len;\n });\n}\n\n/**\n * The sum of the last `lengths[i]` non-na values on each bar `i` (a series length), as PineScript computes it (see\n * {@link RunningSum}). A bar with an na value gives the sum of the last `lengths[i]` earlier values.\n *\n * @param name - Function name for the error messages\n */\nexport function runningSumSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n name = 'math.sum'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return sumWindows(source, (i) => lens[i]!);\n}\n\n/** Variance from the running sums of the values and of their squares; rules in {@link runningVariance}. */\nfunction varianceFromSums(\n source: ArrayLike<number | null | undefined>,\n sumOf: (src: ArrayLike<number | null | undefined>) => number[],\n lengthAt: (i: number) => number,\n biased: boolean\n): number[] {\n const squares = Array.from({ length: source.length }, (_, i) => {\n const v = source[i];\n return isNa(v) ? NaN : (v as number) * (v as number);\n });\n const sums = sumOf(source);\n const sumSquares = sumOf(squares);\n return sums.map((sum, i) => {\n const len = lengthAt(i);\n const mean = sum / len;\n const sq = sumSquares[i]!;\n return biased ? sq / len - mean * mean : sq / (len - 1) - (mean * sum) / (len - 1);\n });\n}\n\n/**\n * Window variance from the running sums of the values and of their squares, as PineScript computes it:\n * biased `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)`, with `mean = sum / n`.\n */\nexport function runningVariance(\n source: ArrayLike<number | null | undefined>,\n length: number,\n biased: boolean\n): number[] {\n const len = Math.floor(length);\n return varianceFromSums(source, (src) => runningSum(src, len), () => len, biased);\n}\n\n/** {@link runningVariance} with a series length (the length of bar `i` is `lengths[i]`). */\nexport function runningVarianceSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n biased: boolean,\n name = 'ta.variance'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return varianceFromSums(source, (src) => sumWindows(src, (i) => lens[i]!), (i) => lens[i]!, biased);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Running window sum with the floating-point behaviour of PineScript `math.sum` / `ta.sma` / `ta.stdev` /\n * `ta.variance` (bit for bit).\n *\n * PineScript does not sum the window again on each bar. It keeps a compensated (Kahan) running sum:\n * - each bar first removes, with a Kahan step, the compensated value that was added for the value that leaves the\n * window, then adds the new value with a Kahan step and keeps its compensated value;\n * - when the compensation of the previous step would be lost when applied to the new value, the sum is computed\n * again from the window values (newest first) and the compensation is reset. The test moves the new value toward\n * +infinity by the size of the compensation, in floating point (#136, #142).\n *\n * So the result can differ from the exact window sum in the last bits (e.g. a small residue on a window of zeros),\n * as in PineScript.\n *\n * @internal\n */\nimport { checkSumLength } from './limits.js';\n\n/**\n * Whether the compensation `c` is (partly) lost when it is applied to `x`: `x + |c|` in floating point moves `x` by\n * less than `|c|`. Moving toward +infinity uses the grid above `x` (the coarser binade just below a power of two, the\n * finer binade for a negative power of two), as PineScript (measured bit for bit, #142).\n */\nfunction compensationLost(x: number, c: number): boolean {\n if (c === 0 || x === 0) return false;\n const size = Math.abs(c);\n return Math.abs(x + size - x) < size;\n}\n\n/** A value PineScript treats as na in window functions (also +/-Infinity). */\nexport function isNa(v: number | null | undefined): boolean {\n return v === undefined || v === null || !Number.isFinite(v);\n}\n\n/**\n * Running sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without\n * changing it; {@link commit} keeps the last step. So several candidate values can be tried on one bar and only the\n * last one kept (a ta.* call in a loop).\n *\n * The length can change from one step to the next (a series length). PineScript then first moves the kept sum to the\n * new length with Kahan steps of the raw values (not the stored compensated values): a smaller length removes the\n * values that leave the window, oldest first; a larger length adds back the values from the one before the old window\n * down to the one `length` values back, newest first (one more than the window needs). Then the usual step runs with\n * the new length: it removes the stored value of the one `length` values back and adds the new value.\n */\nexport class RunningSum {\n private readonly values: number[] = [];\n private readonly stored: number[] = [];\n private keptLength = NaN;\n private s = 0;\n private c = 0;\n private stepLength = NaN;\n private stepX = NaN;\n private stepY = NaN;\n private stepS = 0;\n private stepC = 0;\n\n /** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */\n private resize(len: number): void {\n const values = this.values;\n const n = values.length;\n const kept = this.keptLength;\n let s = this.s;\n let c = this.c;\n const add = (v: number) => {\n const y = v - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n };\n if (len < kept) {\n for (let k = Math.max(0, n - kept); k <= n - len - 1; k++) add(-values[k]!);\n } else if (len > kept) {\n for (let k = n - kept - 1; k >= Math.max(0, n - len); k--) add(values[k]!);\n }\n this.stepS = s;\n this.stepC = c;\n }\n\n /**\n * The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is\n * unchanged until {@link commit}.\n *\n * @returns The sum, or NaN while fewer than `length` values exist (with `x`)\n */\n step(x: number, length: number): number {\n const len = length;\n const values = this.values;\n this.resize(len);\n let s = this.stepS;\n let c = this.stepC;\n const c0 = c;\n const n = values.length;\n if (n >= len) {\n const y = -this.stored[n - len]! - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n }\n if (compensationLost(x, c0)) {\n let fresh = x;\n for (let k = n - 1; k >= Math.max(0, n + 1 - len); k--) fresh += values[k]!;\n s = fresh;\n c = 0;\n this.stepY = x;\n } else {\n const y = x - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n this.stepY = y;\n }\n this.stepLength = len;\n this.stepX = x;\n this.stepS = s;\n this.stepC = c;\n return n + 1 >= len ? s : NaN;\n }\n\n /**\n * The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the\n * state is unchanged until {@link commit}. With an unchanged length, it is the previous result.\n *\n * @returns The sum, or NaN while fewer than `length` values exist\n */\n stepNa(length: number): number {\n this.resize(length);\n this.stepLength = length;\n this.stepX = NaN;\n const n = this.values.length;\n return n > 0 && n >= length ? this.stepS : NaN;\n }\n\n /** Keeps the state of the last {@link step} or {@link stepNa}. */\n commit(): void {\n if (!Number.isNaN(this.stepX)) {\n this.values.push(this.stepX);\n this.stored.push(this.stepY);\n }\n this.keptLength = this.stepLength;\n this.s = this.stepS;\n this.c = this.stepC;\n }\n}\n\n/** The running sums of `source` with the length `lengthAt(i)` on bar `i`. */\nfunction sumWindows(source: ArrayLike<number | null | undefined>, lengthAt: (i: number) => number): number[] {\n const out: number[] = new Array<number>(source.length);\n const sum = new RunningSum();\n for (let i = 0; i < source.length; i++) {\n const v = source[i];\n const len = lengthAt(i);\n out[i] = isNa(v) ? sum.stepNa(len) : sum.step(v as number, len);\n sum.commit();\n }\n return out;\n}\n\n/**\n * The sum of the last `length` non-na values on each bar, as PineScript computes it.\n *\n * @param source - Values (na: NaN, null, undefined or +/-Infinity, skipped)\n * @param length - Number of non-na values in the window\n * @returns The running sum per bar: NaN until `length` non-na values exist; a bar with an na value keeps the\n * previous result\n */\nexport function runningSum(source: ArrayLike<number | null | undefined>, length: number): number[] {\n const len = Math.floor(length);\n if (!(len >= 1)) return new Array<number>(source.length).fill(NaN);\n return sumWindows(source, () => len);\n}\n\n/** The values of a series length, floored, checked to be at least 1 on every bar. */\nfunction seriesLengths(lengths: ArrayLike<number>, count: number, name: string): number[] {\n if (lengths.length < count) {\n throw new Error(`${name}: the length series has ${lengths.length} values for ${count} bars`);\n }\n return Array.from({ length: count }, (_, i) => {\n const len = Math.floor(lengths[i]!);\n checkSumLength(name, len, i);\n if (!(len >= 1)) throw new Error(`${name}: length must be at least 1 (bar ${i}: ${lengths[i]})`);\n return len;\n });\n}\n\n/**\n * The sum of the last `lengths[i]` non-na values on each bar `i` (a series length), as PineScript computes it (see\n * {@link RunningSum}). A bar with an na value gives the sum of the last `lengths[i]` earlier values.\n *\n * @param name - Function name for the error messages\n */\nexport function runningSumSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n name = 'math.sum'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return sumWindows(source, (i) => lens[i]!);\n}\n\n/** Variance from the running sums of the values and of their squares; rules in {@link runningVariance}. */\nfunction varianceFromSums(\n source: ArrayLike<number | null | undefined>,\n sumOf: (src: ArrayLike<number | null | undefined>) => number[],\n lengthAt: (i: number) => number,\n biased: boolean\n): number[] {\n const squares = Array.from({ length: source.length }, (_, i) => {\n const v = source[i];\n return isNa(v) ? NaN : (v as number) * (v as number);\n });\n const sums = sumOf(source);\n const sumSquares = sumOf(squares);\n return sums.map((sum, i) => {\n const len = lengthAt(i);\n const mean = sum / len;\n const sq = sumSquares[i]!;\n return biased ? sq / len - mean * mean : sq / (len - 1) - (mean * sum) / (len - 1);\n });\n}\n\n/**\n * Window variance from the running sums of the values and of their squares, as PineScript computes it:\n * biased `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)`, with `mean = sum / n`.\n */\nexport function runningVariance(\n source: ArrayLike<number | null | undefined>,\n length: number,\n biased: boolean\n): number[] {\n const len = Math.floor(length);\n return varianceFromSums(source, (src) => runningSum(src, len), () => len, biased);\n}\n\n/** {@link runningVariance} with a series length (the length of bar `i` is `lengths[i]`). */\nexport function runningVarianceSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n biased: boolean,\n name = 'ta.variance'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return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,iBACP,QACA,OACA,UACA,QACU;AACV,QAAM,UAAU,MAAM,KAAK,EAAE,QAAQ,OAAO,OAAO,GAAG,CAAC,GAAG,MAAM;AAC9D,UAAM,IAAI,OAAO,CAAC;AAClB,WAAO,KAAK,CAAC,IAAI,MAAO,IAAgB;AAAA,EAC1C,CAAC;AACD,QAAM,OAAO,MAAM,MAAM;AACzB,QAAM,aAAa,MAAM,OAAO;AAChC,SAAO,KAAK,IAAI,CAAC,KAAK,MAAM;AAC1B,UAAM,MAAM,SAAS,CAAC;AACtB,UAAM,OAAO,MAAM;AACnB,UAAM,KAAK,WAAW,CAAC;AACvB,WAAO,SAAS,KAAK,MAAM,OAAO,OAAO,MAAM,MAAM,KAAM,OAAO,OAAQ,MAAM;AAAA,EAClF,CAAC;AACH;AAMO,SAAS,gBACd,QACA,QACA,QACU;AACV,QAAM,MAAM,KAAK,MAAM,MAAM;AAC7B,SAAO,iBAAiB,QAAQ,CAAC,QAAQ,WAAW,KAAK,GAAG,GAAG,MAAM,KAAK,MAAM;AAClF;AAGO,SAAS,sBACd,QACA,SACA,QACA,OAAO,eACG;AACV,QAAM,OAAO,cAAc,SAAS,OAAO,QAAQ,IAAI;AACvD,SAAO,iBAAiB,QAAQ,CAAC,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,CAAC,CAAE,GAAG,CAAC,MAAM,KAAK,CAAC,GAAI,MAAM;AACpG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/ta-series.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare function ema(source: Series, length: number): Series;
|
|
|
25
25
|
* @param length - Period length
|
|
26
26
|
* @returns Series with WMA values
|
|
27
27
|
*/
|
|
28
|
-
export declare function wma(source: Series, length: number): Series;
|
|
28
|
+
export declare function wma(source: Series, length: number | Series): Series;
|
|
29
29
|
/**
|
|
30
30
|
* Relative Moving Average
|
|
31
31
|
* @param source - Source series
|
|
@@ -39,7 +39,7 @@ export declare function rma(source: Series, length: number): Series;
|
|
|
39
39
|
* @param length - Period length
|
|
40
40
|
* @returns Series with RSI values
|
|
41
41
|
*/
|
|
42
|
-
export declare function rsi(source: Series, length: number): Series;
|
|
42
|
+
export declare function rsi(source: Series, length: number | Series): Series;
|
|
43
43
|
/**
|
|
44
44
|
* Moving Average Convergence Divergence
|
|
45
45
|
* @param source - Source series
|
|
@@ -152,14 +152,14 @@ export declare function roc(source: Series, length: number): Series;
|
|
|
152
152
|
* @param length - Period length
|
|
153
153
|
* @returns Series with highest values
|
|
154
154
|
*/
|
|
155
|
-
export declare function highest(source: Series, length: number): Series;
|
|
155
|
+
export declare function highest(source: Series, length: number | Series): Series;
|
|
156
156
|
/**
|
|
157
157
|
* Lowest value in period
|
|
158
158
|
* @param source - Source series
|
|
159
159
|
* @param length - Period length
|
|
160
160
|
* @returns Series with lowest values
|
|
161
161
|
*/
|
|
162
|
-
export declare function lowest(source: Series, length: number): Series;
|
|
162
|
+
export declare function lowest(source: Series, length: number | Series): Series;
|
|
163
163
|
/**
|
|
164
164
|
* Rising detection
|
|
165
165
|
* @param source - Source series
|
|
@@ -332,7 +332,7 @@ export declare function hma(source: Series, length: number): Series;
|
|
|
332
332
|
* @returns Series with the pivot high value on the bar where the pivot is confirmed,
|
|
333
333
|
* `rightbars` bars after the pivot bar (as in PineScript), NaN elsewhere
|
|
334
334
|
*/
|
|
335
|
-
export declare function pivothigh(source: Series, leftbars: number, rightbars: number): Series;
|
|
335
|
+
export declare function pivothigh(source: Series, leftbars: number | Series, rightbars: number | Series): Series;
|
|
336
336
|
/**
|
|
337
337
|
* Pivot Low
|
|
338
338
|
* @param source - Source series
|
|
@@ -341,7 +341,7 @@ export declare function pivothigh(source: Series, leftbars: number, rightbars: n
|
|
|
341
341
|
* @returns Series with the pivot low value on the bar where the pivot is confirmed,
|
|
342
342
|
* `rightbars` bars after the pivot bar (as in PineScript), NaN elsewhere
|
|
343
343
|
*/
|
|
344
|
-
export declare function pivotlow(source: Series, leftbars: number, rightbars: number): Series;
|
|
344
|
+
export declare function pivotlow(source: Series, leftbars: number | Series, rightbars: number | Series): Series;
|
|
345
345
|
/**
|
|
346
346
|
* Bars Since condition was true
|
|
347
347
|
* @param condition - Boolean series (1/0 values)
|
|
@@ -427,14 +427,14 @@ export declare function range(source: Series, length: number): Series;
|
|
|
427
427
|
* @param length - Period length
|
|
428
428
|
* @returns Series with bar offsets to highest value
|
|
429
429
|
*/
|
|
430
|
-
export declare function highestbars(source: Series, length: number): Series;
|
|
430
|
+
export declare function highestbars(source: Series, length: number | Series): Series;
|
|
431
431
|
/**
|
|
432
432
|
* Lowest Bars - offset to the lowest value
|
|
433
433
|
* @param source - Source series
|
|
434
434
|
* @param length - Period length
|
|
435
435
|
* @returns Series with bar offsets to lowest value
|
|
436
436
|
*/
|
|
437
|
-
export declare function lowestbars(source: Series, length: number): Series;
|
|
437
|
+
export declare function lowestbars(source: Series, length: number | Series): Series;
|
|
438
438
|
/**
|
|
439
439
|
* All-time highest value (PineScript ta.max)
|
|
440
440
|
* @param source - Source series
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ta-series.d.ts","sourceRoot":"","sources":["../../src/ta-series.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAKnE;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAK1D;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ta-series.d.ts","sourceRoot":"","sources":["../../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;;CAsEd,CAAC"}
|
package/dist/cjs/ta-series.js
CHANGED
|
@@ -117,7 +117,7 @@ function ema(source, length) {
|
|
|
117
117
|
function wma(source, length) {
|
|
118
118
|
const bars = source.bars;
|
|
119
119
|
const sourceValues = source.toArray();
|
|
120
|
-
const result = taCore.wma(sourceValues, length);
|
|
120
|
+
const result = taCore.wma(sourceValues, length instanceof import_series.Series ? length.toArray() : length);
|
|
121
121
|
return import_series.Series.fromArray(bars, result);
|
|
122
122
|
}
|
|
123
123
|
function rma(source, length) {
|
|
@@ -129,7 +129,7 @@ function rma(source, length) {
|
|
|
129
129
|
function rsi(source, length) {
|
|
130
130
|
const bars = source.bars;
|
|
131
131
|
const sourceValues = source.toArray();
|
|
132
|
-
const result = taCore.rsi(sourceValues, length);
|
|
132
|
+
const result = length instanceof import_series.Series ? taCore.rsi(sourceValues, length.toArray()) : taCore.rsi(sourceValues, length);
|
|
133
133
|
return import_series.Series.fromArray(bars, result);
|
|
134
134
|
}
|
|
135
135
|
function macd(source, fastLength, slowLength, signalLength) {
|
|
@@ -256,13 +256,13 @@ function roc(source, length) {
|
|
|
256
256
|
function highest(source, length) {
|
|
257
257
|
const bars = source.bars;
|
|
258
258
|
const sourceValues = source.toArray();
|
|
259
|
-
const result = taCore.highest(sourceValues, length);
|
|
259
|
+
const result = taCore.highest(sourceValues, length instanceof import_series.Series ? length.toArray() : length);
|
|
260
260
|
return import_series.Series.fromArray(bars, result);
|
|
261
261
|
}
|
|
262
262
|
function lowest(source, length) {
|
|
263
263
|
const bars = source.bars;
|
|
264
264
|
const sourceValues = source.toArray();
|
|
265
|
-
const result = taCore.lowest(sourceValues, length);
|
|
265
|
+
const result = taCore.lowest(sourceValues, length instanceof import_series.Series ? length.toArray() : length);
|
|
266
266
|
return import_series.Series.fromArray(bars, result);
|
|
267
267
|
}
|
|
268
268
|
function rising(source, length) {
|
|
@@ -415,12 +415,14 @@ function hma(source, length) {
|
|
|
415
415
|
}
|
|
416
416
|
function pivothigh(source, leftbars, rightbars) {
|
|
417
417
|
const bars = source.bars;
|
|
418
|
-
const
|
|
418
|
+
const arr = (v) => v instanceof import_series.Series ? v.toArray() : v;
|
|
419
|
+
const result = taCore.pivothigh(source.toArray(), arr(leftbars), arr(rightbars));
|
|
419
420
|
return import_series.Series.fromArray(bars, result);
|
|
420
421
|
}
|
|
421
422
|
function pivotlow(source, leftbars, rightbars) {
|
|
422
423
|
const bars = source.bars;
|
|
423
|
-
const
|
|
424
|
+
const arr = (v) => v instanceof import_series.Series ? v.toArray() : v;
|
|
425
|
+
const result = taCore.pivotlow(source.toArray(), arr(leftbars), arr(rightbars));
|
|
424
426
|
return import_series.Series.fromArray(bars, result);
|
|
425
427
|
}
|
|
426
428
|
function barssince(condition) {
|
|
@@ -492,12 +494,12 @@ function range(source, length) {
|
|
|
492
494
|
}
|
|
493
495
|
function highestbars(source, length) {
|
|
494
496
|
const bars = source.bars;
|
|
495
|
-
const result = taCore.highestbars(source.toArray(), length);
|
|
497
|
+
const result = taCore.highestbars(source.toArray(), length instanceof import_series.Series ? length.toArray() : length);
|
|
496
498
|
return import_series.Series.fromArray(bars, result);
|
|
497
499
|
}
|
|
498
500
|
function lowestbars(source, length) {
|
|
499
501
|
const bars = source.bars;
|
|
500
|
-
const result = taCore.lowestbars(source.toArray(), length);
|
|
502
|
+
const result = taCore.lowestbars(source.toArray(), length instanceof import_series.Series ? length.toArray() : length);
|
|
501
503
|
return import_series.Series.fromArray(bars, result);
|
|
502
504
|
}
|
|
503
505
|
function max(source) {
|