@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.
- package/LICENSE +21 -0
- package/README.md +125 -2
- package/dist/Column.d.ts +21 -0
- package/dist/Column.d.ts.map +1 -0
- package/dist/Ring.d.ts +28 -0
- package/dist/Ring.d.ts.map +1 -0
- package/dist/ScriptRun.d.ts +85 -0
- package/dist/ScriptRun.d.ts.map +1 -0
- package/dist/defineScript.d.ts +216 -0
- package/dist/defineScript.d.ts.map +1 -0
- package/dist/drawings.d.ts +46 -0
- package/dist/drawings.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1726 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +30 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/outputs.d.ts +129 -0
- package/dist/outputs.d.ts.map +1 -0
- package/dist/points.d.ts +13 -0
- package/dist/points.d.ts.map +1 -0
- package/dist/scope.d.ts +33 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scriptIndicator.d.ts +25 -0
- package/dist/scriptIndicator.d.ts.map +1 -0
- package/dist/security.d.ts +52 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/state.d.ts +52 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/ta/averages.d.ts +19 -0
- package/dist/ta/averages.d.ts.map +1 -0
- package/dist/ta/common.d.ts +24 -0
- package/dist/ta/common.d.ts.map +1 -0
- package/dist/ta/events.d.ts +16 -0
- package/dist/ta/events.d.ts.map +1 -0
- package/dist/ta/index.d.ts +65 -0
- package/dist/ta/index.d.ts.map +1 -0
- package/dist/ta/moves.d.ts +26 -0
- package/dist/ta/moves.d.ts.map +1 -0
- package/dist/ta/oscillators.d.ts +29 -0
- package/dist/ta/oscillators.d.ts.map +1 -0
- package/dist/ta/ranges.d.ts +18 -0
- package/dist/ta/ranges.d.ts.map +1 -0
- package/dist/ta/statistics.d.ts +26 -0
- package/dist/ta/statistics.d.ts.map +1 -0
- package/dist/worker/messages.d.ts +49 -0
- package/dist/worker/messages.d.ts.map +1 -0
- package/dist/worker/scriptWorkerIndicator.d.ts +40 -0
- package/dist/worker/scriptWorkerIndicator.d.ts.map +1 -0
- package/dist/worker/serveScripts.d.ts +28 -0
- package/dist/worker/serveScripts.d.ts.map +1 -0
- package/package.json +39 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1726 @@
|
|
|
1
|
+
import { fadeBy as e, timeframeToMs as t } from "@tradecanvas/commons";
|
|
2
|
+
import { IndicatorBase as n, IndicatorValueMap as r, periodKeyer as i } from "@tradecanvas/core";
|
|
3
|
+
//#region src/defineScript.ts
|
|
4
|
+
function a(e) {
|
|
5
|
+
if (typeof e.id != "string" || e.id.trim() === "") throw Error("defineScript: a script needs an id");
|
|
6
|
+
if (typeof e.setup != "function") throw Error(`defineScript('${e.id}'): a script needs a setup function`);
|
|
7
|
+
return Object.freeze({
|
|
8
|
+
...e,
|
|
9
|
+
kind: "script"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function o(e, t) {
|
|
13
|
+
let n = t.default;
|
|
14
|
+
if (typeof n == "number") {
|
|
15
|
+
let r = typeof e == "string" && e.trim() !== "" ? Number(e) : e;
|
|
16
|
+
if (typeof r != "number" || !Number.isFinite(r)) return n;
|
|
17
|
+
let i = t.kind === "int" ? Math.floor(r) : r;
|
|
18
|
+
return Math.min(t.max ?? Infinity, Math.max(t.min ?? -Infinity, i));
|
|
19
|
+
}
|
|
20
|
+
return typeof e != typeof n || t.options && !t.options.some((t) => (typeof t == "object" ? t.value : t) === e) ? n : e;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/Column.ts
|
|
24
|
+
var s = 256, c = class {
|
|
25
|
+
data;
|
|
26
|
+
filled = 0;
|
|
27
|
+
constructor(e, t) {
|
|
28
|
+
this.make = e, this.empty = t, this.data = e(s), this.data.fill(t);
|
|
29
|
+
}
|
|
30
|
+
set(e, t) {
|
|
31
|
+
this.reach(e + 1), this.data[e] = t;
|
|
32
|
+
}
|
|
33
|
+
get(e) {
|
|
34
|
+
return e >= 0 && e < this.filled ? this.data[e] : this.empty;
|
|
35
|
+
}
|
|
36
|
+
reach(e) {
|
|
37
|
+
if (e > this.data.length) {
|
|
38
|
+
let t = this.data.length;
|
|
39
|
+
for (; t < e;) t *= 2;
|
|
40
|
+
let n = this.make(t);
|
|
41
|
+
n.fill(this.empty), n.set(this.data), this.data = n;
|
|
42
|
+
}
|
|
43
|
+
e > this.filled && (this.filled = e);
|
|
44
|
+
}
|
|
45
|
+
view(e) {
|
|
46
|
+
return this.reach(e), this.data.subarray(0, e);
|
|
47
|
+
}
|
|
48
|
+
}, l = () => new c((e) => new Float64Array(e), NaN), u = () => new c((e) => new Uint16Array(e), 0), d = () => new c((e) => new Uint8Array(e), 0), f = 65535, p = class {
|
|
49
|
+
plots = [];
|
|
50
|
+
handles = /* @__PURE__ */ new Map();
|
|
51
|
+
shapes = [];
|
|
52
|
+
fills = [];
|
|
53
|
+
backgrounds = [];
|
|
54
|
+
conditions = [];
|
|
55
|
+
barColorSlots = [];
|
|
56
|
+
levels = [];
|
|
57
|
+
drawingLists = [];
|
|
58
|
+
palette = [];
|
|
59
|
+
paletteIndex = /* @__PURE__ */ new Map();
|
|
60
|
+
open = !0;
|
|
61
|
+
constructor(e) {
|
|
62
|
+
this.scope = e, e.clearers.push((e) => {
|
|
63
|
+
for (let t of this.plots) t.values.set(e, NaN), t.colors.set(e, 0);
|
|
64
|
+
for (let t of this.shapes) t.on.set(e, 0);
|
|
65
|
+
for (let t of this.fills) t.colors.set(e, 0);
|
|
66
|
+
for (let t of this.backgrounds) t.colors.set(e, 0);
|
|
67
|
+
for (let t of this.conditions) t.on.set(e, 0);
|
|
68
|
+
for (let t of this.barColorSlots) t.set(e, 0);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
close() {
|
|
72
|
+
this.open = !1;
|
|
73
|
+
}
|
|
74
|
+
declaring(e) {
|
|
75
|
+
if (!this.open) throw Error(`${e} is declared in the script's setup, not on a bar`);
|
|
76
|
+
}
|
|
77
|
+
colorIndex(e) {
|
|
78
|
+
let t = this.paletteIndex.get(e);
|
|
79
|
+
if (t === void 0) {
|
|
80
|
+
if (this.palette.length >= f) throw Error(`a script gives its bars at most ${f} colours`);
|
|
81
|
+
this.palette.push(e), t = this.palette.length, this.paletteIndex.set(e, t);
|
|
82
|
+
}
|
|
83
|
+
return t;
|
|
84
|
+
}
|
|
85
|
+
plot(e, t = {}) {
|
|
86
|
+
this.declaring("plot");
|
|
87
|
+
let n = {
|
|
88
|
+
declaration: {
|
|
89
|
+
title: e,
|
|
90
|
+
kind: t.kind ?? "line",
|
|
91
|
+
...t.color ? { color: t.color } : {},
|
|
92
|
+
...t.width ? { width: t.width } : {}
|
|
93
|
+
},
|
|
94
|
+
values: l(),
|
|
95
|
+
colors: u()
|
|
96
|
+
};
|
|
97
|
+
this.plots.push(n);
|
|
98
|
+
let r = { set: (e, t) => (n.values.set(this.scope.bar, Number.isFinite(e) ? e : NaN), t !== void 0 && n.colors.set(this.scope.bar, this.colorIndex(t)), e) };
|
|
99
|
+
return this.handles.set(r, this.plots.length - 1), r;
|
|
100
|
+
}
|
|
101
|
+
shape(e, t = {}) {
|
|
102
|
+
this.declaring("shape");
|
|
103
|
+
let n = {
|
|
104
|
+
declaration: {
|
|
105
|
+
title: e,
|
|
106
|
+
shape: t.shape ?? "triangleUp",
|
|
107
|
+
position: t.position ?? "belowBar",
|
|
108
|
+
...t.color ? { color: t.color } : {}
|
|
109
|
+
},
|
|
110
|
+
on: d()
|
|
111
|
+
};
|
|
112
|
+
return this.shapes.push(n), { set: (e) => (n.on.set(this.scope.bar, +!!e), e) };
|
|
113
|
+
}
|
|
114
|
+
fill(e, t, n = {}) {
|
|
115
|
+
this.declaring("fill");
|
|
116
|
+
let r = this.handles.get(e), i = this.handles.get(t);
|
|
117
|
+
if (r === void 0 || i === void 0) throw Error("fill is between two plots of the same script");
|
|
118
|
+
let a = {
|
|
119
|
+
declaration: {
|
|
120
|
+
between: [r, i],
|
|
121
|
+
...n.color ? { color: n.color } : {}
|
|
122
|
+
},
|
|
123
|
+
colors: u()
|
|
124
|
+
};
|
|
125
|
+
return this.fills.push(a), { set: (e) => {
|
|
126
|
+
a.colors.set(this.scope.bar, e === void 0 ? 0 : this.colorIndex(e));
|
|
127
|
+
} };
|
|
128
|
+
}
|
|
129
|
+
bgcolor(e = {}) {
|
|
130
|
+
this.declaring("bgcolor");
|
|
131
|
+
let t = {
|
|
132
|
+
declaration: { title: e.title ?? "Background" },
|
|
133
|
+
colors: u()
|
|
134
|
+
};
|
|
135
|
+
return this.backgrounds.push(t), { set: (e) => {
|
|
136
|
+
t.colors.set(this.scope.bar, e === void 0 ? 0 : this.colorIndex(e));
|
|
137
|
+
} };
|
|
138
|
+
}
|
|
139
|
+
addDrawings(e) {
|
|
140
|
+
return this.drawingLists.push(e), e;
|
|
141
|
+
}
|
|
142
|
+
barcolor() {
|
|
143
|
+
this.declaring("barcolor");
|
|
144
|
+
let e = u();
|
|
145
|
+
return this.barColorSlots.push(e), { set: (t) => {
|
|
146
|
+
e.set(this.scope.bar, t === void 0 ? 0 : this.colorIndex(t));
|
|
147
|
+
} };
|
|
148
|
+
}
|
|
149
|
+
alertCondition(e, t = {}) {
|
|
150
|
+
this.declaring("alertCondition");
|
|
151
|
+
let n = {
|
|
152
|
+
declaration: {
|
|
153
|
+
title: e,
|
|
154
|
+
...t.message ? { message: t.message } : {}
|
|
155
|
+
},
|
|
156
|
+
on: d()
|
|
157
|
+
};
|
|
158
|
+
return this.conditions.push(n), { set: (e) => (n.on.set(this.scope.bar, +!!e), e) };
|
|
159
|
+
}
|
|
160
|
+
hline(e, t = {}) {
|
|
161
|
+
this.declaring("hline"), this.levels.push({
|
|
162
|
+
price: e,
|
|
163
|
+
...t
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
declarations(e) {
|
|
167
|
+
return {
|
|
168
|
+
overlay: e,
|
|
169
|
+
plots: this.plots.map((e) => e.declaration),
|
|
170
|
+
shapes: this.shapes.map((e) => e.declaration),
|
|
171
|
+
levels: [...this.levels],
|
|
172
|
+
fills: this.fills.map((e) => e.declaration),
|
|
173
|
+
backgrounds: this.backgrounds.map((e) => e.declaration),
|
|
174
|
+
barColors: this.barColorSlots.length,
|
|
175
|
+
alertConditions: this.conditions.map((e) => e.declaration)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
output(e, t) {
|
|
179
|
+
return {
|
|
180
|
+
length: e,
|
|
181
|
+
plots: this.plots.map((t) => ({
|
|
182
|
+
...t.declaration,
|
|
183
|
+
values: t.values.view(e),
|
|
184
|
+
colors: t.colors.view(e)
|
|
185
|
+
})),
|
|
186
|
+
shapes: this.shapes.map((t) => ({
|
|
187
|
+
...t.declaration,
|
|
188
|
+
on: t.on.view(e)
|
|
189
|
+
})),
|
|
190
|
+
levels: [...this.levels],
|
|
191
|
+
fills: this.fills.map((t) => ({
|
|
192
|
+
...t.declaration,
|
|
193
|
+
colors: t.colors.view(e)
|
|
194
|
+
})),
|
|
195
|
+
backgrounds: this.backgrounds.map((t) => ({
|
|
196
|
+
...t.declaration,
|
|
197
|
+
colors: t.colors.view(e)
|
|
198
|
+
})),
|
|
199
|
+
barColors: this.barColorSlots.map((t) => t.view(e)),
|
|
200
|
+
alertConditions: this.conditions.map((t) => ({
|
|
201
|
+
...t.declaration,
|
|
202
|
+
on: t.on.view(e)
|
|
203
|
+
})),
|
|
204
|
+
palette: [...this.palette],
|
|
205
|
+
drawings: this.drawingLists.flatMap((e) => e.list()),
|
|
206
|
+
errors: [...t]
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}, m = null;
|
|
210
|
+
function h(e, t) {
|
|
211
|
+
let n = m;
|
|
212
|
+
m = e;
|
|
213
|
+
try {
|
|
214
|
+
return t();
|
|
215
|
+
} finally {
|
|
216
|
+
m = n;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function g(e = "ta and state") {
|
|
220
|
+
if (!m) throw Error(`${e} are made in a script's setup, not on a bar: each keeps the state of one script`);
|
|
221
|
+
return m;
|
|
222
|
+
}
|
|
223
|
+
function _(e) {
|
|
224
|
+
let t = { ...e }, n = { ...e };
|
|
225
|
+
return g().units.push({
|
|
226
|
+
commit: () => Object.assign(n, t),
|
|
227
|
+
rollback: () => Object.assign(t, n)
|
|
228
|
+
}), t;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/limits.ts
|
|
232
|
+
var v = {
|
|
233
|
+
loopSteps: 1e6,
|
|
234
|
+
arraySize: 1e5,
|
|
235
|
+
runMs: Infinity
|
|
236
|
+
}, y = class extends Error {
|
|
237
|
+
constructor(e, t) {
|
|
238
|
+
super(t), this.limit = e, this.name = "ScriptLimitError";
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
function b(e = {}) {
|
|
242
|
+
let t = Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0)), n = {
|
|
243
|
+
...v,
|
|
244
|
+
...t
|
|
245
|
+
};
|
|
246
|
+
for (let e of Object.keys(v)) {
|
|
247
|
+
let t = n[e];
|
|
248
|
+
if (typeof t != "number" || Number.isNaN(t) || t <= 0) throw RangeError(`script limits: ${e} must be a positive number, not ${String(t)}`);
|
|
249
|
+
}
|
|
250
|
+
return n;
|
|
251
|
+
}
|
|
252
|
+
function x(e, t, n) {
|
|
253
|
+
let r = new y(t, n);
|
|
254
|
+
throw e.breach ??= r, r;
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/state.ts
|
|
258
|
+
function ee(e) {
|
|
259
|
+
let t = g("state.var"), n = { value: e }, r = e;
|
|
260
|
+
return t.units.push({
|
|
261
|
+
commit: () => {
|
|
262
|
+
r = n.value;
|
|
263
|
+
},
|
|
264
|
+
rollback: () => {
|
|
265
|
+
n.value = r;
|
|
266
|
+
}
|
|
267
|
+
}), n;
|
|
268
|
+
}
|
|
269
|
+
function te() {
|
|
270
|
+
let e = g("state.series"), t = l();
|
|
271
|
+
return e.clearers.push((e) => t.set(e, NaN)), {
|
|
272
|
+
set: (n) => (t.set(e.bar, n), n),
|
|
273
|
+
at: (n = 0) => n >= 0 ? t.get(e.bar - Math.floor(n)) : NaN
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
var ne = class {
|
|
277
|
+
items = [];
|
|
278
|
+
undo = [];
|
|
279
|
+
constructor(e) {
|
|
280
|
+
this.scope = e, e.units.push({
|
|
281
|
+
commit: () => {
|
|
282
|
+
this.undo = [];
|
|
283
|
+
},
|
|
284
|
+
rollback: () => {
|
|
285
|
+
for (let e = this.undo.length - 1; e >= 0; e--) this.undo[e]();
|
|
286
|
+
this.undo = [];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
record(e) {
|
|
291
|
+
this.scope.live && this.undo.push(e);
|
|
292
|
+
}
|
|
293
|
+
grow() {
|
|
294
|
+
let e = this.scope.limits.arraySize;
|
|
295
|
+
this.items.length >= e && x(this.scope, "array", `a list holds at most ${e} numbers`);
|
|
296
|
+
}
|
|
297
|
+
size() {
|
|
298
|
+
return this.items.length;
|
|
299
|
+
}
|
|
300
|
+
get(e) {
|
|
301
|
+
let t = e < 0 ? this.items.length + e : e;
|
|
302
|
+
return t >= 0 && t < this.items.length ? this.items[t] : NaN;
|
|
303
|
+
}
|
|
304
|
+
set(e, t) {
|
|
305
|
+
if (e < 0 || e >= this.items.length) throw RangeError(`array.set: index ${e} is outside a list of ${this.items.length}`);
|
|
306
|
+
let n = this.items[e];
|
|
307
|
+
this.items[e] = t, this.record(() => {
|
|
308
|
+
this.items[e] = n;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
push(e) {
|
|
312
|
+
this.grow(), this.items.push(e), this.record(() => {
|
|
313
|
+
this.items.pop();
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
pop() {
|
|
317
|
+
if (this.items.length === 0) return NaN;
|
|
318
|
+
let e = this.items.pop();
|
|
319
|
+
return this.record(() => {
|
|
320
|
+
this.items.push(e);
|
|
321
|
+
}), e;
|
|
322
|
+
}
|
|
323
|
+
shift() {
|
|
324
|
+
if (this.items.length === 0) return NaN;
|
|
325
|
+
let e = this.items.shift();
|
|
326
|
+
return this.record(() => {
|
|
327
|
+
this.items.unshift(e);
|
|
328
|
+
}), e;
|
|
329
|
+
}
|
|
330
|
+
unshift(e) {
|
|
331
|
+
this.grow(), this.items.unshift(e), this.record(() => {
|
|
332
|
+
this.items.shift();
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
clear() {
|
|
336
|
+
let e = this.items;
|
|
337
|
+
this.items = [], this.record(() => {
|
|
338
|
+
this.items = e;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
toArray() {
|
|
342
|
+
return [...this.items];
|
|
343
|
+
}
|
|
344
|
+
sum() {
|
|
345
|
+
let e = 0;
|
|
346
|
+
for (let t of this.items) e += t;
|
|
347
|
+
return e;
|
|
348
|
+
}
|
|
349
|
+
avg() {
|
|
350
|
+
return this.items.length > 0 ? this.sum() / this.items.length : NaN;
|
|
351
|
+
}
|
|
352
|
+
min() {
|
|
353
|
+
return this.items.reduce((e, t) => t < e ? t : e, this.items.length > 0 ? Infinity : NaN);
|
|
354
|
+
}
|
|
355
|
+
max() {
|
|
356
|
+
return this.items.reduce((e, t) => t > e ? t : e, this.items.length > 0 ? -Infinity : NaN);
|
|
357
|
+
}
|
|
358
|
+
median() {
|
|
359
|
+
let e = this.items.length;
|
|
360
|
+
if (e === 0) return NaN;
|
|
361
|
+
let t = [...this.items].sort((e, t) => e - t), n = e >> 1;
|
|
362
|
+
return e % 2 == 1 ? t[n] : (t[n - 1] + t[n]) / 2;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
function re() {
|
|
366
|
+
return new ne(g("state.array"));
|
|
367
|
+
}
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region src/drawings.ts
|
|
370
|
+
var ie = 50, ae = 500, S = (e) => e === void 0 || Number.isNaN(e) ? ie : Math.min(ae, Math.max(1, Math.floor(e))), oe = (e) => !!e && typeof e.bar == "number" && typeof e.value == "number", se = {
|
|
371
|
+
label: ["at"],
|
|
372
|
+
line: ["from", "to"],
|
|
373
|
+
box: ["from", "to"]
|
|
374
|
+
};
|
|
375
|
+
function ce(e) {
|
|
376
|
+
for (let t of se[e.kind]) if (!oe(e[t])) throw Error(`a ${e.kind} needs ${t}: { bar, value }`);
|
|
377
|
+
return e;
|
|
378
|
+
}
|
|
379
|
+
var le = (e) => ({
|
|
380
|
+
bar: e.bar,
|
|
381
|
+
value: e.value
|
|
382
|
+
});
|
|
383
|
+
function C(e) {
|
|
384
|
+
let t = { ...e };
|
|
385
|
+
for (let e of [
|
|
386
|
+
"at",
|
|
387
|
+
"from",
|
|
388
|
+
"to"
|
|
389
|
+
]) {
|
|
390
|
+
let n = t[e];
|
|
391
|
+
n && (t[e] = le(n));
|
|
392
|
+
}
|
|
393
|
+
return t;
|
|
394
|
+
}
|
|
395
|
+
var ue = class {
|
|
396
|
+
items = /* @__PURE__ */ new Map();
|
|
397
|
+
order = {
|
|
398
|
+
label: [],
|
|
399
|
+
line: [],
|
|
400
|
+
box: []
|
|
401
|
+
};
|
|
402
|
+
limits;
|
|
403
|
+
nextId = 0;
|
|
404
|
+
undo = [];
|
|
405
|
+
constructor(e, t = {}) {
|
|
406
|
+
this.scope = e, this.limits = {
|
|
407
|
+
label: S(t.maxLabels),
|
|
408
|
+
line: S(t.maxLines),
|
|
409
|
+
box: S(t.maxBoxes)
|
|
410
|
+
}, e.units.push({
|
|
411
|
+
commit: () => {
|
|
412
|
+
this.undo = [];
|
|
413
|
+
},
|
|
414
|
+
rollback: () => {
|
|
415
|
+
for (let e = this.undo.length - 1; e >= 0; e--) this.undo[e]();
|
|
416
|
+
this.undo = [];
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
label(e) {
|
|
421
|
+
return this.add({
|
|
422
|
+
kind: "label",
|
|
423
|
+
...e
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
line(e) {
|
|
427
|
+
return this.add({
|
|
428
|
+
kind: "line",
|
|
429
|
+
...e
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
box(e) {
|
|
433
|
+
return this.add({
|
|
434
|
+
kind: "box",
|
|
435
|
+
...e
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
list() {
|
|
439
|
+
return [...this.items.keys()].sort((e, t) => e - t).map((e) => this.items.get(e));
|
|
440
|
+
}
|
|
441
|
+
record(e) {
|
|
442
|
+
this.scope.live && this.undo.push(e);
|
|
443
|
+
}
|
|
444
|
+
add(e) {
|
|
445
|
+
ce(e);
|
|
446
|
+
let t = this.nextId++;
|
|
447
|
+
this.record(() => {
|
|
448
|
+
this.nextId = t;
|
|
449
|
+
}), this.items.set(t, C(e)), this.record(() => {
|
|
450
|
+
this.items.delete(t);
|
|
451
|
+
});
|
|
452
|
+
let n = this.order[e.kind];
|
|
453
|
+
for (n.push(t), this.record(() => {
|
|
454
|
+
n.pop();
|
|
455
|
+
}); n.length > this.limits[e.kind];) {
|
|
456
|
+
let e = n.shift(), t = this.items.get(e);
|
|
457
|
+
this.items.delete(e), this.record(() => {
|
|
458
|
+
this.items.set(e, t), n.unshift(e);
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
set: (e) => this.change(t, e),
|
|
463
|
+
remove: () => this.remove(t)
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
change(e, t) {
|
|
467
|
+
let n = this.items.get(e);
|
|
468
|
+
n && (this.items.set(e, C(ce({
|
|
469
|
+
...n,
|
|
470
|
+
...t,
|
|
471
|
+
kind: n.kind
|
|
472
|
+
}))), this.record(() => {
|
|
473
|
+
this.items.set(e, n);
|
|
474
|
+
}));
|
|
475
|
+
}
|
|
476
|
+
remove(e) {
|
|
477
|
+
let t = this.items.get(e);
|
|
478
|
+
if (!t) return;
|
|
479
|
+
this.items.delete(e);
|
|
480
|
+
let n = this.order[t.kind], r = n.indexOf(e);
|
|
481
|
+
r >= 0 && n.splice(r, 1), this.record(() => {
|
|
482
|
+
this.items.set(e, t), r >= 0 && n.splice(r, 0, e);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}, de = 1e11, w = (e, t) => e ? {
|
|
486
|
+
open: e.open,
|
|
487
|
+
high: Math.max(e.high, t.high),
|
|
488
|
+
low: Math.min(e.low, t.low),
|
|
489
|
+
close: t.close,
|
|
490
|
+
volume: e.volume + t.volume
|
|
491
|
+
} : {
|
|
492
|
+
open: t.open,
|
|
493
|
+
high: t.high,
|
|
494
|
+
low: t.low,
|
|
495
|
+
close: t.close,
|
|
496
|
+
volume: t.volume
|
|
497
|
+
}, fe = (e, t) => !!e && e.open === t.open && e.high === t.high && e.low === t.low && e.close === t.close && e.volume === t.volume;
|
|
498
|
+
function pe(e) {
|
|
499
|
+
let t = Infinity;
|
|
500
|
+
for (let n = 1; n < e.length; n++) t = Math.min(t, e[n].time - e[n - 1].time);
|
|
501
|
+
return !Number.isFinite(t) || t <= 0 ? NaN : e[e.length - 1].time < de ? t * 1e3 : t;
|
|
502
|
+
}
|
|
503
|
+
function me(e, n, r, o = {}) {
|
|
504
|
+
let s = typeof n == "string" ? t(n) : NaN;
|
|
505
|
+
if (!Number.isFinite(s)) throw Error(`request.security: '${String(n)}' is no interval it can read: a count and a unit, as '15m', '1h', '4h', '1d', '1w', '1M' (case matters)`);
|
|
506
|
+
let c = [], l = !1, u = new T(a({
|
|
507
|
+
id: `security:${n}`,
|
|
508
|
+
name: n,
|
|
509
|
+
setup(e) {
|
|
510
|
+
let t = r({
|
|
511
|
+
prices: e.prices,
|
|
512
|
+
state: e.state
|
|
513
|
+
});
|
|
514
|
+
return (e) => {
|
|
515
|
+
c[e.index] = t(e.live && !l ? {
|
|
516
|
+
...e,
|
|
517
|
+
live: !1
|
|
518
|
+
} : e);
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}), {}, e.limits ? { limits: {
|
|
522
|
+
loopSteps: e.limits.loopSteps,
|
|
523
|
+
arraySize: e.limits.arraySize
|
|
524
|
+
} } : {}), d = null, f = -1, p = NaN, m = NaN, h = null, g = null, _ = 0, v = (t, r, i) => {
|
|
525
|
+
let a = {
|
|
526
|
+
time: r,
|
|
527
|
+
...t
|
|
528
|
+
};
|
|
529
|
+
u.length === 0 ? u.load([a]) : i && u.length === _ ? u.next(a) : u.tick(a);
|
|
530
|
+
let o = u.errors[0];
|
|
531
|
+
if (!o) return;
|
|
532
|
+
let s = `request.security('${n}'), on its bar ${o.bar}: ${o.message}`;
|
|
533
|
+
if (!o.limit) throw Error(s);
|
|
534
|
+
let c = new y(o.limit, s);
|
|
535
|
+
throw e.onLimit?.(c), c;
|
|
536
|
+
}, b = () => {
|
|
537
|
+
if (d) return d;
|
|
538
|
+
let t = e.timeline(), r = pe(t);
|
|
539
|
+
if (Number.isFinite(r) && s < r) throw Error(`request.security('${n}') reads a higher interval than the chart's bars: they are ${r / 6e4} minutes apart`);
|
|
540
|
+
return d = i(t, n, e.exchangeTimeZone, e.sessionStart), d;
|
|
541
|
+
};
|
|
542
|
+
return (t) => {
|
|
543
|
+
let r = b();
|
|
544
|
+
if (l = t.live, t.index === f) {
|
|
545
|
+
if (r(t.time) !== p) throw Error(`request.security('${n}'): the live bar's time moved to another period; load the bars again`);
|
|
546
|
+
let e = w(h, t);
|
|
547
|
+
v(e, m, !1), g = e;
|
|
548
|
+
} else if (t.index === f + 1) {
|
|
549
|
+
if (f >= 0) {
|
|
550
|
+
let n = w(h, e.barAt(f));
|
|
551
|
+
l = !1, fe(g, n) || v(n, m, !1), l = t.live, g = n;
|
|
552
|
+
}
|
|
553
|
+
let n = r(t.time), i = n !== p || g === null, a = i ? null : g, o = w(a, t), s = i ? t.time : m;
|
|
554
|
+
v(o, s, i), p = n, m = s, h = a, g = o, f = t.index, _ = u.length;
|
|
555
|
+
} else throw Error(`request.security('${n}') is called on every bar: it was not on bar ${f + 1}`);
|
|
556
|
+
let i = u.length - 1, a = o.live ? c[i] : c[i - 1];
|
|
557
|
+
return a === void 0 ? NaN : a;
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/ScriptRun.ts
|
|
562
|
+
var he = [
|
|
563
|
+
"time",
|
|
564
|
+
"open",
|
|
565
|
+
"high",
|
|
566
|
+
"low",
|
|
567
|
+
"close",
|
|
568
|
+
"volume"
|
|
569
|
+
], T = class {
|
|
570
|
+
scope;
|
|
571
|
+
outputs;
|
|
572
|
+
onBar;
|
|
573
|
+
prices;
|
|
574
|
+
count = 0;
|
|
575
|
+
failures = [];
|
|
576
|
+
haltedAt = -1;
|
|
577
|
+
declared;
|
|
578
|
+
fresh = !1;
|
|
579
|
+
get declarations() {
|
|
580
|
+
return this.declared;
|
|
581
|
+
}
|
|
582
|
+
loaded = [];
|
|
583
|
+
limits;
|
|
584
|
+
began = 0;
|
|
585
|
+
intervalRead = !1;
|
|
586
|
+
constructor(e, t = {}, n = {}) {
|
|
587
|
+
this.script = e, this.params = t, this.options = n, this.limits = b(n.limits), this.start();
|
|
588
|
+
}
|
|
589
|
+
get errors() {
|
|
590
|
+
return this.failures;
|
|
591
|
+
}
|
|
592
|
+
get length() {
|
|
593
|
+
return this.count;
|
|
594
|
+
}
|
|
595
|
+
get output() {
|
|
596
|
+
return this.outputs.output(this.count, this.failures);
|
|
597
|
+
}
|
|
598
|
+
load(e) {
|
|
599
|
+
this.loaded = e, this.fresh || this.start(), this.fresh = !1, this.clockIn();
|
|
600
|
+
for (let t = 0; t < e.length; t++) t === e.length - 1 && this.goLive(), this.write(t, e[t]), this.count = t + 1, this.runBar(t);
|
|
601
|
+
}
|
|
602
|
+
tick(e) {
|
|
603
|
+
if (this.count === 0) return this.load([e]);
|
|
604
|
+
this.fresh = !1, this.clockIn();
|
|
605
|
+
let t = this.count - 1;
|
|
606
|
+
this.write(t, e);
|
|
607
|
+
for (let e of this.scope.units) e.rollback();
|
|
608
|
+
this.haltedAt === t && (this.haltedAt = -1, this.failures = this.failures.filter((e) => e.bar !== t)), this.runBar(t);
|
|
609
|
+
}
|
|
610
|
+
next(e) {
|
|
611
|
+
if (this.count === 0) return this.load([e]);
|
|
612
|
+
this.fresh = !1, this.clockIn(), this.closeLive(), this.goLive();
|
|
613
|
+
let t = this.count;
|
|
614
|
+
this.write(t, e), this.count = t + 1, this.runBar(t);
|
|
615
|
+
}
|
|
616
|
+
update(e) {
|
|
617
|
+
if (this.count === 0) return this.load([e]), "bar";
|
|
618
|
+
let t = this.prices.time.get(this.count - 1);
|
|
619
|
+
return e.time === t ? (this.tick(e), "tick") : e.time > t ? (this.next(e), "bar") : "reload";
|
|
620
|
+
}
|
|
621
|
+
start() {
|
|
622
|
+
let e = {
|
|
623
|
+
units: [],
|
|
624
|
+
live: !1,
|
|
625
|
+
bar: 0,
|
|
626
|
+
clearers: [],
|
|
627
|
+
limits: this.limits,
|
|
628
|
+
steps: 0,
|
|
629
|
+
breach: null
|
|
630
|
+
};
|
|
631
|
+
this.scope = e, this.prices = Object.fromEntries(he.map((e) => [e, l()])), this.outputs = new p(e), this.count = 0, this.failures = [], this.haltedAt = -1;
|
|
632
|
+
let t = this.script.inputs ?? {}, n = Object.fromEntries(Object.keys(t).map((e) => [e, o(this.params[e], t[e])]));
|
|
633
|
+
if (this.onBar = h(e, () => this.script.setup({
|
|
634
|
+
inputs: n,
|
|
635
|
+
chart: this.chart(),
|
|
636
|
+
prices: this.priceSeries(),
|
|
637
|
+
plot: (e, t) => this.outputs.plot(e, t),
|
|
638
|
+
loop: () => {
|
|
639
|
+
++e.steps > e.limits.loopSteps && x(e, "loop", `a bar takes at most ${e.limits.loopSteps} loop steps`);
|
|
640
|
+
},
|
|
641
|
+
shape: (e, t) => this.outputs.shape(e, t),
|
|
642
|
+
fill: (e, t, n) => this.outputs.fill(e, t, n),
|
|
643
|
+
bgcolor: (e) => this.outputs.bgcolor(e),
|
|
644
|
+
barcolor: () => this.outputs.barcolor(),
|
|
645
|
+
alertCondition: (e, t) => this.outputs.alertCondition(e, t),
|
|
646
|
+
drawings: (e) => this.outputs.addDrawings(new ue(g("drawings"), e)),
|
|
647
|
+
request: { security: (e, t, n) => {
|
|
648
|
+
let r = g("request.security");
|
|
649
|
+
return me({
|
|
650
|
+
timeline: () => this.loaded,
|
|
651
|
+
barAt: (e) => this.barAt(e),
|
|
652
|
+
...this.options,
|
|
653
|
+
limits: this.limits,
|
|
654
|
+
onLimit: (e) => {
|
|
655
|
+
r.breach ??= e;
|
|
656
|
+
}
|
|
657
|
+
}, e, t, n);
|
|
658
|
+
} },
|
|
659
|
+
hline: (e, t) => this.outputs.hline(e, t),
|
|
660
|
+
state: {
|
|
661
|
+
var: ee,
|
|
662
|
+
array: re,
|
|
663
|
+
series: te
|
|
664
|
+
}
|
|
665
|
+
})), this.outputs.close(), typeof this.onBar != "function") throw Error(`script '${this.script.id}': setup must return what each bar runs`);
|
|
666
|
+
this.declared = this.outputs.declarations(this.script.overlay === !0), this.fresh = !0;
|
|
667
|
+
}
|
|
668
|
+
chart() {
|
|
669
|
+
let { exchangeTimeZone: e = "UTC", interval: t = null } = this.options, n = () => (this.intervalRead = !0, t);
|
|
670
|
+
return Object.freeze({
|
|
671
|
+
timeZone: e,
|
|
672
|
+
get interval() {
|
|
673
|
+
return n();
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
get readsInterval() {
|
|
678
|
+
return this.intervalRead;
|
|
679
|
+
}
|
|
680
|
+
goLive() {
|
|
681
|
+
for (let e of this.scope.units) e.commit();
|
|
682
|
+
this.scope.live = !0;
|
|
683
|
+
}
|
|
684
|
+
closeLive() {
|
|
685
|
+
if (!(this.haltedAt >= 0)) {
|
|
686
|
+
for (let e of this.scope.units) e.rollback();
|
|
687
|
+
this.scope.live = !1, this.runBar(this.count - 1);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
priceSeries() {
|
|
691
|
+
let e = (e) => ({ at: (t = 0) => t >= 0 ? this.prices[e].get(this.scope.bar - Math.floor(t)) : NaN });
|
|
692
|
+
return Object.fromEntries(he.map((t) => [t, e(t)]));
|
|
693
|
+
}
|
|
694
|
+
write(e, t) {
|
|
695
|
+
let n = this.prices;
|
|
696
|
+
n.time.set(e, t.time), n.open.set(e, t.open), n.high.set(e, t.high), n.low.set(e, t.low), n.close.set(e, t.close), n.volume.set(e, t.volume ?? 0);
|
|
697
|
+
}
|
|
698
|
+
barAt(e) {
|
|
699
|
+
let t = this.prices;
|
|
700
|
+
return {
|
|
701
|
+
index: e,
|
|
702
|
+
time: t.time.get(e),
|
|
703
|
+
open: t.open.get(e),
|
|
704
|
+
high: t.high.get(e),
|
|
705
|
+
low: t.low.get(e),
|
|
706
|
+
close: t.close.get(e),
|
|
707
|
+
volume: t.volume.get(e),
|
|
708
|
+
live: this.scope.live && e === this.count - 1
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
runBar(e) {
|
|
712
|
+
let t = this.scope;
|
|
713
|
+
t.bar = e;
|
|
714
|
+
for (let n of t.clearers) n(e);
|
|
715
|
+
if (this.haltedAt >= 0) return;
|
|
716
|
+
let n = this.barAt(e);
|
|
717
|
+
t.steps = 0, t.breach = null;
|
|
718
|
+
let r = null;
|
|
719
|
+
try {
|
|
720
|
+
this.onBar(n);
|
|
721
|
+
} catch (e) {
|
|
722
|
+
r = e;
|
|
723
|
+
}
|
|
724
|
+
if (r = t.breach ?? r ?? this.overTime(), r === null) return;
|
|
725
|
+
this.haltedAt = e;
|
|
726
|
+
let i = r instanceof y ? { limit: r.limit } : {};
|
|
727
|
+
this.failures.push({
|
|
728
|
+
bar: e,
|
|
729
|
+
message: r instanceof Error ? r.message : String(r),
|
|
730
|
+
...i
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
clockIn() {
|
|
734
|
+
Number.isFinite(this.limits.runMs) && (this.began = performance.now());
|
|
735
|
+
}
|
|
736
|
+
overTime() {
|
|
737
|
+
let e = this.limits.runMs;
|
|
738
|
+
return !Number.isFinite(e) || performance.now() - this.began <= e ? null : new y("time", `a run takes at most ${e} ms; it was past that at this bar`);
|
|
739
|
+
}
|
|
740
|
+
}, E = class {
|
|
741
|
+
slots;
|
|
742
|
+
count = 0;
|
|
743
|
+
run = 0;
|
|
744
|
+
kept = {
|
|
745
|
+
count: 0,
|
|
746
|
+
run: 0
|
|
747
|
+
};
|
|
748
|
+
overwritten = [];
|
|
749
|
+
constructor(e) {
|
|
750
|
+
this.size = e;
|
|
751
|
+
let t = g();
|
|
752
|
+
this.slots = new Float64Array(e + 1).fill(NaN), t.units.push({
|
|
753
|
+
commit: () => {
|
|
754
|
+
this.kept = {
|
|
755
|
+
count: this.count,
|
|
756
|
+
run: this.run
|
|
757
|
+
}, this.overwritten = [];
|
|
758
|
+
},
|
|
759
|
+
rollback: () => {
|
|
760
|
+
for (let e = this.overwritten.length - 2; e >= 0; e -= 2) this.slots[this.overwritten[e]] = this.overwritten[e + 1];
|
|
761
|
+
this.overwritten = [], this.count = this.kept.count, this.run = this.kept.run;
|
|
762
|
+
}
|
|
763
|
+
}), this.live = () => t.live;
|
|
764
|
+
}
|
|
765
|
+
live;
|
|
766
|
+
push(e) {
|
|
767
|
+
let t = this.count % this.slots.length;
|
|
768
|
+
this.live() && this.overwritten.push(t, this.slots[t]), this.slots[t] = e, this.count++, this.run = Number.isNaN(e) ? 0 : this.run + 1;
|
|
769
|
+
}
|
|
770
|
+
at(e) {
|
|
771
|
+
let t = this.count - 1 - e;
|
|
772
|
+
return e < 0 || e > this.size || t < 0 ? NaN : this.slots[t % this.slots.length];
|
|
773
|
+
}
|
|
774
|
+
get given() {
|
|
775
|
+
return this.count;
|
|
776
|
+
}
|
|
777
|
+
get numbersInRow() {
|
|
778
|
+
return this.run;
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
//#endregion
|
|
782
|
+
//#region src/ta/common.ts
|
|
783
|
+
function D(e) {
|
|
784
|
+
return Number.isFinite(e) ? e : NaN;
|
|
785
|
+
}
|
|
786
|
+
function O(e) {
|
|
787
|
+
return Number.isFinite(e) ? Math.max(1, Math.floor(e)) : 1;
|
|
788
|
+
}
|
|
789
|
+
function k(e, t) {
|
|
790
|
+
let n = _({ last: NaN });
|
|
791
|
+
return (r) => {
|
|
792
|
+
let i = D(r);
|
|
793
|
+
return Number.isNaN(i) ? (Number.isNaN(n.last) || e(n.last), t) : (n.last = i, e(i));
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
function A() {
|
|
797
|
+
let e = _({ close: NaN });
|
|
798
|
+
return (t) => {
|
|
799
|
+
let n = Number.isFinite(t.close) ? t.close : e.close;
|
|
800
|
+
e.close = n;
|
|
801
|
+
let r = (e) => Number.isFinite(e) ? e : n;
|
|
802
|
+
return {
|
|
803
|
+
high: r(t.high),
|
|
804
|
+
low: r(t.low),
|
|
805
|
+
close: n
|
|
806
|
+
};
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
//#endregion
|
|
810
|
+
//#region src/ta/averages.ts
|
|
811
|
+
function j(e) {
|
|
812
|
+
let t = O(e), n = new E(t), r = _({ sum: 0 });
|
|
813
|
+
return (e) => {
|
|
814
|
+
let i = D(e);
|
|
815
|
+
return n.push(i), Number.isNaN(i) ? (r.sum = 0, NaN) : (r.sum += i, n.numbersInRow > t && (r.sum -= n.at(t)), n.numbersInRow >= t ? r.sum / t : NaN);
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function M(e, t) {
|
|
819
|
+
let n = O(e), r = t(n), i = _({
|
|
820
|
+
seed: 0,
|
|
821
|
+
count: 0,
|
|
822
|
+
value: NaN
|
|
823
|
+
});
|
|
824
|
+
return (e) => {
|
|
825
|
+
let t = D(e);
|
|
826
|
+
return Number.isNaN(t) ? NaN : Number.isNaN(i.value) ? (i.seed += t, i.count++, i.count === n && (i.value = i.seed / n), i.value) : (i.value += r * (t - i.value), i.value);
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
function N(e) {
|
|
830
|
+
return M(e, (e) => 2 / (e + 1));
|
|
831
|
+
}
|
|
832
|
+
function ge(e) {
|
|
833
|
+
return M(e, (e) => 1 / e);
|
|
834
|
+
}
|
|
835
|
+
function P(e, t) {
|
|
836
|
+
if (e.given < t) return null;
|
|
837
|
+
let n = Array(t);
|
|
838
|
+
for (let r = 0; r < t; r++) {
|
|
839
|
+
let i = e.at(t - 1 - r);
|
|
840
|
+
if (Number.isNaN(i)) return null;
|
|
841
|
+
n[r] = i;
|
|
842
|
+
}
|
|
843
|
+
return n;
|
|
844
|
+
}
|
|
845
|
+
function F(e) {
|
|
846
|
+
let t = O(e), n = new E(t), r = t * (t + 1) / 2;
|
|
847
|
+
return (e) => {
|
|
848
|
+
n.push(D(e));
|
|
849
|
+
let i = P(n, t);
|
|
850
|
+
if (!i) return NaN;
|
|
851
|
+
let a = 0;
|
|
852
|
+
for (let e = 0; e < t; e++) a += i[e] * (e + 1);
|
|
853
|
+
return a / r;
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
function _e(e) {
|
|
857
|
+
let t = O(e), n = new E(t);
|
|
858
|
+
return (e) => {
|
|
859
|
+
n.push(D(e));
|
|
860
|
+
let r = P(n, t);
|
|
861
|
+
if (!r) return NaN;
|
|
862
|
+
let i = 0, a = 0;
|
|
863
|
+
for (let e of r) i += e, a += e * e;
|
|
864
|
+
let o = i / t;
|
|
865
|
+
return Math.sqrt(Math.max(0, a / t - o * o));
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
function ve(e) {
|
|
869
|
+
return k(ye(e), NaN);
|
|
870
|
+
}
|
|
871
|
+
function ye(e) {
|
|
872
|
+
let t = Math.max(2, O(e)), n = F(Math.max(2, Math.floor(t / 2))), r = F(t), i = F(Math.max(2, Math.floor(Math.sqrt(t))));
|
|
873
|
+
return (e) => {
|
|
874
|
+
let t = n(e), a = r(e);
|
|
875
|
+
return i(Number.isNaN(t) || Number.isNaN(a) ? NaN : 2 * t - a);
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
function be(e) {
|
|
879
|
+
let t = O(e), n = new E(t), r = new E(t), i = _({
|
|
880
|
+
pv: 0,
|
|
881
|
+
volume: 0,
|
|
882
|
+
last: NaN
|
|
883
|
+
});
|
|
884
|
+
return (e, a) => {
|
|
885
|
+
let o = D(e);
|
|
886
|
+
Number.isNaN(o) || (i.last = o);
|
|
887
|
+
let s = i.last;
|
|
888
|
+
if (Number.isNaN(s)) return NaN;
|
|
889
|
+
let c = Number.isFinite(a) ? a : 0;
|
|
890
|
+
return n.push(s), r.push(c), i.pv += s * c, i.volume += c, n.given > t && (i.pv -= n.at(t) * r.at(t), i.volume -= r.at(t)), Number.isNaN(o) ? NaN : n.given >= t && i.volume > 0 ? i.pv / i.volume : NaN;
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
//#endregion
|
|
894
|
+
//#region src/ta/events.ts
|
|
895
|
+
function xe(e) {
|
|
896
|
+
let t = _({
|
|
897
|
+
a: NaN,
|
|
898
|
+
b: NaN
|
|
899
|
+
});
|
|
900
|
+
return (n, r) => {
|
|
901
|
+
let i = D(n), a = D(r), o = t.a, s = t.b;
|
|
902
|
+
return t.a = i, t.b = a, [
|
|
903
|
+
i,
|
|
904
|
+
a,
|
|
905
|
+
o,
|
|
906
|
+
s
|
|
907
|
+
].some(Number.isNaN) ? !1 : e ? o <= s && i > a : o >= s && i < a;
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
function Se() {
|
|
911
|
+
return xe(!0);
|
|
912
|
+
}
|
|
913
|
+
function Ce() {
|
|
914
|
+
return xe(!1);
|
|
915
|
+
}
|
|
916
|
+
function we() {
|
|
917
|
+
let e = Se(), t = Ce();
|
|
918
|
+
return (n, r) => {
|
|
919
|
+
let i = e(n, r), a = t(n, r);
|
|
920
|
+
return i || a;
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
function Te(e, t, n) {
|
|
924
|
+
let r = O(e), i = O(t), a = new E(r + i);
|
|
925
|
+
return (e) => {
|
|
926
|
+
if (a.push(D(e)), a.given < r + i + 1) return NaN;
|
|
927
|
+
let t = a.at(i);
|
|
928
|
+
if (Number.isNaN(t)) return NaN;
|
|
929
|
+
for (let e = 0; e <= r + i; e++) {
|
|
930
|
+
if (e === i) continue;
|
|
931
|
+
let r = a.at(e);
|
|
932
|
+
if (Number.isNaN(r) || !n(t, r)) return NaN;
|
|
933
|
+
}
|
|
934
|
+
return t;
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
function Ee(e, t) {
|
|
938
|
+
return Te(e, t, (e, t) => e > t);
|
|
939
|
+
}
|
|
940
|
+
function De(e, t) {
|
|
941
|
+
return Te(e, t, (e, t) => e < t);
|
|
942
|
+
}
|
|
943
|
+
function Oe() {
|
|
944
|
+
let e = _({ since: NaN });
|
|
945
|
+
return (t) => (e.since = t ? 0 : e.since + 1, e.since);
|
|
946
|
+
}
|
|
947
|
+
function ke(e = 0) {
|
|
948
|
+
let t = Math.max(0, Math.floor(e)), n = new E(t);
|
|
949
|
+
return (e, r) => (e && n.push(D(r)), n.at(t));
|
|
950
|
+
}
|
|
951
|
+
//#endregion
|
|
952
|
+
//#region src/ta/oscillators.ts
|
|
953
|
+
function Ae(e = 14) {
|
|
954
|
+
return k(je(e), NaN);
|
|
955
|
+
}
|
|
956
|
+
function je(e) {
|
|
957
|
+
let t = O(e), n = _({
|
|
958
|
+
prev: NaN,
|
|
959
|
+
count: 0,
|
|
960
|
+
gain: 0,
|
|
961
|
+
loss: 0
|
|
962
|
+
}), r = () => n.loss === 0 ? 100 : 100 - 100 / (1 + n.gain / n.loss);
|
|
963
|
+
return (e) => {
|
|
964
|
+
let i = D(e);
|
|
965
|
+
if (Number.isNaN(i)) return NaN;
|
|
966
|
+
if (Number.isNaN(n.prev)) return n.prev = i, NaN;
|
|
967
|
+
let a = i - n.prev;
|
|
968
|
+
n.prev = i;
|
|
969
|
+
let o = a > 0 ? a : 0, s = a < 0 ? -a : 0;
|
|
970
|
+
return n.count < t ? (n.gain += o, n.loss += s, n.count++, n.count < t ? NaN : (n.gain /= t, n.loss /= t, r())) : (n.gain = (n.gain * (t - 1) + o) / t, n.loss = (n.loss * (t - 1) + s) / t, r());
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
function Me(e = 12, t = 26, n = 9) {
|
|
974
|
+
return k(Ne(e, t, n), {
|
|
975
|
+
macd: NaN,
|
|
976
|
+
signal: NaN,
|
|
977
|
+
histogram: NaN
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
function Ne(e, t, n) {
|
|
981
|
+
let r = N(e), i = N(t), a = N(n);
|
|
982
|
+
return (e) => {
|
|
983
|
+
let t = r(e), n = i(e), o = Number.isNaN(t) || Number.isNaN(n) ? NaN : t - n, s = a(o);
|
|
984
|
+
return {
|
|
985
|
+
macd: o,
|
|
986
|
+
signal: s,
|
|
987
|
+
histogram: o - s
|
|
988
|
+
};
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
function Pe(e = 20, t = 2) {
|
|
992
|
+
return k(Fe(e, t), {
|
|
993
|
+
basis: NaN,
|
|
994
|
+
upper: NaN,
|
|
995
|
+
lower: NaN
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
function Fe(e, t) {
|
|
999
|
+
let n = j(e), r = _e(e);
|
|
1000
|
+
return (e) => {
|
|
1001
|
+
let i = n(e), a = t * r(e);
|
|
1002
|
+
return {
|
|
1003
|
+
basis: i,
|
|
1004
|
+
upper: i + a,
|
|
1005
|
+
lower: i - a
|
|
1006
|
+
};
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
function Ie(e = 1) {
|
|
1010
|
+
let t = O(e), n = new E(t);
|
|
1011
|
+
return (e) => (n.push(D(e)), n.at(0) - n.at(t));
|
|
1012
|
+
}
|
|
1013
|
+
function Le(e = 10) {
|
|
1014
|
+
return k(Ie(e), NaN);
|
|
1015
|
+
}
|
|
1016
|
+
function Re(e = 12) {
|
|
1017
|
+
return k(ze(e), NaN);
|
|
1018
|
+
}
|
|
1019
|
+
function ze(e) {
|
|
1020
|
+
let t = O(e), n = new E(t);
|
|
1021
|
+
return (e) => {
|
|
1022
|
+
n.push(D(e));
|
|
1023
|
+
let r = n.at(0), i = n.at(t);
|
|
1024
|
+
return Number.isNaN(r) || Number.isNaN(i) ? NaN : i === 0 ? 0 : (r - i) / i * 100;
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
//#endregion
|
|
1028
|
+
//#region src/ta/ranges.ts
|
|
1029
|
+
function Be() {
|
|
1030
|
+
let e = A(), t = _({ prevClose: NaN });
|
|
1031
|
+
return (n) => {
|
|
1032
|
+
let r = e(n);
|
|
1033
|
+
if (Number.isNaN(r.close)) return NaN;
|
|
1034
|
+
let i = r.high - r.low, a = t.prevClose;
|
|
1035
|
+
return t.prevClose = r.close, Number.isNaN(a) ? i : Math.max(i, Math.abs(r.high - a), Math.abs(r.low - a));
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
function I(e = 14) {
|
|
1039
|
+
let t = O(e), n = Be(), r = _({
|
|
1040
|
+
count: 0,
|
|
1041
|
+
value: 0
|
|
1042
|
+
});
|
|
1043
|
+
return (e) => {
|
|
1044
|
+
let i = n(e);
|
|
1045
|
+
return Number.isNaN(i) ? NaN : r.count < t ? (r.value += i, r.count++, r.count < t ? NaN : (r.value /= t, r.value)) : (r.value = (r.value * (t - 1) + i) / t, r.value);
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
function Ve(e = 3, t = 10) {
|
|
1049
|
+
let n = I(O(t)), r = _({
|
|
1050
|
+
prevClose: NaN,
|
|
1051
|
+
upper: 0,
|
|
1052
|
+
lower: 0,
|
|
1053
|
+
line: 0
|
|
1054
|
+
}), i = A();
|
|
1055
|
+
return (t) => {
|
|
1056
|
+
let a = n(t), o = i(t), s = Number.isNaN(r.prevClose) ? o.close : r.prevClose;
|
|
1057
|
+
if (r.prevClose = o.close, Number.isNaN(a)) return {
|
|
1058
|
+
value: NaN,
|
|
1059
|
+
trend: NaN
|
|
1060
|
+
};
|
|
1061
|
+
let c = (o.high + o.low) / 2, l = c + e * a, u = c - e * a, d = l < r.upper || s > r.upper ? l : r.upper, f = u > r.lower || s < r.lower ? u : r.lower, p = r.line === r.upper ? o.close <= d ? d : f : o.close >= f ? f : d;
|
|
1062
|
+
return r.upper = d, r.lower = f, r.line = p, {
|
|
1063
|
+
value: p,
|
|
1064
|
+
trend: p === f ? 1 : -1
|
|
1065
|
+
};
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
function L(e, t) {
|
|
1069
|
+
let n = O(e), r = new E(n);
|
|
1070
|
+
return (e) => {
|
|
1071
|
+
if (r.push(D(e)), r.given < n) return NaN;
|
|
1072
|
+
let i = r.at(0);
|
|
1073
|
+
for (let e = 0; e < n; e++) {
|
|
1074
|
+
let n = r.at(e);
|
|
1075
|
+
if (Number.isNaN(n)) return NaN;
|
|
1076
|
+
t(n, i) && (i = n);
|
|
1077
|
+
}
|
|
1078
|
+
return i;
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
function He(e) {
|
|
1082
|
+
return L(e, (e, t) => e > t);
|
|
1083
|
+
}
|
|
1084
|
+
function Ue(e) {
|
|
1085
|
+
return L(e, (e, t) => e < t);
|
|
1086
|
+
}
|
|
1087
|
+
//#endregion
|
|
1088
|
+
//#region src/ta/moves.ts
|
|
1089
|
+
function We(e) {
|
|
1090
|
+
let t = O(e), n = new E(t), r = new E(t);
|
|
1091
|
+
return (e, i, a) => {
|
|
1092
|
+
n.push(D(i)), r.push(D(a));
|
|
1093
|
+
let o = P(n, t), s = P(r, t), c = D(e);
|
|
1094
|
+
if (!o || !s || Number.isNaN(c)) return NaN;
|
|
1095
|
+
let l = Math.max(...o), u = Math.min(...s);
|
|
1096
|
+
return l === u ? 50 : (c - u) / (l - u) * 100;
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function Ge(e) {
|
|
1100
|
+
let t = O(e), n = new E(t + 1), r = new E(t + 1);
|
|
1101
|
+
return (e, i) => {
|
|
1102
|
+
n.push(D(e)), r.push(D(i));
|
|
1103
|
+
let a = P(n, t + 1), o = P(r, t + 1);
|
|
1104
|
+
if (!a || !o) return NaN;
|
|
1105
|
+
let s = 0, c = 0;
|
|
1106
|
+
for (let e = 1; e <= t; e++) a[e] > a[e - 1] ? s += a[e] * o[e] : a[e] < a[e - 1] && (c += a[e] * o[e]);
|
|
1107
|
+
return c === 0 ? 100 : 100 - 100 / (1 + s / c);
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function Ke() {
|
|
1111
|
+
let e = _({
|
|
1112
|
+
value: 0,
|
|
1113
|
+
prev: NaN
|
|
1114
|
+
});
|
|
1115
|
+
return (t, n) => {
|
|
1116
|
+
let r = D(t);
|
|
1117
|
+
if (Number.isNaN(r)) return NaN;
|
|
1118
|
+
let i = e.prev;
|
|
1119
|
+
if (e.prev = r, Number.isNaN(i)) return e.value;
|
|
1120
|
+
let a = Number.isFinite(n) ? n : 0;
|
|
1121
|
+
return r > i ? e.value += a : r < i && (e.value -= a), e.value;
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
function qe(e = .02, t = .02, n = .2) {
|
|
1125
|
+
let r = A(), i = _({
|
|
1126
|
+
bars: 0,
|
|
1127
|
+
up: 0,
|
|
1128
|
+
af: 0,
|
|
1129
|
+
ep: 0,
|
|
1130
|
+
sar: 0,
|
|
1131
|
+
high1: 0,
|
|
1132
|
+
low1: 0,
|
|
1133
|
+
high2: 0,
|
|
1134
|
+
low2: 0,
|
|
1135
|
+
close1: 0
|
|
1136
|
+
});
|
|
1137
|
+
return (a) => {
|
|
1138
|
+
let o = r(a);
|
|
1139
|
+
return Number.isNaN(o.close) ? NaN : (i.bars++, i.bars === 1 ? (i.high1 = o.high, i.low1 = o.low, i.close1 = o.close, NaN) : (i.bars === 2 && (i.up = +(o.close > i.close1), i.af = e, i.ep = i.up ? i.high1 : i.low1, i.sar = i.up ? i.low1 : i.high1), i.sar += i.af * (i.ep - i.sar), i.up ? (i.sar = Math.min(i.sar, i.low1), i.bars > 2 && (i.sar = Math.min(i.sar, i.low2)), o.low < i.sar ? (i.up = 0, i.sar = i.ep, i.ep = o.low, i.af = e) : o.high > i.ep && (i.ep = o.high, i.af = Math.min(i.af + t, n))) : (i.sar = Math.max(i.sar, i.high1), i.bars > 2 && (i.sar = Math.max(i.sar, i.high2)), o.high > i.sar ? (i.up = 1, i.sar = i.ep, i.ep = o.high, i.af = e) : o.low < i.ep && (i.ep = o.low, i.af = Math.min(i.af + t, n))), i.high2 = i.high1, i.low2 = i.low1, i.high1 = o.high, i.low1 = o.low, i.sar));
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
function R(e, t) {
|
|
1143
|
+
let n = O(e), r = new E(n);
|
|
1144
|
+
return (e) => {
|
|
1145
|
+
r.push(D(e));
|
|
1146
|
+
let i = P(r, n);
|
|
1147
|
+
if (!i) return NaN;
|
|
1148
|
+
let a = n - 1;
|
|
1149
|
+
for (let e = n - 2; e >= 0; e--) t(i[e], i[a]) && (a = e);
|
|
1150
|
+
return a - (n - 1);
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
function Je(e) {
|
|
1154
|
+
return R(e, (e, t) => e > t);
|
|
1155
|
+
}
|
|
1156
|
+
function Ye(e) {
|
|
1157
|
+
return R(e, (e, t) => e < t);
|
|
1158
|
+
}
|
|
1159
|
+
function z(e, t) {
|
|
1160
|
+
let n = O(e), r = new E(n + 1);
|
|
1161
|
+
return (e) => {
|
|
1162
|
+
r.push(D(e));
|
|
1163
|
+
let i = P(r, n + 1);
|
|
1164
|
+
if (!i) return !1;
|
|
1165
|
+
for (let e = 0; e < n; e++) if (!t(i[n], i[e])) return !1;
|
|
1166
|
+
return !0;
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
function Xe(e) {
|
|
1170
|
+
return z(e, (e, t) => e > t);
|
|
1171
|
+
}
|
|
1172
|
+
function Ze(e) {
|
|
1173
|
+
return z(e, (e, t) => e < t);
|
|
1174
|
+
}
|
|
1175
|
+
//#endregion
|
|
1176
|
+
//#region src/ta/statistics.ts
|
|
1177
|
+
function B(e, t) {
|
|
1178
|
+
let n = O(e), r = new E(n);
|
|
1179
|
+
return (e) => {
|
|
1180
|
+
r.push(D(e));
|
|
1181
|
+
let i = P(r, n);
|
|
1182
|
+
return i ? t(i, n) : NaN;
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
var V = 5e3, H = (e) => e.reduce((e, t) => e + t, 0), U = (e) => [...e].sort((e, t) => e - t);
|
|
1186
|
+
function Qe(e) {
|
|
1187
|
+
return B(e, H);
|
|
1188
|
+
}
|
|
1189
|
+
function $e() {
|
|
1190
|
+
let e = _({
|
|
1191
|
+
total: 0,
|
|
1192
|
+
seen: 0
|
|
1193
|
+
});
|
|
1194
|
+
return (t) => {
|
|
1195
|
+
let n = D(t);
|
|
1196
|
+
return Number.isNaN(n) || (e.total += n, e.seen = 1), e.seen ? e.total : NaN;
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
function et(e) {
|
|
1200
|
+
return B(e, (e, t) => {
|
|
1201
|
+
let n = U(e), r = Math.floor(t / 2);
|
|
1202
|
+
return t % 2 == 1 ? n[r] : (n[r - 1] + n[r]) / 2;
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
function W(e) {
|
|
1206
|
+
return Number.isFinite(e) ? Math.min(100, Math.max(0, e)) : NaN;
|
|
1207
|
+
}
|
|
1208
|
+
function tt(e, t) {
|
|
1209
|
+
let n = W(t);
|
|
1210
|
+
return B(e, (e, t) => {
|
|
1211
|
+
if (Number.isNaN(n)) return NaN;
|
|
1212
|
+
let r = Math.max(1, Math.ceil(Math.round(n * t * 1e6) / 1e8));
|
|
1213
|
+
return U(e)[r - 1];
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
function nt(e, t) {
|
|
1217
|
+
let n = W(t);
|
|
1218
|
+
return B(e, (e, t) => {
|
|
1219
|
+
if (Number.isNaN(n)) return NaN;
|
|
1220
|
+
let r = U(e), i = n * (t - 1) / 100, a = Math.floor(i);
|
|
1221
|
+
return r[a] + (r[Math.ceil(i)] - r[a]) * (i - a);
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
function rt(e) {
|
|
1225
|
+
let t = O(e), n = new E(t + 1);
|
|
1226
|
+
return (e) => {
|
|
1227
|
+
n.push(D(e));
|
|
1228
|
+
let r = P(n, t + 1);
|
|
1229
|
+
if (!r) return NaN;
|
|
1230
|
+
let i = r[t], a = 0;
|
|
1231
|
+
for (let e = 0; e < t; e++) r[e] <= i && a++;
|
|
1232
|
+
return a / t * 100;
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
function it(e) {
|
|
1236
|
+
return B(e, (e, t) => {
|
|
1237
|
+
let n = H(e) / t;
|
|
1238
|
+
return H(e.map((e) => Math.abs(e - n))) / t;
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
function at(e) {
|
|
1242
|
+
return B(e, (e, t) => {
|
|
1243
|
+
let n = 0, r = 0;
|
|
1244
|
+
for (let t of e) n += t, r += t * t;
|
|
1245
|
+
let i = n / t;
|
|
1246
|
+
return Math.max(0, r / t - i * i);
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
function ot(e) {
|
|
1250
|
+
let t = O(e), n = new E(t), r = new E(t);
|
|
1251
|
+
return (e, i) => {
|
|
1252
|
+
n.push(D(e)), r.push(D(i));
|
|
1253
|
+
let a = P(n, t), o = P(r, t);
|
|
1254
|
+
if (!a || !o) return NaN;
|
|
1255
|
+
let s = H(a) / t, c = H(o) / t, l = 0, u = 0, d = 0;
|
|
1256
|
+
for (let e = 0; e < t; e++) l += (a[e] - s) * (o[e] - c), u += (a[e] - s) ** 2, d += (o[e] - c) ** 2;
|
|
1257
|
+
return u > 0 && d > 0 ? l / Math.sqrt(u * d) : NaN;
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
function st(e, t = 0) {
|
|
1261
|
+
let n = Math.max(-1e3, Math.round(Number.isFinite(t) ? t : 0));
|
|
1262
|
+
return B(Math.min(V, Math.max(2, O(e))), (e, t) => {
|
|
1263
|
+
let r = t * (t - 1) / 2, i = t * ((t - 1) * t * (2 * t - 1) / 6) - r * r, a = 0, o = 0;
|
|
1264
|
+
for (let n = 0; n < t; n++) a += e[n], o += n * e[n];
|
|
1265
|
+
let s = (t * o - r * a) / i;
|
|
1266
|
+
return (a - s * r) / t + s * (t - 1 - n);
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
function ct(e, t = .85, n = 6) {
|
|
1270
|
+
let r = Math.min(V, O(e)), i = Math.min(1, Math.max(0, Number.isFinite(t) ? t : .85)) * (r - 1), a = r / Math.max(.5, Number.isFinite(n) ? n : 6), o = Array.from({ length: r }, (e, t) => Math.exp(-((t - i) ** 2) / (2 * a * a))), s = H(o);
|
|
1271
|
+
return B(r, (e) => {
|
|
1272
|
+
let t = 0;
|
|
1273
|
+
for (let n = 0; n < r; n++) t += o[n] * e[n];
|
|
1274
|
+
return t / s;
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
function lt() {
|
|
1278
|
+
return B(4, (e) => (e[0] + 2 * e[1] + 2 * e[2] + e[3]) / 6);
|
|
1279
|
+
}
|
|
1280
|
+
//#endregion
|
|
1281
|
+
//#region src/ta/index.ts
|
|
1282
|
+
var ut = {
|
|
1283
|
+
sma: j,
|
|
1284
|
+
ema: N,
|
|
1285
|
+
rma: ge,
|
|
1286
|
+
wma: F,
|
|
1287
|
+
vwma: be,
|
|
1288
|
+
hma: ve,
|
|
1289
|
+
stdev: _e,
|
|
1290
|
+
bb: Pe,
|
|
1291
|
+
rsi: Ae,
|
|
1292
|
+
macd: Me,
|
|
1293
|
+
change: Ie,
|
|
1294
|
+
mom: Le,
|
|
1295
|
+
roc: Re,
|
|
1296
|
+
tr: Be,
|
|
1297
|
+
atr: I,
|
|
1298
|
+
supertrend: Ve,
|
|
1299
|
+
highest: He,
|
|
1300
|
+
lowest: Ue,
|
|
1301
|
+
crossover: Se,
|
|
1302
|
+
crossunder: Ce,
|
|
1303
|
+
cross: we,
|
|
1304
|
+
pivothigh: Ee,
|
|
1305
|
+
pivotlow: De,
|
|
1306
|
+
barssince: Oe,
|
|
1307
|
+
valuewhen: ke,
|
|
1308
|
+
sum: Qe,
|
|
1309
|
+
cum: $e,
|
|
1310
|
+
median: et,
|
|
1311
|
+
percentileNearestRank: tt,
|
|
1312
|
+
percentileLinearInterpolation: nt,
|
|
1313
|
+
percentrank: rt,
|
|
1314
|
+
dev: it,
|
|
1315
|
+
variance: at,
|
|
1316
|
+
correlation: ot,
|
|
1317
|
+
linreg: st,
|
|
1318
|
+
alma: ct,
|
|
1319
|
+
swma: lt,
|
|
1320
|
+
stoch: We,
|
|
1321
|
+
mfi: Ge,
|
|
1322
|
+
obv: Ke,
|
|
1323
|
+
sar: qe,
|
|
1324
|
+
highestbars: Je,
|
|
1325
|
+
lowestbars: Ye,
|
|
1326
|
+
rising: Xe,
|
|
1327
|
+
falling: Ze
|
|
1328
|
+
}, G = 1, K = (e) => `p${e}`, dt = (e) => `s${e}`, q = (e) => `bg${e}`, J = (e) => `bc${e}`, Y = (e) => `${e}c`, ft = (e) => `f${e}c`, pt = (e) => `a${e}`;
|
|
1329
|
+
function X(e, t, n, r) {
|
|
1330
|
+
let i = n[r];
|
|
1331
|
+
i > 0 && (e[t] = i - 1);
|
|
1332
|
+
}
|
|
1333
|
+
function mt(e, t) {
|
|
1334
|
+
let n = {};
|
|
1335
|
+
e.plots.forEach((e, r) => {
|
|
1336
|
+
let i = e.values[t];
|
|
1337
|
+
Number.isFinite(i) && (n[K(r)] = i, X(n, Y(K(r)), e.colors, t));
|
|
1338
|
+
}), e.shapes.forEach((e, r) => {
|
|
1339
|
+
e.on[t] === 1 && (n[dt(r)] = G);
|
|
1340
|
+
}), e.backgrounds.forEach((e, r) => {
|
|
1341
|
+
e.colors[t] !== 0 && (n[q(r)] = G, X(n, Y(q(r)), e.colors, t));
|
|
1342
|
+
}), e.fills.forEach((e, r) => X(n, ft(r), e.colors, t)), e.barColors.forEach((e, r) => {
|
|
1343
|
+
e[t] !== 0 && (n[J(r)] = G, X(n, Y(J(r)), e, t));
|
|
1344
|
+
}), e.alertConditions.forEach((e, r) => {
|
|
1345
|
+
n[pt(r)] = +(e.on[t] === 1);
|
|
1346
|
+
});
|
|
1347
|
+
for (let e in n) return n;
|
|
1348
|
+
return null;
|
|
1349
|
+
}
|
|
1350
|
+
//#endregion
|
|
1351
|
+
//#region src/scriptIndicator.ts
|
|
1352
|
+
var ht = [
|
|
1353
|
+
"#2962ff",
|
|
1354
|
+
"#ff6d00",
|
|
1355
|
+
"#00bfa5",
|
|
1356
|
+
"#d500f9",
|
|
1357
|
+
"#ffd600",
|
|
1358
|
+
"#ef5350",
|
|
1359
|
+
"#26a69a",
|
|
1360
|
+
"#8d6e63"
|
|
1361
|
+
], gt = .15;
|
|
1362
|
+
function _t(e, t) {
|
|
1363
|
+
return t || e === "top" || e === "bottom" ? e : e === "aboveBar" ? "top" : "bottom";
|
|
1364
|
+
}
|
|
1365
|
+
function vt(e, t) {
|
|
1366
|
+
return {
|
|
1367
|
+
...t ? { limits: t } : {},
|
|
1368
|
+
...e.exchangeTimeZone ? { exchangeTimeZone: e.exchangeTimeZone } : {},
|
|
1369
|
+
...e.sessionStart === void 0 ? {} : { sessionStart: e.sessionStart },
|
|
1370
|
+
...e.interval === void 0 ? {} : { interval: e.interval }
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
function Z(e) {
|
|
1374
|
+
return JSON.stringify(Object.keys(e).sort().map((t) => [t, e[t]]));
|
|
1375
|
+
}
|
|
1376
|
+
function yt(t) {
|
|
1377
|
+
let n = [], r = 0, i = (e) => (n.push(e ?? ht[r++ % ht.length]), n.length - 1), a = t.plots.map((e, t) => ({
|
|
1378
|
+
key: K(t),
|
|
1379
|
+
title: e.title,
|
|
1380
|
+
color: i(e.color),
|
|
1381
|
+
paletteBy: Y(K(t)),
|
|
1382
|
+
...e.kind === "line" ? {} : { kind: e.kind },
|
|
1383
|
+
...e.width === void 0 ? {} : { width: e.width }
|
|
1384
|
+
})), o = t.shapes.map((e, n) => ({
|
|
1385
|
+
key: dt(n),
|
|
1386
|
+
title: e.title,
|
|
1387
|
+
color: i(e.color),
|
|
1388
|
+
kind: "markers",
|
|
1389
|
+
shape: e.shape,
|
|
1390
|
+
position: _t(e.position, t.overlay)
|
|
1391
|
+
})), s = t.backgrounds.map((e, t) => ({
|
|
1392
|
+
key: q(t),
|
|
1393
|
+
title: e.title,
|
|
1394
|
+
color: i(void 0),
|
|
1395
|
+
kind: "background",
|
|
1396
|
+
paletteBy: Y(q(t)),
|
|
1397
|
+
opacity: 1
|
|
1398
|
+
})), c = t.fills.map((t, r) => {
|
|
1399
|
+
let o = n[a[t.between[0]].color];
|
|
1400
|
+
return {
|
|
1401
|
+
between: [K(t.between[0]), K(t.between[1])],
|
|
1402
|
+
color: i(t.color ?? e(o, gt)),
|
|
1403
|
+
paletteBy: ft(r),
|
|
1404
|
+
opacity: 1
|
|
1405
|
+
};
|
|
1406
|
+
}), l = Array.from({ length: t.barColors }, (e, t) => ({
|
|
1407
|
+
key: J(t),
|
|
1408
|
+
title: "Bars",
|
|
1409
|
+
color: i(void 0),
|
|
1410
|
+
kind: "barColor",
|
|
1411
|
+
paletteBy: Y(J(t))
|
|
1412
|
+
}));
|
|
1413
|
+
return {
|
|
1414
|
+
plots: [
|
|
1415
|
+
...a,
|
|
1416
|
+
...o,
|
|
1417
|
+
...s,
|
|
1418
|
+
...l
|
|
1419
|
+
],
|
|
1420
|
+
fills: c,
|
|
1421
|
+
colors: n
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
function bt(e) {
|
|
1425
|
+
let t = new T(e), n = t.declarations, { plots: r, fills: i, colors: a } = yt(n), o = e.inputs ?? {}, s = Object.keys(o);
|
|
1426
|
+
return {
|
|
1427
|
+
id: e.id,
|
|
1428
|
+
name: e.name,
|
|
1429
|
+
placement: n.overlay ? "overlay" : "panel",
|
|
1430
|
+
defaultConfig: Object.fromEntries(s.map((e) => [e, o[e].default])),
|
|
1431
|
+
plots: r,
|
|
1432
|
+
...i && i.length > 0 ? { fills: i } : {},
|
|
1433
|
+
...e.shortName === void 0 ? {} : { shortName: e.shortName },
|
|
1434
|
+
...n.levels.length > 0 ? { levels: n.levels.map((e) => e.price) } : {},
|
|
1435
|
+
...St(n.levels),
|
|
1436
|
+
...s.length > 0 ? { inputs: Object.fromEntries(s.map((e) => {
|
|
1437
|
+
let { default: t, ...n } = o[e];
|
|
1438
|
+
return [e, n];
|
|
1439
|
+
})) } : {},
|
|
1440
|
+
...a.length > 0 ? { defaultStyle: { colors: a } } : {},
|
|
1441
|
+
...n.alertConditions.length > 0 ? { alertConditions: n.alertConditions.map((e, t) => ({
|
|
1442
|
+
key: pt(t),
|
|
1443
|
+
...e
|
|
1444
|
+
})) } : {},
|
|
1445
|
+
readsExchangeTimeZone: !0,
|
|
1446
|
+
...t.readsInterval ? { readsInterval: !0 } : {}
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
var xt = class extends n {
|
|
1450
|
+
descriptor;
|
|
1451
|
+
runs = /* @__PURE__ */ new WeakMap();
|
|
1452
|
+
constructor(e, t = {}) {
|
|
1453
|
+
super(), this.script = e, this.options = t, this.descriptor = bt(e);
|
|
1454
|
+
}
|
|
1455
|
+
calculate(e, t) {
|
|
1456
|
+
let n = new T(this.script, t.params, vt(t, this.options.limits));
|
|
1457
|
+
n.load(e);
|
|
1458
|
+
let i = {
|
|
1459
|
+
values: new r(),
|
|
1460
|
+
series: Array(e.length).fill(null),
|
|
1461
|
+
meta: {}
|
|
1462
|
+
};
|
|
1463
|
+
return this.writeFrom(i, e, n, 0), this.runs.set(i, {
|
|
1464
|
+
run: n,
|
|
1465
|
+
params: Z(t.params),
|
|
1466
|
+
interval: t.interval
|
|
1467
|
+
}), i;
|
|
1468
|
+
}
|
|
1469
|
+
update(e, t, n, r) {
|
|
1470
|
+
let i = this.runs.get(n), a = this.descriptor.readsInterval === !0 && i?.interval !== t.interval;
|
|
1471
|
+
if (!i || a || i.params !== Z(t.params) || !this.canResume(e, n, r)) return null;
|
|
1472
|
+
let { run: o } = i;
|
|
1473
|
+
if (r < o.length - 1 || e.length < o.length) return null;
|
|
1474
|
+
for (let t = r; t < e.length; t++) t === o.length - 1 ? o.tick(e[t]) : o.next(e[t]);
|
|
1475
|
+
return n.series.length = e.length, this.writeFrom(n, e, o, Math.max(0, r - 1)), n;
|
|
1476
|
+
}
|
|
1477
|
+
revisesBefore() {
|
|
1478
|
+
return 1;
|
|
1479
|
+
}
|
|
1480
|
+
writeFrom(e, t, n, r) {
|
|
1481
|
+
let i = n.output;
|
|
1482
|
+
e.palette = i.palette, e.drawings = i.drawings, e.meta = {
|
|
1483
|
+
...e.meta,
|
|
1484
|
+
errors: i.errors
|
|
1485
|
+
};
|
|
1486
|
+
for (let n = r; n < t.length; n++) this.writePoint(e, t, n, mt(i, n));
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
function St(e) {
|
|
1490
|
+
let t = e.filter((e) => e.color !== void 0 || e.lineStyle !== void 0 || e.title !== void 0).map(({ price: e, color: t, lineStyle: n, title: r }) => ({
|
|
1491
|
+
price: e,
|
|
1492
|
+
...t === void 0 ? {} : { color: t },
|
|
1493
|
+
...n === void 0 ? {} : { lineStyle: n },
|
|
1494
|
+
...r === void 0 ? {} : { title: r }
|
|
1495
|
+
}));
|
|
1496
|
+
return t.length > 0 ? { levelLooks: t } : {};
|
|
1497
|
+
}
|
|
1498
|
+
function Ct(e, t = {}) {
|
|
1499
|
+
return t.limits && b(t.limits), new xt(e, t);
|
|
1500
|
+
}
|
|
1501
|
+
//#endregion
|
|
1502
|
+
//#region src/worker/scriptWorkerIndicator.ts
|
|
1503
|
+
var wt = 5e3;
|
|
1504
|
+
function Q(e) {
|
|
1505
|
+
let t = e[e.length - 1];
|
|
1506
|
+
return t ? `${e.length}|${t.time}|${t.open}|${t.high}|${t.low}|${t.close}|${t.volume ?? 0}` : "0";
|
|
1507
|
+
}
|
|
1508
|
+
function Tt(e, t) {
|
|
1509
|
+
return `${Z(e.params)}|${e.exchangeTimeZone ?? ""}|${e.sessionStart ?? ""}|${t ? e.interval ?? "" : ""}`;
|
|
1510
|
+
}
|
|
1511
|
+
function Et(e) {
|
|
1512
|
+
return {
|
|
1513
|
+
values: new r(),
|
|
1514
|
+
series: Array(e).fill(null),
|
|
1515
|
+
meta: { errors: [] }
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
function Dt(e, t) {
|
|
1519
|
+
let n = e.series;
|
|
1520
|
+
for (n.length > t && (n.length = t); n.length < t;) n.push(null);
|
|
1521
|
+
return e;
|
|
1522
|
+
}
|
|
1523
|
+
var Ot = class extends n {
|
|
1524
|
+
descriptor;
|
|
1525
|
+
worker = null;
|
|
1526
|
+
hosts = /* @__PURE__ */ new Set();
|
|
1527
|
+
entries = /* @__PURE__ */ new WeakMap();
|
|
1528
|
+
runs = /* @__PURE__ */ new Map();
|
|
1529
|
+
pending = [];
|
|
1530
|
+
due = /* @__PURE__ */ new Set();
|
|
1531
|
+
nextRun = 1;
|
|
1532
|
+
nextSeq = 1;
|
|
1533
|
+
timer = null;
|
|
1534
|
+
timeoutMs;
|
|
1535
|
+
constructor(e, t) {
|
|
1536
|
+
super(), this.script = e, this.options = t, this.descriptor = bt(e), this.timeoutMs = t.timeoutMs ?? wt;
|
|
1537
|
+
}
|
|
1538
|
+
connect(e) {
|
|
1539
|
+
return this.hosts.add(e), () => {
|
|
1540
|
+
this.hosts.delete(e);
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
release(e) {
|
|
1544
|
+
let t = this.entries.get(e);
|
|
1545
|
+
t && (this.entries.delete(e), this.drop(t), this.runs.size === 0 && this.stopWorker());
|
|
1546
|
+
}
|
|
1547
|
+
calculate(e, t) {
|
|
1548
|
+
let n = this.entries.get(t);
|
|
1549
|
+
return n && n.key === this.keyOf(t) && n.bars === e && (n.stopped || n.sent !== "" && n.sent === Q(e)) ? n.output : this.load(e, t, n).output;
|
|
1550
|
+
}
|
|
1551
|
+
update(e, t, n, r) {
|
|
1552
|
+
let i = this.entries.get(t);
|
|
1553
|
+
if (!i || i.output !== n || i.stopped || i.key !== this.keyOf(t) || i.bars !== e || i.sent === "") return null;
|
|
1554
|
+
if (r < i.length - 1 || r > i.length || e.length < i.length) return i.sent = "", null;
|
|
1555
|
+
for (let t = r; t < e.length; t++) {
|
|
1556
|
+
let n = t === i.length - 1 ? "tick" : "next";
|
|
1557
|
+
this.send(i, {
|
|
1558
|
+
type: n,
|
|
1559
|
+
run: i.run,
|
|
1560
|
+
seq: this.nextSeq++,
|
|
1561
|
+
bar: e[t]
|
|
1562
|
+
}), n === "next" && (i.length = t + 1);
|
|
1563
|
+
}
|
|
1564
|
+
return Dt(n, e.length), i.sent = Q(e), n;
|
|
1565
|
+
}
|
|
1566
|
+
keyOf(e) {
|
|
1567
|
+
return Tt(e, this.descriptor.readsInterval === !0);
|
|
1568
|
+
}
|
|
1569
|
+
load(e, t, n) {
|
|
1570
|
+
n && this.drop(n);
|
|
1571
|
+
let r = {
|
|
1572
|
+
run: this.nextRun++,
|
|
1573
|
+
config: t,
|
|
1574
|
+
key: this.keyOf(t),
|
|
1575
|
+
bars: e,
|
|
1576
|
+
output: n ? Dt(n.output, e.length) : Et(e.length),
|
|
1577
|
+
length: e.length,
|
|
1578
|
+
sent: Q(e),
|
|
1579
|
+
stopped: !1
|
|
1580
|
+
};
|
|
1581
|
+
return this.entries.set(t, r), this.runs.set(r.run, r), this.send(r, {
|
|
1582
|
+
type: "load",
|
|
1583
|
+
run: r.run,
|
|
1584
|
+
seq: this.nextSeq++,
|
|
1585
|
+
script: this.script.id,
|
|
1586
|
+
params: { ...t.params },
|
|
1587
|
+
options: vt(t, this.options.limits),
|
|
1588
|
+
bars: e.map((e) => ({ ...e }))
|
|
1589
|
+
}), r;
|
|
1590
|
+
}
|
|
1591
|
+
drop(e) {
|
|
1592
|
+
this.runs.delete(e.run) && this.worker?.postMessage({
|
|
1593
|
+
type: "drop",
|
|
1594
|
+
run: e.run
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
send(e, t) {
|
|
1598
|
+
this.pending.push(e.run), this.ensureWorker().postMessage(t), this.pending.length === 1 && this.armTimer();
|
|
1599
|
+
}
|
|
1600
|
+
ensureWorker() {
|
|
1601
|
+
if (this.worker) return this.worker;
|
|
1602
|
+
let e = this.options.spawn();
|
|
1603
|
+
return e.addEventListener("message", (t) => {
|
|
1604
|
+
this.worker === e && this.receive(t.data);
|
|
1605
|
+
}), this.worker = e, e;
|
|
1606
|
+
}
|
|
1607
|
+
stopWorker() {
|
|
1608
|
+
this.timer && clearTimeout(this.timer), this.timer = null, this.pending = [], this.worker?.terminate(), this.worker = null;
|
|
1609
|
+
}
|
|
1610
|
+
armTimer() {
|
|
1611
|
+
this.timer && clearTimeout(this.timer), this.timer = setTimeout(() => this.timedOut(), this.timeoutMs);
|
|
1612
|
+
}
|
|
1613
|
+
receive(e) {
|
|
1614
|
+
this.pending.shift(), this.timer && clearTimeout(this.timer), this.timer = null, this.pending.length > 0 && this.armTimer();
|
|
1615
|
+
let t = this.runs.get(e.run);
|
|
1616
|
+
t && (e.type === "patch" ? this.apply(t, e.from, e.points, e.palette, e.drawings, e.errors) : this.stop(t, {
|
|
1617
|
+
bar: Math.max(0, t.length - 1),
|
|
1618
|
+
message: e.message
|
|
1619
|
+
}), this.recompute(t));
|
|
1620
|
+
}
|
|
1621
|
+
apply(e, t, n, r, i, a) {
|
|
1622
|
+
let o = e.output, s = o.series;
|
|
1623
|
+
t === 0 && (o.values.clear(), s.fill(null));
|
|
1624
|
+
for (let r = 0; r < n.length; r++) {
|
|
1625
|
+
let i = t + r;
|
|
1626
|
+
if (i >= e.bars.length) break;
|
|
1627
|
+
for (; s.length <= i;) s.push(null);
|
|
1628
|
+
this.writePoint(o, e.bars, i, n[r]);
|
|
1629
|
+
}
|
|
1630
|
+
o.palette = r, o.drawings = i ?? [], o.meta = {
|
|
1631
|
+
...o.meta,
|
|
1632
|
+
errors: a
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
timedOut() {
|
|
1636
|
+
this.timer = null;
|
|
1637
|
+
let e = this.pending[0];
|
|
1638
|
+
this.stopWorker();
|
|
1639
|
+
let t = [...this.runs.values()];
|
|
1640
|
+
this.runs.clear();
|
|
1641
|
+
for (let n of t) n.run === e ? this.stop(n, {
|
|
1642
|
+
bar: Math.max(0, n.length - 1),
|
|
1643
|
+
message: `the script did not answer within ${this.timeoutMs} ms, and was stopped`,
|
|
1644
|
+
limit: "time"
|
|
1645
|
+
}) : n.sent = "", this.recompute(n);
|
|
1646
|
+
}
|
|
1647
|
+
stop(e, t) {
|
|
1648
|
+
e.stopped = !0, this.runs.delete(e.run), e.output.meta = {
|
|
1649
|
+
...e.output.meta,
|
|
1650
|
+
errors: [t]
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
recompute(e) {
|
|
1654
|
+
this.due.size === 0 && queueMicrotask(() => this.flush()), this.due.add(e);
|
|
1655
|
+
}
|
|
1656
|
+
flush() {
|
|
1657
|
+
let e = [...this.due];
|
|
1658
|
+
this.due.clear();
|
|
1659
|
+
for (let t of e) if (this.entries.get(t.config) === t) for (let e of this.hosts) e.recompute(t.config);
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
function kt(e, t) {
|
|
1663
|
+
if (t.limits && b(t.limits), t.timeoutMs !== void 0 && !(t.timeoutMs > 0)) throw RangeError(`scriptWorkerIndicator: timeoutMs must be a positive number, not ${t.timeoutMs}`);
|
|
1664
|
+
return new Ot(e, t);
|
|
1665
|
+
}
|
|
1666
|
+
//#endregion
|
|
1667
|
+
//#region src/worker/serveScripts.ts
|
|
1668
|
+
function $(e) {
|
|
1669
|
+
return e instanceof Error ? e.message : String(e);
|
|
1670
|
+
}
|
|
1671
|
+
function At(e, t, n, r) {
|
|
1672
|
+
let i = n.output, a = [];
|
|
1673
|
+
for (let e = r; e < i.length; e++) a.push(mt(i, e));
|
|
1674
|
+
return {
|
|
1675
|
+
type: "patch",
|
|
1676
|
+
run: e,
|
|
1677
|
+
seq: t,
|
|
1678
|
+
from: r,
|
|
1679
|
+
points: a,
|
|
1680
|
+
palette: [...i.palette],
|
|
1681
|
+
drawings: [...i.drawings],
|
|
1682
|
+
errors: [...i.errors]
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
function jt(e, t) {
|
|
1686
|
+
let n = new Map(e.map((e) => [e.id, e])), r = /* @__PURE__ */ new Map(), i = (e, n, r) => t({
|
|
1687
|
+
type: "failed",
|
|
1688
|
+
run: e,
|
|
1689
|
+
seq: n,
|
|
1690
|
+
message: r
|
|
1691
|
+
});
|
|
1692
|
+
return (e) => {
|
|
1693
|
+
if (e.type === "drop") {
|
|
1694
|
+
r.delete(e.run);
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
if (e.type === "load") {
|
|
1698
|
+
r.delete(e.run);
|
|
1699
|
+
let a = n.get(e.script);
|
|
1700
|
+
if (!a) return i(e.run, e.seq, `no script '${e.script}' in this worker: give it to serveScripts`);
|
|
1701
|
+
try {
|
|
1702
|
+
let n = new T(a, e.params, e.options);
|
|
1703
|
+
n.load(e.bars), r.set(e.run, n), t(At(e.run, e.seq, n, 0));
|
|
1704
|
+
} catch (t) {
|
|
1705
|
+
i(e.run, e.seq, $(t));
|
|
1706
|
+
}
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
let a = r.get(e.run);
|
|
1710
|
+
if (!a) return i(e.run, e.seq, `no run ${e.run} here: load it first`);
|
|
1711
|
+
let o = a.length - 1;
|
|
1712
|
+
try {
|
|
1713
|
+
e.type === "tick" ? a.tick(e.bar) : a.next(e.bar), t(At(e.run, e.seq, a, Math.max(0, o)));
|
|
1714
|
+
} catch (t) {
|
|
1715
|
+
r.delete(e.run), i(e.run, e.seq, $(t));
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
function Mt(e, t = self) {
|
|
1720
|
+
let n = jt(e, (e) => t.postMessage(e));
|
|
1721
|
+
t.addEventListener("message", (e) => n(e.data));
|
|
1722
|
+
}
|
|
1723
|
+
//#endregion
|
|
1724
|
+
export { v as DEFAULT_LIMITS, y as ScriptLimitError, T as ScriptRun, jt as createScriptHandler, a as defineScript, Ct as scriptIndicator, kt as scriptWorkerIndicator, Mt as serveScripts, ut as ta };
|
|
1725
|
+
|
|
1726
|
+
//# sourceMappingURL=index.js.map
|