oakscriptjs 0.23.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 +532 -61
- 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/security/other.d.ts +8 -3
- package/dist/cjs/security/other.d.ts.map +1 -1
- package/dist/cjs/security/other.js +23 -6
- package/dist/cjs/security/other.js.map +2 -2
- 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 +1099 -153
- 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/security/other.d.ts +8 -3
- package/dist/esm/security/other.d.ts.map +1 -1
- package/dist/esm/security/other.js +45 -10
- package/dist/esm/security/other.js.map +1 -1
- 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/skills/oakscript/reference/timeframes-symbols.md +4 -0
- 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 +1520 -241
- package/src/script/json.ts +457 -0
- package/src/security/other.ts +43 -9
- 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/linefill/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Linefill namespace
|
|
3
|
-
* Functions for creating and manipulating linefill drawing objects.
|
|
2
|
+
* Linefill namespace: functions that fill the area between two lines (`linefill.*`).
|
|
4
3
|
*
|
|
5
4
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* and provide a way to retrieve the underlying line references.
|
|
5
|
+
* A linefill colours the space between two lines and follows them when they move. It is deleted with either line,
|
|
6
|
+
* and two lines share one linefill.
|
|
9
7
|
*
|
|
10
8
|
* @version 6
|
|
11
9
|
*/
|
|
@@ -14,32 +12,23 @@ import { Stamped, all as allDrawings, isDeleted, liveFillsOf, register, remove }
|
|
|
14
12
|
import type { Linefill, Line, color } from '../types/index.js';
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param
|
|
22
|
-
* @
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* - Automatically deleted if either line is deleted
|
|
27
|
-
* - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill
|
|
28
|
-
* (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is
|
|
29
|
-
* returned with the new colour instead of a new one; with several, the one created or returned last
|
|
30
|
-
* - If both lines extend in same direction, fill extends too
|
|
31
|
-
* - Purely visual in PineScript, but getters allow retrieving line references
|
|
32
|
-
*
|
|
15
|
+
* Fills the area between two lines with a colour and returns the linefill's handle. The fill follows the lines when
|
|
16
|
+
* they move or extend, and is deleted when either line is deleted. Two lines have one linefill: when they already
|
|
17
|
+
* have one, that linefill gets the new colour and is returned instead of a new one. An `na` line gives `na`.
|
|
18
|
+
* The arguments can also be given by name in an object.
|
|
19
|
+
* @param line1 - The first line.
|
|
20
|
+
* @param line2 - The second line.
|
|
21
|
+
* @param fillColor - Fill colour; a transparent one (`color.new(color.blue, 85)`) keeps the bars visible.
|
|
22
|
+
* Default: none.
|
|
23
|
+
* @returns The linefill.
|
|
33
24
|
* @example
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* // Fill channel with color
|
|
42
|
-
* const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue
|
|
25
|
+
* ```js
|
|
26
|
+
* eachBar((c) => {
|
|
27
|
+
* if (c.i !== c.n - 1) return;
|
|
28
|
+
* const top = line.new(c.i - 20, c.get(high, 20), c.i, c.high, { extend: extend.right });
|
|
29
|
+
* const bottom = line.new(c.i - 20, c.get(low, 20), c.i, c.low, { extend: extend.right });
|
|
30
|
+
* linefill.new(top, bottom, color.new(color.blue, 85));
|
|
31
|
+
* });
|
|
43
32
|
* ```
|
|
44
33
|
*/
|
|
45
34
|
export function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill {
|
|
@@ -78,21 +67,15 @@ class Touched extends Stamped {
|
|
|
78
67
|
let touchCount = 0;
|
|
79
68
|
|
|
80
69
|
/**
|
|
81
|
-
* Returns the first line
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
84
|
-
* @returns First line object
|
|
85
|
-
*
|
|
86
|
-
* @remarks
|
|
87
|
-
* Can be used to retrieve and manipulate the first line.
|
|
88
|
-
*
|
|
70
|
+
* Returns the first line of a linefill, to read or move it.
|
|
71
|
+
* @param id - The linefill.
|
|
72
|
+
* @returns The first line given to `linefill.new()`.
|
|
89
73
|
* @example
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* line.set_y2(line1, 175); // Update upper line's second point
|
|
74
|
+
* ```js
|
|
75
|
+
* eachBar((c) => {
|
|
76
|
+
* const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
|
|
77
|
+
* line.set_color(linefill.get_line1(lf), color.green);
|
|
78
|
+
* });
|
|
96
79
|
* ```
|
|
97
80
|
*/
|
|
98
81
|
export function get_line1(id: Linefill): Line {
|
|
@@ -100,21 +83,15 @@ export function get_line1(id: Linefill): Line {
|
|
|
100
83
|
}
|
|
101
84
|
|
|
102
85
|
/**
|
|
103
|
-
* Returns the second line
|
|
104
|
-
*
|
|
105
|
-
* @
|
|
106
|
-
* @returns Second line object
|
|
107
|
-
*
|
|
108
|
-
* @remarks
|
|
109
|
-
* Can be used to retrieve and manipulate the second line.
|
|
110
|
-
*
|
|
86
|
+
* Returns the second line of a linefill, to read or move it.
|
|
87
|
+
* @param id - The linefill.
|
|
88
|
+
* @returns The second line given to `linefill.new()`.
|
|
111
89
|
* @example
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* line.set_y2(line2, 145); // Update lower line's second point
|
|
90
|
+
* ```js
|
|
91
|
+
* eachBar((c) => {
|
|
92
|
+
* const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
|
|
93
|
+
* line.set_color(linefill.get_line2(lf), color.red);
|
|
94
|
+
* });
|
|
118
95
|
* ```
|
|
119
96
|
*/
|
|
120
97
|
export function get_line2(id: Linefill): Line {
|
|
@@ -122,25 +99,16 @@ export function get_line2(id: Linefill): Line {
|
|
|
122
99
|
}
|
|
123
100
|
|
|
124
101
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @param
|
|
128
|
-
* @
|
|
129
|
-
* @returns Modified linefill object
|
|
130
|
-
*
|
|
131
|
-
* @remarks
|
|
132
|
-
* Useful for dynamically changing channel colors based on conditions.
|
|
133
|
-
*
|
|
102
|
+
* Changes the fill colour. Does nothing on a deleted linefill.
|
|
103
|
+
* @param id - The linefill.
|
|
104
|
+
* @param fillColor - New fill colour.
|
|
105
|
+
* @returns The same linefill.
|
|
134
106
|
* @example
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* linefill.set_color(channelFill, '#00FF0020'); // Green
|
|
141
|
-
* } else {
|
|
142
|
-
* linefill.set_color(channelFill, '#FF000020'); // Red
|
|
143
|
-
* }
|
|
107
|
+
* ```js
|
|
108
|
+
* eachBar((c) => {
|
|
109
|
+
* const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
|
|
110
|
+
* linefill.set_color(lf, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));
|
|
111
|
+
* });
|
|
144
112
|
* ```
|
|
145
113
|
*/
|
|
146
114
|
export function set_color(id: Linefill, fillColor: color): Linefill {
|
|
@@ -150,19 +118,15 @@ export function set_color(id: Linefill, fillColor: color): Linefill {
|
|
|
150
118
|
}
|
|
151
119
|
|
|
152
120
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* @param id -
|
|
156
|
-
*
|
|
157
|
-
* @remarks
|
|
158
|
-
* Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters
|
|
159
|
-
* return NaN and its setters do nothing. Deleting it twice has no effect.
|
|
160
|
-
*
|
|
121
|
+
* Removes the fill from the chart and from `linefill.all`; the two lines stay. Afterwards its setters do nothing;
|
|
122
|
+
* deleting it again does nothing.
|
|
123
|
+
* @param id - The linefill to delete.
|
|
161
124
|
* @example
|
|
162
|
-
* ```
|
|
163
|
-
*
|
|
164
|
-
* linefill.
|
|
165
|
-
*
|
|
125
|
+
* ```js
|
|
126
|
+
* eachBar((c) => {
|
|
127
|
+
* const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
|
|
128
|
+
* if (c.close < c.open) linefill.delete(lf);
|
|
129
|
+
* });
|
|
166
130
|
* ```
|
|
167
131
|
*/
|
|
168
132
|
export function delete_linefill(id: Linefill): void {
|
|
@@ -171,7 +135,15 @@ export function delete_linefill(id: Linefill): void {
|
|
|
171
135
|
|
|
172
136
|
|
|
173
137
|
/**
|
|
174
|
-
*
|
|
138
|
+
* Returns the linefills that are still on the chart, oldest first. The array is a copy.
|
|
139
|
+
* (In a script, `linefill.all` is read as a value, without a call.)
|
|
140
|
+
* @returns The live linefills in creation order.
|
|
141
|
+
* @example
|
|
142
|
+
* ```js
|
|
143
|
+
* eachBar((c) => {
|
|
144
|
+
* if (c.i === c.n - 1) for (const lf of linefill.all) linefill.set_color(lf, color.new(color.gray, 80));
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
175
147
|
*/
|
|
176
148
|
export function all(): Linefill[] {
|
|
177
149
|
return allDrawings('linefill');
|
package/src/math/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ import { checkSumLength } from '../ta/limits.js';
|
|
|
33
33
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
|
-
* ```
|
|
36
|
+
* ```js
|
|
37
37
|
* math.abs(5) // Returns: 5
|
|
38
38
|
* math.abs(-5) // Returns: 5
|
|
39
39
|
* math.abs(0) // Returns: 0
|
|
@@ -72,7 +72,7 @@ export function abs(value: float | Series): float | Series {
|
|
|
72
72
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
73
73
|
*
|
|
74
74
|
* @example
|
|
75
|
-
* ```
|
|
75
|
+
* ```js
|
|
76
76
|
* math.ceil(4.2) // Returns: 5
|
|
77
77
|
* math.ceil(4.8) // Returns: 5
|
|
78
78
|
* math.ceil(-4.2) // Returns: -4
|
|
@@ -112,7 +112,7 @@ export function ceil(value: float | Series): int | Series {
|
|
|
112
112
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
113
113
|
*
|
|
114
114
|
* @example
|
|
115
|
-
* ```
|
|
115
|
+
* ```js
|
|
116
116
|
* math.floor(4.2) // Returns: 4
|
|
117
117
|
* math.floor(4.8) // Returns: 4
|
|
118
118
|
* math.floor(-4.2) // Returns: -5
|
|
@@ -160,7 +160,7 @@ export function floor(value: float | Series): int | Series {
|
|
|
160
160
|
* - an infinite value gives na
|
|
161
161
|
*
|
|
162
162
|
* @example
|
|
163
|
-
* ```
|
|
163
|
+
* ```js
|
|
164
164
|
* math.round(4.2) // Returns: 4
|
|
165
165
|
* math.round(4.5) // Returns: 5
|
|
166
166
|
* math.round(-2.5) // Returns: -3
|
|
@@ -267,7 +267,7 @@ const CONSTANT_SCALE = 10n ** 16n;
|
|
|
267
267
|
* - the same expression with a series operand (`close / 255`) is not rounded: do not wrap it
|
|
268
268
|
*
|
|
269
269
|
* @example
|
|
270
|
-
* ```
|
|
270
|
+
* ```js
|
|
271
271
|
* // Pine: var const float i_255 = 1 / 255
|
|
272
272
|
* const i_255 = math.constant(1 / 255) // 0.003921568627451 (JavaScript: 0.00392156862745098)
|
|
273
273
|
* math.constant(1 / 7) // 0.1428571428571428 (JavaScript: 0.14285714285714285)
|
|
@@ -301,7 +301,7 @@ export function constant(value: float): float {
|
|
|
301
301
|
* - If any argument is a Series, returns a Series; otherwise returns a number
|
|
302
302
|
*
|
|
303
303
|
* @example
|
|
304
|
-
* ```
|
|
304
|
+
* ```js
|
|
305
305
|
* math.max(1, 2, 3) // Returns: 3
|
|
306
306
|
* math.max(-1, -5, -2) // Returns: -1
|
|
307
307
|
* math.max(10) // Returns: 10
|
|
@@ -351,7 +351,7 @@ export function max(...values: (float | Series)[]): float | Series {
|
|
|
351
351
|
* - If any argument is a Series, returns a Series; otherwise returns a number
|
|
352
352
|
*
|
|
353
353
|
* @example
|
|
354
|
-
* ```
|
|
354
|
+
* ```js
|
|
355
355
|
* math.min(1, 2, 3) // Returns: 1
|
|
356
356
|
* math.min(-1, -5, -2) // Returns: -5
|
|
357
357
|
* math.min(10) // Returns: 10
|
|
@@ -402,7 +402,7 @@ export function min(...values: (float | Series)[]): float | Series {
|
|
|
402
402
|
* pending correction is subtracted before the division (math.avg(0.1, 0.2, 0.3) = 0.19999999999999998)
|
|
403
403
|
*
|
|
404
404
|
* @example
|
|
405
|
-
* ```
|
|
405
|
+
* ```js
|
|
406
406
|
* math.avg(1, 2, 3) // Returns: 2
|
|
407
407
|
* math.avg(10, 20) // Returns: 15
|
|
408
408
|
* math.avg(5) // Returns: 5
|
|
@@ -473,7 +473,7 @@ function avgOf(nums: number[]): number {
|
|
|
473
473
|
* gives the sum of the last `length` earlier values
|
|
474
474
|
*
|
|
475
475
|
* @example
|
|
476
|
-
* ```
|
|
476
|
+
* ```js
|
|
477
477
|
* math.sum([1, 2, 3, 4, 5], 3) // Returns: [NaN, NaN, 6, 9, 12]
|
|
478
478
|
* // Explanation: [NaN, NaN, 1+2+3, 2+3+4, 3+4+5]
|
|
479
479
|
* ```
|
|
@@ -514,7 +514,7 @@ export function sum(
|
|
|
514
514
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
515
515
|
*
|
|
516
516
|
* @example
|
|
517
|
-
* ```
|
|
517
|
+
* ```js
|
|
518
518
|
* math.sqrt(9) // Returns: 3
|
|
519
519
|
* math.sqrt(16) // Returns: 4
|
|
520
520
|
* math.sqrt(2) // Returns: 1.414...
|
|
@@ -555,7 +555,7 @@ export function sqrt(value: float | Series): float | Series {
|
|
|
555
555
|
* - If any argument is a Series, returns a Series; if all are numbers, returns a number
|
|
556
556
|
*
|
|
557
557
|
* @example
|
|
558
|
-
* ```
|
|
558
|
+
* ```js
|
|
559
559
|
* math.pow(2, 3) // Returns: 8 (2³)
|
|
560
560
|
* math.pow(10, 2) // Returns: 100
|
|
561
561
|
* math.pow(5, 0) // Returns: 1
|
|
@@ -604,7 +604,7 @@ export function pow(base: float | Series, exponent: float | Series): float | Ser
|
|
|
604
604
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
605
605
|
*
|
|
606
606
|
* @example
|
|
607
|
-
* ```
|
|
607
|
+
* ```js
|
|
608
608
|
* math.exp(0) // Returns: 1
|
|
609
609
|
* math.exp(1) // Returns: 2.71828... (e)
|
|
610
610
|
* math.exp(2) // Returns: 7.389...
|
|
@@ -646,7 +646,7 @@ export function exp(value: float | Series): float | Series {
|
|
|
646
646
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
647
647
|
*
|
|
648
648
|
* @example
|
|
649
|
-
* ```
|
|
649
|
+
* ```js
|
|
650
650
|
* math.log(1) // Returns: 0
|
|
651
651
|
* math.log(Math.E) // Returns: 1
|
|
652
652
|
* math.log(10) // Returns: 2.302...
|
|
@@ -687,7 +687,7 @@ export function log(value: float | Series): float | Series {
|
|
|
687
687
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
688
688
|
*
|
|
689
689
|
* @example
|
|
690
|
-
* ```
|
|
690
|
+
* ```js
|
|
691
691
|
* math.log10(10) // Returns: 1
|
|
692
692
|
* math.log10(100) // Returns: 2
|
|
693
693
|
* math.log10(1000) // Returns: 3
|
|
@@ -728,7 +728,7 @@ export function log10(value: float | Series): float | Series {
|
|
|
728
728
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
729
729
|
*
|
|
730
730
|
* @example
|
|
731
|
-
* ```
|
|
731
|
+
* ```js
|
|
732
732
|
* math.sin(0) // Returns: 0
|
|
733
733
|
* math.sin(Math.PI / 2) // Returns: 1
|
|
734
734
|
* math.sin(Math.PI) // Returns: 0 (approximately)
|
|
@@ -769,7 +769,7 @@ export function sin(value: float | Series): float | Series {
|
|
|
769
769
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
770
770
|
*
|
|
771
771
|
* @example
|
|
772
|
-
* ```
|
|
772
|
+
* ```js
|
|
773
773
|
* math.cos(0) // Returns: 1
|
|
774
774
|
* math.cos(Math.PI / 2) // Returns: 0 (approximately)
|
|
775
775
|
* math.cos(Math.PI) // Returns: -1
|
|
@@ -810,7 +810,7 @@ export function cos(value: float | Series): float | Series {
|
|
|
810
810
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
811
811
|
*
|
|
812
812
|
* @example
|
|
813
|
-
* ```
|
|
813
|
+
* ```js
|
|
814
814
|
* math.tan(0) // Returns: 0
|
|
815
815
|
* math.tan(Math.PI / 4) // Returns: 1
|
|
816
816
|
* math.tan(Math.PI / 6) // Returns: 0.577... (1/√3)
|
|
@@ -850,7 +850,7 @@ export function tan(value: float | Series): float | Series {
|
|
|
850
850
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
851
851
|
*
|
|
852
852
|
* @example
|
|
853
|
-
* ```
|
|
853
|
+
* ```js
|
|
854
854
|
* math.asin(0) // Returns: 0
|
|
855
855
|
* math.asin(1) // Returns: 1.5707... (π/2)
|
|
856
856
|
* math.asin(0.5) // Returns: 0.5235... (π/6)
|
|
@@ -891,7 +891,7 @@ export function asin(value: float | Series): float | Series {
|
|
|
891
891
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
892
892
|
*
|
|
893
893
|
* @example
|
|
894
|
-
* ```
|
|
894
|
+
* ```js
|
|
895
895
|
* math.acos(1) // Returns: 0
|
|
896
896
|
* math.acos(0) // Returns: 1.5707... (π/2)
|
|
897
897
|
* math.acos(0.5) // Returns: 1.0471... (π/3)
|
|
@@ -932,7 +932,7 @@ export function acos(value: float | Series): float | Series {
|
|
|
932
932
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
933
933
|
*
|
|
934
934
|
* @example
|
|
935
|
-
* ```
|
|
935
|
+
* ```js
|
|
936
936
|
* math.atan(0) // Returns: 0
|
|
937
937
|
* math.atan(1) // Returns: 0.7853... (π/4)
|
|
938
938
|
* math.atan(-1) // Returns: -0.7853... (-π/4)
|
|
@@ -972,7 +972,7 @@ export function atan(value: float | Series): float | Series {
|
|
|
972
972
|
* - If degrees is a Series, returns a Series; if degrees is a number, returns a number
|
|
973
973
|
*
|
|
974
974
|
* @example
|
|
975
|
-
* ```
|
|
975
|
+
* ```js
|
|
976
976
|
* math.toradians(0) // Returns: 0
|
|
977
977
|
* math.toradians(90) // Returns: 1.5707... (π/2)
|
|
978
978
|
* math.toradians(180) // Returns: 3.1415... (π)
|
|
@@ -1012,7 +1012,7 @@ export function toradians(degrees: float | Series): float | Series {
|
|
|
1012
1012
|
* - If radians is a Series, returns a Series; if radians is a number, returns a number
|
|
1013
1013
|
*
|
|
1014
1014
|
* @example
|
|
1015
|
-
* ```
|
|
1015
|
+
* ```js
|
|
1016
1016
|
* math.todegrees(0) // Returns: 0
|
|
1017
1017
|
* math.todegrees(Math.PI / 2) // Returns: 90
|
|
1018
1018
|
* math.todegrees(Math.PI) // Returns: 180
|
|
@@ -1040,8 +1040,17 @@ export function todegrees(radians: float | Series): float | Series {
|
|
|
1040
1040
|
}
|
|
1041
1041
|
|
|
1042
1042
|
/**
|
|
1043
|
-
*
|
|
1044
|
-
* Each generator draws
|
|
1043
|
+
* Makes a repeatable random number generator: the same seed always gives the same sequence of numbers (the
|
|
1044
|
+
* sequence of `math.random(min, max, seed)`). Each call of the generator draws the next number. In a script, prefer
|
|
1045
|
+
* `math.random(min, max, seed)`.
|
|
1046
|
+
* @param seed - Whole number that picks the sequence.
|
|
1047
|
+
* @returns A function `(min?, max?)` that gives the next number, from `min` (included, default 0) to `max`
|
|
1048
|
+
* (excluded, default 1).
|
|
1049
|
+
* @example
|
|
1050
|
+
* ```js
|
|
1051
|
+
* const draw = math.seededRandom(42);
|
|
1052
|
+
* const first = draw(0, 100);
|
|
1053
|
+
* ```
|
|
1045
1054
|
*/
|
|
1046
1055
|
export function seededRandom(seed: int): (min?: float, max?: float) => float {
|
|
1047
1056
|
const mask = (1n << 48n) - 1n;
|
|
@@ -1092,7 +1101,7 @@ export function restoreRandom(saved: Map<number, (min?: float, max?: float) => f
|
|
|
1092
1101
|
* with the same seed use `callsite.random(seed)`
|
|
1093
1102
|
*
|
|
1094
1103
|
* @example
|
|
1095
|
-
* ```
|
|
1104
|
+
* ```js
|
|
1096
1105
|
* math.random() // Returns: value between 0 and 1 (e.g., 0.234...)
|
|
1097
1106
|
* math.random(0, 10) // Returns: value between 0 and 10 (e.g., 7.45...)
|
|
1098
1107
|
* math.random(0, 1, 42) // Returns: 0.7275636800328681 on the first call, as PineScript
|
|
@@ -1129,7 +1138,7 @@ export function random(min?: float, max?: float, seed?: int): float {
|
|
|
1129
1138
|
* - If value is a Series, returns a Series; if value is a number, returns a number
|
|
1130
1139
|
*
|
|
1131
1140
|
* @example
|
|
1132
|
-
* ```
|
|
1141
|
+
* ```js
|
|
1133
1142
|
* math.sign(5) // Returns: 1
|
|
1134
1143
|
* math.sign(-3) // Returns: -1
|
|
1135
1144
|
* math.sign(0) // Returns: 0
|
|
@@ -1158,15 +1167,15 @@ export function sign(value: float | Series): int | Series {
|
|
|
1158
1167
|
}
|
|
1159
1168
|
|
|
1160
1169
|
/**
|
|
1161
|
-
* Rounds a
|
|
1170
|
+
* Rounds a price to the nearest tick, the smallest price step of the symbol (`syminfo.mintick`). Use it for levels
|
|
1171
|
+
* that must be real prices (a stop, a target).
|
|
1162
1172
|
*
|
|
1163
|
-
* @param number - The
|
|
1164
|
-
* @param mintick -
|
|
1165
|
-
*
|
|
1173
|
+
* @param number - The price to round: a number or a Series
|
|
1174
|
+
* @param mintick - The tick size, e.g. 0.01. Default in a script: the chart symbol's tick (`syminfo.mintick`);
|
|
1175
|
+
* called outside a script it is required (it throws without it)
|
|
1176
|
+
* @returns The value rounded to the tick: a Series for a Series, a number for a number
|
|
1166
1177
|
*
|
|
1167
1178
|
* @remarks
|
|
1168
|
-
* - **PineScript v6 signature**: `math.round_to_mintick(number)` - uses implicit syminfo.mintick
|
|
1169
|
-
* - **JavaScript signature**: Requires explicit `mintick` OR use `createContext()` with syminfo
|
|
1170
1179
|
* - Rounds to the nearest value divisible by mintick
|
|
1171
1180
|
* - Returns NaN for NaN input
|
|
1172
1181
|
* - If number is a Series, returns a Series; if number is a float, returns a float
|
|
@@ -1178,14 +1187,10 @@ export function sign(value: float | Series): int | Series {
|
|
|
1178
1187
|
* (-1.075 -> -1.08, 1.005 -> 1.01, 2.675 -> 2.68 at mintick 0.01)
|
|
1179
1188
|
*
|
|
1180
1189
|
* @example
|
|
1181
|
-
* ```
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1185
|
-
*
|
|
1186
|
-
* // Or use context API for cleaner syntax
|
|
1187
|
-
* const { math } = createContext({ syminfo: { mintick: 0.01 } });
|
|
1188
|
-
* const rounded = math.round_to_mintick(1.2345); // Returns: 1.23
|
|
1190
|
+
* ```js
|
|
1191
|
+
* const stop = math.round_to_mintick(low.mul(0.98));
|
|
1192
|
+
* plot(stop, "Stop");
|
|
1193
|
+
* math.round_to_mintick(1.2345, 0.01) // Returns: 1.23
|
|
1189
1194
|
* ```
|
|
1190
1195
|
*/
|
|
1191
1196
|
export function round_to_mintick(number: Series, mintick?: float): Series;
|
|
@@ -1264,7 +1269,11 @@ function roundToTick(number: number, mintick: number): number {
|
|
|
1264
1269
|
}
|
|
1265
1270
|
|
|
1266
1271
|
// Constants
|
|
1272
|
+
/** Pi, the ratio of a circle's circumference to its diameter: 3.141592653589793. */
|
|
1267
1273
|
export const pi = Math.PI;
|
|
1274
|
+
/** Euler's number e, the base of natural logarithms (`math.log`): 2.718281828459045. */
|
|
1268
1275
|
export const e = Math.E;
|
|
1269
|
-
|
|
1270
|
-
export const
|
|
1276
|
+
/** The golden ratio: 1.618033988749895. */
|
|
1277
|
+
export const phi = 1.618033988749895;
|
|
1278
|
+
/** The reciprocal of the golden ratio (1 / phi): 0.6180339887498948. */
|
|
1279
|
+
export const rphi = 0.6180339887498948;
|