@tradecanvas/script 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -2
  3. package/dist/Column.d.ts +21 -0
  4. package/dist/Column.d.ts.map +1 -0
  5. package/dist/Ring.d.ts +28 -0
  6. package/dist/Ring.d.ts.map +1 -0
  7. package/dist/ScriptRun.d.ts +85 -0
  8. package/dist/ScriptRun.d.ts.map +1 -0
  9. package/dist/defineScript.d.ts +216 -0
  10. package/dist/defineScript.d.ts.map +1 -0
  11. package/dist/drawings.d.ts +46 -0
  12. package/dist/drawings.d.ts.map +1 -0
  13. package/dist/index.cjs +2 -0
  14. package/dist/index.cjs.map +1 -0
  15. package/dist/index.d.ts +20 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +1726 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/limits.d.ts +30 -0
  20. package/dist/limits.d.ts.map +1 -0
  21. package/dist/outputs.d.ts +129 -0
  22. package/dist/outputs.d.ts.map +1 -0
  23. package/dist/points.d.ts +13 -0
  24. package/dist/points.d.ts.map +1 -0
  25. package/dist/scope.d.ts +33 -0
  26. package/dist/scope.d.ts.map +1 -0
  27. package/dist/scriptIndicator.d.ts +25 -0
  28. package/dist/scriptIndicator.d.ts.map +1 -0
  29. package/dist/security.d.ts +52 -0
  30. package/dist/security.d.ts.map +1 -0
  31. package/dist/state.d.ts +52 -0
  32. package/dist/state.d.ts.map +1 -0
  33. package/dist/ta/averages.d.ts +19 -0
  34. package/dist/ta/averages.d.ts.map +1 -0
  35. package/dist/ta/common.d.ts +24 -0
  36. package/dist/ta/common.d.ts.map +1 -0
  37. package/dist/ta/events.d.ts +16 -0
  38. package/dist/ta/events.d.ts.map +1 -0
  39. package/dist/ta/index.d.ts +65 -0
  40. package/dist/ta/index.d.ts.map +1 -0
  41. package/dist/ta/moves.d.ts +26 -0
  42. package/dist/ta/moves.d.ts.map +1 -0
  43. package/dist/ta/oscillators.d.ts +29 -0
  44. package/dist/ta/oscillators.d.ts.map +1 -0
  45. package/dist/ta/ranges.d.ts +18 -0
  46. package/dist/ta/ranges.d.ts.map +1 -0
  47. package/dist/ta/statistics.d.ts +26 -0
  48. package/dist/ta/statistics.d.ts.map +1 -0
  49. package/dist/worker/messages.d.ts +49 -0
  50. package/dist/worker/messages.d.ts.map +1 -0
  51. package/dist/worker/scriptWorkerIndicator.d.ts +40 -0
  52. package/dist/worker/scriptWorkerIndicator.d.ts.map +1 -0
  53. package/dist/worker/serveScripts.d.ts +28 -0
  54. package/dist/worker/serveScripts.d.ts.map +1 -0
  55. package/package.json +39 -3
@@ -0,0 +1,33 @@
1
+ import { ScriptLimitError, ScriptLimits } from './limits.js';
2
+ /** A piece of a script's state the run keeps and puts back. */
3
+ export interface Unit {
4
+ /** Keep the state as it is now: the live bar will start again from here. */
5
+ commit(): void;
6
+ /** Put back the state kept last. */
7
+ rollback(): void;
8
+ }
9
+ export interface Scope {
10
+ readonly units: Unit[];
11
+ /**
12
+ * Whether the bar being run is the live one, run again on each tick. Only
13
+ * then a list records how to undo what it does.
14
+ */
15
+ live: boolean;
16
+ /** The bar being run, by its index. */
17
+ bar: number;
18
+ /** What empties a value a bar the script writes, before a bar is run (again). */
19
+ readonly clearers: ((bar: number) => void)[];
20
+ /** How far the run may go. */
21
+ readonly limits: Readonly<Required<ScriptLimits>>;
22
+ /** The loop steps the bar being run has taken. */
23
+ steps: number;
24
+ /** The limit the bar being run went past, caught by the script or not; null: none. */
25
+ breach: ScriptLimitError | null;
26
+ }
27
+ /** Run `fn` with `scope` taking the state made meanwhile. */
28
+ export declare function inScope<T>(scope: Scope, fn: () => T): T;
29
+ /** The scope a script's setup is running in. */
30
+ export declare function currentScope(what?: string): Scope;
31
+ /** A set of numbers the run keeps and puts back as one. */
32
+ export declare function cell<T extends Record<string, number>>(init: T): T;
33
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAElE,+DAA+D;AAC/D,MAAM,WAAW,IAAI;IACnB,4EAA4E;IAC5E,MAAM,IAAI,IAAI,CAAC;IACf,oCAAoC;IACpC,QAAQ,IAAI,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;IACvB;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;IACd,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;IAC7C,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;IAClD,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC;AAID,6DAA6D;AAC7D,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAQvD;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,IAAI,SAAiB,GAAG,KAAK,CAGzD;AAED,2DAA2D;AAC3D,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAQjE"}
@@ -0,0 +1,25 @@
1
+ import { IndicatorConfig, IndicatorDescriptor, IndicatorPlugin } from '@tradecanvas/commons';
2
+ import { Script, ScriptInputs } from './defineScript.js';
3
+ import { ScriptLimits } from './limits.js';
4
+ import { ScriptRunOptions } from './ScriptRun.js';
5
+ /** A run's options for an instance: its limits, and the exchange's clock its days are counted on. */
6
+ export declare function runOptionsOf(config: IndicatorConfig, limits?: ScriptLimits): ScriptRunOptions;
7
+ /** The inputs a run was made with, to tell whether a config asks for others. */
8
+ export declare function paramsKey(params: Readonly<Record<string, unknown>>): string;
9
+ /** The indicator a script is to the chart: its id, inputs, plots, fills and levels, known from its setup. */
10
+ export declare function describeScript(script: Script<ScriptInputs>): IndicatorDescriptor;
11
+ /** How a script is run as an indicator. */
12
+ export interface ScriptIndicatorOptions {
13
+ /** How far each run may go: loop steps a bar, numbers a list, ms a run. */
14
+ limits?: ScriptLimits;
15
+ }
16
+ /**
17
+ * A script as an indicator the chart draws: register it
18
+ * (`chart.registerIndicator(scriptIndicator(script))`) and add it by its id.
19
+ * Its plots are its lines under the keys `p0`, `p1`…, its marks `s0`, `s1`…,
20
+ * its backgrounds `bg0`…, its levels the pane's. A colour a bar is an index
21
+ * into the output's `palette` (`p0c`, `bg0c`, `f0c` for a fill). A tick
22
+ * runs only the live bar again.
23
+ */
24
+ export declare function scriptIndicator(script: Script<ScriptInputs>, options?: ScriptIndicatorOptions): IndicatorPlugin;
25
+ //# sourceMappingURL=scriptIndicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptIndicator.d.ts","sourceRoot":"","sources":["../src/scriptIndicator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EACf,mBAAmB,EAMnB,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAiB,MAAM,mBAAmB,CAAC;AAE7E,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAmBlE,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,gBAAgB,CAO7F;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAE3E;AAyDD,6GAA6G;AAC7G,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,mBAAmB,CAyBhF;AAwED,2CAA2C;AAC3C,MAAM,WAAW,sBAAsB;IACrC,2EAA2E;IAC3E,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,GAAE,sBAA2B,GAAG,eAAe,CAInH"}
@@ -0,0 +1,52 @@
1
+ import { TimeFrame } from '@tradecanvas/commons';
2
+ import { ScriptBar, ScriptPrices } from './defineScript.js';
3
+ import { ScriptLimitError, ScriptLimits } from './limits.js';
4
+ import { ScriptArray, ScriptSeries, Var } from './state.js';
5
+ /** What a higher interval's setup is given: its own bars' prices and state. */
6
+ export interface SecuritySetupApi {
7
+ /** The higher interval's bars, read back from the one being run. Their time is their first chart bar's. */
8
+ readonly prices: ScriptPrices;
9
+ readonly state: {
10
+ var<T>(init: T): Var<T>;
11
+ array(): ScriptArray;
12
+ series(): ScriptSeries;
13
+ };
14
+ }
15
+ /** Run once, before the first bar of the higher interval: makes its sums, returns its value a bar. */
16
+ export type SecuritySetup = (api: SecuritySetupApi) => (bar: ScriptBar) => number;
17
+ export interface SecurityOptions {
18
+ /**
19
+ * Also the bar of the higher interval still forming, as it was at each
20
+ * bar: its bars so far. It changes on the chart's bars as they come, as
21
+ * the forming bar does (it repaints). Unset: only bars that closed.
22
+ */
23
+ live?: boolean;
24
+ }
25
+ /** Where the chart's bars are read and the higher interval is cut. */
26
+ export interface SecurityContext {
27
+ /** The bars loaded, for the keyer to read their clock (seconds or ms, daily) and their spacing. */
28
+ timeline(): readonly {
29
+ time: number;
30
+ }[];
31
+ /** The chart's bar `index` as it now is (the bar before, closed, when a new one comes). */
32
+ barAt(index: number): ScriptBar;
33
+ /** The exchange's zone and the trading day's start, for days and longer. */
34
+ exchangeTimeZone?: string;
35
+ sessionStart?: number;
36
+ /** The script's limits, which the higher interval's run keeps to as well (its loops and lists; the time is the script's). */
37
+ limits?: ScriptLimits;
38
+ /** Told of a limit the higher interval went past, so the script stops even if it catches the error. */
39
+ onLimit?(error: ScriptLimitError): void;
40
+ }
41
+ /**
42
+ * A value of a higher interval of the same symbol, a chart bar at a time:
43
+ * the higher interval's bars are made of the chart's own (as a resample
44
+ * cuts them), and `setup`'s sums run over them in a run of their own, the
45
+ * forming bar run again as a tick is. Each chart bar reads, by default, the
46
+ * value of the last bar of the higher interval that closed before its own
47
+ * (it never changes after); with `live`, the forming bar's as it was then.
48
+ * Neither reads a bar after the chart's own. Called on every bar, as a `ta`
49
+ * sum is.
50
+ */
51
+ export declare function securityOf(context: SecurityContext, interval: TimeFrame, setup: SecuritySetup, options?: SecurityOptions): (bar: ScriptBar) => number;
52
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,EAAgB,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjE,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,2GAA2G;IAC3G,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE;QACd,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACxB,KAAK,IAAI,WAAW,CAAC;QACrB,MAAM,IAAI,YAAY,CAAC;KACxB,CAAC;CACH;AAED,sGAAsG;AACtG,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,gBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,KAAK,MAAM,CAAC;AAElF,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC9B,mGAAmG;IACnG,QAAQ,IAAI,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxC,2FAA2F;IAC3F,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6HAA6H;IAC7H,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,uGAAuG;IACvG,OAAO,CAAC,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACzC;AA6BD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,eAAoB,GAC5B,CAAC,GAAG,EAAE,SAAS,KAAK,MAAM,CA+F5B"}
@@ -0,0 +1,52 @@
1
+ import { Scope } from './scope.js';
2
+ /** A value kept from bar to bar: what a bar leaves in it, the next bar finds. */
3
+ export interface Var<T> {
4
+ value: T;
5
+ }
6
+ /**
7
+ * A value kept from bar to bar, put back to the bar before's when the live
8
+ * bar runs again. An object is put back as the same object: keep a handle
9
+ * in one (a line drawn), and change a list through `state.array`.
10
+ */
11
+ export declare function keep<T>(init: T): Var<T>;
12
+ /** A value a bar the script sets and reads back (`at(1)`: the bar before's). */
13
+ export interface ScriptSeries {
14
+ /** Set this bar's value; returns it. */
15
+ set(value: number): number;
16
+ /** The value `back` bars ago (0: this bar's); NaN where none was set. */
17
+ at(back?: number): number;
18
+ }
19
+ export declare function seriesOf(): ScriptSeries;
20
+ /**
21
+ * A list kept from bar to bar. On the live bar it records how to undo each
22
+ * change, so a tick that runs the bar again starts from the list as the bar
23
+ * before left it; on the closed bars it records nothing.
24
+ */
25
+ export declare class ScriptArray {
26
+ private readonly scope;
27
+ private items;
28
+ private undo;
29
+ constructor(scope: Scope);
30
+ private record;
31
+ /** Room for one more number, or the bar stops. */
32
+ private grow;
33
+ size(): number;
34
+ /** The value at `index` (negative: from the end); NaN outside the list. */
35
+ get(index: number): number;
36
+ set(index: number, value: number): void;
37
+ push(value: number): void;
38
+ pop(): number;
39
+ shift(): number;
40
+ unshift(value: number): void;
41
+ clear(): void;
42
+ /** A copy of the values. */
43
+ toArray(): number[];
44
+ sum(): number;
45
+ avg(): number;
46
+ min(): number;
47
+ max(): number;
48
+ /** The middle value, or the mean of the two middle ones. */
49
+ median(): number;
50
+ }
51
+ export declare function arrayOf(): ScriptArray;
52
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtD,iFAAiF;AACjF,MAAM,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAavC;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,yEAAyE;IACzE,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B;AAED,wBAAgB,QAAQ,IAAI,YAAY,CAYvC;AAED;;;;GAIG;AACH,qBAAa,WAAW;IAIV,OAAO,CAAC,QAAQ,CAAC,KAAK;IAHlC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,IAAI,CAAsB;gBAEL,KAAK,EAAE,KAAK;IAYzC,OAAO,CAAC,MAAM;IAId,kDAAkD;IAClD,OAAO,CAAC,IAAI;IAKZ,IAAI,IAAI,MAAM;IAId,2EAA2E;IAC3E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAK1B,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IASvC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQzB,GAAG,IAAI,MAAM;IASb,KAAK,IAAI,MAAM;IASf,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAQ5B,KAAK,IAAI,IAAI;IAQb,4BAA4B;IAC5B,OAAO,IAAI,MAAM,EAAE;IAInB,GAAG,IAAI,MAAM;IAMb,GAAG,IAAI,MAAM;IAIb,GAAG,IAAI,MAAM;IAIb,GAAG,IAAI,MAAM;IAIb,4DAA4D;IAC5D,MAAM,IAAI,MAAM;CAOjB;AAED,wBAAgB,OAAO,IAAI,WAAW,CAErC"}
@@ -0,0 +1,19 @@
1
+ import { Ring } from '../Ring.js';
2
+ import { Step } from './common.js';
3
+ /** Simple moving average of the last `period` values; a gap starts it again. */
4
+ export declare function sma(period: number): Step;
5
+ /** Exponential moving average, started as the simple average of its first `period` values. */
6
+ export declare function ema(period: number): Step;
7
+ /** Wilder's smoothing (RMA, SMMA): an EMA moving 1 / period of the way. */
8
+ export declare function rma(period: number): Step;
9
+ /** The last `period` values, oldest first, or null when one of them is missing. */
10
+ export declare function windowOf(ring: Ring, p: number): number[] | null;
11
+ /** Linearly weighted moving average: the newest of `period` values weighs `period`, the oldest 1. */
12
+ export declare function wma(period: number): Step;
13
+ /** Standard deviation of the whole population of the last `period` values. */
14
+ export declare function stdev(period: number): Step;
15
+ /** Hull moving average: a weighted average of twice the half-period one less the full one, over the root of the period (each at least 2), as the built-in HMA. */
16
+ export declare function hma(period: number): Step;
17
+ /** Volume-weighted moving average of the last `period` bars, as the built-in VWMA: none while their volume is nothing. */
18
+ export declare function vwma(period: number): (value: number, volume: number) => number;
19
+ //# sourceMappingURL=averages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"averages.d.ts","sourceRoot":"","sources":["../../src/ta/averages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAwB,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAS9D,gFAAgF;AAChF,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAexC;AAqBD,8FAA8F;AAC9F,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAExC;AAED,2EAA2E;AAC3E,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAExC;AAED,mFAAmF;AACnF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAS/D;AAED,qGAAqG;AACrG,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAYxC;AAED,8EAA8E;AAC9E,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAgB1C;AAED,kKAAkK;AAClK,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAExC;AAcD,0HAA0H;AAC1H,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAuB9E"}
@@ -0,0 +1,24 @@
1
+ /** A value a sum takes: a number, or none (NaN) for anything that is not a finite number. */
2
+ export declare function num(value: number): number;
3
+ /** A period of at least one, as the built-in indicators take one: its whole part. */
4
+ export declare function whole(period: number): number;
5
+ /** A sum a bar at a time: given this bar's value, it gives this bar's result. */
6
+ export type Step = (value: number) => number;
7
+ /** The prices of a bar a sum of ranges reads. */
8
+ export interface BarPrices {
9
+ readonly high: number;
10
+ readonly low: number;
11
+ readonly close: number;
12
+ }
13
+ /**
14
+ * A sum over a value a bar as `@tradecanvas/core`'s `ta` runs a built-in
15
+ * indicator over one: from its first number on, a missing value is computed
16
+ * over as the last number (no change on that bar) and gives none itself.
17
+ */
18
+ export declare function holdGaps<T>(step: (value: number) => T, none: T): (value: number) => T;
19
+ /**
20
+ * A bar's prices as the built-in indicators are given them: a close that is
21
+ * no number is the close before, another price that is none is its close.
22
+ */
23
+ export declare function cleanPrices(): (bar: BarPrices) => BarPrices;
24
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/ta/common.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,iFAAiF;AACjF,MAAM,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;AAE7C,iDAAiD;AACjD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAWrF;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,CAAC,GAAG,EAAE,SAAS,KAAK,SAAS,CAQ3D"}
@@ -0,0 +1,16 @@
1
+ import { Step } from './common.js';
2
+ /** True on the bar where `a` goes over `b`: at or under it the bar before, over it now. */
3
+ export declare function crossover(): (a: number, b: number) => boolean;
4
+ /** True on the bar where `a` goes under `b`: at or over it the bar before, under it now. */
5
+ export declare function crossunder(): (a: number, b: number) => boolean;
6
+ /** True on the bar where `a` goes over or under `b`. */
7
+ export declare function cross(): (a: number, b: number) => boolean;
8
+ /** The high of a pivot `right` bars back: higher than the `left` before it and the `right` after it. NaN on other bars. */
9
+ export declare function pivothigh(left: number, right: number): Step;
10
+ /** The low of a pivot `right` bars back: lower than the `left` before it and the `right` after it. NaN on other bars. */
11
+ export declare function pivotlow(left: number, right: number): Step;
12
+ /** How many bars since the condition was last true (0 on a bar it is); NaN before it ever was. */
13
+ export declare function barssince(): (condition: boolean) => number;
14
+ /** The value on the bar of the condition's `occurrence`-th last true (0: the last); NaN until there is one. */
15
+ export declare function valuewhen(occurrence?: number): (condition: boolean, value: number) => number;
16
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/ta/events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAiBpD,2FAA2F;AAC3F,wBAAgB,SAAS,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE7D;AAED,4FAA4F;AAC5F,wBAAgB,UAAU,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE9D;AAED,wDAAwD;AACxD,wBAAgB,KAAK,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAQzD;AAqBD,2HAA2H;AAC3H,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED,yHAAyH;AACzH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE1D;AAED,kGAAkG;AAClG,wBAAgB,SAAS,IAAI,CAAC,SAAS,EAAE,OAAO,KAAK,MAAM,CAM1D;AAED,+GAA+G;AAC/G,wBAAgB,SAAS,CAAC,UAAU,SAAI,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAOvF"}
@@ -0,0 +1,65 @@
1
+ import { ema, hma, rma, sma, stdev, vwma, wma } from './averages.js';
2
+ import { barssince, cross, crossover, crossunder, pivothigh, pivotlow, valuewhen } from './events.js';
3
+ import { bb, change, macd, mom, roc, rsi } from './oscillators.js';
4
+ import { atr, highest, lowest, supertrend, tr } from './ranges.js';
5
+ import { falling, highestbars, lowestbars, mfi, obv, rising, sar, stoch } from './moves.js';
6
+ import { alma, correlation, cum, dev, linreg, median, percentileLinearInterpolation, percentileNearestRank, percentrank, sum, swma, variance } from './statistics.js';
7
+ export type { BandsValue, MacdValue } from './oscillators.js';
8
+ export type { SupertrendValue } from './ranges.js';
9
+ export type { BarPrices, Step } from './common.js';
10
+ /**
11
+ * The sums a script is made of, each run a bar at a time. Make one in the
12
+ * script's setup (`const fast = ta.ema(9)`), then give it a value on each
13
+ * bar (`fast(bar.close)`): it keeps its own state, so two calls of
14
+ * `ta.ema(9)` are two averages. Their values are the chart's own built-in
15
+ * indicators' (`@tradecanvas/core`), a missing value (NaN) handled as there.
16
+ */
17
+ export declare const ta: {
18
+ sma: typeof sma;
19
+ ema: typeof ema;
20
+ rma: typeof rma;
21
+ wma: typeof wma;
22
+ vwma: typeof vwma;
23
+ hma: typeof hma;
24
+ stdev: typeof stdev;
25
+ bb: typeof bb;
26
+ rsi: typeof rsi;
27
+ macd: typeof macd;
28
+ change: typeof change;
29
+ mom: typeof mom;
30
+ roc: typeof roc;
31
+ tr: typeof tr;
32
+ atr: typeof atr;
33
+ supertrend: typeof supertrend;
34
+ highest: typeof highest;
35
+ lowest: typeof lowest;
36
+ crossover: typeof crossover;
37
+ crossunder: typeof crossunder;
38
+ cross: typeof cross;
39
+ pivothigh: typeof pivothigh;
40
+ pivotlow: typeof pivotlow;
41
+ barssince: typeof barssince;
42
+ valuewhen: typeof valuewhen;
43
+ sum: typeof sum;
44
+ cum: typeof cum;
45
+ median: typeof median;
46
+ percentileNearestRank: typeof percentileNearestRank;
47
+ percentileLinearInterpolation: typeof percentileLinearInterpolation;
48
+ percentrank: typeof percentrank;
49
+ dev: typeof dev;
50
+ variance: typeof variance;
51
+ correlation: typeof correlation;
52
+ linreg: typeof linreg;
53
+ alma: typeof alma;
54
+ swma: typeof swma;
55
+ stoch: typeof stoch;
56
+ mfi: typeof mfi;
57
+ obv: typeof obv;
58
+ sar: typeof sar;
59
+ highestbars: typeof highestbars;
60
+ lowestbars: typeof lowestbars;
61
+ rising: typeof rising;
62
+ falling: typeof falling;
63
+ };
64
+ export type ScriptTa = typeof ta;
65
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ta/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtG,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EACL,IAAI,EACJ,WAAW,EACX,GAAG,EACH,GAAG,EACH,MAAM,EACN,MAAM,EACN,6BAA6B,EAC7B,qBAAqB,EACrB,WAAW,EACX,GAAG,EACH,IAAI,EACJ,QAAQ,EACT,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;GAMG;AACH,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Cd,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { BarPrices, Step } from './common.js';
2
+ /** The raw stochastic %K: where `value` stands between the lowest low and the highest high of the last `period` bars, 0 to 100; 50 when they are one. */
3
+ export declare function stoch(period: number): (value: number, high: number, low: number) => number;
4
+ /**
5
+ * The Money Flow Index of `value` (the typical price, as the built-in MFI
6
+ * reads) and the volume: the share of the last `period` bars' money that
7
+ * came on bars where it rose, 0 to 100; 100 when it never fell.
8
+ */
9
+ export declare function mfi(period: number): (value: number, volume: number) => number;
10
+ /** On-balance volume: each bar's volume added when the close rose, taken away when it fell; 0 on the first bar. */
11
+ export declare function obv(): (close: number, volume: number) => number;
12
+ /**
13
+ * Parabolic SAR, as the built-in: from the second bar, its trend first read
14
+ * from the first two closes. The step starts at `start`, grows by
15
+ * `increment` with each new extreme, up to `max`, and starts again at a turn.
16
+ */
17
+ export declare function sar(start?: number, increment?: number, max?: number): (bar: BarPrices) => number;
18
+ /** How many bars back the highest of the last `period` values is, as an offset at or under 0. */
19
+ export declare function highestbars(period: number): Step;
20
+ /** How many bars back the lowest of the last `period` values is, as an offset at or under 0. */
21
+ export declare function lowestbars(period: number): Step;
22
+ /** Whether the value is over every one of the `period` before it. */
23
+ export declare function rising(period: number): (value: number) => boolean;
24
+ /** Whether the value is under every one of the `period` before it. */
25
+ export declare function falling(period: number): (value: number) => boolean;
26
+ //# sourceMappingURL=moves.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moves.d.ts","sourceRoot":"","sources":["../../src/ta/moves.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2B,KAAK,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAQjF,yJAAyJ;AACzJ,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAe1F;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAkB7E;AAED,mHAAmH;AACnH,wBAAgB,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAc/D;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,SAAO,EAAE,SAAS,SAAO,EAAE,GAAG,SAAM,GAAG,CAAC,GAAG,EAAE,SAAS,KAAK,MAAM,CAmDzF;AAgBD,iGAAiG;AACjG,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEhD;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE/C;AAeD,qEAAqE;AACrE,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAEjE;AAED,sEAAsE;AACtE,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAElE"}
@@ -0,0 +1,29 @@
1
+ import { Step } from './common.js';
2
+ /** Relative Strength Index, 0 to 100, as the built-in RSI: Wilder's smoothing of the gains and losses, started as their simple average. */
3
+ export declare function rsi(period?: number): Step;
4
+ export interface MacdValue {
5
+ readonly macd: number;
6
+ readonly signal: number;
7
+ readonly histogram: number;
8
+ }
9
+ /**
10
+ * MACD: the fast average less the slow one, its signal line and the one less
11
+ * the other. Its averages start as simple ones, as every EMA here does (the
12
+ * built-in MACD indicator starts its own at the first close, so its first
13
+ * hundred bars or so differ by a hair).
14
+ */
15
+ export declare function macd(fast?: number, slow?: number, signal?: number): (value: number) => MacdValue;
16
+ export interface BandsValue {
17
+ readonly basis: number;
18
+ readonly upper: number;
19
+ readonly lower: number;
20
+ }
21
+ /** Bollinger Bands: a simple average and the lines `mult` standard deviations either side of it. */
22
+ export declare function bb(period?: number, mult?: number): (value: number) => BandsValue;
23
+ /** How far a value is from the one `bars` before it. */
24
+ export declare function change(bars?: number): Step;
25
+ /** Momentum: how far a value is from the one `period` bars before it. */
26
+ export declare function mom(period?: number): Step;
27
+ /** Rate of change in per cent from the value `period` bars before, as the built-in ROC: 0 from a value of 0. */
28
+ export declare function roc(period?: number): Step;
29
+ //# sourceMappingURL=oscillators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oscillators.d.ts","sourceRoot":"","sources":["../../src/ta/oscillators.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAE9D,2IAA2I;AAC3I,wBAAgB,GAAG,CAAC,MAAM,SAAK,GAAG,IAAI,CAErC;AAgCD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,IAAI,SAAK,EAAE,IAAI,SAAK,EAAE,MAAM,SAAI,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAEnF;AAeD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,oGAAoG;AACpG,wBAAgB,EAAE,CAAC,MAAM,SAAK,EAAE,IAAI,SAAI,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,UAAU,CAEvE;AAYD,wDAAwD;AACxD,wBAAgB,MAAM,CAAC,IAAI,SAAI,GAAG,IAAI,CAOrC;AAED,yEAAyE;AACzE,wBAAgB,GAAG,CAAC,MAAM,SAAK,GAAG,IAAI,CAErC;AAED,gHAAgH;AAChH,wBAAgB,GAAG,CAAC,MAAM,SAAK,GAAG,IAAI,CAErC"}
@@ -0,0 +1,18 @@
1
+ import { BarPrices, Step } from './common.js';
2
+ /** A bar's true range: its range, stretched to the close before it; the first bar's is its own range. */
3
+ export declare function tr(): (bar: BarPrices) => number;
4
+ /** Average True Range, as the built-in ATR: the simple average of the first `period` true ranges, then Wilder's smoothing. */
5
+ export declare function atr(period?: number): (bar: BarPrices) => number;
6
+ export interface SupertrendValue {
7
+ /** The line: under the bars while the trend is up, over them while it is down. */
8
+ readonly value: number;
9
+ /** 1 while the trend is up, -1 while it is down. */
10
+ readonly trend: number;
11
+ }
12
+ /** Supertrend, as the built-in: bands `factor` ATRs from the bar's middle, each held until the close crosses it. */
13
+ export declare function supertrend(factor?: number, period?: number): (bar: BarPrices) => SupertrendValue;
14
+ /** The highest of the last `period` values. */
15
+ export declare function highest(period: number): Step;
16
+ /** The lowest of the last `period` values. */
17
+ export declare function lowest(period: number): Step;
18
+ //# sourceMappingURL=ranges.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ranges.d.ts","sourceRoot":"","sources":["../../src/ta/ranges.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAEjF,yGAAyG;AACzG,wBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE,SAAS,KAAK,MAAM,CAY/C;AAED,8HAA8H;AAC9H,wBAAgB,GAAG,CAAC,MAAM,SAAK,GAAG,CAAC,GAAG,EAAE,SAAS,KAAK,MAAM,CAiB3D;AAED,MAAM,WAAW,eAAe;IAC9B,kFAAkF;IAClF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,oHAAoH;AACpH,wBAAgB,UAAU,CAAC,MAAM,SAAI,EAAE,MAAM,SAAK,GAAG,CAAC,GAAG,EAAE,SAAS,KAAK,eAAe,CAwBvF;AAmBD,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED,8CAA8C;AAC9C,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE3C"}
@@ -0,0 +1,26 @@
1
+ import { Step } from './common.js';
2
+ /** The sum of the last `period` values. */
3
+ export declare function sum(period: number): Step;
4
+ /** The running total of every value so far; a missing one is passed over. None before the first number. */
5
+ export declare function cum(): Step;
6
+ /** The middle of the last `period` values; of an even count, the mean of the two in the middle. */
7
+ export declare function median(period: number): Step;
8
+ /** The value `percentage` of the way up the last `period` values, by the nearest rank: one of the values itself. */
9
+ export declare function percentileNearestRank(period: number, percentage: number): Step;
10
+ /** The value `percentage` of the way up the last `period` values, between the two values either side of it. */
11
+ export declare function percentileLinearInterpolation(period: number, percentage: number): Step;
12
+ /** How many of the `period` values before this one are at or under it, as a percentage. */
13
+ export declare function percentrank(period: number): Step;
14
+ /** The mean distance of the last `period` values from their mean. */
15
+ export declare function dev(period: number): Step;
16
+ /** The variance of the whole population of the last `period` values: `ta.stdev` squared, worked out the same way. */
17
+ export declare function variance(period: number): Step;
18
+ /** How closely two values move together over the last `period` bars, from -1 to 1; none while either stays flat. */
19
+ export declare function correlation(period: number): (a: number, b: number) => number;
20
+ /** The least-squares line through the last `period` values (2 to 5000), read at the newest (or `offset` bars before it), as the built-in LSMA. */
21
+ export declare function linreg(period: number, offset?: number): Step;
22
+ /** The Arnaud Legoux moving average, as the built-in ALMA: weights in a bell `offset` of the way along the window, `sigma` setting its width. */
23
+ export declare function alma(period: number, offset?: number, sigma?: number): Step;
24
+ /** The symmetrically weighted average of the last four values: weights 1, 2, 2, 1. */
25
+ export declare function swma(): Step;
26
+ //# sourceMappingURL=statistics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statistics.d.ts","sourceRoot":"","sources":["../../src/ta/statistics.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AA0BpD,2CAA2C;AAC3C,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAExC;AAED,2GAA2G;AAC3G,wBAAgB,GAAG,IAAI,IAAI,CAU1B;AAED,mGAAmG;AACnG,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAM3C;AAOD,oHAAoH;AACpH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAQ9E;AAED,+GAA+G;AAC/G,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAStF;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAYhD;AAED,qEAAqE;AACrE,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAKxC;AAED,qHAAqH;AACrH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAW7C;AAED,oHAAoH;AACpH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAsB5E;AAED,kJAAkJ;AAClJ,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,IAAI,CAevD;AAED,iJAAiJ;AACjJ,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,SAAO,EAAE,KAAK,SAAI,GAAG,IAAI,CAanE;AAED,sFAAsF;AACtF,wBAAgB,IAAI,IAAI,IAAI,CAE3B"}
@@ -0,0 +1,49 @@
1
+ import { IndicatorDrawing, IndicatorValue, OHLCBar } from '@tradecanvas/commons';
2
+ import { ScriptError } from '../outputs.js';
3
+ import { ScriptRunOptions } from '../ScriptRun.js';
4
+ /** Run a script over all of `bars`, as a run of its own (`run`); one with that number before is dropped. */
5
+ export interface LoadRequest {
6
+ type: 'load';
7
+ run: number;
8
+ seq: number;
9
+ /** The script's id, as `serveScripts` was given it. */
10
+ script: string;
11
+ params: Record<string, unknown>;
12
+ options: ScriptRunOptions;
13
+ bars: OHLCBar[];
14
+ }
15
+ /** The live bar again (`tick`), or a new bar (`next`), in a run loaded before. */
16
+ export interface BarRequest {
17
+ type: 'tick' | 'next';
18
+ run: number;
19
+ seq: number;
20
+ bar: OHLCBar;
21
+ }
22
+ /** Forget a run. */
23
+ export interface DropRequest {
24
+ type: 'drop';
25
+ run: number;
26
+ }
27
+ export type ScriptWorkerRequest = LoadRequest | BarRequest | DropRequest;
28
+ /** What a request changed: the bars from `from` on, as the chart reads them, and what the run holds now. */
29
+ export interface PatchResponse {
30
+ type: 'patch';
31
+ run: number;
32
+ seq: number;
33
+ /** The first bar whose point is in `points`; the bars before are as they were. */
34
+ from: number;
35
+ /** A point a bar, from `from` to the run's last bar. */
36
+ points: (IndicatorValue | null)[];
37
+ palette: string[];
38
+ drawings: IndicatorDrawing[];
39
+ errors: ScriptError[];
40
+ }
41
+ /** A request the worker could not run at all: no such script, a setup that threw, a run it does not hold. */
42
+ export interface FailedResponse {
43
+ type: 'failed';
44
+ run: number;
45
+ seq: number;
46
+ message: string;
47
+ }
48
+ export type ScriptWorkerResponse = PatchResponse | FailedResponse;
49
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/worker/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,4GAA4G;AAC5G,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AAED,kFAAkF;AAClF,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,OAAO,CAAC;CACd;AAED,oBAAoB;AACpB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEzE,4GAA4G;AAC5G,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,MAAM,EAAE,CAAC,cAAc,GAAG,IAAI,CAAC,EAAE,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,6GAA6G;AAC7G,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,cAAc,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { IndicatorPlugin } from '@tradecanvas/commons';
2
+ import { Script, ScriptInputs } from '../defineScript.js';
3
+ import { ScriptLimits } from '../limits.js';
4
+ /** What the page's side needs of a worker: `Worker` is one. */
5
+ export interface ScriptWorkerLike {
6
+ postMessage(message: unknown): void;
7
+ addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
8
+ terminate(): void;
9
+ }
10
+ export interface ScriptWorkerOptions {
11
+ /**
12
+ * Start the worker that serves the script (its module calls
13
+ * `serveScripts`). Called when first needed, and again after a worker
14
+ * was stopped.
15
+ */
16
+ spawn: () => ScriptWorkerLike;
17
+ /**
18
+ * How long one request may go unanswered, in ms, the first load of the
19
+ * bars among them, before the worker is stopped and the script it hung
20
+ * on with it: a bar that never returns is stopped this way. Default 5000.
21
+ */
22
+ timeoutMs?: number;
23
+ /** How far each run may go in the worker: loop steps a bar, numbers a list, ms a run. */
24
+ limits?: ScriptLimits;
25
+ }
26
+ /**
27
+ * A script as an indicator run in a worker: the page sends it the bars,
28
+ * one bar each on a tick, and draws what it answers. A worker that does
29
+ * not answer within `timeoutMs` is stopped, so a script that never returns
30
+ * cannot hang the page. The worker's module serves the same script
31
+ * (`serveScripts`); the setup runs here too, once, to know what it draws.
32
+ *
33
+ * ```ts
34
+ * chart.registerIndicator(scriptWorkerIndicator(emaCross, {
35
+ * spawn: () => new Worker(new URL('./scripts.worker.ts', import.meta.url), { type: 'module' }),
36
+ * }))
37
+ * ```
38
+ */
39
+ export declare function scriptWorkerIndicator(script: Script<ScriptInputs>, options: ScriptWorkerOptions): IndicatorPlugin;
40
+ //# sourceMappingURL=scriptWorkerIndicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptWorkerIndicator.d.ts","sourceRoot":"","sources":["../../src/worker/scriptWorkerIndicator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,eAAe,EAGhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ3D,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACjF,SAAS,IAAI,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,KAAK,EAAE,MAAM,gBAAgB,CAAC;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yFAAyF;IACzF,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAoQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,mBAAmB,GAAG,eAAe,CAKjH"}
@@ -0,0 +1,28 @@
1
+ import { Script, ScriptInputs } from '../defineScript.js';
2
+ import { ScriptWorkerRequest, ScriptWorkerResponse } from './messages.js';
3
+ /** How the worker answers. */
4
+ export type ScriptWorkerPost = (message: ScriptWorkerResponse) => void;
5
+ /** What a worker's global scope gives `serveScripts`: its messages in, and a way to answer. */
6
+ export interface ScriptWorkerScope {
7
+ addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
8
+ postMessage(message: unknown): void;
9
+ }
10
+ /**
11
+ * The worker's side, apart from the worker so a test can run it on its own
12
+ * thread: each run the page loads is kept here, so a tick sends one bar
13
+ * and gets back the points from that bar on.
14
+ */
15
+ export declare function createScriptHandler(scripts: readonly Script<ScriptInputs>[], post: ScriptWorkerPost): (request: ScriptWorkerRequest) => void;
16
+ /**
17
+ * Serve `scripts` from a worker: call it in the worker's module, with the
18
+ * scripts the page runs through `scriptWorkerIndicator`.
19
+ *
20
+ * ```ts
21
+ * // scripts.worker.ts
22
+ * import { serveScripts } from '@tradecanvas/script'
23
+ * import { emaCross } from './emaCross'
24
+ * serveScripts([emaCross])
25
+ * ```
26
+ */
27
+ export declare function serveScripts(scripts: readonly Script<ScriptInputs>[], scope?: ScriptWorkerScope): void;
28
+ //# sourceMappingURL=serveScripts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serveScripts.d.ts","sourceRoot":"","sources":["../../src/worker/serveScripts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG/D,OAAO,KAAK,EAAiB,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE9F,8BAA8B;AAC9B,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAEvE,+FAA+F;AAC/F,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACjF,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAuBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,MAAM,CAAC,YAAY,CAAC,EAAE,EACxC,IAAI,EAAE,gBAAgB,GACrB,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAsCxC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,GAAE,iBAAwD,GAAG,IAAI,CAG5I"}