oakscriptjs 0.9.6 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/array/index.d.ts +9 -23
  3. package/dist/cjs/array/index.d.ts.map +1 -1
  4. package/dist/cjs/array/index.js +4 -0
  5. package/dist/cjs/array/index.js.map +2 -2
  6. package/dist/cjs/drawing/bar-time.d.ts +24 -0
  7. package/dist/cjs/drawing/bar-time.d.ts.map +1 -0
  8. package/dist/cjs/drawing/bar-time.js +47 -0
  9. package/dist/cjs/drawing/bar-time.js.map +7 -0
  10. package/dist/cjs/drawing/output.d.ts +32 -0
  11. package/dist/cjs/drawing/output.d.ts.map +1 -0
  12. package/dist/cjs/drawing/output.js +184 -0
  13. package/dist/cjs/drawing/output.js.map +7 -0
  14. package/dist/cjs/drawing/registry.d.ts +5 -4
  15. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  16. package/dist/cjs/drawing/registry.js +11 -2
  17. package/dist/cjs/drawing/registry.js.map +2 -2
  18. package/dist/cjs/index.d.ts +7 -3
  19. package/dist/cjs/index.d.ts.map +1 -1
  20. package/dist/cjs/index.js +11 -2
  21. package/dist/cjs/index.js.map +2 -2
  22. package/dist/cjs/polyline/index.d.ts +3 -5
  23. package/dist/cjs/polyline/index.d.ts.map +1 -1
  24. package/dist/cjs/polyline/index.js +0 -5
  25. package/dist/cjs/polyline/index.js.map +2 -2
  26. package/dist/cjs/runtime/index.d.ts +2 -1
  27. package/dist/cjs/runtime/index.d.ts.map +1 -1
  28. package/dist/cjs/runtime/index.js +2 -0
  29. package/dist/cjs/runtime/index.js.map +2 -2
  30. package/dist/cjs/runtime/input-active.d.ts +27 -0
  31. package/dist/cjs/runtime/input-active.d.ts.map +1 -0
  32. package/dist/cjs/runtime/input-active.js +44 -0
  33. package/dist/cjs/runtime/input-active.js.map +7 -0
  34. package/dist/cjs/runtime/types.d.ts +51 -2
  35. package/dist/cjs/runtime/types.d.ts.map +1 -1
  36. package/dist/cjs/runtime/types.js.map +1 -1
  37. package/dist/cjs/script/index.d.ts +104 -8
  38. package/dist/cjs/script/index.d.ts.map +1 -1
  39. package/dist/cjs/script/index.js +163 -28
  40. package/dist/cjs/script/index.js.map +3 -3
  41. package/dist/cjs/str/index.d.ts +9 -3
  42. package/dist/cjs/str/index.d.ts.map +1 -1
  43. package/dist/cjs/str/index.js +11 -6
  44. package/dist/cjs/str/index.js.map +2 -2
  45. package/dist/cjs/str/numberformat.d.ts +6 -0
  46. package/dist/cjs/str/numberformat.d.ts.map +1 -1
  47. package/dist/cjs/str/numberformat.js +9 -1
  48. package/dist/cjs/str/numberformat.js.map +2 -2
  49. package/dist/cjs/table/index.d.ts +87 -0
  50. package/dist/cjs/table/index.d.ts.map +1 -0
  51. package/dist/cjs/table/index.js +150 -0
  52. package/dist/cjs/table/index.js.map +7 -0
  53. package/dist/cjs/text/index.d.ts +17 -2
  54. package/dist/cjs/text/index.d.ts.map +1 -1
  55. package/dist/cjs/text/index.js +15 -1
  56. package/dist/cjs/text/index.js.map +2 -2
  57. package/dist/cjs/types/index.d.ts +30 -1
  58. package/dist/cjs/types/index.d.ts.map +1 -1
  59. package/dist/cjs/types/index.js +12 -0
  60. package/dist/cjs/types/index.js.map +2 -2
  61. package/dist/cjs/types/metadata.d.ts +258 -26
  62. package/dist/cjs/types/metadata.d.ts.map +1 -1
  63. package/dist/cjs/types/metadata.js.map +1 -1
  64. package/dist/esm/array/index.d.ts +9 -23
  65. package/dist/esm/array/index.d.ts.map +1 -1
  66. package/dist/esm/array/index.js +10 -22
  67. package/dist/esm/array/index.js.map +1 -1
  68. package/dist/esm/drawing/bar-time.d.ts +24 -0
  69. package/dist/esm/drawing/bar-time.d.ts.map +1 -0
  70. package/dist/esm/drawing/bar-time.js +44 -0
  71. package/dist/esm/drawing/bar-time.js.map +1 -0
  72. package/dist/esm/drawing/output.d.ts +32 -0
  73. package/dist/esm/drawing/output.d.ts.map +1 -0
  74. package/dist/esm/drawing/output.js +190 -0
  75. package/dist/esm/drawing/output.js.map +1 -0
  76. package/dist/esm/drawing/registry.d.ts +5 -4
  77. package/dist/esm/drawing/registry.d.ts.map +1 -1
  78. package/dist/esm/drawing/registry.js +12 -2
  79. package/dist/esm/drawing/registry.js.map +1 -1
  80. package/dist/esm/index.d.ts +7 -3
  81. package/dist/esm/index.d.ts.map +1 -1
  82. package/dist/esm/index.js +8 -3
  83. package/dist/esm/index.js.map +1 -1
  84. package/dist/esm/polyline/index.d.ts +3 -5
  85. package/dist/esm/polyline/index.d.ts.map +1 -1
  86. package/dist/esm/polyline/index.js +3 -9
  87. package/dist/esm/polyline/index.js.map +1 -1
  88. package/dist/esm/runtime/index.d.ts +2 -1
  89. package/dist/esm/runtime/index.d.ts.map +1 -1
  90. package/dist/esm/runtime/index.js +1 -0
  91. package/dist/esm/runtime/index.js.map +1 -1
  92. package/dist/esm/runtime/input-active.d.ts +27 -0
  93. package/dist/esm/runtime/input-active.d.ts.map +1 -0
  94. package/dist/esm/runtime/input-active.js +54 -0
  95. package/dist/esm/runtime/input-active.js.map +1 -0
  96. package/dist/esm/runtime/types.d.ts +51 -2
  97. package/dist/esm/runtime/types.d.ts.map +1 -1
  98. package/dist/esm/script/index.d.ts +104 -8
  99. package/dist/esm/script/index.d.ts.map +1 -1
  100. package/dist/esm/script/index.js +194 -24
  101. package/dist/esm/script/index.js.map +1 -1
  102. package/dist/esm/str/index.d.ts +9 -3
  103. package/dist/esm/str/index.d.ts.map +1 -1
  104. package/dist/esm/str/index.js +25 -10
  105. package/dist/esm/str/index.js.map +1 -1
  106. package/dist/esm/str/numberformat.d.ts +6 -0
  107. package/dist/esm/str/numberformat.d.ts.map +1 -1
  108. package/dist/esm/str/numberformat.js +12 -0
  109. package/dist/esm/str/numberformat.js.map +1 -1
  110. package/dist/esm/table/index.d.ts +87 -0
  111. package/dist/esm/table/index.d.ts.map +1 -0
  112. package/dist/esm/table/index.js +169 -0
  113. package/dist/esm/table/index.js.map +1 -0
  114. package/dist/esm/text/index.d.ts +17 -2
  115. package/dist/esm/text/index.d.ts.map +1 -1
  116. package/dist/esm/text/index.js +17 -2
  117. package/dist/esm/text/index.js.map +1 -1
  118. package/dist/esm/types/index.d.ts +30 -1
  119. package/dist/esm/types/index.d.ts.map +1 -1
  120. package/dist/esm/types/index.js +14 -0
  121. package/dist/esm/types/index.js.map +1 -1
  122. package/dist/esm/types/metadata.d.ts +258 -26
  123. package/dist/esm/types/metadata.d.ts.map +1 -1
  124. package/package.json +1 -1
  125. package/src/array/index.ts +12 -23
  126. package/src/drawing/bar-time.ts +42 -0
  127. package/src/drawing/output.ts +214 -0
  128. package/src/drawing/registry.ts +16 -6
  129. package/src/index.ts +11 -3
  130. package/src/polyline/index.ts +3 -12
  131. package/src/runtime/index.ts +3 -0
  132. package/src/runtime/input-active.ts +50 -0
  133. package/src/runtime/types.ts +48 -2
  134. package/src/script/index.ts +301 -30
  135. package/src/str/index.ts +23 -10
  136. package/src/str/numberformat.ts +13 -0
  137. package/src/table/index.ts +221 -0
  138. package/src/text/index.ts +18 -2
  139. package/src/types/index.ts +32 -1
  140. package/src/types/metadata.ts +325 -26
@@ -223,14 +223,19 @@ export interface FillGradient {
223
223
  }
224
224
 
225
225
  /**
226
- * Marker location on the chart (PineScript plotshape/plotchar locations)
226
+ * Marker location on the chart (PineScript plotshape/plotchar `location.*`)
227
227
  */
228
228
  export type MarkerLocation = 'abovebar' | 'belowbar' | 'top' | 'bottom' | 'absolute';
229
229
 
230
+ /**
231
+ * PineScript size constant (`size.auto`, `size.tiny`, ...)
232
+ */
233
+ export type PineSize = 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';
234
+
230
235
  /**
231
236
  * Marker size (PineScript size.* constants)
232
237
  */
233
- export type MarkerSize = 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';
238
+ export type MarkerSize = PineSize;
234
239
 
235
240
  /**
236
241
  * Shape style (PineScript shape.* constants)
@@ -250,31 +255,76 @@ export type ShapeStyle =
250
255
  | 'diamond';
251
256
 
252
257
  /**
253
- * One marker emitted by plotshape()/plotchar() on a bar where the condition held
258
+ * Position of a marker:
259
+ * - aboveBar / belowBar / inBar: next to the bar (PineScript location.abovebar / location.belowbar)
260
+ * - atPriceTop / atPriceBottom / atPriceMiddle: at `price` (PineScript location.absolute), with the meaning of the
261
+ * lightweight-charts price positions: atPriceTop has the shape above the price, its bottom (the tip of a label) on
262
+ * the price (shape.labeldown); atPriceBottom has the shape below the price, its top on the price (shape.labelup);
263
+ * atPriceMiddle centres the shape on the price (other shapes)
264
+ * - top / bottom: at the top / bottom edge of the pane of the indicator (PineScript location.top / location.bottom),
265
+ * the price pane for an overlay indicator or with forceOverlay
266
+ */
267
+ export type MarkerPosition =
268
+ | 'aboveBar'
269
+ | 'belowBar'
270
+ | 'inBar'
271
+ | 'atPriceTop'
272
+ | 'atPriceBottom'
273
+ | 'atPriceMiddle'
274
+ | 'top'
275
+ | 'bottom';
276
+
277
+ /**
278
+ * Marker shape (PineScript shape.* in the lightweight-charts spelling)
279
+ */
280
+ export type MarkerShape =
281
+ | 'arrowUp'
282
+ | 'arrowDown'
283
+ | 'circle'
284
+ | 'square'
285
+ | 'labelUp'
286
+ | 'labelDown'
287
+ | 'triangleUp'
288
+ | 'triangleDown'
289
+ | 'cross'
290
+ | 'xcross'
291
+ | 'diamond'
292
+ | 'flag';
293
+
294
+ /**
295
+ * One marker: a plotshape()/plotchar() marker on a bar where the condition held, or a marker of a built-in indicator
254
296
  */
255
297
  export interface MarkerData {
256
298
  /** Time of the bar the marker is displayed on (offset already applied) */
257
- time: any;
258
- /** Id of the plotshape/plotchar declaration that produced it */
259
- id: string;
260
- /** Marker location relative to the bar */
261
- location: MarkerLocation;
262
- /** Shape style, or 'char' for plotchar markers */
263
- style: ShapeStyle | 'char';
264
- /** Character (plotchar only) */
265
- char?: string;
266
- /** Marker color */
267
- color?: string;
268
- /** Text shown near the marker */
299
+ time: number;
300
+ /** Where the marker is drawn */
301
+ position: MarkerPosition;
302
+ /** Price of the atPrice* positions (required with them) */
303
+ price?: number;
304
+ /** Shape. A plotchar marker also has `char`: the character is drawn in place of the shape */
305
+ shape: MarkerShape;
306
+ /**
307
+ * Shape colour (the character colour of a plotchar marker). A fully transparent colour ('transparent',
308
+ * '#rrggbb00', 'rgba(r, g, b, 0)') draws no shape, as PineScript `color = na`; the text is still drawn
309
+ */
310
+ color: string;
311
+ /** Text; a line feed starts a new line */
269
312
  text?: string;
270
- /** Text color */
271
- textcolor?: string;
272
- /** Marker size */
273
- size?: MarkerSize;
274
- /** Hover tooltip (extension over PineScript plotshape, used by label.new ports) */
313
+ /**
314
+ * Text colour (PineScript textcolor). When omitted: white inside label shapes (labelUp / labelDown), the shape
315
+ * colour for the other shapes
316
+ */
317
+ textColor?: string;
318
+ /** Size multiplier (1 = default size) or a PineScript size */
319
+ size?: number | PineSize;
320
+ /** PineScript force_overlay = true: the marker of a non-overlay indicator is drawn on the price pane */
321
+ forceOverlay?: boolean;
322
+ /** Id of the plotshape/plotchar declaration that produced it (script markers) */
323
+ id?: string;
324
+ /** plotchar character, drawn in place of the shape */
325
+ char?: string;
326
+ /** Hover tooltip */
275
327
  tooltip?: string;
276
- /** Price for location 'absolute' (the series value on that bar) */
277
- price?: number;
278
328
  }
279
329
 
280
330
  /**
@@ -292,15 +342,248 @@ export interface ArrowData {
292
342
  }
293
343
 
294
344
  /**
295
- * Per-bar color for bgcolor()/barcolor() output
345
+ * Per-bar candle color (barcolor() output)
296
346
  */
297
347
  export interface BarColorData {
298
348
  /** Time of the colored bar (offset already applied) */
299
- time: any;
349
+ time: number;
300
350
  /** Color */
301
351
  color: string;
302
352
  }
303
353
 
354
+ /**
355
+ * Per-bar background color (bgcolor() output)
356
+ */
357
+ export interface BgColorData {
358
+ /** Time of the colored bar (offset already applied) */
359
+ time: number;
360
+ /** Color (with its transparency) */
361
+ color: string;
362
+ /** PineScript bgcolor(..., force_overlay = true): drawn on the price pane even for a non-overlay indicator */
363
+ forceOverlay?: boolean;
364
+ }
365
+
366
+ /**
367
+ * One candle of plotcandle() (or of a built-in indicator that draws candles)
368
+ */
369
+ export interface PlotCandleData {
370
+ time: number;
371
+ open: number;
372
+ high: number;
373
+ low: number;
374
+ close: number;
375
+ /** Body colour */
376
+ color?: string;
377
+ borderColor?: string;
378
+ wickColor?: string;
379
+ /** PineScript force_overlay = true: the candles of a non-overlay indicator are drawn on the price pane */
380
+ forceOverlay?: boolean;
381
+ }
382
+
383
+ /**
384
+ * One bar of plotbar(): an OHLC bar (a vertical line from low to high, the open tick on the left, the close tick on
385
+ * the right)
386
+ */
387
+ export interface PlotBarData {
388
+ time: number;
389
+ open: number;
390
+ high: number;
391
+ low: number;
392
+ close: number;
393
+ color?: string;
394
+ /** PineScript force_overlay = true: the bars of a non-overlay indicator are drawn on the price pane */
395
+ forceOverlay?: boolean;
396
+ }
397
+
398
+ /** PineScript label style (`label.style_*` without the prefix) */
399
+ export type LabelStyle =
400
+ | 'none'
401
+ | 'xcross'
402
+ | 'cross'
403
+ | 'triangleup'
404
+ | 'triangledown'
405
+ | 'flag'
406
+ | 'circle'
407
+ | 'arrowup'
408
+ | 'arrowdown'
409
+ | 'label_up'
410
+ | 'label_down'
411
+ | 'label_left'
412
+ | 'label_right'
413
+ | 'label_lower_left'
414
+ | 'label_lower_right'
415
+ | 'label_upper_left'
416
+ | 'label_upper_right'
417
+ | 'label_center'
418
+ | 'square'
419
+ | 'diamond'
420
+ | 'text_outline';
421
+
422
+ // Drawing outputs (labels, lines, boxes, linefills, polylines, tables). A field the script did not set is omitted and
423
+ // the renderer uses the PineScript default; a colour set to na is 'transparent'. A point on a bar after the last bar
424
+ // (PineScript bar_index + k) has the time of that future bar (see barTime). The same applies to markers and plots.
425
+
426
+ /**
427
+ * A label (PineScript label.new)
428
+ */
429
+ export interface LabelData {
430
+ time: number;
431
+ /** Price; not used with yloc 'abovebar' / 'belowbar' */
432
+ price: number;
433
+ text: string;
434
+ /** Background, border and arrow colour */
435
+ color?: string;
436
+ textColor?: string;
437
+ /** 'none': text only, no background (PineScript label.style_none) */
438
+ style?: LabelStyle;
439
+ size?: PineSize | number;
440
+ /**
441
+ * PineScript yloc: 'price' (default) places the label at `price`; 'abovebar' / 'belowbar' place it above the bar
442
+ * high / below the bar low and ignore `price` (the renderer reads the bar at `time`).
443
+ */
444
+ yloc?: 'price' | 'abovebar' | 'belowbar';
445
+ textAlign?: 'left' | 'center' | 'right';
446
+ tooltip?: string;
447
+ fontFamily?: 'default' | 'monospace';
448
+ /** PineScript text.format_* flags: 0 none, 1 bold, 2 italic, 3 bold + italic */
449
+ textFormatting?: number;
450
+ /** PineScript force_overlay = true: the label of a non-overlay indicator is drawn on the price pane */
451
+ forceOverlay?: boolean;
452
+ }
453
+
454
+ /**
455
+ * A line (PineScript line.new)
456
+ */
457
+ export interface LineDrawingData {
458
+ time1: number;
459
+ price1: number;
460
+ time2: number;
461
+ price2: number;
462
+ color?: string;
463
+ width?: number;
464
+ style?: 'solid' | 'dashed' | 'dotted' | 'arrow_left' | 'arrow_right' | 'arrow_both';
465
+ extend?: 'none' | 'left' | 'right' | 'both';
466
+ /** PineScript force_overlay = true: the line of a non-overlay indicator is drawn on the price pane */
467
+ forceOverlay?: boolean;
468
+ }
469
+
470
+ /**
471
+ * A rectangle (PineScript box.new): time1 / price1 are the left / top, time2 / price2 the right / bottom
472
+ */
473
+ export interface BoxData {
474
+ time1: number;
475
+ price1: number;
476
+ time2: number;
477
+ price2: number;
478
+ bgColor?: string;
479
+ borderColor?: string;
480
+ borderWidth?: number;
481
+ borderStyle?: 'solid' | 'dashed' | 'dotted';
482
+ text?: string;
483
+ textColor?: string;
484
+ textSize?: PineSize | number;
485
+ textHAlign?: 'left' | 'center' | 'right';
486
+ textVAlign?: 'top' | 'center' | 'bottom';
487
+ textWrap?: 'none' | 'auto';
488
+ fontFamily?: 'default' | 'monospace';
489
+ /** PineScript text.format_* flags: 0 none, 1 bold, 2 italic, 3 bold + italic */
490
+ textFormatting?: number;
491
+ /** PineScript box extend: the box continues to the left / right edge of the chart */
492
+ extend?: 'none' | 'left' | 'right' | 'both';
493
+ /** PineScript force_overlay = true: the box of a non-overlay indicator is drawn on the price pane */
494
+ forceOverlay?: boolean;
495
+ }
496
+
497
+ /**
498
+ * The area between two lines (PineScript linefill.new), with the two lines as drawn (their extend included)
499
+ */
500
+ export interface LinefillData {
501
+ line1: LineDrawingData;
502
+ line2: LineDrawingData;
503
+ color?: string;
504
+ }
505
+
506
+ /**
507
+ * A polyline (PineScript polyline.new)
508
+ */
509
+ export interface PolylineData {
510
+ points: Array<{ time: number; price: number }>;
511
+ /** Curved segments between the points */
512
+ curved?: boolean;
513
+ /** The last point is connected to the first */
514
+ closed?: boolean;
515
+ lineColor?: string;
516
+ /** Fill of the area inside the polyline */
517
+ fillColor?: string;
518
+ lineStyle?: 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both';
519
+ lineWidth?: number;
520
+ /** PineScript force_overlay = true: the polyline of a non-overlay indicator is drawn on the price pane */
521
+ forceOverlay?: boolean;
522
+ }
523
+
524
+ /** Table position (PineScript position.*) */
525
+ export type TablePosition =
526
+ | 'top_left'
527
+ | 'top_center'
528
+ | 'top_right'
529
+ | 'middle_left'
530
+ | 'middle_center'
531
+ | 'middle_right'
532
+ | 'bottom_left'
533
+ | 'bottom_center'
534
+ | 'bottom_right';
535
+
536
+ /**
537
+ * A table cell (PineScript table.cell)
538
+ */
539
+ export interface TableCellData {
540
+ row: number;
541
+ column: number;
542
+ text: string;
543
+ bgColor?: string;
544
+ textColor?: string;
545
+ textSize?: PineSize | number;
546
+ /** Width in % of the chart width; 0 fits the text */
547
+ width?: number;
548
+ /** Height in % of the chart height; 0 fits the text */
549
+ height?: number;
550
+ textHAlign?: 'left' | 'center' | 'right';
551
+ textVAlign?: 'top' | 'center' | 'bottom';
552
+ tooltip?: string;
553
+ fontFamily?: 'default' | 'monospace';
554
+ /** PineScript text.format_* flags: 0 none, 1 bold, 2 italic, 3 bold + italic */
555
+ textFormatting?: number;
556
+ }
557
+
558
+ /**
559
+ * Merged cells of a table (PineScript table.merge_cells): the cell at the start column / row covers the range and
560
+ * gives its content
561
+ */
562
+ export interface TableMergeData {
563
+ startColumn: number;
564
+ startRow: number;
565
+ endColumn: number;
566
+ endRow: number;
567
+ }
568
+
569
+ /**
570
+ * A table (PineScript table.new)
571
+ */
572
+ export interface TableData {
573
+ position: TablePosition;
574
+ columns: number;
575
+ rows: number;
576
+ cells: TableCellData[];
577
+ merges?: TableMergeData[];
578
+ bgColor?: string;
579
+ frameColor?: string;
580
+ frameWidth?: number;
581
+ borderColor?: string;
582
+ borderWidth?: number;
583
+ /** PineScript force_overlay = true: the table of a non-overlay indicator is drawn on the price pane */
584
+ forceOverlay?: boolean;
585
+ }
586
+
304
587
  /**
305
588
  * Complete indicator calculation result
306
589
  */
@@ -318,9 +601,25 @@ export interface IndicatorResult {
318
601
  /** Arrows from plotarrow() */
319
602
  arrows?: ArrowData[];
320
603
  /** Background colors from bgcolor() */
321
- bgcolors?: BarColorData[];
604
+ bgColors?: BgColorData[];
322
605
  /** Bar colors from barcolor() */
323
- barcolors?: BarColorData[];
606
+ barColors?: BarColorData[];
607
+ /** Candles from plotcandle(), keyed by plotcandle id */
608
+ plotCandles?: Record<string, PlotCandleData[]>;
609
+ /** OHLC bars from plotbar(), keyed by plotbar id */
610
+ plotBars?: Record<string, PlotBarData[]>;
611
+ /** Labels alive after the last bar */
612
+ labels?: LabelData[];
613
+ /** Lines alive after the last bar */
614
+ lines?: LineDrawingData[];
615
+ /** Boxes alive after the last bar */
616
+ boxes?: BoxData[];
617
+ /** Linefills alive after the last bar */
618
+ linefills?: LinefillData[];
619
+ /** Polylines alive after the last bar */
620
+ polylines?: PolylineData[];
621
+ /** Tables alive after the last bar */
622
+ tables?: TableData[];
324
623
  }
325
624
 
326
625
  /**