oakscriptjs 0.24.0 → 0.25.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.
- package/README.md +25 -1
- package/bin/oakscript.mjs +10 -3
- package/dist/cjs/box/index.d.ts +348 -289
- package/dist/cjs/box/index.d.ts.map +1 -1
- package/dist/cjs/box/index.js.map +2 -2
- package/dist/cjs/check/node.d.ts.map +1 -1
- package/dist/cjs/check/node.js +1 -0
- package/dist/cjs/check/node.js.map +2 -2
- package/dist/cjs/check/preview.d.ts +31 -0
- package/dist/cjs/check/preview.d.ts.map +1 -0
- package/dist/cjs/check/preview.js +303 -0
- package/dist/cjs/check/preview.js.map +7 -0
- package/dist/cjs/color/index.d.ts +11 -11
- package/dist/cjs/color/index.js.map +1 -1
- package/dist/cjs/color/parse.d.ts +2 -0
- package/dist/cjs/color/parse.d.ts.map +1 -1
- package/dist/cjs/color/parse.js +6 -0
- package/dist/cjs/color/parse.js.map +2 -2
- package/dist/cjs/compare/index.d.ts +76 -12
- package/dist/cjs/compare/index.d.ts.map +1 -1
- package/dist/cjs/compare/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +28 -5
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +14 -0
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/label/index.d.ts +265 -187
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +1 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/line/index.d.ts +247 -207
- package/dist/cjs/line/index.d.ts.map +1 -1
- package/dist/cjs/line/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts +61 -89
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +49 -40
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js.map +2 -2
- package/dist/cjs/polyline/index.d.ts +57 -78
- package/dist/cjs/polyline/index.d.ts.map +1 -1
- package/dist/cjs/polyline/index.js.map +2 -2
- package/dist/cjs/runtime/input-active.d.ts +2 -2
- package/dist/cjs/runtime/input-active.js.map +1 -1
- package/dist/cjs/runtime/series.d.ts +241 -161
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +223 -127
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/api/alert.d.ts +37 -0
- package/dist/cjs/script/api/alert.d.ts.map +1 -0
- package/dist/cjs/script/api/alert.js +17 -0
- package/dist/cjs/script/api/alert.js.map +7 -0
- package/dist/cjs/script/api/calc.d.ts +232 -0
- package/dist/cjs/script/api/calc.d.ts.map +1 -0
- package/dist/cjs/script/api/calc.js +17 -0
- package/dist/cjs/script/api/calc.js.map +7 -0
- package/dist/cjs/script/api/color.d.ts +213 -0
- package/dist/cjs/script/api/color.d.ts.map +1 -0
- package/dist/cjs/script/api/color.js +17 -0
- package/dist/cjs/script/api/color.js.map +7 -0
- package/dist/cjs/script/api/context.d.ts +764 -0
- package/dist/cjs/script/api/context.d.ts.map +1 -0
- package/dist/cjs/script/api/context.js +17 -0
- package/dist/cjs/script/api/context.js.map +7 -0
- package/dist/cjs/script/api/log.d.ts +58 -0
- package/dist/cjs/script/api/log.d.ts.map +1 -0
- package/dist/cjs/script/api/log.js +17 -0
- package/dist/cjs/script/api/log.js.map +7 -0
- package/dist/cjs/script/api/strategy.d.ts +391 -0
- package/dist/cjs/script/api/strategy.d.ts.map +1 -0
- package/dist/cjs/script/api/strategy.js +17 -0
- package/dist/cjs/script/api/strategy.js.map +7 -0
- package/dist/cjs/script/api/ta.d.ts +1012 -0
- package/dist/cjs/script/api/ta.d.ts.map +1 -0
- package/dist/cjs/script/api/ta.js +17 -0
- package/dist/cjs/script/api/ta.js.map +7 -0
- package/dist/cjs/script/api/table.d.ts +479 -0
- package/dist/cjs/script/api/table.d.ts.map +1 -0
- package/dist/cjs/script/api/table.js +17 -0
- package/dist/cjs/script/api/table.js.map +7 -0
- package/dist/cjs/script/constants.d.ts +228 -83
- package/dist/cjs/script/constants.d.ts.map +1 -1
- package/dist/cjs/script/constants.js +87 -0
- package/dist/cjs/script/constants.js.map +2 -2
- package/dist/cjs/script/define.d.ts +94 -0
- package/dist/cjs/script/define.d.ts.map +1 -0
- package/dist/cjs/script/define.js +127 -0
- package/dist/cjs/script/define.js.map +7 -0
- package/dist/cjs/script/drawing-args.d.ts.map +1 -1
- package/dist/cjs/script/drawing-args.js +1 -1
- package/dist/cjs/script/drawing-args.js.map +2 -2
- package/dist/cjs/script/formula.d.ts +53 -0
- package/dist/cjs/script/formula.d.ts.map +1 -0
- package/dist/cjs/script/formula.js +402 -0
- package/dist/cjs/script/formula.js.map +7 -0
- package/dist/cjs/script/globals.d.ts +10 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/index.d.ts +1067 -1006
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +530 -60
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/script/json.d.ts +117 -0
- package/dist/cjs/script/json.d.ts.map +1 -0
- package/dist/cjs/script/json.js +321 -0
- package/dist/cjs/script/json.js.map +7 -0
- package/dist/cjs/str/index.d.ts +50 -75
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +2 -2
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/strategy/index.d.ts +102 -1
- package/dist/cjs/strategy/index.d.ts.map +1 -1
- package/dist/cjs/strategy/index.js.map +2 -2
- package/dist/cjs/table/index.d.ts +330 -49
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +55 -27
- package/dist/cjs/table/index.js.map +2 -2
- package/dist/cjs/text/index.d.ts +12 -14
- package/dist/cjs/text/index.d.ts.map +1 -1
- package/dist/cjs/text/index.js.map +2 -2
- package/dist/cjs/types/index.d.ts +15 -8
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +12 -3
- package/dist/cjs/types/index.js.map +2 -2
- package/dist/esm/box/index.d.ts +348 -289
- package/dist/esm/box/index.d.ts.map +1 -1
- package/dist/esm/box/index.js +276 -276
- package/dist/esm/box/index.js.map +1 -1
- package/dist/esm/check/node.d.ts.map +1 -1
- package/dist/esm/check/node.js +1 -0
- package/dist/esm/check/node.js.map +1 -1
- package/dist/esm/check/preview.d.ts +31 -0
- package/dist/esm/check/preview.d.ts.map +1 -0
- package/dist/esm/check/preview.js +296 -0
- package/dist/esm/check/preview.js.map +1 -0
- package/dist/esm/color/index.d.ts +11 -11
- package/dist/esm/color/index.js +11 -11
- package/dist/esm/color/parse.d.ts +2 -0
- package/dist/esm/color/parse.d.ts.map +1 -1
- package/dist/esm/color/parse.js +7 -0
- package/dist/esm/color/parse.js.map +1 -1
- package/dist/esm/compare/index.d.ts +76 -12
- package/dist/esm/compare/index.d.ts.map +1 -1
- package/dist/esm/compare/index.js +76 -12
- package/dist/esm/compare/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +28 -5
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +39 -3
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/label/index.d.ts +265 -187
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +207 -177
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/line/index.d.ts +247 -207
- package/dist/esm/line/index.d.ts.map +1 -1
- package/dist/esm/line/index.js +202 -194
- package/dist/esm/line/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts +61 -89
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +61 -89
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +49 -40
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +22 -9
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/polyline/index.d.ts +57 -78
- package/dist/esm/polyline/index.d.ts.map +1 -1
- package/dist/esm/polyline/index.js +57 -78
- package/dist/esm/polyline/index.js.map +1 -1
- package/dist/esm/runtime/input-active.d.ts +2 -2
- package/dist/esm/runtime/input-active.js +2 -2
- package/dist/esm/runtime/series.d.ts +241 -161
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +241 -161
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/api/alert.d.ts +37 -0
- package/dist/esm/script/api/alert.d.ts.map +1 -0
- package/dist/esm/script/api/alert.js +7 -0
- package/dist/esm/script/api/alert.js.map +1 -0
- package/dist/esm/script/api/calc.d.ts +232 -0
- package/dist/esm/script/api/calc.d.ts.map +1 -0
- package/dist/esm/script/api/calc.js +6 -0
- package/dist/esm/script/api/calc.js.map +1 -0
- package/dist/esm/script/api/color.d.ts +213 -0
- package/dist/esm/script/api/color.d.ts.map +1 -0
- package/dist/esm/script/api/color.js +6 -0
- package/dist/esm/script/api/color.js.map +1 -0
- package/dist/esm/script/api/context.d.ts +764 -0
- package/dist/esm/script/api/context.d.ts.map +1 -0
- package/dist/esm/script/api/context.js +7 -0
- package/dist/esm/script/api/context.js.map +1 -0
- package/dist/esm/script/api/log.d.ts +58 -0
- package/dist/esm/script/api/log.d.ts.map +1 -0
- package/dist/esm/script/api/log.js +6 -0
- package/dist/esm/script/api/log.js.map +1 -0
- package/dist/esm/script/api/strategy.d.ts +391 -0
- package/dist/esm/script/api/strategy.d.ts.map +1 -0
- package/dist/esm/script/api/strategy.js +7 -0
- package/dist/esm/script/api/strategy.js.map +1 -0
- package/dist/esm/script/api/ta.d.ts +1012 -0
- package/dist/esm/script/api/ta.d.ts.map +1 -0
- package/dist/esm/script/api/ta.js +6 -0
- package/dist/esm/script/api/ta.js.map +1 -0
- package/dist/esm/script/api/table.d.ts +479 -0
- package/dist/esm/script/api/table.d.ts.map +1 -0
- package/dist/esm/script/api/table.js +7 -0
- package/dist/esm/script/api/table.js.map +1 -0
- package/dist/esm/script/constants.d.ts +228 -83
- package/dist/esm/script/constants.d.ts.map +1 -1
- package/dist/esm/script/constants.js +110 -24
- package/dist/esm/script/constants.js.map +1 -1
- package/dist/esm/script/define.d.ts +94 -0
- package/dist/esm/script/define.d.ts.map +1 -0
- package/dist/esm/script/define.js +136 -0
- package/dist/esm/script/define.js.map +1 -0
- package/dist/esm/script/drawing-args.d.ts.map +1 -1
- package/dist/esm/script/drawing-args.js +2 -1
- package/dist/esm/script/drawing-args.js.map +1 -1
- package/dist/esm/script/formula.d.ts +53 -0
- package/dist/esm/script/formula.d.ts.map +1 -0
- package/dist/esm/script/formula.js +408 -0
- package/dist/esm/script/formula.js.map +1 -0
- package/dist/esm/script/globals.d.ts +10 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/index.d.ts +1067 -1006
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +1096 -151
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/script/json.d.ts +117 -0
- package/dist/esm/script/json.d.ts.map +1 -0
- package/dist/esm/script/json.js +375 -0
- package/dist/esm/script/json.js.map +1 -0
- package/dist/esm/str/index.d.ts +50 -75
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +51 -76
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/strategy/index.d.ts +102 -1
- package/dist/esm/strategy/index.d.ts.map +1 -1
- package/dist/esm/strategy/index.js +1 -1
- package/dist/esm/strategy/index.js.map +1 -1
- package/dist/esm/table/index.d.ts +330 -49
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +372 -61
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/text/index.d.ts +12 -14
- package/dist/esm/text/index.d.ts.map +1 -1
- package/dist/esm/text/index.js +12 -14
- package/dist/esm/text/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +15 -8
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +15 -8
- package/dist/esm/types/index.js.map +1 -1
- package/docs/first-indicator.md +152 -0
- package/docs/guide.md +1185 -0
- package/docs/inventory.md +772 -0
- package/docs/no-code.md +207 -0
- package/docs/recipes.md +202 -0
- package/package.json +2 -1
- package/skills/oakscript/SKILL.md +8 -0
- package/skills/oakscript/reference/errors.md +3 -2
- package/src/box/index.ts +348 -289
- package/src/check/node.ts +1 -0
- package/src/check/preview.ts +307 -0
- package/src/color/index.ts +11 -11
- package/src/color/parse.ts +7 -0
- package/src/compare/index.ts +76 -12
- package/src/drawing/registry.ts +44 -5
- package/src/index.ts +1 -1
- package/src/label/index.ts +267 -189
- package/src/line/index.ts +248 -208
- package/src/linefill/index.ts +61 -89
- package/src/math/index.ts +51 -42
- package/src/polyline/index.ts +57 -78
- package/src/runtime/input-active.ts +2 -2
- package/src/runtime/series.ts +243 -163
- package/src/script/api/alert.ts +43 -0
- package/src/script/api/calc.ts +250 -0
- package/src/script/api/color.ts +245 -0
- package/src/script/api/context.ts +944 -0
- package/src/script/api/log.ts +60 -0
- package/src/script/api/strategy.ts +410 -0
- package/src/script/api/ta.ts +1115 -0
- package/src/script/api/table.ts +538 -0
- package/src/script/constants.ts +229 -25
- package/src/script/define.ts +221 -0
- package/src/script/drawing-args.ts +2 -1
- package/src/script/formula.ts +438 -0
- package/src/script/globals.ts +10 -0
- package/src/script/index.ts +1519 -239
- package/src/script/json.ts +457 -0
- package/src/str/index.ts +51 -76
- package/src/strategy/index.ts +102 -1
- package/src/table/index.ts +388 -62
- package/src/text/index.ts +12 -14
- package/src/types/index.ts +15 -8
package/src/box/index.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Box namespace
|
|
3
|
-
* Functions for creating and manipulating box drawing objects.
|
|
2
|
+
* Box namespace: functions that create, read, change and delete box drawings (`box.*`).
|
|
4
3
|
*
|
|
5
4
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
* (
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - Rectangle pattern recognition
|
|
5
|
+
* A box is a rectangle between two x coordinates (left, right) and two prices (top, bottom), with an optional text
|
|
6
|
+
* inside. Its x coordinates are bar indexes (`xloc.bar_index`, the default), UNIX times in ms (`xloc.bar_time`) or
|
|
7
|
+
* percents of the pane's width (`xloc.pane`). The getters (`box.get_top()`...) let a script test whether the price
|
|
8
|
+
* entered or left a zone: gaps, ranges, supply and demand areas.
|
|
11
9
|
*
|
|
12
10
|
* @version 6
|
|
13
11
|
*/
|
|
@@ -19,20 +17,39 @@ type BoxXloc = 'bar_index' | 'bar_time' | 'pane';
|
|
|
19
17
|
type BoxExtend = 'none' | 'left' | 'right' | 'both';
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* -
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
20
|
+
* Draws a box between two chart points and returns its handle, to change or delete it later.
|
|
21
|
+
* With `xloc.bar_index` the x of a point is its `index`, with `xloc.bar_time` its `time`. The arguments after the
|
|
22
|
+
* points can also be given by name in an object. Boxes above `max_boxes_count` (default 50) are deleted oldest first.
|
|
23
|
+
* @param top_left - Top-left corner (`chart.point.from_index(...)`, `chart.point.now()`...).
|
|
24
|
+
* @param bottom_right - Bottom-right corner.
|
|
25
|
+
* @param border_color - Colour of the border. Default: blue (#2962FF).
|
|
26
|
+
* @param border_width - Width of the border in pixels; 0 draws no border. Default: 1.
|
|
27
|
+
* @param border_style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`. Default: `line.style_solid`.
|
|
28
|
+
* @param extend - Extends the box sideways to the edge of the pane: `extend.none`, `extend.left`, `extend.right` or
|
|
29
|
+
* `extend.both`. Default: `extend.none`.
|
|
30
|
+
* @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
|
|
31
|
+
* @param bgcolor - Fill colour of the box. Default: blue (#2962FF).
|
|
32
|
+
* @param text - Text written inside the box; `\n` starts a new line. Default: none.
|
|
33
|
+
* @param text_size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in
|
|
34
|
+
* points. Default: `size.auto`.
|
|
35
|
+
* @param text_color - Text colour. Default: white.
|
|
36
|
+
* @param text_halign - Horizontal place of the text: `text.align_left`, `text.align_center` or `text.align_right`.
|
|
37
|
+
* Default: `text.align_center`.
|
|
38
|
+
* @param text_valign - Vertical place of the text: `text.align_top`, `text.align_center` or `text.align_bottom`.
|
|
39
|
+
* Default: `text.align_center`.
|
|
40
|
+
* @param text_wrap - `text.wrap_auto` wraps the text to the width of the box, `text.wrap_none` keeps each line whole.
|
|
41
|
+
* Default: `text.wrap_none`.
|
|
42
|
+
* @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.
|
|
43
|
+
* @param force_overlay - When true, the box is drawn on the price pane even if the script has its own pane.
|
|
44
|
+
* Default: false.
|
|
45
|
+
* @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
|
|
46
|
+
* Default: `text.format_none`.
|
|
47
|
+
* @returns The new box.
|
|
32
48
|
* @example
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
*
|
|
49
|
+
* ```js
|
|
50
|
+
* eachBar((c) => {
|
|
51
|
+
* if (c.i === c.n - 1) box.new(chart.point.from_index(c.i - 20, c.get(high, 20)), chart.point.now(c.low));
|
|
52
|
+
* });
|
|
36
53
|
* ```
|
|
37
54
|
*/
|
|
38
55
|
export function new_box(
|
|
@@ -54,6 +71,46 @@ export function new_box(
|
|
|
54
71
|
force_overlay?: boolean,
|
|
55
72
|
text_formatting?: number
|
|
56
73
|
): Box;
|
|
74
|
+
/**
|
|
75
|
+
* Draws a box from its left, top, right and bottom and returns its handle, to change or delete it later.
|
|
76
|
+
* Inside `eachBar` a Series argument is read on the current bar; the arguments after the coordinates can also be
|
|
77
|
+
* given by name in an object. A bar index x is rounded down; it may be up to 500 bars after the last bar. Boxes
|
|
78
|
+
* above `max_boxes_count` (default 50) are deleted oldest first.
|
|
79
|
+
* @param left - x of the left side: a bar index, a UNIX time in ms (`xloc.bar_time`) or a percent of the pane's
|
|
80
|
+
* width (`xloc.pane`).
|
|
81
|
+
* @param top - Price of the top side.
|
|
82
|
+
* @param right - x of the right side, in the same unit as `left`.
|
|
83
|
+
* @param bottom - Price of the bottom side.
|
|
84
|
+
* @param border_color - Colour of the border. Default: blue (#2962FF).
|
|
85
|
+
* @param border_width - Width of the border in pixels; 0 draws no border. Default: 1.
|
|
86
|
+
* @param border_style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`. Default: `line.style_solid`.
|
|
87
|
+
* @param extend - Extends the box sideways to the edge of the pane: `extend.none`, `extend.left`, `extend.right` or
|
|
88
|
+
* `extend.both`. Default: `extend.none`.
|
|
89
|
+
* @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
|
|
90
|
+
* @param bgcolor - Fill colour of the box. Default: blue (#2962FF).
|
|
91
|
+
* @param text - Text written inside the box; `\n` starts a new line. Default: none.
|
|
92
|
+
* @param text_size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in
|
|
93
|
+
* points. Default: `size.auto`.
|
|
94
|
+
* @param text_color - Text colour. Default: white.
|
|
95
|
+
* @param text_halign - Horizontal place of the text: `text.align_left`, `text.align_center` or `text.align_right`.
|
|
96
|
+
* Default: `text.align_center`.
|
|
97
|
+
* @param text_valign - Vertical place of the text: `text.align_top`, `text.align_center` or `text.align_bottom`.
|
|
98
|
+
* Default: `text.align_center`.
|
|
99
|
+
* @param text_wrap - `text.wrap_auto` wraps the text to the width of the box, `text.wrap_none` keeps each line whole.
|
|
100
|
+
* Default: `text.wrap_none`.
|
|
101
|
+
* @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.
|
|
102
|
+
* @param force_overlay - When true, the box is drawn on the price pane even if the script has its own pane.
|
|
103
|
+
* Default: false.
|
|
104
|
+
* @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
|
|
105
|
+
* Default: `text.format_none`.
|
|
106
|
+
* @returns The new box.
|
|
107
|
+
* @example
|
|
108
|
+
* ```js
|
|
109
|
+
* eachBar((c) => {
|
|
110
|
+
* if (c.i === c.n - 1) box.new(c.i - 20, c.get(high, 20), c.i, c.low, { bgcolor: color.new(color.blue, 85), text: "Range" });
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
57
114
|
export function new_box(
|
|
58
115
|
left: number,
|
|
59
116
|
top: number,
|
|
@@ -117,23 +174,15 @@ export function new_box(...args: unknown[]): Box {
|
|
|
117
174
|
}
|
|
118
175
|
|
|
119
176
|
/**
|
|
120
|
-
* Returns the left
|
|
121
|
-
*
|
|
122
|
-
* @
|
|
123
|
-
* @returns Left border coordinate (bar index or timestamp)
|
|
124
|
-
*
|
|
125
|
-
* @remarks
|
|
126
|
-
* **COMPUTATIONAL USE**: Calculate gap duration, validate range timeframes
|
|
127
|
-
*
|
|
177
|
+
* Returns the x coordinate of the box's left side, for example to count how many bars a zone has been open.
|
|
178
|
+
* @param id - The box.
|
|
179
|
+
* @returns A bar index, a UNIX time in ms or a pane percent, by the box's xloc; NaN for a deleted box.
|
|
128
180
|
* @example
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* if (duration > 50) {
|
|
135
|
-
* console.log('Gap has been open for 50+ bars');
|
|
136
|
-
* }
|
|
181
|
+
* ```js
|
|
182
|
+
* eachBar((c) => {
|
|
183
|
+
* const b = box.new(c.i - 10, c.get(high, 10), c.i, c.low);
|
|
184
|
+
* const age = c.i - box.get_left(b); // 10
|
|
185
|
+
* });
|
|
137
186
|
* ```
|
|
138
187
|
*/
|
|
139
188
|
export function get_left(id: Box): number {
|
|
@@ -141,18 +190,15 @@ export function get_left(id: Box): number {
|
|
|
141
190
|
}
|
|
142
191
|
|
|
143
192
|
/**
|
|
144
|
-
* Returns the
|
|
145
|
-
*
|
|
146
|
-
* @
|
|
147
|
-
* @returns Right border coordinate (bar index or timestamp)
|
|
148
|
-
*
|
|
149
|
-
* @remarks
|
|
150
|
-
* **COMPUTATIONAL USE**: Calculate gap duration, update trailing edges
|
|
151
|
-
*
|
|
193
|
+
* Returns the x coordinate of the box's right side.
|
|
194
|
+
* @param id - The box.
|
|
195
|
+
* @returns A bar index, a UNIX time in ms or a pane percent, by the box's xloc; NaN for a deleted box.
|
|
152
196
|
* @example
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
*
|
|
197
|
+
* ```js
|
|
198
|
+
* eachBar((c) => {
|
|
199
|
+
* const b = box.new(c.i - 10, c.get(high, 10), c.i, c.low);
|
|
200
|
+
* const bars = box.get_right(b) - box.get_left(b); // 10
|
|
201
|
+
* });
|
|
156
202
|
* ```
|
|
157
203
|
*/
|
|
158
204
|
export function get_right(id: Box): number {
|
|
@@ -160,23 +206,15 @@ export function get_right(id: Box): number {
|
|
|
160
206
|
}
|
|
161
207
|
|
|
162
208
|
/**
|
|
163
|
-
* Returns the top
|
|
164
|
-
*
|
|
165
|
-
* @
|
|
166
|
-
* @returns Top border price
|
|
167
|
-
*
|
|
168
|
-
* @remarks
|
|
169
|
-
* **COMPUTATIONAL USE**: Detect breakouts above resistance, check gap fills
|
|
170
|
-
*
|
|
209
|
+
* Returns the price of the box's top side, for example to test a breakout above a range.
|
|
210
|
+
* @param id - The box.
|
|
211
|
+
* @returns The top price; NaN for a deleted box.
|
|
171
212
|
* @example
|
|
172
|
-
* ```
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* if (high > box.get_top(gap)) {
|
|
178
|
-
* console.log('Gap completely filled!');
|
|
179
|
-
* }
|
|
213
|
+
* ```js
|
|
214
|
+
* eachBar((c) => {
|
|
215
|
+
* const b = box.new(c.i - 10, c.get(high, 1), c.i - 1, c.get(low, 1));
|
|
216
|
+
* if (c.close > box.get_top(b)) label.new(c.i, c.high, "Breakout");
|
|
217
|
+
* });
|
|
180
218
|
* ```
|
|
181
219
|
*/
|
|
182
220
|
export function get_top(id: Box): number {
|
|
@@ -184,23 +222,15 @@ export function get_top(id: Box): number {
|
|
|
184
222
|
}
|
|
185
223
|
|
|
186
224
|
/**
|
|
187
|
-
* Returns the bottom
|
|
188
|
-
*
|
|
189
|
-
* @
|
|
190
|
-
* @returns Bottom border price
|
|
191
|
-
*
|
|
192
|
-
* @remarks
|
|
193
|
-
* **COMPUTATIONAL USE**: Detect breakouts below support, check gap fills
|
|
194
|
-
*
|
|
225
|
+
* Returns the price of the box's bottom side, for example to test a breakdown below a range.
|
|
226
|
+
* @param id - The box.
|
|
227
|
+
* @returns The bottom price; NaN for a deleted box.
|
|
195
228
|
* @example
|
|
196
|
-
* ```
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* if (low < box.get_top(gap) && low > box.get_bottom(gap)) {
|
|
202
|
-
* console.log('Price entered the gap!');
|
|
203
|
-
* }
|
|
229
|
+
* ```js
|
|
230
|
+
* eachBar((c) => {
|
|
231
|
+
* const b = box.new(c.i - 10, c.get(high, 1), c.i - 1, c.get(low, 1));
|
|
232
|
+
* if (c.close < box.get_bottom(b)) label.new(c.i, c.low, "Breakdown", { style: label.style_label_up });
|
|
233
|
+
* });
|
|
204
234
|
* ```
|
|
205
235
|
*/
|
|
206
236
|
export function get_bottom(id: Box): number {
|
|
@@ -208,21 +238,16 @@ export function get_bottom(id: Box): number {
|
|
|
208
238
|
}
|
|
209
239
|
|
|
210
240
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* @param id -
|
|
214
|
-
* @returns
|
|
215
|
-
*
|
|
216
|
-
* @remarks
|
|
217
|
-
* Creates a shallow copy of the box. Modifications to the copy won't affect the original.
|
|
218
|
-
*
|
|
241
|
+
* Makes a new box with the same sides, colours and text as `id` (it counts toward `max_boxes_count`).
|
|
242
|
+
* Changing the copy does not change the original.
|
|
243
|
+
* @param id - The box to copy.
|
|
244
|
+
* @returns The new box.
|
|
219
245
|
* @example
|
|
220
|
-
* ```
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* copiedBox.top = 110;
|
|
246
|
+
* ```js
|
|
247
|
+
* eachBar((c) => {
|
|
248
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
249
|
+
* box.set_bgcolor(box.copy(b), color.new(color.red, 80)); // a red copy over the same bars
|
|
250
|
+
* });
|
|
226
251
|
* ```
|
|
227
252
|
*/
|
|
228
253
|
export function copy(id: Box): Box {
|
|
@@ -234,16 +259,17 @@ export function copy(id: Box): Box {
|
|
|
234
259
|
// =============================================================================
|
|
235
260
|
|
|
236
261
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* @param
|
|
240
|
-
*
|
|
241
|
-
* @returns
|
|
242
|
-
*
|
|
262
|
+
* Moves the box's left side. Does nothing on a deleted box.
|
|
263
|
+
* @param id - The box.
|
|
264
|
+
* @param left - New x: a bar index, a UNIX time in ms or a pane percent, by the box's xloc. A bar index is rounded
|
|
265
|
+
* down.
|
|
266
|
+
* @returns The same box.
|
|
243
267
|
* @example
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* box.
|
|
268
|
+
* ```js
|
|
269
|
+
* eachBar((c) => {
|
|
270
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
271
|
+
* box.set_left(b, c.i - 20);
|
|
272
|
+
* });
|
|
247
273
|
* ```
|
|
248
274
|
*/
|
|
249
275
|
export function set_left(id: Box, left: number): Box {
|
|
@@ -254,16 +280,17 @@ export function set_left(id: Box, left: number): Box {
|
|
|
254
280
|
}
|
|
255
281
|
|
|
256
282
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* @param
|
|
260
|
-
*
|
|
261
|
-
* @returns
|
|
262
|
-
*
|
|
283
|
+
* Moves the box's right side, for example to stretch a zone to the current bar. Does nothing on a deleted box.
|
|
284
|
+
* @param id - The box.
|
|
285
|
+
* @param right - New x: a bar index, a UNIX time in ms or a pane percent, by the box's xloc. A bar index is rounded
|
|
286
|
+
* down.
|
|
287
|
+
* @returns The same box.
|
|
263
288
|
* @example
|
|
264
|
-
* ```
|
|
265
|
-
*
|
|
266
|
-
* box.
|
|
289
|
+
* ```js
|
|
290
|
+
* eachBar((c) => {
|
|
291
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
292
|
+
* box.set_right(b, c.i + 10); // reach 10 bars into the future
|
|
293
|
+
* });
|
|
267
294
|
* ```
|
|
268
295
|
*/
|
|
269
296
|
export function set_right(id: Box, right: number): Box {
|
|
@@ -274,16 +301,16 @@ export function set_right(id: Box, right: number): Box {
|
|
|
274
301
|
}
|
|
275
302
|
|
|
276
303
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* @param
|
|
280
|
-
* @
|
|
281
|
-
* @returns Modified box object
|
|
282
|
-
*
|
|
304
|
+
* Moves the box's top side. Does nothing on a deleted box.
|
|
305
|
+
* @param id - The box.
|
|
306
|
+
* @param top - New top price.
|
|
307
|
+
* @returns The same box.
|
|
283
308
|
* @example
|
|
284
|
-
* ```
|
|
285
|
-
*
|
|
286
|
-
* box.
|
|
309
|
+
* ```js
|
|
310
|
+
* eachBar((c) => {
|
|
311
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
312
|
+
* box.set_top(b, c.get(high, 10));
|
|
313
|
+
* });
|
|
287
314
|
* ```
|
|
288
315
|
*/
|
|
289
316
|
export function set_top(id: Box, top: number): Box {
|
|
@@ -293,16 +320,16 @@ export function set_top(id: Box, top: number): Box {
|
|
|
293
320
|
}
|
|
294
321
|
|
|
295
322
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
* @param
|
|
299
|
-
* @
|
|
300
|
-
* @returns Modified box object
|
|
301
|
-
*
|
|
323
|
+
* Moves the box's bottom side. Does nothing on a deleted box.
|
|
324
|
+
* @param id - The box.
|
|
325
|
+
* @param bottom - New bottom price.
|
|
326
|
+
* @returns The same box.
|
|
302
327
|
* @example
|
|
303
|
-
* ```
|
|
304
|
-
*
|
|
305
|
-
* box.
|
|
328
|
+
* ```js
|
|
329
|
+
* eachBar((c) => {
|
|
330
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
331
|
+
* box.set_bottom(b, c.get(low, 10));
|
|
332
|
+
* });
|
|
306
333
|
* ```
|
|
307
334
|
*/
|
|
308
335
|
export function set_bottom(id: Box, bottom: number): Box {
|
|
@@ -312,17 +339,17 @@ export function set_bottom(id: Box, bottom: number): Box {
|
|
|
312
339
|
}
|
|
313
340
|
|
|
314
341
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* @param
|
|
318
|
-
* @param
|
|
319
|
-
* @
|
|
320
|
-
* @returns Modified box object
|
|
321
|
-
*
|
|
342
|
+
* Moves the box's top-left corner (left side and top price). Does nothing on a deleted box.
|
|
343
|
+
* @param id - The box.
|
|
344
|
+
* @param left - New x of the left side, by the box's xloc. A bar index is rounded down.
|
|
345
|
+
* @param top - New top price.
|
|
346
|
+
* @returns The same box.
|
|
322
347
|
* @example
|
|
323
|
-
* ```
|
|
324
|
-
*
|
|
325
|
-
* box.
|
|
348
|
+
* ```js
|
|
349
|
+
* eachBar((c) => {
|
|
350
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
351
|
+
* box.set_lefttop(b, c.i - 20, c.get(high, 20));
|
|
352
|
+
* });
|
|
326
353
|
* ```
|
|
327
354
|
*/
|
|
328
355
|
export function set_lefttop(id: Box, left: number, top: number): Box {
|
|
@@ -334,17 +361,17 @@ export function set_lefttop(id: Box, left: number, top: number): Box {
|
|
|
334
361
|
}
|
|
335
362
|
|
|
336
363
|
/**
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* @param
|
|
340
|
-
* @param
|
|
341
|
-
* @
|
|
342
|
-
* @returns Modified box object
|
|
343
|
-
*
|
|
364
|
+
* Moves the box's bottom-right corner (right side and bottom price). Does nothing on a deleted box.
|
|
365
|
+
* @param id - The box.
|
|
366
|
+
* @param right - New x of the right side, by the box's xloc. A bar index is rounded down.
|
|
367
|
+
* @param bottom - New bottom price.
|
|
368
|
+
* @returns The same box.
|
|
344
369
|
* @example
|
|
345
|
-
* ```
|
|
346
|
-
*
|
|
347
|
-
* box.
|
|
370
|
+
* ```js
|
|
371
|
+
* eachBar((c) => {
|
|
372
|
+
* const b = box.new(c.i - 10, c.high, c.i - 1, c.low);
|
|
373
|
+
* box.set_rightbottom(b, c.i, c.low);
|
|
374
|
+
* });
|
|
348
375
|
* ```
|
|
349
376
|
*/
|
|
350
377
|
export function set_rightbottom(id: Box, right: number, bottom: number): Box {
|
|
@@ -356,22 +383,20 @@ export function set_rightbottom(id: Box, right: number, bottom: number): Box {
|
|
|
356
383
|
}
|
|
357
384
|
|
|
358
385
|
/**
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* @param id -
|
|
362
|
-
* @param left - New left
|
|
363
|
-
* @param right - New right
|
|
364
|
-
* @param xloc -
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* @remarks
|
|
368
|
-
* When changing xloc, you must provide appropriate x coordinates for the new system.
|
|
369
|
-
*
|
|
386
|
+
* Changes what the box's x coordinates are and sets its left and right sides in that unit. Does nothing on a
|
|
387
|
+
* deleted box.
|
|
388
|
+
* @param id - The box.
|
|
389
|
+
* @param left - New x of the left side, in the unit of `xloc`.
|
|
390
|
+
* @param right - New x of the right side, in the unit of `xloc`.
|
|
391
|
+
* @param xloc - `xloc.bar_index` (bar indexes), `xloc.bar_time` (UNIX times in ms) or `xloc.pane` (percents of the
|
|
392
|
+
* pane's width).
|
|
393
|
+
* @returns The same box.
|
|
370
394
|
* @example
|
|
371
|
-
* ```
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
395
|
+
* ```js
|
|
396
|
+
* eachBar((c) => {
|
|
397
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
398
|
+
* box.set_xloc(b, c.time - 3600000, c.time, xloc.bar_time);
|
|
399
|
+
* });
|
|
375
400
|
* ```
|
|
376
401
|
*/
|
|
377
402
|
export function set_xloc(id: Box, left: number, right: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Box {
|
|
@@ -383,16 +408,16 @@ export function set_xloc(id: Box, left: number, right: number, xloc: 'bar_index'
|
|
|
383
408
|
}
|
|
384
409
|
|
|
385
410
|
/**
|
|
386
|
-
* Sets the
|
|
387
|
-
*
|
|
388
|
-
* @param
|
|
389
|
-
* @
|
|
390
|
-
* @returns Modified box object
|
|
391
|
-
*
|
|
411
|
+
* Sets whether the box continues sideways to the edge of the pane. Does nothing on a deleted box.
|
|
412
|
+
* @param id - The box.
|
|
413
|
+
* @param extend - `extend.none`, `extend.left`, `extend.right` or `extend.both`.
|
|
414
|
+
* @returns The same box.
|
|
392
415
|
* @example
|
|
393
|
-
* ```
|
|
394
|
-
*
|
|
395
|
-
* box.
|
|
416
|
+
* ```js
|
|
417
|
+
* eachBar((c) => {
|
|
418
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
419
|
+
* box.set_extend(b, extend.right);
|
|
420
|
+
* });
|
|
396
421
|
* ```
|
|
397
422
|
*/
|
|
398
423
|
export function set_extend(id: Box, extend: 'none' | 'left' | 'right' | 'both'): Box {
|
|
@@ -406,16 +431,16 @@ export function set_extend(id: Box, extend: 'none' | 'left' | 'right' | 'both'):
|
|
|
406
431
|
// =============================================================================
|
|
407
432
|
|
|
408
433
|
/**
|
|
409
|
-
* Sets the border
|
|
410
|
-
*
|
|
411
|
-
* @param
|
|
412
|
-
* @
|
|
413
|
-
* @returns Modified box object
|
|
414
|
-
*
|
|
434
|
+
* Sets the colour of the box's border. Does nothing on a deleted box.
|
|
435
|
+
* @param id - The box.
|
|
436
|
+
* @param borderColor - New colour (`color.red`, `"#FF0000"`, `color.new(color.red, 50)`...).
|
|
437
|
+
* @returns The same box.
|
|
415
438
|
* @example
|
|
416
|
-
* ```
|
|
417
|
-
*
|
|
418
|
-
* box.
|
|
439
|
+
* ```js
|
|
440
|
+
* eachBar((c) => {
|
|
441
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
442
|
+
* box.set_border_color(b, color.red);
|
|
443
|
+
* });
|
|
419
444
|
* ```
|
|
420
445
|
*/
|
|
421
446
|
export function set_border_color(id: Box, borderColor: color): Box {
|
|
@@ -425,16 +450,16 @@ export function set_border_color(id: Box, borderColor: color): Box {
|
|
|
425
450
|
}
|
|
426
451
|
|
|
427
452
|
/**
|
|
428
|
-
* Sets the border
|
|
429
|
-
*
|
|
430
|
-
* @param
|
|
431
|
-
* @
|
|
432
|
-
* @returns Modified box object
|
|
433
|
-
*
|
|
453
|
+
* Sets the width of the box's border. Does nothing on a deleted box.
|
|
454
|
+
* @param id - The box.
|
|
455
|
+
* @param width - New width in pixels; 0 draws no border.
|
|
456
|
+
* @returns The same box.
|
|
434
457
|
* @example
|
|
435
|
-
* ```
|
|
436
|
-
*
|
|
437
|
-
* box.
|
|
458
|
+
* ```js
|
|
459
|
+
* eachBar((c) => {
|
|
460
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
461
|
+
* box.set_border_width(b, 2);
|
|
462
|
+
* });
|
|
438
463
|
* ```
|
|
439
464
|
*/
|
|
440
465
|
export function set_border_width(id: Box, width: number): Box {
|
|
@@ -444,16 +469,16 @@ export function set_border_width(id: Box, width: number): Box {
|
|
|
444
469
|
}
|
|
445
470
|
|
|
446
471
|
/**
|
|
447
|
-
* Sets the border
|
|
448
|
-
*
|
|
449
|
-
* @param
|
|
450
|
-
* @
|
|
451
|
-
* @returns Modified box object
|
|
452
|
-
*
|
|
472
|
+
* Sets the style of the box's border. Does nothing on a deleted box.
|
|
473
|
+
* @param id - The box.
|
|
474
|
+
* @param style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`.
|
|
475
|
+
* @returns The same box.
|
|
453
476
|
* @example
|
|
454
|
-
* ```
|
|
455
|
-
*
|
|
456
|
-
* box.
|
|
477
|
+
* ```js
|
|
478
|
+
* eachBar((c) => {
|
|
479
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
480
|
+
* box.set_border_style(b, line.style_dashed);
|
|
481
|
+
* });
|
|
457
482
|
* ```
|
|
458
483
|
*/
|
|
459
484
|
export function set_border_style(id: Box, style: 'solid' | 'dotted' | 'dashed'): Box {
|
|
@@ -463,16 +488,16 @@ export function set_border_style(id: Box, style: 'solid' | 'dotted' | 'dashed'):
|
|
|
463
488
|
}
|
|
464
489
|
|
|
465
490
|
/**
|
|
466
|
-
* Sets the
|
|
467
|
-
*
|
|
468
|
-
* @param
|
|
469
|
-
* @
|
|
470
|
-
* @returns Modified box object
|
|
471
|
-
*
|
|
491
|
+
* Sets the fill colour of the box. Does nothing on a deleted box.
|
|
492
|
+
* @param id - The box.
|
|
493
|
+
* @param bgColor - New fill colour; a transparent one (`color.new(color.green, 80)`) keeps the bars visible.
|
|
494
|
+
* @returns The same box.
|
|
472
495
|
* @example
|
|
473
|
-
* ```
|
|
474
|
-
*
|
|
475
|
-
* box.
|
|
496
|
+
* ```js
|
|
497
|
+
* eachBar((c) => {
|
|
498
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
499
|
+
* box.set_bgcolor(b, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));
|
|
500
|
+
* });
|
|
476
501
|
* ```
|
|
477
502
|
*/
|
|
478
503
|
export function set_bgcolor(id: Box, bgColor: color): Box {
|
|
@@ -486,16 +511,16 @@ export function set_bgcolor(id: Box, bgColor: color): Box {
|
|
|
486
511
|
// =============================================================================
|
|
487
512
|
|
|
488
513
|
/**
|
|
489
|
-
* Sets the text
|
|
490
|
-
*
|
|
491
|
-
* @param
|
|
492
|
-
* @
|
|
493
|
-
* @returns Modified box object
|
|
494
|
-
*
|
|
514
|
+
* Sets the text written inside the box. Does nothing on a deleted box.
|
|
515
|
+
* @param id - The box.
|
|
516
|
+
* @param text - New text; `\n` starts a new line.
|
|
517
|
+
* @returns The same box.
|
|
495
518
|
* @example
|
|
496
|
-
* ```
|
|
497
|
-
*
|
|
498
|
-
* box.
|
|
519
|
+
* ```js
|
|
520
|
+
* eachBar((c) => {
|
|
521
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
522
|
+
* box.set_text(b, "Range " + str.tostring(c.high - c.low, "#.##"));
|
|
523
|
+
* });
|
|
499
524
|
* ```
|
|
500
525
|
*/
|
|
501
526
|
export function set_text(id: Box, text: string): Box {
|
|
@@ -505,16 +530,16 @@ export function set_text(id: Box, text: string): Box {
|
|
|
505
530
|
}
|
|
506
531
|
|
|
507
532
|
/**
|
|
508
|
-
* Sets the text
|
|
509
|
-
*
|
|
510
|
-
* @param
|
|
511
|
-
* @
|
|
512
|
-
* @returns Modified box object
|
|
513
|
-
*
|
|
533
|
+
* Sets the colour of the box's text. Does nothing on a deleted box.
|
|
534
|
+
* @param id - The box.
|
|
535
|
+
* @param textColor - New text colour.
|
|
536
|
+
* @returns The same box.
|
|
514
537
|
* @example
|
|
515
|
-
* ```
|
|
516
|
-
*
|
|
517
|
-
* box.
|
|
538
|
+
* ```js
|
|
539
|
+
* eachBar((c) => {
|
|
540
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
541
|
+
* box.set_text_color(b, color.black);
|
|
542
|
+
* });
|
|
518
543
|
* ```
|
|
519
544
|
*/
|
|
520
545
|
export function set_text_color(id: Box, textColor: color): Box {
|
|
@@ -524,16 +549,16 @@ export function set_text_color(id: Box, textColor: color): Box {
|
|
|
524
549
|
}
|
|
525
550
|
|
|
526
551
|
/**
|
|
527
|
-
* Sets the text
|
|
528
|
-
*
|
|
529
|
-
* @param
|
|
530
|
-
* @
|
|
531
|
-
* @returns Modified box object
|
|
532
|
-
*
|
|
552
|
+
* Sets the size of the box's text. Does nothing on a deleted box.
|
|
553
|
+
* @param id - The box.
|
|
554
|
+
* @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.
|
|
555
|
+
* @returns The same box.
|
|
533
556
|
* @example
|
|
534
|
-
* ```
|
|
535
|
-
*
|
|
536
|
-
* box.
|
|
557
|
+
* ```js
|
|
558
|
+
* eachBar((c) => {
|
|
559
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
560
|
+
* box.set_text_size(b, size.large);
|
|
561
|
+
* });
|
|
537
562
|
* ```
|
|
538
563
|
*/
|
|
539
564
|
export function set_text_size(id: Box, size: string | number): Box {
|
|
@@ -543,16 +568,16 @@ export function set_text_size(id: Box, size: string | number): Box {
|
|
|
543
568
|
}
|
|
544
569
|
|
|
545
570
|
/**
|
|
546
|
-
* Sets the horizontal text
|
|
547
|
-
*
|
|
548
|
-
* @param
|
|
549
|
-
* @
|
|
550
|
-
* @returns Modified box object
|
|
551
|
-
*
|
|
571
|
+
* Sets the horizontal place of the text inside the box. Does nothing on a deleted box.
|
|
572
|
+
* @param id - The box.
|
|
573
|
+
* @param align - `text.align_left`, `text.align_center` or `text.align_right`.
|
|
574
|
+
* @returns The same box.
|
|
552
575
|
* @example
|
|
553
|
-
* ```
|
|
554
|
-
*
|
|
555
|
-
* box.
|
|
576
|
+
* ```js
|
|
577
|
+
* eachBar((c) => {
|
|
578
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
579
|
+
* box.set_text_halign(b, text.align_left);
|
|
580
|
+
* });
|
|
556
581
|
* ```
|
|
557
582
|
*/
|
|
558
583
|
export function set_text_halign(id: Box, align: 'left' | 'center' | 'right'): Box {
|
|
@@ -562,16 +587,16 @@ export function set_text_halign(id: Box, align: 'left' | 'center' | 'right'): Bo
|
|
|
562
587
|
}
|
|
563
588
|
|
|
564
589
|
/**
|
|
565
|
-
* Sets the vertical text
|
|
566
|
-
*
|
|
567
|
-
* @param
|
|
568
|
-
* @
|
|
569
|
-
* @returns Modified box object
|
|
570
|
-
*
|
|
590
|
+
* Sets the vertical place of the text inside the box. Does nothing on a deleted box.
|
|
591
|
+
* @param id - The box.
|
|
592
|
+
* @param align - `text.align_top`, `text.align_center` or `text.align_bottom`.
|
|
593
|
+
* @returns The same box.
|
|
571
594
|
* @example
|
|
572
|
-
* ```
|
|
573
|
-
*
|
|
574
|
-
* box.
|
|
595
|
+
* ```js
|
|
596
|
+
* eachBar((c) => {
|
|
597
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
598
|
+
* box.set_text_valign(b, text.align_top);
|
|
599
|
+
* });
|
|
575
600
|
* ```
|
|
576
601
|
*/
|
|
577
602
|
export function set_text_valign(id: Box, align: 'top' | 'center' | 'bottom'): Box {
|
|
@@ -581,16 +606,16 @@ export function set_text_valign(id: Box, align: 'top' | 'center' | 'bottom'): Bo
|
|
|
581
606
|
}
|
|
582
607
|
|
|
583
608
|
/**
|
|
584
|
-
* Sets
|
|
585
|
-
*
|
|
586
|
-
* @param
|
|
587
|
-
* @
|
|
588
|
-
* @returns Modified box object
|
|
589
|
-
*
|
|
609
|
+
* Sets whether a long text wraps onto several lines to fit the width of the box. Does nothing on a deleted box.
|
|
610
|
+
* @param id - The box.
|
|
611
|
+
* @param wrap - `text.wrap_auto` (wrap to the box's width) or `text.wrap_none` (each line stays whole).
|
|
612
|
+
* @returns The same box.
|
|
590
613
|
* @example
|
|
591
|
-
* ```
|
|
592
|
-
*
|
|
593
|
-
* box.
|
|
614
|
+
* ```js
|
|
615
|
+
* eachBar((c) => {
|
|
616
|
+
* const b = box.new(c.i - 3, c.high, c.i, c.low, { text: "A long note about this zone" });
|
|
617
|
+
* box.set_text_wrap(b, text.wrap_auto);
|
|
618
|
+
* });
|
|
594
619
|
* ```
|
|
595
620
|
*/
|
|
596
621
|
export function set_text_wrap(id: Box, wrap: 'none' | 'auto'): Box {
|
|
@@ -600,16 +625,16 @@ export function set_text_wrap(id: Box, wrap: 'none' | 'auto'): Box {
|
|
|
600
625
|
}
|
|
601
626
|
|
|
602
627
|
/**
|
|
603
|
-
* Sets the text
|
|
604
|
-
*
|
|
605
|
-
* @param
|
|
606
|
-
* @
|
|
607
|
-
* @returns Modified box object
|
|
608
|
-
*
|
|
628
|
+
* Sets the font of the box's text. Does nothing on a deleted box.
|
|
629
|
+
* @param id - The box.
|
|
630
|
+
* @param font - `font.family_default` or `font.family_monospace`.
|
|
631
|
+
* @returns The same box.
|
|
609
632
|
* @example
|
|
610
|
-
* ```
|
|
611
|
-
*
|
|
612
|
-
* box.
|
|
633
|
+
* ```js
|
|
634
|
+
* eachBar((c) => {
|
|
635
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "123.45" });
|
|
636
|
+
* box.set_text_font_family(b, font.family_monospace);
|
|
637
|
+
* });
|
|
613
638
|
* ```
|
|
614
639
|
*/
|
|
615
640
|
export function set_text_font_family(id: Box, font: 'default' | 'monospace'): Box {
|
|
@@ -619,19 +644,15 @@ export function set_text_font_family(id: Box, font: 'default' | 'monospace'): Bo
|
|
|
619
644
|
}
|
|
620
645
|
|
|
621
646
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* @param id -
|
|
625
|
-
*
|
|
626
|
-
* @remarks
|
|
627
|
-
* Removes the box from `box.all()`. As in PineScript, the deleted box is `na`: its getters
|
|
628
|
-
* return NaN and its setters do nothing. Deleting it twice has no effect.
|
|
629
|
-
*
|
|
647
|
+
* Removes the box from the chart and from `box.all`. Afterwards its getters return NaN and its setters do nothing;
|
|
648
|
+
* deleting it again does nothing.
|
|
649
|
+
* @param id - The box to delete.
|
|
630
650
|
* @example
|
|
631
|
-
* ```
|
|
632
|
-
*
|
|
633
|
-
* box.
|
|
634
|
-
*
|
|
651
|
+
* ```js
|
|
652
|
+
* eachBar((c) => {
|
|
653
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
654
|
+
* if (c.i < c.n - 1) box.delete(b); // keep only the box of the last bar
|
|
655
|
+
* });
|
|
635
656
|
* ```
|
|
636
657
|
*/
|
|
637
658
|
export function delete_box(id: Box): void {
|
|
@@ -645,14 +666,33 @@ function pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): num
|
|
|
645
666
|
}
|
|
646
667
|
|
|
647
668
|
/**
|
|
648
|
-
*
|
|
669
|
+
* Returns the boxes that are still on the chart, oldest first. The array is a copy.
|
|
670
|
+
* (In a script, `box.all` is read as a value, without a call.)
|
|
671
|
+
* @returns The live boxes in creation order.
|
|
672
|
+
* @example
|
|
673
|
+
* ```js
|
|
674
|
+
* eachBar((c) => {
|
|
675
|
+
* if (c.i === c.n - 1) for (const b of box.all) box.set_right(b, c.i);
|
|
676
|
+
* });
|
|
677
|
+
* ```
|
|
649
678
|
*/
|
|
650
679
|
export function all(): Box[] {
|
|
651
680
|
return allDrawings('box');
|
|
652
681
|
}
|
|
653
682
|
|
|
654
683
|
/**
|
|
655
|
-
*
|
|
684
|
+
* Moves the box's top-left corner to a chart point: its `index` for a `xloc.bar_index` box, its `time` for a
|
|
685
|
+
* `xloc.bar_time` box (NaN when the point has none), and its `price`. Does nothing on a deleted box.
|
|
686
|
+
* @param id - The box.
|
|
687
|
+
* @param point - The new top-left corner.
|
|
688
|
+
* @returns The same box.
|
|
689
|
+
* @example
|
|
690
|
+
* ```js
|
|
691
|
+
* eachBar((c) => {
|
|
692
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
693
|
+
* box.set_top_left_point(b, chart.point.from_index(c.i - 20, c.get(high, 20)));
|
|
694
|
+
* });
|
|
695
|
+
* ```
|
|
656
696
|
*/
|
|
657
697
|
export function set_top_left_point(id: Box, point: ChartPoint): Box {
|
|
658
698
|
if (isDeleted(id)) return id;
|
|
@@ -662,7 +702,17 @@ export function set_top_left_point(id: Box, point: ChartPoint): Box {
|
|
|
662
702
|
}
|
|
663
703
|
|
|
664
704
|
/**
|
|
665
|
-
*
|
|
705
|
+
* Moves the box's bottom-right corner to a chart point (see `box.set_top_left_point`). Does nothing on a deleted box.
|
|
706
|
+
* @param id - The box.
|
|
707
|
+
* @param point - The new bottom-right corner.
|
|
708
|
+
* @returns The same box.
|
|
709
|
+
* @example
|
|
710
|
+
* ```js
|
|
711
|
+
* eachBar((c) => {
|
|
712
|
+
* const b = box.new(c.i - 10, c.high, c.i - 1, c.low);
|
|
713
|
+
* box.set_bottom_right_point(b, chart.point.now(c.low));
|
|
714
|
+
* });
|
|
715
|
+
* ```
|
|
666
716
|
*/
|
|
667
717
|
export function set_bottom_right_point(id: Box, point: ChartPoint): Box {
|
|
668
718
|
if (isDeleted(id)) return id;
|
|
@@ -672,8 +722,17 @@ export function set_bottom_right_point(id: Box, point: ChartPoint): Box {
|
|
|
672
722
|
}
|
|
673
723
|
|
|
674
724
|
/**
|
|
675
|
-
*
|
|
676
|
-
*
|
|
725
|
+
* Makes the box's text bold, italic, both or plain. Does nothing on a deleted box.
|
|
726
|
+
* @param id - The box.
|
|
727
|
+
* @param formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
|
|
728
|
+
* @returns The same box.
|
|
729
|
+
* @example
|
|
730
|
+
* ```js
|
|
731
|
+
* eachBar((c) => {
|
|
732
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
733
|
+
* box.set_text_formatting(b, text.format_bold);
|
|
734
|
+
* });
|
|
735
|
+
* ```
|
|
677
736
|
*/
|
|
678
737
|
export function set_text_formatting(id: Box, formatting: number): Box {
|
|
679
738
|
if (isDeleted(id)) return id;
|