oakscriptjs 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +1065 -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 +1065 -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 +1517 -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/line/index.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Line namespace
|
|
3
|
-
* Functions for creating and manipulating line drawing objects.
|
|
2
|
+
* Line namespace: functions that create, read, change and delete line drawings (`line.*`).
|
|
4
3
|
*
|
|
5
4
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* A line joins two points. Its x coordinates are bar indexes (`xloc.bar_index`, the default), UNIX times in ms
|
|
6
|
+
* (`xloc.bar_time`) or percents of the pane's width (`xloc.pane`); its y coordinates are prices. Besides drawing,
|
|
7
|
+
* `line.get_price()` reads the price of a trend line on any bar, for breakout tests.
|
|
9
8
|
*
|
|
10
9
|
* @version 6
|
|
11
10
|
*/
|
|
@@ -18,21 +17,26 @@ type LineExtend = 'none' | 'left' | 'right' | 'both';
|
|
|
18
17
|
type LineStyle = 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both';
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
20
|
+
* Draws a line 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`. Lines above
|
|
22
|
+
* `max_lines_count` (default 50) are deleted oldest first.
|
|
23
|
+
* @param first_point - Start of the line (`chart.point.from_index(...)`, `chart.point.now()`...).
|
|
24
|
+
* @param second_point - End of the line.
|
|
25
|
+
* @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
|
|
26
|
+
* @param extend - Extends the line past its points: `extend.none`, `extend.left`, `extend.right` or `extend.both`.
|
|
27
|
+
* Default: `extend.none`.
|
|
28
|
+
* @param lineColor - Line colour. Default: blue (#2962FF).
|
|
29
|
+
* @param style - `line.style_solid`, `line.style_dotted`, `line.style_dashed`, `line.style_arrow_left`,
|
|
30
|
+
* `line.style_arrow_right` or `line.style_arrow_both`. Default: `line.style_solid`.
|
|
31
|
+
* @param width - Line width in pixels. Default: 1.
|
|
32
|
+
* @param force_overlay - When true, the line is drawn on the price pane even if the script has its own pane.
|
|
33
|
+
* Default: false.
|
|
34
|
+
* @returns The new line.
|
|
28
35
|
* @example
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* // Calculate price at bar 75 (extrapolated)
|
|
35
|
-
* const price = line.get_price(trendLine, 75); // Returns 175
|
|
36
|
+
* ```js
|
|
37
|
+
* eachBar((c) => {
|
|
38
|
+
* if (c.i === c.n - 1) line.new(chart.point.from_index(c.i - 20, c.get(low, 20)), chart.point.now(c.high));
|
|
39
|
+
* });
|
|
36
40
|
* ```
|
|
37
41
|
*/
|
|
38
42
|
export function new_line(
|
|
@@ -45,6 +49,33 @@ export function new_line(
|
|
|
45
49
|
width?: number,
|
|
46
50
|
force_overlay?: boolean
|
|
47
51
|
): Line;
|
|
52
|
+
/**
|
|
53
|
+
* Draws a line from (x1, y1) to (x2, y2) and returns its handle, to change or delete it later.
|
|
54
|
+
* Inside `eachBar` a Series argument is read on the current bar; the optional arguments can also be given by name in
|
|
55
|
+
* an object after the coordinates. A bar index x is rounded down; it may be up to 500 bars after the last bar.
|
|
56
|
+
* Lines above `max_lines_count` (default 50) are deleted oldest first.
|
|
57
|
+
* @param x1 - x of the first point: a bar index, a UNIX time in ms (`xloc.bar_time`) or a percent of the pane's
|
|
58
|
+
* width (`xloc.pane`).
|
|
59
|
+
* @param y1 - Price of the first point.
|
|
60
|
+
* @param x2 - x of the second point, in the same unit as `x1`.
|
|
61
|
+
* @param y2 - Price of the second point.
|
|
62
|
+
* @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
|
|
63
|
+
* @param extend - Extends the line past its points: `extend.none`, `extend.left`, `extend.right` or `extend.both`.
|
|
64
|
+
* Default: `extend.none`.
|
|
65
|
+
* @param lineColor - Line colour. Default: blue (#2962FF).
|
|
66
|
+
* @param style - `line.style_solid`, `line.style_dotted`, `line.style_dashed`, `line.style_arrow_left`,
|
|
67
|
+
* `line.style_arrow_right` or `line.style_arrow_both`. Default: `line.style_solid`.
|
|
68
|
+
* @param width - Line width in pixels. Default: 1.
|
|
69
|
+
* @param force_overlay - When true, the line is drawn on the price pane even if the script has its own pane.
|
|
70
|
+
* Default: false.
|
|
71
|
+
* @returns The new line.
|
|
72
|
+
* @example
|
|
73
|
+
* ```js
|
|
74
|
+
* eachBar((c) => {
|
|
75
|
+
* if (c.i === c.n - 1) line.new(c.i - 20, c.get(low, 20), c.i, c.low, { color: "#2962FF", extend: extend.right });
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
48
79
|
export function new_line(
|
|
49
80
|
x1: number,
|
|
50
81
|
y1: number,
|
|
@@ -87,26 +118,18 @@ export function new_line(...args: unknown[]): Line {
|
|
|
87
118
|
}
|
|
88
119
|
|
|
89
120
|
/**
|
|
90
|
-
* Returns the price
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @param
|
|
94
|
-
* @
|
|
95
|
-
*
|
|
96
|
-
* @remarks
|
|
97
|
-
* As in PineScript (#174):
|
|
98
|
-
* - the line is read as extended on both sides whatever its `extend`: a point before x1 or after x2 has a price
|
|
99
|
-
* - the price is `y1 + (y2 - y1) * (x - x1) / (x2 - x1)`, in that order (bit for bit)
|
|
100
|
-
* - a line placed with `xloc.bar_time` (or `xloc.pane`) throws "'line.get_price' must be used with lines created using
|
|
101
|
-
* 'xloc=xloc.bar_index'." (runtime error RE10119)
|
|
102
|
-
*
|
|
121
|
+
* Returns the price of the line at a bar index, for example to test whether the close crossed a trend line.
|
|
122
|
+
* The line is read as extended on both sides whatever its `extend`, so any bar has a price.
|
|
123
|
+
* Only for lines placed with `xloc.bar_index`: other lines throw an error.
|
|
124
|
+
* @param id - The line.
|
|
125
|
+
* @param x - Bar index to read the price at.
|
|
126
|
+
* @returns The price on the line at `x`; NaN for a vertical line (x1 equal to x2) or a deleted line.
|
|
103
127
|
* @example
|
|
104
|
-
* ```
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* line.get_price(
|
|
108
|
-
*
|
|
109
|
-
* line.get_price(trendLine, -10); // 90: extended to the left too
|
|
128
|
+
* ```js
|
|
129
|
+
* eachBar((c) => {
|
|
130
|
+
* const l = line.new(c.i - 10, c.get(high, 10), c.i - 1, c.get(high, 1));
|
|
131
|
+
* if (c.close > line.get_price(l, c.i)) label.new(c.i, c.high, "Break");
|
|
132
|
+
* });
|
|
110
133
|
* ```
|
|
111
134
|
*/
|
|
112
135
|
export function get_price(id: Line, x: number): number {
|
|
@@ -119,15 +142,15 @@ export function get_price(id: Line, x: number): number {
|
|
|
119
142
|
}
|
|
120
143
|
|
|
121
144
|
/**
|
|
122
|
-
* Returns the
|
|
123
|
-
*
|
|
124
|
-
* @
|
|
125
|
-
* @returns X coordinate of the first point
|
|
126
|
-
*
|
|
145
|
+
* Returns the x coordinate of the line's first point.
|
|
146
|
+
* @param id - The line.
|
|
147
|
+
* @returns A bar index, a UNIX time in ms or a pane percent, by the line's xloc; NaN for a deleted line.
|
|
127
148
|
* @example
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
*
|
|
149
|
+
* ```js
|
|
150
|
+
* eachBar((c) => {
|
|
151
|
+
* const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);
|
|
152
|
+
* const length = c.i - line.get_x1(l); // 10
|
|
153
|
+
* });
|
|
131
154
|
* ```
|
|
132
155
|
*/
|
|
133
156
|
export function get_x1(id: Line): number {
|
|
@@ -135,15 +158,15 @@ export function get_x1(id: Line): number {
|
|
|
135
158
|
}
|
|
136
159
|
|
|
137
160
|
/**
|
|
138
|
-
* Returns the
|
|
139
|
-
*
|
|
140
|
-
* @
|
|
141
|
-
* @returns X coordinate of the second point
|
|
142
|
-
*
|
|
161
|
+
* Returns the x coordinate of the line's second point.
|
|
162
|
+
* @param id - The line.
|
|
163
|
+
* @returns A bar index, a UNIX time in ms or a pane percent, by the line's xloc; NaN for a deleted line.
|
|
143
164
|
* @example
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
*
|
|
165
|
+
* ```js
|
|
166
|
+
* eachBar((c) => {
|
|
167
|
+
* const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);
|
|
168
|
+
* const bars = line.get_x2(l) - line.get_x1(l); // 10
|
|
169
|
+
* });
|
|
147
170
|
* ```
|
|
148
171
|
*/
|
|
149
172
|
export function get_x2(id: Line): number {
|
|
@@ -151,15 +174,15 @@ export function get_x2(id: Line): number {
|
|
|
151
174
|
}
|
|
152
175
|
|
|
153
176
|
/**
|
|
154
|
-
* Returns the
|
|
155
|
-
*
|
|
156
|
-
* @
|
|
157
|
-
* @returns Y coordinate (price) of the first point
|
|
158
|
-
*
|
|
177
|
+
* Returns the price of the line's first point.
|
|
178
|
+
* @param id - The line.
|
|
179
|
+
* @returns The price of the first point; NaN for a deleted line.
|
|
159
180
|
* @example
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
*
|
|
181
|
+
* ```js
|
|
182
|
+
* eachBar((c) => {
|
|
183
|
+
* const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);
|
|
184
|
+
* const rising = c.low > line.get_y1(l);
|
|
185
|
+
* });
|
|
163
186
|
* ```
|
|
164
187
|
*/
|
|
165
188
|
export function get_y1(id: Line): number {
|
|
@@ -167,15 +190,15 @@ export function get_y1(id: Line): number {
|
|
|
167
190
|
}
|
|
168
191
|
|
|
169
192
|
/**
|
|
170
|
-
* Returns the
|
|
171
|
-
*
|
|
172
|
-
* @
|
|
173
|
-
* @returns Y coordinate (price) of the second point
|
|
174
|
-
*
|
|
193
|
+
* Returns the price of the line's second point.
|
|
194
|
+
* @param id - The line.
|
|
195
|
+
* @returns The price of the second point; NaN for a deleted line.
|
|
175
196
|
* @example
|
|
176
|
-
* ```
|
|
177
|
-
*
|
|
178
|
-
*
|
|
197
|
+
* ```js
|
|
198
|
+
* eachBar((c) => {
|
|
199
|
+
* const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);
|
|
200
|
+
* const change = line.get_y2(l) - line.get_y1(l);
|
|
201
|
+
* });
|
|
179
202
|
* ```
|
|
180
203
|
*/
|
|
181
204
|
export function get_y2(id: Line): number {
|
|
@@ -183,21 +206,16 @@ export function get_y2(id: Line): number {
|
|
|
183
206
|
}
|
|
184
207
|
|
|
185
208
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @param id -
|
|
189
|
-
* @returns
|
|
190
|
-
*
|
|
191
|
-
* @remarks
|
|
192
|
-
* Creates a shallow copy of the line. Modifications to the copy won't affect the original.
|
|
193
|
-
*
|
|
209
|
+
* Makes a new line with the same points and style as `id` (it counts toward `max_lines_count`).
|
|
210
|
+
* Changing the copy does not change the original.
|
|
211
|
+
* @param id - The line to copy.
|
|
212
|
+
* @returns The new line.
|
|
194
213
|
* @example
|
|
195
|
-
* ```
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* copiedLine.y2 = 200;
|
|
214
|
+
* ```js
|
|
215
|
+
* eachBar((c) => {
|
|
216
|
+
* const l = line.new(c.i - 10, c.high, c.i, c.high);
|
|
217
|
+
* line.set_y1(line.copy(l), c.low); // a second line from the same start bar, at the low
|
|
218
|
+
* });
|
|
201
219
|
* ```
|
|
202
220
|
*/
|
|
203
221
|
export function copy(id: Line): Line {
|
|
@@ -205,16 +223,16 @@ export function copy(id: Line): Line {
|
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* @param
|
|
211
|
-
* @
|
|
212
|
-
* @returns Modified line object
|
|
213
|
-
*
|
|
226
|
+
* Moves the x coordinate of the line's first point. Does nothing on a deleted line.
|
|
227
|
+
* @param id - The line.
|
|
228
|
+
* @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.
|
|
229
|
+
* @returns The same line.
|
|
214
230
|
* @example
|
|
215
|
-
* ```
|
|
216
|
-
*
|
|
217
|
-
* line.
|
|
231
|
+
* ```js
|
|
232
|
+
* eachBar((c) => {
|
|
233
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
234
|
+
* line.set_x1(l, c.i - 20);
|
|
235
|
+
* });
|
|
218
236
|
* ```
|
|
219
237
|
*/
|
|
220
238
|
export function set_x1(id: Line, x: number): Line {
|
|
@@ -225,16 +243,16 @@ export function set_x1(id: Line, x: number): Line {
|
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* @param
|
|
231
|
-
* @
|
|
232
|
-
* @returns Modified line object
|
|
233
|
-
*
|
|
246
|
+
* Moves the x coordinate of the line's second point. Does nothing on a deleted line.
|
|
247
|
+
* @param id - The line.
|
|
248
|
+
* @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.
|
|
249
|
+
* @returns The same line.
|
|
234
250
|
* @example
|
|
235
|
-
* ```
|
|
236
|
-
*
|
|
237
|
-
* line.
|
|
251
|
+
* ```js
|
|
252
|
+
* eachBar((c) => {
|
|
253
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
254
|
+
* line.set_x2(l, c.i + 10); // reach 10 bars into the future
|
|
255
|
+
* });
|
|
238
256
|
* ```
|
|
239
257
|
*/
|
|
240
258
|
export function set_x2(id: Line, x: number): Line {
|
|
@@ -245,16 +263,16 @@ export function set_x2(id: Line, x: number): Line {
|
|
|
245
263
|
}
|
|
246
264
|
|
|
247
265
|
/**
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* @param
|
|
251
|
-
* @
|
|
252
|
-
* @returns Modified line object
|
|
253
|
-
*
|
|
266
|
+
* Moves the price of the line's first point. Does nothing on a deleted line.
|
|
267
|
+
* @param id - The line.
|
|
268
|
+
* @param y - New price.
|
|
269
|
+
* @returns The same line.
|
|
254
270
|
* @example
|
|
255
|
-
* ```
|
|
256
|
-
*
|
|
257
|
-
* line.
|
|
271
|
+
* ```js
|
|
272
|
+
* eachBar((c) => {
|
|
273
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
274
|
+
* line.set_y1(l, c.get(low, 10));
|
|
275
|
+
* });
|
|
258
276
|
* ```
|
|
259
277
|
*/
|
|
260
278
|
export function set_y1(id: Line, y: number): Line {
|
|
@@ -264,16 +282,16 @@ export function set_y1(id: Line, y: number): Line {
|
|
|
264
282
|
}
|
|
265
283
|
|
|
266
284
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* @param
|
|
270
|
-
* @
|
|
271
|
-
* @returns Modified line object
|
|
272
|
-
*
|
|
285
|
+
* Moves the price of the line's second point. Does nothing on a deleted line.
|
|
286
|
+
* @param id - The line.
|
|
287
|
+
* @param y - New price.
|
|
288
|
+
* @returns The same line.
|
|
273
289
|
* @example
|
|
274
|
-
* ```
|
|
275
|
-
*
|
|
276
|
-
* line.
|
|
290
|
+
* ```js
|
|
291
|
+
* eachBar((c) => {
|
|
292
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
293
|
+
* line.set_y2(l, c.high);
|
|
294
|
+
* });
|
|
277
295
|
* ```
|
|
278
296
|
*/
|
|
279
297
|
export function set_y2(id: Line, y: number): Line {
|
|
@@ -283,17 +301,17 @@ export function set_y2(id: Line, y: number): Line {
|
|
|
283
301
|
}
|
|
284
302
|
|
|
285
303
|
/**
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* @param
|
|
289
|
-
* @param
|
|
290
|
-
* @
|
|
291
|
-
* @returns Modified line object
|
|
292
|
-
*
|
|
304
|
+
* Moves the line's first point (x and price). Does nothing on a deleted line.
|
|
305
|
+
* @param id - The line.
|
|
306
|
+
* @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.
|
|
307
|
+
* @param y - New price.
|
|
308
|
+
* @returns The same line.
|
|
293
309
|
* @example
|
|
294
|
-
* ```
|
|
295
|
-
*
|
|
296
|
-
* line.
|
|
310
|
+
* ```js
|
|
311
|
+
* eachBar((c) => {
|
|
312
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
313
|
+
* line.set_xy1(l, c.i - 20, c.get(low, 20));
|
|
314
|
+
* });
|
|
297
315
|
* ```
|
|
298
316
|
*/
|
|
299
317
|
export function set_xy1(id: Line, x: number, y: number): Line {
|
|
@@ -305,17 +323,17 @@ export function set_xy1(id: Line, x: number, y: number): Line {
|
|
|
305
323
|
}
|
|
306
324
|
|
|
307
325
|
/**
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
312
|
-
* @
|
|
313
|
-
* @returns Modified line object
|
|
314
|
-
*
|
|
326
|
+
* Moves the line's second point (x and price). Does nothing on a deleted line.
|
|
327
|
+
* @param id - The line.
|
|
328
|
+
* @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.
|
|
329
|
+
* @param y - New price.
|
|
330
|
+
* @returns The same line.
|
|
315
331
|
* @example
|
|
316
|
-
* ```
|
|
317
|
-
*
|
|
318
|
-
* line.
|
|
332
|
+
* ```js
|
|
333
|
+
* eachBar((c) => {
|
|
334
|
+
* const l = line.new(c.i - 10, c.low, c.i - 1, c.low);
|
|
335
|
+
* line.set_xy2(l, c.i, c.close);
|
|
336
|
+
* });
|
|
319
337
|
* ```
|
|
320
338
|
*/
|
|
321
339
|
export function set_xy2(id: Line, x: number, y: number): Line {
|
|
@@ -327,22 +345,19 @@ export function set_xy2(id: Line, x: number, y: number): Line {
|
|
|
327
345
|
}
|
|
328
346
|
|
|
329
347
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* @param
|
|
333
|
-
* @param
|
|
334
|
-
* @param
|
|
335
|
-
*
|
|
336
|
-
* @returns
|
|
337
|
-
*
|
|
338
|
-
* @remarks
|
|
339
|
-
* When changing xloc, you must provide appropriate x coordinates for the new system.
|
|
340
|
-
*
|
|
348
|
+
* Changes what the line's x coordinates are and sets both of them in that unit. Does nothing on a deleted line.
|
|
349
|
+
* @param id - The line.
|
|
350
|
+
* @param x1 - New x of the first point, in the unit of `xloc`.
|
|
351
|
+
* @param x2 - New x of the second point, in the unit of `xloc`.
|
|
352
|
+
* @param xloc - `xloc.bar_index` (bar indexes), `xloc.bar_time` (UNIX times in ms) or `xloc.pane` (percents of the
|
|
353
|
+
* pane's width).
|
|
354
|
+
* @returns The same line.
|
|
341
355
|
* @example
|
|
342
|
-
* ```
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
356
|
+
* ```js
|
|
357
|
+
* eachBar((c) => {
|
|
358
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
359
|
+
* line.set_xloc(l, c.time - 3600000, c.time, xloc.bar_time);
|
|
360
|
+
* });
|
|
346
361
|
* ```
|
|
347
362
|
*/
|
|
348
363
|
export function set_xloc(id: Line, x1: number, x2: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Line {
|
|
@@ -354,16 +369,16 @@ export function set_xloc(id: Line, x1: number, x2: number, xloc: 'bar_index' | '
|
|
|
354
369
|
}
|
|
355
370
|
|
|
356
371
|
/**
|
|
357
|
-
* Sets the
|
|
358
|
-
*
|
|
359
|
-
* @param
|
|
360
|
-
* @
|
|
361
|
-
* @returns Modified line object
|
|
362
|
-
*
|
|
372
|
+
* Sets whether the line continues past its points. Does nothing on a deleted line.
|
|
373
|
+
* @param id - The line.
|
|
374
|
+
* @param extend - `extend.none`, `extend.left`, `extend.right` or `extend.both`.
|
|
375
|
+
* @returns The same line.
|
|
363
376
|
* @example
|
|
364
|
-
* ```
|
|
365
|
-
*
|
|
366
|
-
* line.
|
|
377
|
+
* ```js
|
|
378
|
+
* eachBar((c) => {
|
|
379
|
+
* const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);
|
|
380
|
+
* line.set_extend(l, extend.right);
|
|
381
|
+
* });
|
|
367
382
|
* ```
|
|
368
383
|
*/
|
|
369
384
|
export function set_extend(id: Line, extend: 'none' | 'left' | 'right' | 'both'): Line {
|
|
@@ -373,16 +388,16 @@ export function set_extend(id: Line, extend: 'none' | 'left' | 'right' | 'both')
|
|
|
373
388
|
}
|
|
374
389
|
|
|
375
390
|
/**
|
|
376
|
-
* Sets the line
|
|
377
|
-
*
|
|
378
|
-
* @param
|
|
379
|
-
* @
|
|
380
|
-
* @returns Modified line object
|
|
381
|
-
*
|
|
391
|
+
* Sets the line colour. Does nothing on a deleted line.
|
|
392
|
+
* @param id - The line.
|
|
393
|
+
* @param lineColor - New colour (`color.red`, `"#FF0000"`, `color.new(color.red, 50)`...).
|
|
394
|
+
* @returns The same line.
|
|
382
395
|
* @example
|
|
383
|
-
* ```
|
|
384
|
-
*
|
|
385
|
-
* line.
|
|
396
|
+
* ```js
|
|
397
|
+
* eachBar((c) => {
|
|
398
|
+
* const l = line.new(c.i - 10, c.get(close, 10), c.i, c.close);
|
|
399
|
+
* line.set_color(l, c.close > c.get(close, 10) ? color.green : color.red);
|
|
400
|
+
* });
|
|
386
401
|
* ```
|
|
387
402
|
*/
|
|
388
403
|
export function set_color(id: Line, lineColor: color): Line {
|
|
@@ -392,16 +407,17 @@ export function set_color(id: Line, lineColor: color): Line {
|
|
|
392
407
|
}
|
|
393
408
|
|
|
394
409
|
/**
|
|
395
|
-
* Sets the line style.
|
|
396
|
-
*
|
|
397
|
-
* @param
|
|
398
|
-
*
|
|
399
|
-
* @returns
|
|
400
|
-
*
|
|
410
|
+
* Sets the line style (solid, dotted, dashed, or with arrow heads). Does nothing on a deleted line.
|
|
411
|
+
* @param id - The line.
|
|
412
|
+
* @param style - `line.style_solid`, `line.style_dotted`, `line.style_dashed`, `line.style_arrow_left`,
|
|
413
|
+
* `line.style_arrow_right` or `line.style_arrow_both`.
|
|
414
|
+
* @returns The same line.
|
|
401
415
|
* @example
|
|
402
|
-
* ```
|
|
403
|
-
*
|
|
404
|
-
* line.
|
|
416
|
+
* ```js
|
|
417
|
+
* eachBar((c) => {
|
|
418
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
419
|
+
* line.set_style(l, line.style_dashed);
|
|
420
|
+
* });
|
|
405
421
|
* ```
|
|
406
422
|
*/
|
|
407
423
|
export function set_style(id: Line, style: 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both'): Line {
|
|
@@ -411,16 +427,16 @@ export function set_style(id: Line, style: 'solid' | 'dotted' | 'dashed' | 'arro
|
|
|
411
427
|
}
|
|
412
428
|
|
|
413
429
|
/**
|
|
414
|
-
* Sets the line width.
|
|
415
|
-
*
|
|
416
|
-
* @param
|
|
417
|
-
* @
|
|
418
|
-
* @returns Modified line object
|
|
419
|
-
*
|
|
430
|
+
* Sets the line width. Does nothing on a deleted line.
|
|
431
|
+
* @param id - The line.
|
|
432
|
+
* @param width - New width in pixels.
|
|
433
|
+
* @returns The same line.
|
|
420
434
|
* @example
|
|
421
|
-
* ```
|
|
422
|
-
*
|
|
423
|
-
* line.
|
|
435
|
+
* ```js
|
|
436
|
+
* eachBar((c) => {
|
|
437
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
438
|
+
* line.set_width(l, 3);
|
|
439
|
+
* });
|
|
424
440
|
* ```
|
|
425
441
|
*/
|
|
426
442
|
export function set_width(id: Line, width: number): Line {
|
|
@@ -430,19 +446,15 @@ export function set_width(id: Line, width: number): Line {
|
|
|
430
446
|
}
|
|
431
447
|
|
|
432
448
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* @param id -
|
|
436
|
-
*
|
|
437
|
-
* @remarks
|
|
438
|
-
* Removes the line from `line.all()`. As in PineScript, the deleted line is `na`: its getters
|
|
439
|
-
* return NaN and its setters do nothing. Deleting it twice has no effect. Deleting a line also deletes the linefills that use it.
|
|
440
|
-
*
|
|
449
|
+
* Removes the line from the chart and from `line.all`. The linefills that use it are deleted too.
|
|
450
|
+
* Afterwards its getters return NaN and its setters do nothing; deleting it again does nothing.
|
|
451
|
+
* @param id - The line to delete.
|
|
441
452
|
* @example
|
|
442
|
-
* ```
|
|
443
|
-
*
|
|
444
|
-
* line.
|
|
445
|
-
*
|
|
453
|
+
* ```js
|
|
454
|
+
* eachBar((c) => {
|
|
455
|
+
* const l = line.new(c.i - 1, c.get(close, 1), c.i, c.close);
|
|
456
|
+
* if (c.i < c.n - 1) line.delete(l); // keep only the line of the last bar
|
|
457
|
+
* });
|
|
446
458
|
* ```
|
|
447
459
|
*/
|
|
448
460
|
export function delete_line(id: Line): void {
|
|
@@ -456,15 +468,33 @@ function pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): num
|
|
|
456
468
|
}
|
|
457
469
|
|
|
458
470
|
/**
|
|
459
|
-
*
|
|
471
|
+
* Returns the lines that are still on the chart, oldest first. The array is a copy: later changes do not affect it.
|
|
472
|
+
* (In a script, `line.all` is read as a value, without a call.)
|
|
473
|
+
* @returns The live lines in creation order.
|
|
474
|
+
* @example
|
|
475
|
+
* ```js
|
|
476
|
+
* eachBar((c) => {
|
|
477
|
+
* if (c.i === c.n - 1) for (const l of line.all) line.set_color(l, color.gray);
|
|
478
|
+
* });
|
|
479
|
+
* ```
|
|
460
480
|
*/
|
|
461
481
|
export function all(): Line[] {
|
|
462
482
|
return allDrawings('line');
|
|
463
483
|
}
|
|
464
484
|
|
|
465
485
|
/**
|
|
466
|
-
*
|
|
467
|
-
* `
|
|
486
|
+
* Moves the line's first point to a chart point: its `index` for a `xloc.bar_index` line, its `time` for a
|
|
487
|
+
* `xloc.bar_time` line (NaN when the point has none), and its `price`. Does nothing on a deleted line.
|
|
488
|
+
* @param id - The line.
|
|
489
|
+
* @param point - The new first point.
|
|
490
|
+
* @returns The same line.
|
|
491
|
+
* @example
|
|
492
|
+
* ```js
|
|
493
|
+
* eachBar((c) => {
|
|
494
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
495
|
+
* line.set_first_point(l, chart.point.from_index(c.i - 20, c.get(low, 20)));
|
|
496
|
+
* });
|
|
497
|
+
* ```
|
|
468
498
|
*/
|
|
469
499
|
export function set_first_point(id: Line, point: ChartPoint): Line {
|
|
470
500
|
if (isDeleted(id)) return id;
|
|
@@ -474,7 +504,17 @@ export function set_first_point(id: Line, point: ChartPoint): Line {
|
|
|
474
504
|
}
|
|
475
505
|
|
|
476
506
|
/**
|
|
477
|
-
*
|
|
507
|
+
* Moves the line's second point to a chart point (see `line.set_first_point`). Does nothing on a deleted line.
|
|
508
|
+
* @param id - The line.
|
|
509
|
+
* @param point - The new second point.
|
|
510
|
+
* @returns The same line.
|
|
511
|
+
* @example
|
|
512
|
+
* ```js
|
|
513
|
+
* eachBar((c) => {
|
|
514
|
+
* const l = line.new(c.i - 10, c.low, c.i, c.low);
|
|
515
|
+
* line.set_second_point(l, chart.point.now(c.high));
|
|
516
|
+
* });
|
|
517
|
+
* ```
|
|
478
518
|
*/
|
|
479
519
|
export function set_second_point(id: Line, point: ChartPoint): Line {
|
|
480
520
|
if (isDeleted(id)) return id;
|
|
@@ -483,6 +523,6 @@ export function set_second_point(id: Line, point: ChartPoint): Line {
|
|
|
483
523
|
return id;
|
|
484
524
|
}
|
|
485
525
|
|
|
486
|
-
//
|
|
526
|
+
// Script names: line.new / line.delete
|
|
487
527
|
export { new_line as new };
|
|
488
528
|
export { delete_line as delete };
|