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/dist/esm/box/index.js
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
|
*/
|
|
@@ -49,108 +47,76 @@ export function new_box(...args) {
|
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
52
|
-
* Returns the left
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
-
* @returns Left border coordinate (bar index or timestamp)
|
|
56
|
-
*
|
|
57
|
-
* @remarks
|
|
58
|
-
* **COMPUTATIONAL USE**: Calculate gap duration, validate range timeframes
|
|
59
|
-
*
|
|
50
|
+
* Returns the x coordinate of the box's left side, for example to count how many bars a zone has been open.
|
|
51
|
+
* @param id - The box.
|
|
52
|
+
* @returns A bar index, a UNIX time in ms or a pane percent, by the box's xloc; NaN for a deleted box.
|
|
60
53
|
* @example
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* if (duration > 50) {
|
|
67
|
-
* console.log('Gap has been open for 50+ bars');
|
|
68
|
-
* }
|
|
54
|
+
* ```js
|
|
55
|
+
* eachBar((c) => {
|
|
56
|
+
* const b = box.new(c.i - 10, c.get(high, 10), c.i, c.low);
|
|
57
|
+
* const age = c.i - box.get_left(b); // 10
|
|
58
|
+
* });
|
|
69
59
|
* ```
|
|
70
60
|
*/
|
|
71
61
|
export function get_left(id) {
|
|
72
62
|
return id.left;
|
|
73
63
|
}
|
|
74
64
|
/**
|
|
75
|
-
* Returns the
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
* @returns Right border coordinate (bar index or timestamp)
|
|
79
|
-
*
|
|
80
|
-
* @remarks
|
|
81
|
-
* **COMPUTATIONAL USE**: Calculate gap duration, update trailing edges
|
|
82
|
-
*
|
|
65
|
+
* Returns the x coordinate of the box's right side.
|
|
66
|
+
* @param id - The box.
|
|
67
|
+
* @returns A bar index, a UNIX time in ms or a pane percent, by the box's xloc; NaN for a deleted box.
|
|
83
68
|
* @example
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
*
|
|
69
|
+
* ```js
|
|
70
|
+
* eachBar((c) => {
|
|
71
|
+
* const b = box.new(c.i - 10, c.get(high, 10), c.i, c.low);
|
|
72
|
+
* const bars = box.get_right(b) - box.get_left(b); // 10
|
|
73
|
+
* });
|
|
87
74
|
* ```
|
|
88
75
|
*/
|
|
89
76
|
export function get_right(id) {
|
|
90
77
|
return id.right;
|
|
91
78
|
}
|
|
92
79
|
/**
|
|
93
|
-
* Returns the top
|
|
94
|
-
*
|
|
95
|
-
* @
|
|
96
|
-
* @returns Top border price
|
|
97
|
-
*
|
|
98
|
-
* @remarks
|
|
99
|
-
* **COMPUTATIONAL USE**: Detect breakouts above resistance, check gap fills
|
|
100
|
-
*
|
|
80
|
+
* Returns the price of the box's top side, for example to test a breakout above a range.
|
|
81
|
+
* @param id - The box.
|
|
82
|
+
* @returns The top price; NaN for a deleted box.
|
|
101
83
|
* @example
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* if (high > box.get_top(gap)) {
|
|
108
|
-
* console.log('Gap completely filled!');
|
|
109
|
-
* }
|
|
84
|
+
* ```js
|
|
85
|
+
* eachBar((c) => {
|
|
86
|
+
* const b = box.new(c.i - 10, c.get(high, 1), c.i - 1, c.get(low, 1));
|
|
87
|
+
* if (c.close > box.get_top(b)) label.new(c.i, c.high, "Breakout");
|
|
88
|
+
* });
|
|
110
89
|
* ```
|
|
111
90
|
*/
|
|
112
91
|
export function get_top(id) {
|
|
113
92
|
return id.top;
|
|
114
93
|
}
|
|
115
94
|
/**
|
|
116
|
-
* Returns the bottom
|
|
117
|
-
*
|
|
118
|
-
* @
|
|
119
|
-
* @returns Bottom border price
|
|
120
|
-
*
|
|
121
|
-
* @remarks
|
|
122
|
-
* **COMPUTATIONAL USE**: Detect breakouts below support, check gap fills
|
|
123
|
-
*
|
|
95
|
+
* Returns the price of the box's bottom side, for example to test a breakdown below a range.
|
|
96
|
+
* @param id - The box.
|
|
97
|
+
* @returns The bottom price; NaN for a deleted box.
|
|
124
98
|
* @example
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* if (low < box.get_top(gap) && low > box.get_bottom(gap)) {
|
|
131
|
-
* console.log('Price entered the gap!');
|
|
132
|
-
* }
|
|
99
|
+
* ```js
|
|
100
|
+
* eachBar((c) => {
|
|
101
|
+
* const b = box.new(c.i - 10, c.get(high, 1), c.i - 1, c.get(low, 1));
|
|
102
|
+
* if (c.close < box.get_bottom(b)) label.new(c.i, c.low, "Breakdown", { style: label.style_label_up });
|
|
103
|
+
* });
|
|
133
104
|
* ```
|
|
134
105
|
*/
|
|
135
106
|
export function get_bottom(id) {
|
|
136
107
|
return id.bottom;
|
|
137
108
|
}
|
|
138
109
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* @param id -
|
|
142
|
-
* @returns
|
|
143
|
-
*
|
|
144
|
-
* @remarks
|
|
145
|
-
* Creates a shallow copy of the box. Modifications to the copy won't affect the original.
|
|
146
|
-
*
|
|
110
|
+
* Makes a new box with the same sides, colours and text as `id` (it counts toward `max_boxes_count`).
|
|
111
|
+
* Changing the copy does not change the original.
|
|
112
|
+
* @param id - The box to copy.
|
|
113
|
+
* @returns The new box.
|
|
147
114
|
* @example
|
|
148
|
-
* ```
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* copiedBox.top = 110;
|
|
115
|
+
* ```js
|
|
116
|
+
* eachBar((c) => {
|
|
117
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
118
|
+
* box.set_bgcolor(box.copy(b), color.new(color.red, 80)); // a red copy over the same bars
|
|
119
|
+
* });
|
|
154
120
|
* ```
|
|
155
121
|
*/
|
|
156
122
|
export function copy(id) {
|
|
@@ -160,16 +126,17 @@ export function copy(id) {
|
|
|
160
126
|
// COORDINATE SETTERS
|
|
161
127
|
// =============================================================================
|
|
162
128
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* @param
|
|
166
|
-
*
|
|
167
|
-
* @returns
|
|
168
|
-
*
|
|
129
|
+
* Moves the box's left side. Does nothing on a deleted box.
|
|
130
|
+
* @param id - The box.
|
|
131
|
+
* @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
|
|
132
|
+
* down.
|
|
133
|
+
* @returns The same box.
|
|
169
134
|
* @example
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
* box.
|
|
135
|
+
* ```js
|
|
136
|
+
* eachBar((c) => {
|
|
137
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
138
|
+
* box.set_left(b, c.i - 20);
|
|
139
|
+
* });
|
|
173
140
|
* ```
|
|
174
141
|
*/
|
|
175
142
|
export function set_left(id, left) {
|
|
@@ -180,16 +147,17 @@ export function set_left(id, left) {
|
|
|
180
147
|
return id;
|
|
181
148
|
}
|
|
182
149
|
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* @param
|
|
186
|
-
*
|
|
187
|
-
* @returns
|
|
188
|
-
*
|
|
150
|
+
* Moves the box's right side, for example to stretch a zone to the current bar. Does nothing on a deleted box.
|
|
151
|
+
* @param id - The box.
|
|
152
|
+
* @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
|
|
153
|
+
* down.
|
|
154
|
+
* @returns The same box.
|
|
189
155
|
* @example
|
|
190
|
-
* ```
|
|
191
|
-
*
|
|
192
|
-
* box.
|
|
156
|
+
* ```js
|
|
157
|
+
* eachBar((c) => {
|
|
158
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
159
|
+
* box.set_right(b, c.i + 10); // reach 10 bars into the future
|
|
160
|
+
* });
|
|
193
161
|
* ```
|
|
194
162
|
*/
|
|
195
163
|
export function set_right(id, right) {
|
|
@@ -200,16 +168,16 @@ export function set_right(id, right) {
|
|
|
200
168
|
return id;
|
|
201
169
|
}
|
|
202
170
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @param
|
|
206
|
-
* @
|
|
207
|
-
* @returns Modified box object
|
|
208
|
-
*
|
|
171
|
+
* Moves the box's top side. Does nothing on a deleted box.
|
|
172
|
+
* @param id - The box.
|
|
173
|
+
* @param top - New top price.
|
|
174
|
+
* @returns The same box.
|
|
209
175
|
* @example
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* box.
|
|
176
|
+
* ```js
|
|
177
|
+
* eachBar((c) => {
|
|
178
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
179
|
+
* box.set_top(b, c.get(high, 10));
|
|
180
|
+
* });
|
|
213
181
|
* ```
|
|
214
182
|
*/
|
|
215
183
|
export function set_top(id, top) {
|
|
@@ -219,16 +187,16 @@ export function set_top(id, top) {
|
|
|
219
187
|
return id;
|
|
220
188
|
}
|
|
221
189
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @param
|
|
225
|
-
* @
|
|
226
|
-
* @returns Modified box object
|
|
227
|
-
*
|
|
190
|
+
* Moves the box's bottom side. Does nothing on a deleted box.
|
|
191
|
+
* @param id - The box.
|
|
192
|
+
* @param bottom - New bottom price.
|
|
193
|
+
* @returns The same box.
|
|
228
194
|
* @example
|
|
229
|
-
* ```
|
|
230
|
-
*
|
|
231
|
-
* box.
|
|
195
|
+
* ```js
|
|
196
|
+
* eachBar((c) => {
|
|
197
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
198
|
+
* box.set_bottom(b, c.get(low, 10));
|
|
199
|
+
* });
|
|
232
200
|
* ```
|
|
233
201
|
*/
|
|
234
202
|
export function set_bottom(id, bottom) {
|
|
@@ -238,17 +206,17 @@ export function set_bottom(id, bottom) {
|
|
|
238
206
|
return id;
|
|
239
207
|
}
|
|
240
208
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* @param
|
|
244
|
-
* @param
|
|
245
|
-
* @
|
|
246
|
-
* @returns Modified box object
|
|
247
|
-
*
|
|
209
|
+
* Moves the box's top-left corner (left side and top price). Does nothing on a deleted box.
|
|
210
|
+
* @param id - The box.
|
|
211
|
+
* @param left - New x of the left side, by the box's xloc. A bar index is rounded down.
|
|
212
|
+
* @param top - New top price.
|
|
213
|
+
* @returns The same box.
|
|
248
214
|
* @example
|
|
249
|
-
* ```
|
|
250
|
-
*
|
|
251
|
-
* box.
|
|
215
|
+
* ```js
|
|
216
|
+
* eachBar((c) => {
|
|
217
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
218
|
+
* box.set_lefttop(b, c.i - 20, c.get(high, 20));
|
|
219
|
+
* });
|
|
252
220
|
* ```
|
|
253
221
|
*/
|
|
254
222
|
export function set_lefttop(id, left, top) {
|
|
@@ -260,17 +228,17 @@ export function set_lefttop(id, left, top) {
|
|
|
260
228
|
return id;
|
|
261
229
|
}
|
|
262
230
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* @param
|
|
266
|
-
* @param
|
|
267
|
-
* @
|
|
268
|
-
* @returns Modified box object
|
|
269
|
-
*
|
|
231
|
+
* Moves the box's bottom-right corner (right side and bottom price). Does nothing on a deleted box.
|
|
232
|
+
* @param id - The box.
|
|
233
|
+
* @param right - New x of the right side, by the box's xloc. A bar index is rounded down.
|
|
234
|
+
* @param bottom - New bottom price.
|
|
235
|
+
* @returns The same box.
|
|
270
236
|
* @example
|
|
271
|
-
* ```
|
|
272
|
-
*
|
|
273
|
-
* box.
|
|
237
|
+
* ```js
|
|
238
|
+
* eachBar((c) => {
|
|
239
|
+
* const b = box.new(c.i - 10, c.high, c.i - 1, c.low);
|
|
240
|
+
* box.set_rightbottom(b, c.i, c.low);
|
|
241
|
+
* });
|
|
274
242
|
* ```
|
|
275
243
|
*/
|
|
276
244
|
export function set_rightbottom(id, right, bottom) {
|
|
@@ -282,22 +250,20 @@ export function set_rightbottom(id, right, bottom) {
|
|
|
282
250
|
return id;
|
|
283
251
|
}
|
|
284
252
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* @param id -
|
|
288
|
-
* @param left - New left
|
|
289
|
-
* @param right - New right
|
|
290
|
-
* @param xloc -
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* @remarks
|
|
294
|
-
* When changing xloc, you must provide appropriate x coordinates for the new system.
|
|
295
|
-
*
|
|
253
|
+
* Changes what the box's x coordinates are and sets its left and right sides in that unit. Does nothing on a
|
|
254
|
+
* deleted box.
|
|
255
|
+
* @param id - The box.
|
|
256
|
+
* @param left - New x of the left side, in the unit of `xloc`.
|
|
257
|
+
* @param right - New x of the right side, in the unit of `xloc`.
|
|
258
|
+
* @param xloc - `xloc.bar_index` (bar indexes), `xloc.bar_time` (UNIX times in ms) or `xloc.pane` (percents of the
|
|
259
|
+
* pane's width).
|
|
260
|
+
* @returns The same box.
|
|
296
261
|
* @example
|
|
297
|
-
* ```
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
262
|
+
* ```js
|
|
263
|
+
* eachBar((c) => {
|
|
264
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
265
|
+
* box.set_xloc(b, c.time - 3600000, c.time, xloc.bar_time);
|
|
266
|
+
* });
|
|
301
267
|
* ```
|
|
302
268
|
*/
|
|
303
269
|
export function set_xloc(id, left, right, xloc) {
|
|
@@ -309,16 +275,16 @@ export function set_xloc(id, left, right, xloc) {
|
|
|
309
275
|
return id;
|
|
310
276
|
}
|
|
311
277
|
/**
|
|
312
|
-
* Sets the
|
|
313
|
-
*
|
|
314
|
-
* @param
|
|
315
|
-
* @
|
|
316
|
-
* @returns Modified box object
|
|
317
|
-
*
|
|
278
|
+
* Sets whether the box continues sideways to the edge of the pane. Does nothing on a deleted box.
|
|
279
|
+
* @param id - The box.
|
|
280
|
+
* @param extend - `extend.none`, `extend.left`, `extend.right` or `extend.both`.
|
|
281
|
+
* @returns The same box.
|
|
318
282
|
* @example
|
|
319
|
-
* ```
|
|
320
|
-
*
|
|
321
|
-
* box.
|
|
283
|
+
* ```js
|
|
284
|
+
* eachBar((c) => {
|
|
285
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
286
|
+
* box.set_extend(b, extend.right);
|
|
287
|
+
* });
|
|
322
288
|
* ```
|
|
323
289
|
*/
|
|
324
290
|
export function set_extend(id, extend) {
|
|
@@ -331,16 +297,16 @@ export function set_extend(id, extend) {
|
|
|
331
297
|
// STYLING SETTERS
|
|
332
298
|
// =============================================================================
|
|
333
299
|
/**
|
|
334
|
-
* Sets the border
|
|
335
|
-
*
|
|
336
|
-
* @param
|
|
337
|
-
* @
|
|
338
|
-
* @returns Modified box object
|
|
339
|
-
*
|
|
300
|
+
* Sets the colour of the box's border. Does nothing on a deleted box.
|
|
301
|
+
* @param id - The box.
|
|
302
|
+
* @param borderColor - New colour (`color.red`, `"#FF0000"`, `color.new(color.red, 50)`...).
|
|
303
|
+
* @returns The same box.
|
|
340
304
|
* @example
|
|
341
|
-
* ```
|
|
342
|
-
*
|
|
343
|
-
* box.
|
|
305
|
+
* ```js
|
|
306
|
+
* eachBar((c) => {
|
|
307
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
308
|
+
* box.set_border_color(b, color.red);
|
|
309
|
+
* });
|
|
344
310
|
* ```
|
|
345
311
|
*/
|
|
346
312
|
export function set_border_color(id, borderColor) {
|
|
@@ -350,16 +316,16 @@ export function set_border_color(id, borderColor) {
|
|
|
350
316
|
return id;
|
|
351
317
|
}
|
|
352
318
|
/**
|
|
353
|
-
* Sets the border
|
|
354
|
-
*
|
|
355
|
-
* @param
|
|
356
|
-
* @
|
|
357
|
-
* @returns Modified box object
|
|
358
|
-
*
|
|
319
|
+
* Sets the width of the box's border. Does nothing on a deleted box.
|
|
320
|
+
* @param id - The box.
|
|
321
|
+
* @param width - New width in pixels; 0 draws no border.
|
|
322
|
+
* @returns The same box.
|
|
359
323
|
* @example
|
|
360
|
-
* ```
|
|
361
|
-
*
|
|
362
|
-
* box.
|
|
324
|
+
* ```js
|
|
325
|
+
* eachBar((c) => {
|
|
326
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
327
|
+
* box.set_border_width(b, 2);
|
|
328
|
+
* });
|
|
363
329
|
* ```
|
|
364
330
|
*/
|
|
365
331
|
export function set_border_width(id, width) {
|
|
@@ -369,16 +335,16 @@ export function set_border_width(id, width) {
|
|
|
369
335
|
return id;
|
|
370
336
|
}
|
|
371
337
|
/**
|
|
372
|
-
* Sets the border
|
|
373
|
-
*
|
|
374
|
-
* @param
|
|
375
|
-
* @
|
|
376
|
-
* @returns Modified box object
|
|
377
|
-
*
|
|
338
|
+
* Sets the style of the box's border. Does nothing on a deleted box.
|
|
339
|
+
* @param id - The box.
|
|
340
|
+
* @param style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`.
|
|
341
|
+
* @returns The same box.
|
|
378
342
|
* @example
|
|
379
|
-
* ```
|
|
380
|
-
*
|
|
381
|
-
* box.
|
|
343
|
+
* ```js
|
|
344
|
+
* eachBar((c) => {
|
|
345
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
346
|
+
* box.set_border_style(b, line.style_dashed);
|
|
347
|
+
* });
|
|
382
348
|
* ```
|
|
383
349
|
*/
|
|
384
350
|
export function set_border_style(id, style) {
|
|
@@ -388,16 +354,16 @@ export function set_border_style(id, style) {
|
|
|
388
354
|
return id;
|
|
389
355
|
}
|
|
390
356
|
/**
|
|
391
|
-
* Sets the
|
|
392
|
-
*
|
|
393
|
-
* @param
|
|
394
|
-
* @
|
|
395
|
-
* @returns Modified box object
|
|
396
|
-
*
|
|
357
|
+
* Sets the fill colour of the box. Does nothing on a deleted box.
|
|
358
|
+
* @param id - The box.
|
|
359
|
+
* @param bgColor - New fill colour; a transparent one (`color.new(color.green, 80)`) keeps the bars visible.
|
|
360
|
+
* @returns The same box.
|
|
397
361
|
* @example
|
|
398
|
-
* ```
|
|
399
|
-
*
|
|
400
|
-
* box.
|
|
362
|
+
* ```js
|
|
363
|
+
* eachBar((c) => {
|
|
364
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
365
|
+
* box.set_bgcolor(b, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));
|
|
366
|
+
* });
|
|
401
367
|
* ```
|
|
402
368
|
*/
|
|
403
369
|
export function set_bgcolor(id, bgColor) {
|
|
@@ -410,16 +376,16 @@ export function set_bgcolor(id, bgColor) {
|
|
|
410
376
|
// TEXT SETTERS
|
|
411
377
|
// =============================================================================
|
|
412
378
|
/**
|
|
413
|
-
* Sets the text
|
|
414
|
-
*
|
|
415
|
-
* @param
|
|
416
|
-
* @
|
|
417
|
-
* @returns Modified box object
|
|
418
|
-
*
|
|
379
|
+
* Sets the text written inside the box. Does nothing on a deleted box.
|
|
380
|
+
* @param id - The box.
|
|
381
|
+
* @param text - New text; `\n` starts a new line.
|
|
382
|
+
* @returns The same box.
|
|
419
383
|
* @example
|
|
420
|
-
* ```
|
|
421
|
-
*
|
|
422
|
-
* box.
|
|
384
|
+
* ```js
|
|
385
|
+
* eachBar((c) => {
|
|
386
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
387
|
+
* box.set_text(b, "Range " + str.tostring(c.high - c.low, "#.##"));
|
|
388
|
+
* });
|
|
423
389
|
* ```
|
|
424
390
|
*/
|
|
425
391
|
export function set_text(id, text) {
|
|
@@ -429,16 +395,16 @@ export function set_text(id, text) {
|
|
|
429
395
|
return id;
|
|
430
396
|
}
|
|
431
397
|
/**
|
|
432
|
-
* Sets the text
|
|
433
|
-
*
|
|
434
|
-
* @param
|
|
435
|
-
* @
|
|
436
|
-
* @returns Modified box object
|
|
437
|
-
*
|
|
398
|
+
* Sets the colour of the box's text. Does nothing on a deleted box.
|
|
399
|
+
* @param id - The box.
|
|
400
|
+
* @param textColor - New text colour.
|
|
401
|
+
* @returns The same box.
|
|
438
402
|
* @example
|
|
439
|
-
* ```
|
|
440
|
-
*
|
|
441
|
-
* box.
|
|
403
|
+
* ```js
|
|
404
|
+
* eachBar((c) => {
|
|
405
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
406
|
+
* box.set_text_color(b, color.black);
|
|
407
|
+
* });
|
|
442
408
|
* ```
|
|
443
409
|
*/
|
|
444
410
|
export function set_text_color(id, textColor) {
|
|
@@ -448,16 +414,16 @@ export function set_text_color(id, textColor) {
|
|
|
448
414
|
return id;
|
|
449
415
|
}
|
|
450
416
|
/**
|
|
451
|
-
* Sets the text
|
|
452
|
-
*
|
|
453
|
-
* @param
|
|
454
|
-
* @
|
|
455
|
-
* @returns Modified box object
|
|
456
|
-
*
|
|
417
|
+
* Sets the size of the box's text. Does nothing on a deleted box.
|
|
418
|
+
* @param id - The box.
|
|
419
|
+
* @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.
|
|
420
|
+
* @returns The same box.
|
|
457
421
|
* @example
|
|
458
|
-
* ```
|
|
459
|
-
*
|
|
460
|
-
* box.
|
|
422
|
+
* ```js
|
|
423
|
+
* eachBar((c) => {
|
|
424
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
425
|
+
* box.set_text_size(b, size.large);
|
|
426
|
+
* });
|
|
461
427
|
* ```
|
|
462
428
|
*/
|
|
463
429
|
export function set_text_size(id, size) {
|
|
@@ -467,16 +433,16 @@ export function set_text_size(id, size) {
|
|
|
467
433
|
return id;
|
|
468
434
|
}
|
|
469
435
|
/**
|
|
470
|
-
* Sets the horizontal text
|
|
471
|
-
*
|
|
472
|
-
* @param
|
|
473
|
-
* @
|
|
474
|
-
* @returns Modified box object
|
|
475
|
-
*
|
|
436
|
+
* Sets the horizontal place of the text inside the box. Does nothing on a deleted box.
|
|
437
|
+
* @param id - The box.
|
|
438
|
+
* @param align - `text.align_left`, `text.align_center` or `text.align_right`.
|
|
439
|
+
* @returns The same box.
|
|
476
440
|
* @example
|
|
477
|
-
* ```
|
|
478
|
-
*
|
|
479
|
-
* box.
|
|
441
|
+
* ```js
|
|
442
|
+
* eachBar((c) => {
|
|
443
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
444
|
+
* box.set_text_halign(b, text.align_left);
|
|
445
|
+
* });
|
|
480
446
|
* ```
|
|
481
447
|
*/
|
|
482
448
|
export function set_text_halign(id, align) {
|
|
@@ -486,16 +452,16 @@ export function set_text_halign(id, align) {
|
|
|
486
452
|
return id;
|
|
487
453
|
}
|
|
488
454
|
/**
|
|
489
|
-
* Sets the vertical text
|
|
490
|
-
*
|
|
491
|
-
* @param
|
|
492
|
-
* @
|
|
493
|
-
* @returns Modified box object
|
|
494
|
-
*
|
|
455
|
+
* Sets the vertical place of the text inside the box. Does nothing on a deleted box.
|
|
456
|
+
* @param id - The box.
|
|
457
|
+
* @param align - `text.align_top`, `text.align_center` or `text.align_bottom`.
|
|
458
|
+
* @returns The same box.
|
|
495
459
|
* @example
|
|
496
|
-
* ```
|
|
497
|
-
*
|
|
498
|
-
* box.
|
|
460
|
+
* ```js
|
|
461
|
+
* eachBar((c) => {
|
|
462
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
463
|
+
* box.set_text_valign(b, text.align_top);
|
|
464
|
+
* });
|
|
499
465
|
* ```
|
|
500
466
|
*/
|
|
501
467
|
export function set_text_valign(id, align) {
|
|
@@ -505,16 +471,16 @@ export function set_text_valign(id, align) {
|
|
|
505
471
|
return id;
|
|
506
472
|
}
|
|
507
473
|
/**
|
|
508
|
-
* Sets
|
|
509
|
-
*
|
|
510
|
-
* @param
|
|
511
|
-
* @
|
|
512
|
-
* @returns Modified box object
|
|
513
|
-
*
|
|
474
|
+
* Sets whether a long text wraps onto several lines to fit the width of the box. Does nothing on a deleted box.
|
|
475
|
+
* @param id - The box.
|
|
476
|
+
* @param wrap - `text.wrap_auto` (wrap to the box's width) or `text.wrap_none` (each line stays whole).
|
|
477
|
+
* @returns The same box.
|
|
514
478
|
* @example
|
|
515
|
-
* ```
|
|
516
|
-
*
|
|
517
|
-
* box.
|
|
479
|
+
* ```js
|
|
480
|
+
* eachBar((c) => {
|
|
481
|
+
* const b = box.new(c.i - 3, c.high, c.i, c.low, { text: "A long note about this zone" });
|
|
482
|
+
* box.set_text_wrap(b, text.wrap_auto);
|
|
483
|
+
* });
|
|
518
484
|
* ```
|
|
519
485
|
*/
|
|
520
486
|
export function set_text_wrap(id, wrap) {
|
|
@@ -524,16 +490,16 @@ export function set_text_wrap(id, wrap) {
|
|
|
524
490
|
return id;
|
|
525
491
|
}
|
|
526
492
|
/**
|
|
527
|
-
* Sets the text
|
|
528
|
-
*
|
|
529
|
-
* @param
|
|
530
|
-
* @
|
|
531
|
-
* @returns Modified box object
|
|
532
|
-
*
|
|
493
|
+
* Sets the font of the box's text. Does nothing on a deleted box.
|
|
494
|
+
* @param id - The box.
|
|
495
|
+
* @param font - `font.family_default` or `font.family_monospace`.
|
|
496
|
+
* @returns The same box.
|
|
533
497
|
* @example
|
|
534
|
-
* ```
|
|
535
|
-
*
|
|
536
|
-
* box.
|
|
498
|
+
* ```js
|
|
499
|
+
* eachBar((c) => {
|
|
500
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "123.45" });
|
|
501
|
+
* box.set_text_font_family(b, font.family_monospace);
|
|
502
|
+
* });
|
|
537
503
|
* ```
|
|
538
504
|
*/
|
|
539
505
|
export function set_text_font_family(id, font) {
|
|
@@ -543,19 +509,15 @@ export function set_text_font_family(id, font) {
|
|
|
543
509
|
return id;
|
|
544
510
|
}
|
|
545
511
|
/**
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
* @param id -
|
|
549
|
-
*
|
|
550
|
-
* @remarks
|
|
551
|
-
* Removes the box from `box.all()`. As in PineScript, the deleted box is `na`: its getters
|
|
552
|
-
* return NaN and its setters do nothing. Deleting it twice has no effect.
|
|
553
|
-
*
|
|
512
|
+
* Removes the box from the chart and from `box.all`. Afterwards its getters return NaN and its setters do nothing;
|
|
513
|
+
* deleting it again does nothing.
|
|
514
|
+
* @param id - The box to delete.
|
|
554
515
|
* @example
|
|
555
|
-
* ```
|
|
556
|
-
*
|
|
557
|
-
* box.
|
|
558
|
-
*
|
|
516
|
+
* ```js
|
|
517
|
+
* eachBar((c) => {
|
|
518
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
519
|
+
* if (c.i < c.n - 1) box.delete(b); // keep only the box of the last bar
|
|
520
|
+
* });
|
|
559
521
|
* ```
|
|
560
522
|
*/
|
|
561
523
|
export function delete_box(id) {
|
|
@@ -567,13 +529,32 @@ function pointX(point, xloc) {
|
|
|
567
529
|
return x ?? NaN;
|
|
568
530
|
}
|
|
569
531
|
/**
|
|
570
|
-
*
|
|
532
|
+
* Returns the boxes that are still on the chart, oldest first. The array is a copy.
|
|
533
|
+
* (In a script, `box.all` is read as a value, without a call.)
|
|
534
|
+
* @returns The live boxes in creation order.
|
|
535
|
+
* @example
|
|
536
|
+
* ```js
|
|
537
|
+
* eachBar((c) => {
|
|
538
|
+
* if (c.i === c.n - 1) for (const b of box.all) box.set_right(b, c.i);
|
|
539
|
+
* });
|
|
540
|
+
* ```
|
|
571
541
|
*/
|
|
572
542
|
export function all() {
|
|
573
543
|
return allDrawings('box');
|
|
574
544
|
}
|
|
575
545
|
/**
|
|
576
|
-
*
|
|
546
|
+
* Moves the box's top-left corner to a chart point: its `index` for a `xloc.bar_index` box, its `time` for a
|
|
547
|
+
* `xloc.bar_time` box (NaN when the point has none), and its `price`. Does nothing on a deleted box.
|
|
548
|
+
* @param id - The box.
|
|
549
|
+
* @param point - The new top-left corner.
|
|
550
|
+
* @returns The same box.
|
|
551
|
+
* @example
|
|
552
|
+
* ```js
|
|
553
|
+
* eachBar((c) => {
|
|
554
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low);
|
|
555
|
+
* box.set_top_left_point(b, chart.point.from_index(c.i - 20, c.get(high, 20)));
|
|
556
|
+
* });
|
|
557
|
+
* ```
|
|
577
558
|
*/
|
|
578
559
|
export function set_top_left_point(id, point) {
|
|
579
560
|
if (isDeleted(id))
|
|
@@ -583,7 +564,17 @@ export function set_top_left_point(id, point) {
|
|
|
583
564
|
return id;
|
|
584
565
|
}
|
|
585
566
|
/**
|
|
586
|
-
*
|
|
567
|
+
* Moves the box's bottom-right corner to a chart point (see `box.set_top_left_point`). Does nothing on a deleted box.
|
|
568
|
+
* @param id - The box.
|
|
569
|
+
* @param point - The new bottom-right corner.
|
|
570
|
+
* @returns The same box.
|
|
571
|
+
* @example
|
|
572
|
+
* ```js
|
|
573
|
+
* eachBar((c) => {
|
|
574
|
+
* const b = box.new(c.i - 10, c.high, c.i - 1, c.low);
|
|
575
|
+
* box.set_bottom_right_point(b, chart.point.now(c.low));
|
|
576
|
+
* });
|
|
577
|
+
* ```
|
|
587
578
|
*/
|
|
588
579
|
export function set_bottom_right_point(id, point) {
|
|
589
580
|
if (isDeleted(id))
|
|
@@ -593,8 +584,17 @@ export function set_bottom_right_point(id, point) {
|
|
|
593
584
|
return id;
|
|
594
585
|
}
|
|
595
586
|
/**
|
|
596
|
-
*
|
|
597
|
-
*
|
|
587
|
+
* Makes the box's text bold, italic, both or plain. Does nothing on a deleted box.
|
|
588
|
+
* @param id - The box.
|
|
589
|
+
* @param formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
|
|
590
|
+
* @returns The same box.
|
|
591
|
+
* @example
|
|
592
|
+
* ```js
|
|
593
|
+
* eachBar((c) => {
|
|
594
|
+
* const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
|
|
595
|
+
* box.set_text_formatting(b, text.format_bold);
|
|
596
|
+
* });
|
|
597
|
+
* ```
|
|
598
598
|
*/
|
|
599
599
|
export function set_text_formatting(id, formatting) {
|
|
600
600
|
if (isDeleted(id))
|