@alphacharts/indicators 0.0.0-stage → 0.1.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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -2
  3. package/dist/all-DeXJJd7D.js +21 -0
  4. package/dist/all-DeXJJd7D.js.map +1 -0
  5. package/dist/all.js +10 -0
  6. package/dist/all.js.map +1 -0
  7. package/dist/assets/worker-BrUuzTIJ.js +2 -0
  8. package/dist/assets/worker-BrUuzTIJ.js.map +1 -0
  9. package/dist/define-BPvQbaq9.js +472 -0
  10. package/dist/define-BPvQbaq9.js.map +1 -0
  11. package/dist/index.js +593 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/registry-CYZuqhXX.js +49 -0
  14. package/dist/registry-CYZuqhXX.js.map +1 -0
  15. package/dist/runner-DBP0M8z3.js +229 -0
  16. package/dist/runner-DBP0M8z3.js.map +1 -0
  17. package/dist/studies.js +1 -0
  18. package/dist/tv-volume-7hh6ajKt.js +3457 -0
  19. package/dist/tv-volume-7hh6ajKt.js.map +1 -0
  20. package/dist/types/all.d.ts +3 -0
  21. package/dist/types/chart/studies.d.ts +165 -0
  22. package/dist/types/define.d.ts +46 -0
  23. package/dist/types/engine/graph.d.ts +101 -0
  24. package/dist/types/engine/kernels.d.ts +9 -0
  25. package/dist/types/engine/study.d.ts +31 -0
  26. package/dist/types/index.d.ts +12 -0
  27. package/dist/types/registry.d.ts +7 -0
  28. package/dist/types/runner.d.ts +82 -0
  29. package/dist/types/studies/all.d.ts +2 -0
  30. package/dist/types/studies/cycle.d.ts +7 -0
  31. package/dist/types/studies/index.d.ts +13 -0
  32. package/dist/types/studies/ma.d.ts +26 -0
  33. package/dist/types/studies/math.d.ts +28 -0
  34. package/dist/types/studies/momentum.d.ts +30 -0
  35. package/dist/types/studies/overlap.d.ts +14 -0
  36. package/dist/types/studies/patterns.d.ts +62 -0
  37. package/dist/types/studies/price.d.ts +6 -0
  38. package/dist/types/studies/sar.d.ts +2 -0
  39. package/dist/types/studies/statistic.d.ts +9 -0
  40. package/dist/types/studies/tv-osc.d.ts +18 -0
  41. package/dist/types/studies/tv-trend.d.ts +20 -0
  42. package/dist/types/studies/tv-volume.d.ts +14 -0
  43. package/dist/types/studies/volatility.d.ts +3 -0
  44. package/dist/types/studies/volume.d.ts +3 -0
  45. package/dist/types/types.d.ts +133 -0
  46. package/dist/types/wasm.d.ts +2 -0
  47. package/dist/types/worker.d.ts +1 -0
  48. package/dist/worker.js +8 -0
  49. package/dist/worker.js.map +1 -0
  50. package/package.json +69 -3
@@ -0,0 +1,3 @@
1
+ import { ALL_STUDIES } from "./studies/all.js";
2
+ export { ALL_STUDIES };
3
+ export declare function registerAllStudies(): void;
@@ -0,0 +1,165 @@
1
+ import { type Chart, type ChartPlugin, type DataChange, type PluginApi, type PluginPaneView, type Series, type SeriesType } from "@alphacharts/core";
2
+ import { type StudyRunner } from "../runner.js";
3
+ import type { InputValue, Params, StudyDef } from "../types.js";
4
+ export declare const PLUGIN_ID = "alphacharts.studies";
5
+ type AnySeries = Series<SeriesType>;
6
+ type SourceSeries = Series<"candles" | "bars" | "line" | "area" | "histogram">;
7
+ export interface AddStudyOptions {
8
+ /** Volume series (histogram or line) for studies that need volume. */
9
+ volume?: Series<"histogram" | "line" | "area">;
10
+ /** Instance id; default `s<n>`. Layout state is keyed by it. */
11
+ id?: string;
12
+ /** Batch evaluation off the UI thread; ticks always run inline. */
13
+ runner?: StudyRunner;
14
+ /** Called once when the study is dropped or disposed (removed, source removed, layout restored over it). */
15
+ onDispose?: () => void;
16
+ /**
17
+ * Whether `StudiesPlugin.toJSON` saves this study (default true). A study
18
+ * that something else rebuilds on restore (a script, through
19
+ * `restoreScript`) sets it false: the plugin could not recreate it, and a
20
+ * layout holding it would be refused.
21
+ */
22
+ persist?: boolean;
23
+ }
24
+ export interface PlotStyle {
25
+ color?: string;
26
+ width?: number;
27
+ }
28
+ export declare class Study {
29
+ private readonly host;
30
+ readonly id: string;
31
+ private readonly source;
32
+ private readonly volume;
33
+ private readonly ownRunner?;
34
+ private readonly onDispose?;
35
+ readonly def: StudyDef;
36
+ private params;
37
+ private engine;
38
+ private outs;
39
+ private lines;
40
+ private styles;
41
+ private shown;
42
+ private pane;
43
+ private scaleId;
44
+ private version;
45
+ private job;
46
+ /** A tick arrived while a job was pending (caught up on adoption). */
47
+ private dirty;
48
+ /** A replace/prepend arrived while a job was pending: the job's data is stale. */
49
+ private structural;
50
+ /** Set when a computation failed: the study stops following the source and says why. */
51
+ error: Error | null;
52
+ private ready_;
53
+ disposed: boolean;
54
+ /** Decimals a separate-pane study's axis and labels show when its def does not set `minMove`: two, more when the values are small. */
55
+ private decimals;
56
+ /** Whether the plugin saves this study (see `AddStudyOptions.persist`). */
57
+ persist: boolean;
58
+ inputs(): Params;
59
+ get visible(): boolean;
60
+ /** Resolves when the last requested computation has been applied to the chart. */
61
+ ready(): Promise<void>;
62
+ /**
63
+ * Redraw from the engine's columns after they were written from outside (a
64
+ * computation that arrives late, e.g. a script worker): the last bar when
65
+ * `onlyLast`, else every bar.
66
+ */
67
+ refresh(onlyLast?: boolean): void;
68
+ /** Output series, in plot order. */
69
+ series(): readonly AnySeries[];
70
+ /** Change inputs; unspecified ones keep their value. Validated before anything changes. */
71
+ setInputs(partial: Readonly<Record<string, InputValue>>): void;
72
+ setVisible(visible: boolean): void;
73
+ setStyle(plotKey: string, style: PlotStyle): void;
74
+ remove(): void;
75
+ /** The last computed value of each column (undefined while in warm-up), by column name. */
76
+ lastValues(): Record<string, number | undefined>;
77
+ /** Output column `name` over the source bars (a view: copy it to keep it). */
78
+ column(name: string): Float64Array;
79
+ /** Bar times of the columns. */
80
+ times(): Float64Array;
81
+ /** The study as saved: its id, definition, inputs, source series ids, visibility and styles. `StudiesPlugin.toJSON` is a list of these. */
82
+ state(): {
83
+ visible: boolean;
84
+ styles: Record<string, PlotStyle>;
85
+ volume?: string;
86
+ id: string;
87
+ study: string;
88
+ inputs: Record<string, InputValue>;
89
+ source: string;
90
+ };
91
+ private get ohlc();
92
+ private checkSource;
93
+ /** Whether `d` is the store of one of this study's inputs. */
94
+ private watches;
95
+ private bars;
96
+ private barAt;
97
+ /** Recompute everything from the source's bars. */
98
+ private recompute;
99
+ /** Bring an adopted engine up to the source's current last bars (ticks that arrived during the job). */
100
+ private catchUp;
101
+ private fullLoad;
102
+ private title;
103
+ private retitle;
104
+ private color;
105
+ private seriesOptions;
106
+ private createSeries;
107
+ private syncAll;
108
+ private writeSeries;
109
+ /** Show enough decimals for values below 1 (three significant digits); only ever grows. A def's own `minMove` wins; an overlay reads like its source. */
110
+ private widen;
111
+ /** The output series that draws `column`, or undefined when no plot does (a column that is only an input to others). */
112
+ seriesOfColumn(column: string): AnySeries | undefined;
113
+ /** After one appended or revised bar: one point per output series. */
114
+ private tickSync;
115
+ private drawMarkers;
116
+ }
117
+ export declare class StudiesPlugin implements ChartPlugin {
118
+ readonly chart: Chart;
119
+ readonly runner: StudyRunner | undefined;
120
+ private readonly resolve;
121
+ readonly id = "alphacharts.studies";
122
+ api: PluginApi | null;
123
+ private readonly studies;
124
+ private counter;
125
+ constructor(chart: Chart, runner: StudyRunner | undefined, resolve: (id: string) => StudyDef);
126
+ install(api: PluginApi): void;
127
+ uninstall(): void;
128
+ dataChanged(c: DataChange): void;
129
+ drawPane(ctx: CanvasRenderingContext2D, view: PluginPaneView): void;
130
+ list(): Study[];
131
+ get(id: string): Study | undefined;
132
+ /** Lowest pane index >= 1 holding no series (reuses a gap), else a new pane. */
133
+ freePane(): number;
134
+ add(def: StudyDef, inputs: Readonly<Record<string, InputValue>>, source: SourceSeries, o?: AddStudyOptions, saved?: {
135
+ visible?: boolean;
136
+ styles?: Record<string, PlotStyle>;
137
+ }): Study;
138
+ removeStudy(id: string): void;
139
+ /** Drop studies whose source series was removed from the chart. */
140
+ private reap;
141
+ /** Never hand out an id at or below `n` again: ids of removed studies stay retired, so an alert that still names one cannot land on a different study. */
142
+ reserveIds(n: number): void;
143
+ /** The highest `s<n>` number handed out or restored so far. */
144
+ idHighWater(): number;
145
+ private nextId;
146
+ toJSON(): unknown;
147
+ /** Throws what `fromJSON(state)` would, changing nothing: the layout is refused whole when a study cannot be rebuilt. */
148
+ validateState(state: unknown, ctx: {
149
+ seriesIds: readonly string[];
150
+ }): void;
151
+ /** Called after the chart restored its series: rebuild each study over the restored series. */
152
+ fromJSON(state: unknown): void;
153
+ }
154
+ /** Install the studies plugin on a chart (idempotent). Restoring a layout that holds studies needs this first. */
155
+ export declare function installStudies(chart: Chart, opts?: {
156
+ runner?: StudyRunner;
157
+ resolve?: (id: string) => StudyDef;
158
+ }): StudiesPlugin;
159
+ /**
160
+ * Add a study over `source`. `study` is a definition (tree-shakable) or the id of
161
+ * a registered one. Throws on unknown inputs, out-of-range values or a source
162
+ * that lacks what the study needs.
163
+ */
164
+ export declare function addStudy(chart: Chart, source: SourceSeries, study: StudyDef | string, inputs?: Readonly<Record<string, InputValue>>, opts?: AddStudyOptions): Study;
165
+ export {};
@@ -0,0 +1,46 @@
1
+ import type { InputDef, LineStyleName, MarkerShape, PlotDef, StudyDef } from "./types.js";
2
+ export declare const int: (key: string, def: number, min?: number, max?: number, label?: string) => InputDef;
3
+ export declare const float: (key: string, def: number, min?: number, max?: number, step?: number, label?: string) => InputDef;
4
+ export declare const bool: (key: string, def: boolean, label?: string) => InputDef;
5
+ export declare const select: (key: string, def: string, options: readonly string[], label?: string) => InputDef;
6
+ export declare const source: (def?: string, key?: string) => InputDef;
7
+ export declare const COLORS: {
8
+ readonly blue: "#2962FF";
9
+ readonly orange: "#FF6D00";
10
+ readonly red: "#F23645";
11
+ readonly green: "#089981";
12
+ readonly purple: "#9C27B0";
13
+ readonly teal: "#00897B";
14
+ readonly yellow: "#FBC02D";
15
+ readonly pink: "#E91E63";
16
+ readonly gray: "#787B86";
17
+ readonly lime: "#8BC34A";
18
+ readonly cyan: "#00BCD4";
19
+ readonly brown: "#795548";
20
+ };
21
+ export declare const line: (col: string, color: string, o?: {
22
+ title?: string;
23
+ key?: string;
24
+ width?: number;
25
+ style?: LineStyleName;
26
+ offset?: number;
27
+ connect?: boolean;
28
+ }) => PlotDef;
29
+ export declare const hist: (col: string, color: string, colorDown?: string, o?: {
30
+ title?: string;
31
+ key?: string;
32
+ }) => PlotDef;
33
+ export declare const areaPlot: (col: string, color: string, o?: {
34
+ title?: string;
35
+ key?: string;
36
+ }) => PlotDef;
37
+ export declare const band: (key: string, upper: string, lower: string, color: string, fill: string, title?: string) => PlotDef;
38
+ export declare const fillBetween: (key: string, a: string, b: string, color: string, title?: string) => PlotDef;
39
+ export declare const hline: (key: string, value: number | ((p: import("./types.js").Params) => number), color?: string, style?: LineStyleName) => PlotDef;
40
+ export declare const markers: (col: string, shape: MarkerShape, position: "value" | "above" | "below" | "sign", color: string, o?: {
41
+ title?: string;
42
+ key?: string;
43
+ offset?: number;
44
+ text?: boolean;
45
+ }) => PlotDef;
46
+ export declare function defineStudy(def: StudyDef): StudyDef;
@@ -0,0 +1,101 @@
1
+ export type Ref = Col | number;
2
+ export declare class Col {
3
+ v: Float64Array;
4
+ constructor(cap: number);
5
+ }
6
+ export declare class Node extends Col {
7
+ /** Evaluate bars [from, to). */
8
+ run: (from: number, to: number) => void;
9
+ }
10
+ export type SourceName = "open" | "high" | "low" | "close" | "hl2" | "hlc3" | "ohlc4" | "hlcc4";
11
+ export declare const SOURCE_NAMES: readonly SourceName[];
12
+ export declare class Graph {
13
+ /** Bars currently loaded. */
14
+ n: number;
15
+ private cap;
16
+ /** Every column (inputs, aux, nodes) in creation order: the unit of transfer between threads. */
17
+ readonly cols: Col[];
18
+ private readonly nodes;
19
+ readonly time: Col;
20
+ readonly open: Col;
21
+ readonly high: Col;
22
+ readonly low: Col;
23
+ readonly close: Col;
24
+ readonly volume: Col;
25
+ private readonly sources;
26
+ constructor(cap?: number);
27
+ /** An auxiliary column (state a node keeps per bar). */
28
+ col(): Col;
29
+ /** Make room for `n` bars; existing values are kept. */
30
+ reserve(n: number): void;
31
+ /** Evaluate bars [from, to) on every node. `to` bars must already be loaded. */
32
+ run(from: number, to: number): void;
33
+ /** Forget all values (new data is loaded from bar 0). */
34
+ clear(): void;
35
+ /** Replace every column by transferred buffers (same builder, same order). */
36
+ adopt(buffers: readonly Float64Array[], n: number): void;
37
+ /** A node whose evaluation is `body`; the body reads other columns' `.v` when it runs. */
38
+ node(body: (self: Node, from: number, to: number) => void): Node;
39
+ /** Per-bar function of the index; it may read any column at <= i (own columns at <= i-1). */
40
+ calc(fn: (i: number) => number): Node;
41
+ /** A constant as a column-compatible value. */
42
+ private val;
43
+ src(name: SourceName): Node;
44
+ map(x: Col, f: (x: number) => number): Node;
45
+ map2(x: Ref, y: Ref, f: (x: number, y: number) => number): Node;
46
+ add(x: Ref, y: Ref): Node;
47
+ sub(x: Ref, y: Ref): Node;
48
+ mul(x: Ref, y: Ref): Node;
49
+ /** x / y; a zero divisor gives NaN (absent), never Infinity. */
50
+ div(x: Ref, y: Ref): Node;
51
+ max2(x: Ref, y: Ref): Node;
52
+ min2(x: Ref, y: Ref): Node;
53
+ abs(x: Col): Node;
54
+ neg(x: Col): Node;
55
+ lag(x: Col, k: number): Node;
56
+ change(x: Col, k?: number): Node;
57
+ /** Consecutive valid (non-NaN) values of x ending at each bar. */
58
+ validRun(x: Col): Col;
59
+ /** Sum over the last p bars (NaN until p valid bars). */
60
+ sum(x: Col, p: number): Node;
61
+ sma(x: Col, p: number): Node;
62
+ /**
63
+ * Recursive smoothing y = y' + alpha (x - y'), seeded with the simple mean of
64
+ * the first p valid values (TA-Lib's EMA/Wilder seeding; also Pine's).
65
+ */
66
+ smooth(x: Col, p: number, alpha: number): Node;
67
+ ema(x: Col, p: number): Node;
68
+ /** Wilder's smoothing (RMA / SMMA). */
69
+ rma(x: Col, p: number): Node;
70
+ /** Linearly weighted mean, newest bar weighted p. */
71
+ wma(x: Col, p: number): Node;
72
+ /** Highest value over the last p bars. */
73
+ highest(x: Col, p: number): Node;
74
+ lowest(x: Col, p: number): Node;
75
+ /** Bars since the highest/lowest value in the window (0 = this bar); ties pick the most recent. */
76
+ highestBars(x: Col, p: number, oldest?: boolean): Node;
77
+ lowestBars(x: Col, p: number, oldest?: boolean): Node;
78
+ /** `oldest`: ties pick the oldest bar (TA-Lib's MAXINDEX/MININDEX) instead of the newest (Aroon). */
79
+ private extreme;
80
+ /**
81
+ * Population variance over p bars (TA-Lib VAR): mean-centred two-pass over the
82
+ * window, because running sums of squares lose ~1e-8 relative on price series.
83
+ */
84
+ variance(x: Col, p: number): Node;
85
+ stdev(x: Col, p: number): Node;
86
+ /**
87
+ * Least-squares line over the last p bars against x = 0..p-1 (oldest..newest).
88
+ * `value` is the line at the newest bar; `slope` per bar; `intercept` at the oldest bar.
89
+ */
90
+ linreg(x: Col, p: number): {
91
+ value: Node;
92
+ slope: Node;
93
+ intercept: Node;
94
+ };
95
+ /** A node that mirrors an aux column (so it can be returned as an output). */
96
+ alias(c: Col): Node;
97
+ /** True range: max(h-l, |h-c'|, |l-c'|); the first bar has no previous close, so is absent (TA-Lib TRANGE). */
98
+ tr(): Node;
99
+ atr(p: number): Node;
100
+ }
101
+ export declare function checkPeriod(p: number): void;
@@ -0,0 +1,9 @@
1
+ import type { Kernels } from "@alphacharts/wasm";
2
+ export type BatchKernels = Pick<Kernels, "sumState" | "variance" | "highest" | "lowest" | "highestBars" | "lowestBars" | "linreg">;
3
+ /** Route eligible batch runs through `k`; null restores the JS loops. */
4
+ export declare function setKernels(k: BatchKernels | null): void;
5
+ export declare function kernels(): BatchKernels | null;
6
+ /** Below this many bars the call overhead beats the win. */
7
+ export declare const KERNEL_MIN_BARS = 4096;
8
+ /** A kernel run needs the whole series from bar 0 and no absent values. */
9
+ export declare function eligible(x: Float64Array, from: number, to: number): boolean;
@@ -0,0 +1,31 @@
1
+ import { Graph, type Col } from "./graph.js";
2
+ import type { BarColumns, BarInput, InputValue, Params, StudyDef } from "../types.js";
3
+ /** Validate `given` against the study's inputs and fill defaults. Throws on anything unknown or out of range. */
4
+ export declare function resolveParams(def: StudyDef, given?: Readonly<Record<string, InputValue>>): Params;
5
+ /** A study bound to parameters and a graph: appends, revises and batch-loads bars. */
6
+ export declare class StudyEngine {
7
+ readonly def: StudyDef;
8
+ readonly graph: Graph;
9
+ readonly outputs: readonly Col[];
10
+ readonly params: Params;
11
+ constructor(def: StudyDef, params?: Readonly<Record<string, InputValue>>);
12
+ get length(): number;
13
+ /** Replace all bars and compute. */
14
+ load(d: BarColumns): void;
15
+ /**
16
+ * Like `load`, but evaluates in chunks of `chunk` bars and awaits `pause()`
17
+ * between them, so a runner can service cancel messages. Stops quietly and
18
+ * returns false when `cancelled()` turns true.
19
+ */
20
+ loadChunked(d: BarColumns, chunk: number, pause: () => Promise<void>, cancelled: () => boolean): Promise<boolean>;
21
+ /** Append a bar (time later than the last). */
22
+ push(b: BarInput): void;
23
+ /** Replace the last bar (a tick revision). */
24
+ reviseLast(b: BarInput): void;
25
+ /** Output column `k` as a view over the bars loaded (valid until the next push that grows the graph). */
26
+ column(k: number): Float64Array;
27
+ private write;
28
+ private requireColumns;
29
+ }
30
+ /** One-shot: run a study over columns and return its output columns (copies, length n). */
31
+ export declare function runStudy(def: StudyDef, params: Readonly<Record<string, InputValue>>, d: BarColumns): Float64Array[];
@@ -0,0 +1,12 @@
1
+ export * from "./types.js";
2
+ export { Graph, Col, Node, SOURCE_NAMES } from "./engine/graph.js";
3
+ export type { Ref, SourceName } from "./engine/graph.js";
4
+ export { StudyEngine, resolveParams, runStudy } from "./engine/study.js";
5
+ export { registerStudy, registerStudies, getStudy, listStudies, validateDef } from "./registry.js";
6
+ export { defineStudy } from "./define.js";
7
+ export { addStudy, installStudies, StudiesPlugin, Study, PLUGIN_ID } from "./chart/studies.js";
8
+ export type { AddStudyOptions, PlotStyle } from "./chart/studies.js";
9
+ export { InlineRunner, WorkerRunner, createRunner, serveWorker, CancelledError, CHUNK } from "./runner.js";
10
+ export type { StudyRunner, RunRequest, RunResult, WorkerLike } from "./runner.js";
11
+ export { enableWasm, disableWasm } from "./wasm.js";
12
+ export { setKernels } from "./engine/kernels.js";
@@ -0,0 +1,7 @@
1
+ import type { StudyDef } from "./types.js";
2
+ export declare function registerStudy(def: StudyDef): void;
3
+ export declare function registerStudies(defs: readonly StudyDef[]): void;
4
+ export declare function getStudy(id: string): StudyDef;
5
+ export declare function listStudies(): StudyDef[];
6
+ /** Catch an inconsistent definition when it is registered, not when it is drawn. */
7
+ export declare function validateDef(def: StudyDef): void;
@@ -0,0 +1,82 @@
1
+ import type { BarColumns, InputValue, StudyDef } from "./types.js";
2
+ export declare const CHUNK: number;
3
+ export interface RunRequest {
4
+ studyId: string;
5
+ params: Readonly<Record<string, InputValue>>;
6
+ /** Transferred to the runner when it is a worker: do not use afterwards. */
7
+ bars: BarColumns;
8
+ }
9
+ export interface RunResult {
10
+ n: number;
11
+ /** All graph columns (inputs, state, outputs), in registration order. */
12
+ buffers: Float64Array[];
13
+ }
14
+ export declare class CancelledError extends Error {
15
+ constructor();
16
+ }
17
+ export interface StudyRunner {
18
+ /** Whether this runner can evaluate `def` (a worker only knows built-ins). */
19
+ canRun(def: StudyDef): boolean;
20
+ /** Rejects with CancelledError when `cancel(handle)` is called first. */
21
+ run(def: StudyDef, req: RunRequest): {
22
+ promise: Promise<RunResult>;
23
+ cancel(): void;
24
+ };
25
+ dispose(): void;
26
+ }
27
+ /** Main-thread fallback: same chunked evaluation, same cancellation. */
28
+ export declare class InlineRunner implements StudyRunner {
29
+ canRun(): boolean;
30
+ run(def: StudyDef, req: RunRequest): {
31
+ promise: Promise<RunResult>;
32
+ cancel: () => undefined;
33
+ };
34
+ dispose(): void;
35
+ }
36
+ export interface WorkerLike {
37
+ postMessage(msg: unknown, transfer?: Transferable[]): void;
38
+ addEventListener(type: "message", fn: (e: {
39
+ data: unknown;
40
+ }) => void): void;
41
+ addEventListener(type: "error", fn: (e: {
42
+ message?: string;
43
+ }) => void): void;
44
+ terminate(): void;
45
+ }
46
+ type WorkerReply = {
47
+ type: "result";
48
+ id: number;
49
+ n: number;
50
+ buffers: Float64Array[];
51
+ } | {
52
+ type: "cancelled";
53
+ id: number;
54
+ } | {
55
+ type: "error";
56
+ id: number;
57
+ message: string;
58
+ };
59
+ /** Runs built-in studies in a Web Worker. `isBuiltin` says which ids the worker knows. */
60
+ export declare class WorkerRunner implements StudyRunner {
61
+ private readonly worker;
62
+ private readonly isBuiltin;
63
+ private nextId;
64
+ /** Set once the worker has failed: later runs reject at once instead of waiting on a dead worker. */
65
+ private dead;
66
+ private readonly pending;
67
+ constructor(worker: WorkerLike, isBuiltin: (def: StudyDef) => boolean);
68
+ canRun(def: StudyDef): boolean;
69
+ run(def: StudyDef, req: RunRequest): {
70
+ promise: Promise<RunResult>;
71
+ cancel: () => void;
72
+ };
73
+ dispose(): void;
74
+ }
75
+ /** Worker-side message handler: wire it to `self.onmessage` (see worker.ts). */
76
+ export declare function serveWorker(post: (msg: WorkerReply, transfer?: Transferable[]) => void, find: (id: string) => StudyDef | undefined): (data: unknown) => void;
77
+ /**
78
+ * A worker runner when Workers exist and start, otherwise the inline fallback.
79
+ * `factory` creates the worker (default: dist/worker.js next to this module).
80
+ */
81
+ export declare function createRunner(builtinIds: ReadonlySet<string>, factory?: () => WorkerLike): StudyRunner;
82
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { StudyDef } from "../types.js";
2
+ export declare const ALL_STUDIES: readonly StudyDef[];
@@ -0,0 +1,7 @@
1
+ export declare const htDcPeriod: import("../types.js").StudyDef;
2
+ export declare const htDcPhase: import("../types.js").StudyDef;
3
+ export declare const htPhasor: import("../types.js").StudyDef;
4
+ export declare const htSine: import("../types.js").StudyDef;
5
+ export declare const htTrendline: import("../types.js").StudyDef;
6
+ export declare const htTrendMode: import("../types.js").StudyDef;
7
+ export declare const mama: import("../types.js").StudyDef;
@@ -0,0 +1,13 @@
1
+ export * from "./overlap.js";
2
+ export * from "./momentum.js";
3
+ export * from "./volume.js";
4
+ export * from "./volatility.js";
5
+ export * from "./price.js";
6
+ export * from "./statistic.js";
7
+ export * from "./math.js";
8
+ export * from "./cycle.js";
9
+ export * from "./sar.js";
10
+ export * from "./patterns.js";
11
+ export * from "./tv-trend.js";
12
+ export * from "./tv-osc.js";
13
+ export * from "./tv-volume.js";
@@ -0,0 +1,26 @@
1
+ import type { Col, Graph, Node } from "../engine/graph.js";
2
+ export declare const MA_TYPES: readonly ["sma", "ema", "wma", "rma", "dema", "tema", "trima", "kama", "t3"];
3
+ export type MaType = (typeof MA_TYPES)[number];
4
+ /** Kaufman's adaptive MA: efficiency ratio over p bars, fast/slow smoothing limits. TA-Lib seeds with the bar before the first output. */
5
+ export declare function kama(g: Graph, x: Col, p: number, fast?: number, slow?: number): Node;
6
+ /** Tillson T3: six EMAs, volume factor `a`. */
7
+ export declare function t3(g: Graph, x: Col, p: number, a?: number): Node;
8
+ export declare function dema(g: Graph, x: Col, p: number): Node;
9
+ export declare function tema(g: Graph, x: Col, p: number): Node;
10
+ /** Triangular MA: an SMA of an SMA with the periods TA-Lib splits p into. */
11
+ export declare function trima(g: Graph, x: Col, p: number): Node;
12
+ /**
13
+ * EMA that starts at the first bar `gate` is valid, seeded with the simple
14
+ * mean of the p values ending there (TA-Lib seeds MACD's fast EMA at the slow
15
+ * EMA's first bar this way).
16
+ */
17
+ export declare function emaGated(g: Graph, x: Col, p: number, alpha: number, gate: Col): Node;
18
+ /** EMA seeded with the first value instead of a mean (TA-Lib ADOSC). */
19
+ export declare function emaFirst(g: Graph, x: Col, alpha: number): Node;
20
+ /** One moving average of the given type. */
21
+ export declare function ma(g: Graph, type: MaType, x: Col, p: number): Node;
22
+ /**
23
+ * `ma`, except that an EMA starts where `gate` first has a value (TA-Lib's APO,
24
+ * PPO and MACD compute the fast average from the slow average's first bar).
25
+ */
26
+ export declare function maGated(g: Graph, type: MaType, x: Col, p: number, gate: Col): Node;
@@ -0,0 +1,28 @@
1
+ import type { Col } from "../engine/graph.js";
2
+ export declare const acos: import("../types.js").StudyDef;
3
+ export declare const asin: import("../types.js").StudyDef;
4
+ export declare const atan: import("../types.js").StudyDef;
5
+ export declare const ceil: import("../types.js").StudyDef;
6
+ export declare const cos: import("../types.js").StudyDef;
7
+ export declare const cosh: import("../types.js").StudyDef;
8
+ export declare const exp: import("../types.js").StudyDef;
9
+ export declare const floor: import("../types.js").StudyDef;
10
+ export declare const ln: import("../types.js").StudyDef;
11
+ export declare const log10: import("../types.js").StudyDef;
12
+ export declare const sin: import("../types.js").StudyDef;
13
+ export declare const sinh: import("../types.js").StudyDef;
14
+ export declare const sqrt: import("../types.js").StudyDef;
15
+ export declare const tan: import("../types.js").StudyDef;
16
+ export declare const tanh: import("../types.js").StudyDef;
17
+ export declare const add: import("../types.js").StudyDef;
18
+ export declare const sub: import("../types.js").StudyDef;
19
+ export declare const mult: import("../types.js").StudyDef;
20
+ export declare const div: import("../types.js").StudyDef;
21
+ export declare const max: import("../types.js").StudyDef;
22
+ export declare const min: import("../types.js").StudyDef;
23
+ export declare const sum: import("../types.js").StudyDef;
24
+ export declare const maxindex: import("../types.js").StudyDef;
25
+ export declare const minindex: import("../types.js").StudyDef;
26
+ export declare const minmax: import("../types.js").StudyDef;
27
+ export declare const minmaxindex: import("../types.js").StudyDef;
28
+ export type { Col };
@@ -0,0 +1,30 @@
1
+ export declare const rsi: import("../types.js").StudyDef;
2
+ export declare const cmo: import("../types.js").StudyDef;
3
+ export declare const mom: import("../types.js").StudyDef;
4
+ export declare const roc: import("../types.js").StudyDef;
5
+ export declare const rocp: import("../types.js").StudyDef;
6
+ export declare const rocr: import("../types.js").StudyDef;
7
+ export declare const rocr100: import("../types.js").StudyDef;
8
+ export declare const trix: import("../types.js").StudyDef;
9
+ export declare const apo: import("../types.js").StudyDef;
10
+ export declare const ppo: import("../types.js").StudyDef;
11
+ export declare const macd: import("../types.js").StudyDef;
12
+ export declare const macdfix: import("../types.js").StudyDef;
13
+ export declare const macdext: import("../types.js").StudyDef;
14
+ export declare const stoch: import("../types.js").StudyDef;
15
+ export declare const stochf: import("../types.js").StudyDef;
16
+ export declare const stochrsi: import("../types.js").StudyDef;
17
+ export declare const willr: import("../types.js").StudyDef;
18
+ export declare const cci: import("../types.js").StudyDef;
19
+ export declare const bop: import("../types.js").StudyDef;
20
+ export declare const mfi: import("../types.js").StudyDef;
21
+ export declare const ultosc: import("../types.js").StudyDef;
22
+ export declare const aroon: import("../types.js").StudyDef;
23
+ export declare const aroonosc: import("../types.js").StudyDef;
24
+ export declare const adx: import("../types.js").StudyDef;
25
+ export declare const adxr: import("../types.js").StudyDef;
26
+ export declare const dx: import("../types.js").StudyDef;
27
+ export declare const plusDi: import("../types.js").StudyDef;
28
+ export declare const minusDi: import("../types.js").StudyDef;
29
+ export declare const plusDm: import("../types.js").StudyDef;
30
+ export declare const minusDm: import("../types.js").StudyDef;
@@ -0,0 +1,14 @@
1
+ export declare const sma: import("../types.js").StudyDef;
2
+ export declare const ema: import("../types.js").StudyDef;
3
+ export declare const wma: import("../types.js").StudyDef;
4
+ export declare const dema: import("../types.js").StudyDef;
5
+ export declare const tema: import("../types.js").StudyDef;
6
+ export declare const trima: import("../types.js").StudyDef;
7
+ export declare const kama: import("../types.js").StudyDef;
8
+ export declare const t3: import("../types.js").StudyDef;
9
+ export declare const ma: import("../types.js").StudyDef;
10
+ export declare const bbands: import("../types.js").StudyDef;
11
+ export declare const bbpb: import("../types.js").StudyDef;
12
+ export declare const bbw: import("../types.js").StudyDef;
13
+ export declare const midpoint: import("../types.js").StudyDef;
14
+ export declare const midprice: import("../types.js").StudyDef;
@@ -0,0 +1,62 @@
1
+ import type { StudyDef } from "../types.js";
2
+ export declare const cdl2Crows: StudyDef;
3
+ export declare const cdl3BlackCrows: StudyDef;
4
+ export declare const cdl3Inside: StudyDef;
5
+ export declare const cdl3LineStrike: StudyDef;
6
+ export declare const cdl3Outside: StudyDef;
7
+ export declare const cdl3StarsInSouth: StudyDef;
8
+ export declare const cdl3WhiteSoldiers: StudyDef;
9
+ export declare const cdlAbandonedBaby: StudyDef;
10
+ export declare const cdlAdvanceBlock: StudyDef;
11
+ export declare const cdlBeltHold: StudyDef;
12
+ export declare const cdlBreakaway: StudyDef;
13
+ export declare const cdlClosingMarubozu: StudyDef;
14
+ export declare const cdlConcealBabySwall: StudyDef;
15
+ export declare const cdlCounterAttack: StudyDef;
16
+ export declare const cdlDarkCloudCover: StudyDef;
17
+ export declare const cdlDoji: StudyDef;
18
+ export declare const cdlDojiStar: StudyDef;
19
+ export declare const cdlDragonflyDoji: StudyDef;
20
+ export declare const cdlEngulfing: StudyDef;
21
+ export declare const cdlEveningDojiStar: StudyDef;
22
+ export declare const cdlEveningStar: StudyDef;
23
+ export declare const cdlGapSideSideWhite: StudyDef;
24
+ export declare const cdlGravestoneDoji: StudyDef;
25
+ export declare const cdlHammer: StudyDef;
26
+ export declare const cdlHangingMan: StudyDef;
27
+ export declare const cdlHarami: StudyDef;
28
+ export declare const cdlHaramiCross: StudyDef;
29
+ export declare const cdlHighWave: StudyDef;
30
+ export declare const cdlHikkake: StudyDef;
31
+ export declare const cdlHikkakeMod: StudyDef;
32
+ export declare const cdlHomingPigeon: StudyDef;
33
+ export declare const cdlIdentical3Crows: StudyDef;
34
+ export declare const cdlInNeck: StudyDef;
35
+ export declare const cdlInvertedHammer: StudyDef;
36
+ export declare const cdlKicking: StudyDef;
37
+ export declare const cdlKickingByLength: StudyDef;
38
+ export declare const cdlLadderBottom: StudyDef;
39
+ export declare const cdlLongLeggedDoji: StudyDef;
40
+ export declare const cdlLongLine: StudyDef;
41
+ export declare const cdlMarubozu: StudyDef;
42
+ export declare const cdlMatchingLow: StudyDef;
43
+ export declare const cdlMatHold: StudyDef;
44
+ export declare const cdlMorningDojiStar: StudyDef;
45
+ export declare const cdlMorningStar: StudyDef;
46
+ export declare const cdlOnNeck: StudyDef;
47
+ export declare const cdlPiercing: StudyDef;
48
+ export declare const cdlRickshawMan: StudyDef;
49
+ export declare const cdlRiseFall3Methods: StudyDef;
50
+ export declare const cdlSeparatingLines: StudyDef;
51
+ export declare const cdlShootingStar: StudyDef;
52
+ export declare const cdlShortLine: StudyDef;
53
+ export declare const cdlSpinningTop: StudyDef;
54
+ export declare const cdlStalledPattern: StudyDef;
55
+ export declare const cdlStickSandwich: StudyDef;
56
+ export declare const cdlTakuri: StudyDef;
57
+ export declare const cdlTasukiGap: StudyDef;
58
+ export declare const cdlThrusting: StudyDef;
59
+ export declare const cdlTriStar: StudyDef;
60
+ export declare const cdlUnique3River: StudyDef;
61
+ export declare const cdlUpsideGap2Crows: StudyDef;
62
+ export declare const cdlXSideGap3Methods: StudyDef;