@hoox-sh/pynets 0.2.0 → 0.4.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/CHANGELOG.md +56 -0
- package/README.md +21 -12
- package/dist/browser.js +89 -84
- package/dist/index.js +21011 -12972
- package/package.json +1 -1
- package/src/ast/builder.ts +235 -12
- package/src/ast/nodes.ts +114 -4
- package/src/ast/unparse.ts +192 -17
- package/src/cli/rich.ts +1 -1
- package/src/generated/PinescriptLexer.interp +5 -1
- package/src/generated/PinescriptLexer.tokens +97 -95
- package/src/generated/PinescriptLexer.ts +512 -502
- package/src/generated/PinescriptParser.interp +8 -1
- package/src/generated/PinescriptParser.tokens +97 -95
- package/src/generated/PinescriptParser.ts +1907 -1287
- package/src/generated/PinescriptParserVisitor.ts +36 -1
- package/src/index.ts +1 -0
- package/src/runtime/array.ts +238 -68
- package/src/runtime/compile/collections.ts +191 -34
- package/src/runtime/compile/draw.ts +609 -19
- package/src/runtime/compile/emit.ts +346 -9
- package/src/runtime/compile/emit_call.ts +737 -44
- package/src/runtime/compile/runtime.ts +82 -2
- package/src/runtime/compile/strategy.ts +339 -6
- package/src/runtime/compile/types.ts +2 -0
- package/src/runtime/drawings.ts +405 -8
- package/src/runtime/interpret.ts +2352 -277
- package/src/runtime/matrix.ts +371 -42
- package/src/runtime/strategy.ts +695 -33
- package/src/runtime/ta.ts +1046 -20
- package/src/runtime/timeframe.ts +199 -0
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Compile-path drawings. Wraps DrawingBook; extras go on `__drawings`.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { PineArray } from "../array.ts";
|
|
8
|
+
import { DrawingBook, type DrawingEvent, type DrawingKind } from "../drawings.ts";
|
|
8
9
|
import { naNum } from "./helpers.ts";
|
|
9
10
|
|
|
10
11
|
function n(v: unknown, fallback = 0): number {
|
|
@@ -16,31 +17,123 @@ function idOf(v: unknown): number {
|
|
|
16
17
|
return n(v, -1);
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/** Null id stays null (id 0 is a real drawing). */
|
|
21
|
+
function idNum(v: unknown): number | null {
|
|
22
|
+
if (typeof v === "boolean") return v ? 1 : 0;
|
|
23
|
+
if (typeof v === "number" && Number.isFinite(v)) return Math.trunc(v);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function putNum(extra: Record<string, unknown>, key: string, v: unknown): void {
|
|
28
|
+
const x = naNum(v);
|
|
29
|
+
if (x != null) extra[key] = x;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function pointsOf(v: unknown): unknown[] {
|
|
33
|
+
if (v instanceof PineArray) return v.toValues().filter((p) => p != null);
|
|
34
|
+
if (Array.isArray(v)) return v.filter((p) => p != null);
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type ChartPoint = {
|
|
39
|
+
__chartPoint: true;
|
|
40
|
+
index: number | null;
|
|
41
|
+
time: number | null;
|
|
42
|
+
x: number | null;
|
|
43
|
+
y: number | null;
|
|
44
|
+
price: number | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function isPoint(v: unknown): v is ChartPoint {
|
|
48
|
+
return typeof v === "object" && v !== null && (v as ChartPoint).__chartPoint === true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function makePoint(index: number | null, time: number | null, price: number | null): ChartPoint {
|
|
52
|
+
return { __chartPoint: true, index, time, x: index ?? time, y: price, price };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function pointXY(v: unknown): { x: number; y: number } | null {
|
|
56
|
+
if (!isPoint(v)) return null;
|
|
57
|
+
return { x: v.index ?? v.time ?? v.x ?? 0, y: v.price ?? v.y ?? 0 };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function truthy(v: unknown): boolean {
|
|
61
|
+
if (typeof v === "boolean") return v;
|
|
62
|
+
if (typeof v === "number") return Number.isFinite(v) && v !== 0;
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function alertText(v: unknown, fallback: string): string {
|
|
67
|
+
if (v == null) return fallback;
|
|
68
|
+
if (typeof v === "string") return v;
|
|
69
|
+
if (typeof v === "boolean") return v ? "1" : "0";
|
|
70
|
+
if (typeof v === "number") return Number.isFinite(v) ? String(v) : fallback;
|
|
71
|
+
return fallback;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const DRAW_KINDS = new Set<DrawingKind>(["line", "label", "box", "table", "polyline", "linefill"]);
|
|
75
|
+
|
|
19
76
|
export class CompileDraw {
|
|
20
77
|
readonly book = new DrawingBook();
|
|
78
|
+
private alertKeys = new Map<string, number>();
|
|
21
79
|
|
|
22
|
-
label_new(bar: unknown, text?: unknown): number {
|
|
23
|
-
|
|
80
|
+
label_new(bar: unknown, text?: unknown, x?: unknown, y?: unknown): number {
|
|
81
|
+
const extra: Record<string, unknown> = {};
|
|
82
|
+
putNum(extra, "x", x);
|
|
83
|
+
putNum(extra, "y", y);
|
|
84
|
+
const t = text == null ? "" : String(text);
|
|
85
|
+
return this.book.labelNew(n(bar, 0), t, Object.keys(extra).length ? extra : undefined);
|
|
24
86
|
}
|
|
25
87
|
|
|
26
|
-
line_new(bar: unknown): number {
|
|
27
|
-
|
|
88
|
+
line_new(bar: unknown, x1?: unknown, y1?: unknown, x2?: unknown, y2?: unknown): number {
|
|
89
|
+
const extra: Record<string, unknown> = {};
|
|
90
|
+
putNum(extra, "x1", x1);
|
|
91
|
+
putNum(extra, "y1", y1);
|
|
92
|
+
putNum(extra, "x2", x2);
|
|
93
|
+
putNum(extra, "y2", y2);
|
|
94
|
+
return this.book.lineNew(n(bar, 0), Object.keys(extra).length ? extra : undefined);
|
|
28
95
|
}
|
|
29
96
|
|
|
30
|
-
box_new(bar: unknown): number {
|
|
31
|
-
|
|
97
|
+
box_new(bar: unknown, left?: unknown, top?: unknown, right?: unknown, bottom?: unknown): number {
|
|
98
|
+
const extra: Record<string, unknown> = {};
|
|
99
|
+
putNum(extra, "left", left);
|
|
100
|
+
putNum(extra, "top", top);
|
|
101
|
+
putNum(extra, "right", right);
|
|
102
|
+
putNum(extra, "bottom", bottom);
|
|
103
|
+
return this.book.boxNew(n(bar, 0), Object.keys(extra).length ? extra : undefined);
|
|
32
104
|
}
|
|
33
105
|
|
|
34
106
|
table_new(bar: unknown): number {
|
|
35
107
|
return this.book.tableNew(n(bar, 0));
|
|
36
108
|
}
|
|
37
109
|
|
|
38
|
-
polyline_new(bar: unknown): number {
|
|
39
|
-
|
|
110
|
+
polyline_new(bar: unknown, points?: unknown): number {
|
|
111
|
+
const pts = pointsOf(points);
|
|
112
|
+
return this.book.polylineNew(n(bar, 0), pts.length ? { points: pts } : undefined);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
linefill_new(bar: unknown, id1?: unknown, id2?: unknown, color?: unknown): number {
|
|
116
|
+
const extra: Record<string, unknown> = {};
|
|
117
|
+
const a = idNum(id1);
|
|
118
|
+
const b = idNum(id2);
|
|
119
|
+
if (a != null) extra.id1 = a;
|
|
120
|
+
if (b != null) extra.id2 = b;
|
|
121
|
+
if (color != null) extra.color = color;
|
|
122
|
+
return this.book.linefillNew(n(bar, 0), Object.keys(extra).length ? extra : undefined);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
all(kind: unknown): PineArray {
|
|
126
|
+
const arr = new PineArray();
|
|
127
|
+
if (typeof kind === "string" && DRAW_KINDS.has(kind as DrawingKind)) {
|
|
128
|
+
for (const id of this.book.allIds(kind as DrawingKind)) arr.push(id);
|
|
129
|
+
}
|
|
130
|
+
return arr;
|
|
40
131
|
}
|
|
41
132
|
|
|
42
|
-
|
|
43
|
-
|
|
133
|
+
copy(id: unknown): number | null {
|
|
134
|
+
const i = idNum(id);
|
|
135
|
+
if (i == null) return null;
|
|
136
|
+
return this.book.copy(i);
|
|
44
137
|
}
|
|
45
138
|
|
|
46
139
|
label_set_text(id: unknown, text?: unknown): void {
|
|
@@ -111,16 +204,42 @@ export class CompileDraw {
|
|
|
111
204
|
this.book.labelSetTooltip(idOf(id), tooltip);
|
|
112
205
|
}
|
|
113
206
|
|
|
114
|
-
label_get_x(id: unknown): number
|
|
115
|
-
|
|
207
|
+
label_get_x(id: unknown): number {
|
|
208
|
+
const i = idNum(id);
|
|
209
|
+
if (i == null) return 0;
|
|
210
|
+
return this.book.labelGetX(i) ?? 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
label_get_y(id: unknown): number {
|
|
214
|
+
const i = idNum(id);
|
|
215
|
+
if (i == null) return 0;
|
|
216
|
+
return this.book.labelGetY(i) ?? 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
label_get_text(id: unknown): string {
|
|
220
|
+
const i = idNum(id);
|
|
221
|
+
if (i == null) return "";
|
|
222
|
+
return this.book.labelGetText(i) ?? "";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
line_get_x1(id: unknown): number | null {
|
|
226
|
+
const i = idNum(id);
|
|
227
|
+
return i == null ? null : this.book.lineGetX1(i);
|
|
116
228
|
}
|
|
117
229
|
|
|
118
|
-
|
|
119
|
-
|
|
230
|
+
line_get_y1(id: unknown): number | null {
|
|
231
|
+
const i = idNum(id);
|
|
232
|
+
return i == null ? null : this.book.lineGetY1(i);
|
|
120
233
|
}
|
|
121
234
|
|
|
122
|
-
|
|
123
|
-
|
|
235
|
+
line_get_x2(id: unknown): number | null {
|
|
236
|
+
const i = idNum(id);
|
|
237
|
+
return i == null ? null : this.book.lineGetX2(i);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
line_get_y2(id: unknown): number | null {
|
|
241
|
+
const i = idNum(id);
|
|
242
|
+
return i == null ? null : this.book.lineGetY2(i);
|
|
124
243
|
}
|
|
125
244
|
|
|
126
245
|
box_delete(id: unknown): void {
|
|
@@ -155,8 +274,17 @@ export class CompileDraw {
|
|
|
155
274
|
this.book.tableCell(idOf(id), column, row, text);
|
|
156
275
|
}
|
|
157
276
|
|
|
158
|
-
table_cell_set_text(id: unknown,
|
|
159
|
-
|
|
277
|
+
table_cell_set_text(id: unknown, row?: unknown, column?: unknown, text?: unknown): null {
|
|
278
|
+
const i = idNum(id);
|
|
279
|
+
if (i == null) return null;
|
|
280
|
+
this.book.tableCellSetText(i, column, row, text == null ? "" : String(text));
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
table_cell_get_text(id: unknown, row?: unknown, column?: unknown): string {
|
|
285
|
+
const i = idNum(id);
|
|
286
|
+
if (i == null) return "";
|
|
287
|
+
return this.book.tableCellGetText(i, column, row) ?? "";
|
|
160
288
|
}
|
|
161
289
|
|
|
162
290
|
table_set_position(id: unknown, position?: unknown): void {
|
|
@@ -171,6 +299,468 @@ export class CompileDraw {
|
|
|
171
299
|
this.book.alert(n(bar, 0), message == null ? "" : String(message));
|
|
172
300
|
}
|
|
173
301
|
|
|
302
|
+
/** Interpret `fireAlertCondition`: truthy condition, once per bar, source tag. */
|
|
303
|
+
alertcondition(bar: unknown, condition: unknown, title?: unknown, message?: unknown): null {
|
|
304
|
+
if (!truthy(condition)) return null;
|
|
305
|
+
const t = alertText(title, "Alert");
|
|
306
|
+
const m = alertText(message, "Alert");
|
|
307
|
+
const b = n(bar, 0);
|
|
308
|
+
const key = `alertcondition|${t}|${m}|once_per_bar`;
|
|
309
|
+
if (this.alertKeys.get(key) === b) return null;
|
|
310
|
+
this.alertKeys.set(key, b);
|
|
311
|
+
this.book.alert(b, m);
|
|
312
|
+
const ev = this.book.items[this.book.items.length - 1];
|
|
313
|
+
if (ev != null) ev.extra = { source: "alertcondition", title: t, freq: "once_per_bar" };
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
line_set_x1(id: unknown, x?: unknown): null {
|
|
318
|
+
return this.kindNum("lineSetX1", id, x);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
line_set_y1(id: unknown, y?: unknown): null {
|
|
322
|
+
return this.kindNum("lineSetY1", id, y);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
line_set_x2(id: unknown, x?: unknown): null {
|
|
326
|
+
return this.kindNum("lineSetX2", id, x);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
line_set_y2(id: unknown, y?: unknown): null {
|
|
330
|
+
return this.kindNum("lineSetY2", id, y);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
line_set_xloc(id: unknown, xloc?: unknown): null {
|
|
334
|
+
return this.kindAny("lineSetXloc", id, xloc);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
line_set_first_point(id: unknown, point?: unknown): null {
|
|
338
|
+
const i = idNum(id);
|
|
339
|
+
const xy = pointXY(point);
|
|
340
|
+
if (i != null && xy) this.book.lineSetXy1(i, xy.x, xy.y);
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
line_set_second_point(id: unknown, point?: unknown): null {
|
|
345
|
+
const i = idNum(id);
|
|
346
|
+
const xy = pointXY(point);
|
|
347
|
+
if (i != null && xy) this.book.lineSetXy2(i, xy.x, xy.y);
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
label_set_x(id: unknown, x?: unknown): null {
|
|
352
|
+
return this.kindAny("labelSetX", id, x);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
label_set_y(id: unknown, y?: unknown): null {
|
|
356
|
+
return this.kindAny("labelSetY", id, y);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
label_set_textcolor(id: unknown, color?: unknown): null {
|
|
360
|
+
return this.kindAny("labelSetTextcolor", id, color);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
label_set_text_font_family(id: unknown, font?: unknown): null {
|
|
364
|
+
return this.kindAny("labelSetTextFontFamily", id, font);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
label_set_text_halign(id: unknown, halign?: unknown): null {
|
|
368
|
+
return this.kindAny("labelSetTextHalign", id, halign);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
label_set_text_valign(id: unknown, valign?: unknown): null {
|
|
372
|
+
return this.kindAny("labelSetTextValign", id, valign);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
label_set_text_size(id: unknown, size?: unknown): null {
|
|
376
|
+
return this.kindAny("labelSetTextSize", id, size);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
label_set_text_formatting(id: unknown, formatting?: unknown): null {
|
|
380
|
+
return this.kindAny("labelSetTextFormatting", id, formatting);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
label_set_border_color(id: unknown, color?: unknown): null {
|
|
384
|
+
return this.kindAny("labelSetBorderColor", id, color);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
label_set_border_width(id: unknown, width?: unknown): null {
|
|
388
|
+
return this.kindAny("labelSetBorderWidth", id, width);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
label_set_border_style(id: unknown, style?: unknown): null {
|
|
392
|
+
return this.kindAny("labelSetBorderStyle", id, style);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
label_set_xloc(id: unknown, xloc?: unknown): null {
|
|
396
|
+
return this.kindAny("labelSetXloc", id, xloc);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
label_set_yloc(id: unknown, yloc?: unknown): null {
|
|
400
|
+
return this.kindAny("labelSetYloc", id, yloc);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
label_set_point(id: unknown, point?: unknown): null {
|
|
404
|
+
const i = idNum(id);
|
|
405
|
+
const xy = pointXY(point);
|
|
406
|
+
if (i != null && xy) this.book.labelSetXy(i, xy.x, xy.y);
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
box_get_left(id: unknown): number {
|
|
411
|
+
return this.boxGet("boxGetLeft", id);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
box_get_right(id: unknown): number {
|
|
415
|
+
return this.boxGet("boxGetRight", id);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
box_get_top(id: unknown): number {
|
|
419
|
+
return this.boxGet("boxGetTop", id);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
box_get_bottom(id: unknown): number {
|
|
423
|
+
return this.boxGet("boxGetBottom", id);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
box_set_left(id: unknown, left?: unknown): null {
|
|
427
|
+
return this.kindAny("boxSetLeft", id, left);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
box_set_right(id: unknown, right?: unknown): null {
|
|
431
|
+
return this.kindAny("boxSetRight", id, right);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
box_set_top(id: unknown, top?: unknown): null {
|
|
435
|
+
return this.kindAny("boxSetTop", id, top);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
box_set_bottom(id: unknown, bottom?: unknown): null {
|
|
439
|
+
return this.kindAny("boxSetBottom", id, bottom);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
box_set_border_width(id: unknown, width?: unknown): null {
|
|
443
|
+
return this.kindAny("boxSetBorderWidth", id, width);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
box_set_border_style(id: unknown, style?: unknown): null {
|
|
447
|
+
return this.kindAny("boxSetBorderStyle", id, style);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
box_set_closed(id: unknown, closed?: unknown): null {
|
|
451
|
+
return this.kindAny("boxSetClosed", id, closed);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
box_set_rightbottom(id: unknown, right?: unknown, bottom?: unknown): null {
|
|
455
|
+
const i = idNum(id);
|
|
456
|
+
if (i != null) this.book.boxSetRightBottom(i, right, bottom);
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
box_set_text_color(id: unknown, color?: unknown): null {
|
|
461
|
+
return this.kindAny("boxSetTextColor", id, color);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
box_set_text_font_family(id: unknown, font?: unknown): null {
|
|
465
|
+
return this.kindAny("boxSetTextFontFamily", id, font);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
box_set_text_halign(id: unknown, halign?: unknown): null {
|
|
469
|
+
return this.kindAny("boxSetTextHalign", id, halign);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
box_set_text_valign(id: unknown, valign?: unknown): null {
|
|
473
|
+
return this.kindAny("boxSetTextValign", id, valign);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
box_set_text_size(id: unknown, size?: unknown): null {
|
|
477
|
+
return this.kindAny("boxSetTextSize", id, size);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
box_set_text_formatting(id: unknown, formatting?: unknown): null {
|
|
481
|
+
return this.kindAny("boxSetTextFormatting", id, formatting);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
box_set_text_wrap(id: unknown, wrap?: unknown): null {
|
|
485
|
+
return this.kindAny("boxSetTextWrap", id, wrap);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
box_set_xloc(id: unknown, left?: unknown, right?: unknown, xloc?: unknown): null {
|
|
489
|
+
const i = idNum(id);
|
|
490
|
+
if (i == null) return null;
|
|
491
|
+
this.book.boxSetLeft(i, left);
|
|
492
|
+
this.book.boxSetRight(i, right);
|
|
493
|
+
this.book.boxSetXloc(i, xloc);
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
box_set_top_left_point(id: unknown, point?: unknown): null {
|
|
498
|
+
const i = idNum(id);
|
|
499
|
+
const xy = pointXY(point);
|
|
500
|
+
if (i != null && xy) this.book.boxSetLeftTop(i, xy.x, xy.y);
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
box_set_bottom_right_point(id: unknown, point?: unknown): null {
|
|
505
|
+
const i = idNum(id);
|
|
506
|
+
const xy = pointXY(point);
|
|
507
|
+
if (i != null && xy) this.book.boxSetRightBottom(i, xy.x, xy.y);
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
table_delete(id: unknown): null {
|
|
512
|
+
const i = idNum(id);
|
|
513
|
+
if (i != null) this.book.tableDelete(i);
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
table_set_bgcolor(id: unknown, color?: unknown): null {
|
|
518
|
+
return this.kindAny("tableSetBgcolor", id, color);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
table_set_border_color(id: unknown, color?: unknown): null {
|
|
522
|
+
return this.kindAny("tableSetBorderColor", id, color);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
table_set_border_width(id: unknown, width?: unknown): null {
|
|
526
|
+
return this.kindAny("tableSetBorderWidth", id, width);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
table_set_frame_color(id: unknown, color?: unknown): null {
|
|
530
|
+
return this.kindAny("tableSetFrameColor", id, color);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
table_set_frame_width(id: unknown, width?: unknown): null {
|
|
534
|
+
return this.kindAny("tableSetFrameWidth", id, width);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
table_clear(id: unknown, startRow?: unknown, startCol?: unknown, endRow?: unknown, endCol?: unknown): null {
|
|
538
|
+
const i = idNum(id);
|
|
539
|
+
if (i == null) return null;
|
|
540
|
+
if (arguments.length < 2) this.book.tableClear(i);
|
|
541
|
+
else this.book.tableClear(i, startRow, startCol, endRow, endCol);
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
table_merge_cells(id: unknown, startRow?: unknown, startCol?: unknown, endRow?: unknown, endCol?: unknown): null {
|
|
546
|
+
const i = idNum(id);
|
|
547
|
+
if (i != null) this.book.tableMergeCells(i, startRow, startCol, endRow, endCol);
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
table_cell_set_text_color(id: unknown, row?: unknown, column?: unknown, value?: unknown): null {
|
|
552
|
+
return this.cellField(id, column, row, "text_color", value);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
table_cell_set_bgcolor(id: unknown, row?: unknown, column?: unknown, value?: unknown): null {
|
|
556
|
+
return this.cellField(id, column, row, "bgcolor", value);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
table_cell_set_border_color(id: unknown, row?: unknown, column?: unknown, value?: unknown): null {
|
|
560
|
+
return this.cellField(id, column, row, "border_color", value);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
table_cell_set_border_width(id: unknown, row?: unknown, column?: unknown, value?: unknown): null {
|
|
564
|
+
return this.cellField(id, column, row, "border_width", value);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
table_cell_set_tooltip(id: unknown, row?: unknown, column?: unknown, value?: unknown): null {
|
|
568
|
+
return this.cellField(id, column, row, "tooltip", value);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
table_cell_set_width(id: unknown, column?: unknown, row?: unknown, value?: unknown): null {
|
|
572
|
+
return this.cellField(id, column, row, "width", value);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
table_cell_set_height(id: unknown, column?: unknown, row?: unknown, value?: unknown): null {
|
|
576
|
+
return this.cellField(id, column, row, "height", value);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
table_cell_set_text_halign(id: unknown, column?: unknown, row?: unknown, value?: unknown): null {
|
|
580
|
+
return this.cellField(id, column, row, "text_halign", value);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
table_cell_set_text_valign(id: unknown, column?: unknown, row?: unknown, value?: unknown): null {
|
|
584
|
+
return this.cellField(id, column, row, "text_valign", value);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
table_cell_set_text_size(id: unknown, column?: unknown, row?: unknown, value?: unknown): null {
|
|
588
|
+
return this.cellField(id, column, row, "text_size", value);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
table_cell_set_text_font_family(id: unknown, column?: unknown, row?: unknown, value?: unknown): null {
|
|
592
|
+
return this.cellField(id, column, row, "text_font_family", value);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
table_cell_set_text_formatting(id: unknown, column?: unknown, row?: unknown, value?: unknown): null {
|
|
596
|
+
return this.cellField(id, column, row, "text_formatting", value);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
polyline_delete(id: unknown): null {
|
|
600
|
+
const i = idNum(id);
|
|
601
|
+
if (i != null) this.book.polylineDelete(i);
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
polyline_get_points(id: unknown): PineArray {
|
|
606
|
+
const arr = new PineArray();
|
|
607
|
+
const i = idNum(id);
|
|
608
|
+
if (i == null) return arr;
|
|
609
|
+
for (const p of this.book.polylineGetPoints(i)) arr.push(p);
|
|
610
|
+
return arr;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
polyline_set_points(id: unknown, points?: unknown): null {
|
|
614
|
+
const i = idNum(id);
|
|
615
|
+
if (i != null) this.book.polylineSetPoints(i, pointsOf(points));
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
polyline_set_line_color(id: unknown, color?: unknown): null {
|
|
620
|
+
return this.kindAny("polylineSetLineColor", id, color);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
polyline_set_line_width(id: unknown, width?: unknown): null {
|
|
624
|
+
return this.kindAny("polylineSetLineWidth", id, width);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
polyline_set_line_style(id: unknown, style?: unknown): null {
|
|
628
|
+
return this.kindAny("polylineSetLineStyle", id, style);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
polyline_set_fill_color(id: unknown, color?: unknown): null {
|
|
632
|
+
return this.kindAny("polylineSetFillColor", id, color);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
polyline_set_curved(id: unknown, curved?: unknown): null {
|
|
636
|
+
return this.kindAny("polylineSetCurved", id, curved);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
polyline_set_force_overlay(id: unknown, force?: unknown): null {
|
|
640
|
+
return this.kindAny("polylineSetForceOverlay", id, force);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
polyline_set_closed(id: unknown, closed?: unknown): null {
|
|
644
|
+
return this.kindAny("polylineSetClosed", id, closed);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
polyline_set_xloc(id: unknown, xloc?: unknown): null {
|
|
648
|
+
return this.kindAny("polylineSetXloc", id, xloc);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
linefill_delete(id: unknown): null {
|
|
652
|
+
const i = idNum(id);
|
|
653
|
+
if (i != null) this.book.linefillDelete(i);
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
linefill_get_line1(id: unknown): number | null {
|
|
658
|
+
const i = idNum(id);
|
|
659
|
+
return i == null ? null : this.book.linefillGetLine1(i);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
linefill_get_line2(id: unknown): number | null {
|
|
663
|
+
const i = idNum(id);
|
|
664
|
+
return i == null ? null : this.book.linefillGetLine2(i);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
point_new(time: unknown, price: unknown): ChartPoint | null {
|
|
668
|
+
const p = naNum(price);
|
|
669
|
+
if (p == null) return null;
|
|
670
|
+
return makePoint(null, naNum(time), p);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
point_from_index(index: unknown, price: unknown): ChartPoint | null {
|
|
674
|
+
const ix = naNum(index);
|
|
675
|
+
const p = naNum(price);
|
|
676
|
+
if (ix == null || p == null) return null;
|
|
677
|
+
return makePoint(Math.trunc(ix), null, p);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
point_now(bar: unknown, time: unknown, price: unknown): ChartPoint | null {
|
|
681
|
+
const p = naNum(price);
|
|
682
|
+
if (p == null) return null;
|
|
683
|
+
const ix = naNum(bar);
|
|
684
|
+
return makePoint(ix == null ? null : Math.trunc(ix), naNum(time), p);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
point_copy(raw: unknown): ChartPoint {
|
|
688
|
+
if (isPoint(raw)) return makePoint(raw.index, raw.time, raw.price);
|
|
689
|
+
return makePoint(null, null, 0);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
private kindNum(method: "lineSetX1" | "lineSetY1" | "lineSetX2" | "lineSetY2", id: unknown, value: unknown): null {
|
|
693
|
+
const i = idNum(id);
|
|
694
|
+
if (i != null) this.book[method](i, value);
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
private kindAny(
|
|
699
|
+
method:
|
|
700
|
+
| "lineSetXloc"
|
|
701
|
+
| "labelSetX"
|
|
702
|
+
| "labelSetY"
|
|
703
|
+
| "labelSetTextcolor"
|
|
704
|
+
| "labelSetTextFontFamily"
|
|
705
|
+
| "labelSetTextHalign"
|
|
706
|
+
| "labelSetTextValign"
|
|
707
|
+
| "labelSetTextSize"
|
|
708
|
+
| "labelSetTextFormatting"
|
|
709
|
+
| "labelSetBorderColor"
|
|
710
|
+
| "labelSetBorderWidth"
|
|
711
|
+
| "labelSetBorderStyle"
|
|
712
|
+
| "labelSetXloc"
|
|
713
|
+
| "labelSetYloc"
|
|
714
|
+
| "boxSetLeft"
|
|
715
|
+
| "boxSetRight"
|
|
716
|
+
| "boxSetTop"
|
|
717
|
+
| "boxSetBottom"
|
|
718
|
+
| "boxSetBorderWidth"
|
|
719
|
+
| "boxSetBorderStyle"
|
|
720
|
+
| "boxSetClosed"
|
|
721
|
+
| "boxSetTextColor"
|
|
722
|
+
| "boxSetTextFontFamily"
|
|
723
|
+
| "boxSetTextHalign"
|
|
724
|
+
| "boxSetTextValign"
|
|
725
|
+
| "boxSetTextSize"
|
|
726
|
+
| "boxSetTextFormatting"
|
|
727
|
+
| "boxSetTextWrap"
|
|
728
|
+
| "tableSetBgcolor"
|
|
729
|
+
| "tableSetBorderColor"
|
|
730
|
+
| "tableSetBorderWidth"
|
|
731
|
+
| "tableSetFrameColor"
|
|
732
|
+
| "tableSetFrameWidth"
|
|
733
|
+
| "polylineSetLineColor"
|
|
734
|
+
| "polylineSetLineWidth"
|
|
735
|
+
| "polylineSetLineStyle"
|
|
736
|
+
| "polylineSetFillColor"
|
|
737
|
+
| "polylineSetCurved"
|
|
738
|
+
| "polylineSetForceOverlay"
|
|
739
|
+
| "polylineSetClosed"
|
|
740
|
+
| "polylineSetXloc",
|
|
741
|
+
id: unknown,
|
|
742
|
+
value: unknown,
|
|
743
|
+
): null {
|
|
744
|
+
const i = idNum(id);
|
|
745
|
+
if (i != null) this.book[method](i, value);
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
private boxGet(
|
|
750
|
+
method: "boxGetLeft" | "boxGetRight" | "boxGetTop" | "boxGetBottom",
|
|
751
|
+
id: unknown,
|
|
752
|
+
): number {
|
|
753
|
+
const i = idNum(id);
|
|
754
|
+
if (i == null) return 0;
|
|
755
|
+
return this.book[method](i) ?? 0;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
private cellField(id: unknown, column: unknown, row: unknown, field: string, value: unknown): null {
|
|
759
|
+
const i = idNum(id);
|
|
760
|
+
if (i != null) this.book.tableCellSetField(i, column, row, field, value);
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
763
|
+
|
|
174
764
|
extras(): { __drawings: DrawingEvent[] } {
|
|
175
765
|
return { __drawings: this.book.items.slice() };
|
|
176
766
|
}
|