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.
Files changed (300) hide show
  1. package/README.md +25 -1
  2. package/bin/oakscript.mjs +10 -3
  3. package/dist/cjs/box/index.d.ts +348 -289
  4. package/dist/cjs/box/index.d.ts.map +1 -1
  5. package/dist/cjs/box/index.js.map +2 -2
  6. package/dist/cjs/check/node.d.ts.map +1 -1
  7. package/dist/cjs/check/node.js +1 -0
  8. package/dist/cjs/check/node.js.map +2 -2
  9. package/dist/cjs/check/preview.d.ts +31 -0
  10. package/dist/cjs/check/preview.d.ts.map +1 -0
  11. package/dist/cjs/check/preview.js +303 -0
  12. package/dist/cjs/check/preview.js.map +7 -0
  13. package/dist/cjs/color/index.d.ts +11 -11
  14. package/dist/cjs/color/index.js.map +1 -1
  15. package/dist/cjs/color/parse.d.ts +2 -0
  16. package/dist/cjs/color/parse.d.ts.map +1 -1
  17. package/dist/cjs/color/parse.js +6 -0
  18. package/dist/cjs/color/parse.js.map +2 -2
  19. package/dist/cjs/compare/index.d.ts +76 -12
  20. package/dist/cjs/compare/index.d.ts.map +1 -1
  21. package/dist/cjs/compare/index.js.map +2 -2
  22. package/dist/cjs/drawing/registry.d.ts +28 -5
  23. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  24. package/dist/cjs/drawing/registry.js +14 -0
  25. package/dist/cjs/drawing/registry.js.map +2 -2
  26. package/dist/cjs/index.d.ts +1 -1
  27. package/dist/cjs/index.js +1 -1
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/label/index.d.ts +265 -187
  30. package/dist/cjs/label/index.d.ts.map +1 -1
  31. package/dist/cjs/label/index.js +1 -1
  32. package/dist/cjs/label/index.js.map +2 -2
  33. package/dist/cjs/line/index.d.ts +247 -207
  34. package/dist/cjs/line/index.d.ts.map +1 -1
  35. package/dist/cjs/line/index.js.map +2 -2
  36. package/dist/cjs/linefill/index.d.ts +61 -89
  37. package/dist/cjs/linefill/index.d.ts.map +1 -1
  38. package/dist/cjs/linefill/index.js.map +2 -2
  39. package/dist/cjs/math/index.d.ts +49 -40
  40. package/dist/cjs/math/index.d.ts.map +1 -1
  41. package/dist/cjs/math/index.js.map +2 -2
  42. package/dist/cjs/polyline/index.d.ts +57 -78
  43. package/dist/cjs/polyline/index.d.ts.map +1 -1
  44. package/dist/cjs/polyline/index.js.map +2 -2
  45. package/dist/cjs/runtime/input-active.d.ts +2 -2
  46. package/dist/cjs/runtime/input-active.js.map +1 -1
  47. package/dist/cjs/runtime/series.d.ts +241 -161
  48. package/dist/cjs/runtime/series.d.ts.map +1 -1
  49. package/dist/cjs/runtime/series.js +223 -127
  50. package/dist/cjs/runtime/series.js.map +2 -2
  51. package/dist/cjs/script/api/alert.d.ts +37 -0
  52. package/dist/cjs/script/api/alert.d.ts.map +1 -0
  53. package/dist/cjs/script/api/alert.js +17 -0
  54. package/dist/cjs/script/api/alert.js.map +7 -0
  55. package/dist/cjs/script/api/calc.d.ts +232 -0
  56. package/dist/cjs/script/api/calc.d.ts.map +1 -0
  57. package/dist/cjs/script/api/calc.js +17 -0
  58. package/dist/cjs/script/api/calc.js.map +7 -0
  59. package/dist/cjs/script/api/color.d.ts +213 -0
  60. package/dist/cjs/script/api/color.d.ts.map +1 -0
  61. package/dist/cjs/script/api/color.js +17 -0
  62. package/dist/cjs/script/api/color.js.map +7 -0
  63. package/dist/cjs/script/api/context.d.ts +764 -0
  64. package/dist/cjs/script/api/context.d.ts.map +1 -0
  65. package/dist/cjs/script/api/context.js +17 -0
  66. package/dist/cjs/script/api/context.js.map +7 -0
  67. package/dist/cjs/script/api/log.d.ts +58 -0
  68. package/dist/cjs/script/api/log.d.ts.map +1 -0
  69. package/dist/cjs/script/api/log.js +17 -0
  70. package/dist/cjs/script/api/log.js.map +7 -0
  71. package/dist/cjs/script/api/strategy.d.ts +391 -0
  72. package/dist/cjs/script/api/strategy.d.ts.map +1 -0
  73. package/dist/cjs/script/api/strategy.js +17 -0
  74. package/dist/cjs/script/api/strategy.js.map +7 -0
  75. package/dist/cjs/script/api/ta.d.ts +1012 -0
  76. package/dist/cjs/script/api/ta.d.ts.map +1 -0
  77. package/dist/cjs/script/api/ta.js +17 -0
  78. package/dist/cjs/script/api/ta.js.map +7 -0
  79. package/dist/cjs/script/api/table.d.ts +479 -0
  80. package/dist/cjs/script/api/table.d.ts.map +1 -0
  81. package/dist/cjs/script/api/table.js +17 -0
  82. package/dist/cjs/script/api/table.js.map +7 -0
  83. package/dist/cjs/script/constants.d.ts +228 -83
  84. package/dist/cjs/script/constants.d.ts.map +1 -1
  85. package/dist/cjs/script/constants.js +87 -0
  86. package/dist/cjs/script/constants.js.map +2 -2
  87. package/dist/cjs/script/define.d.ts +94 -0
  88. package/dist/cjs/script/define.d.ts.map +1 -0
  89. package/dist/cjs/script/define.js +127 -0
  90. package/dist/cjs/script/define.js.map +7 -0
  91. package/dist/cjs/script/drawing-args.d.ts.map +1 -1
  92. package/dist/cjs/script/drawing-args.js +1 -1
  93. package/dist/cjs/script/drawing-args.js.map +2 -2
  94. package/dist/cjs/script/formula.d.ts +53 -0
  95. package/dist/cjs/script/formula.d.ts.map +1 -0
  96. package/dist/cjs/script/formula.js +402 -0
  97. package/dist/cjs/script/formula.js.map +7 -0
  98. package/dist/cjs/script/globals.d.ts +10 -0
  99. package/dist/cjs/script/globals.d.ts.map +1 -1
  100. package/dist/cjs/script/globals.js.map +1 -1
  101. package/dist/cjs/script/index.d.ts +1067 -1006
  102. package/dist/cjs/script/index.d.ts.map +1 -1
  103. package/dist/cjs/script/index.js +530 -60
  104. package/dist/cjs/script/index.js.map +3 -3
  105. package/dist/cjs/script/json.d.ts +117 -0
  106. package/dist/cjs/script/json.d.ts.map +1 -0
  107. package/dist/cjs/script/json.js +321 -0
  108. package/dist/cjs/script/json.js.map +7 -0
  109. package/dist/cjs/str/index.d.ts +50 -75
  110. package/dist/cjs/str/index.d.ts.map +1 -1
  111. package/dist/cjs/str/index.js +2 -2
  112. package/dist/cjs/str/index.js.map +2 -2
  113. package/dist/cjs/strategy/index.d.ts +102 -1
  114. package/dist/cjs/strategy/index.d.ts.map +1 -1
  115. package/dist/cjs/strategy/index.js.map +2 -2
  116. package/dist/cjs/table/index.d.ts +330 -49
  117. package/dist/cjs/table/index.d.ts.map +1 -1
  118. package/dist/cjs/table/index.js +55 -27
  119. package/dist/cjs/table/index.js.map +2 -2
  120. package/dist/cjs/text/index.d.ts +12 -14
  121. package/dist/cjs/text/index.d.ts.map +1 -1
  122. package/dist/cjs/text/index.js.map +2 -2
  123. package/dist/cjs/types/index.d.ts +15 -8
  124. package/dist/cjs/types/index.d.ts.map +1 -1
  125. package/dist/cjs/types/index.js +12 -3
  126. package/dist/cjs/types/index.js.map +2 -2
  127. package/dist/esm/box/index.d.ts +348 -289
  128. package/dist/esm/box/index.d.ts.map +1 -1
  129. package/dist/esm/box/index.js +276 -276
  130. package/dist/esm/box/index.js.map +1 -1
  131. package/dist/esm/check/node.d.ts.map +1 -1
  132. package/dist/esm/check/node.js +1 -0
  133. package/dist/esm/check/node.js.map +1 -1
  134. package/dist/esm/check/preview.d.ts +31 -0
  135. package/dist/esm/check/preview.d.ts.map +1 -0
  136. package/dist/esm/check/preview.js +296 -0
  137. package/dist/esm/check/preview.js.map +1 -0
  138. package/dist/esm/color/index.d.ts +11 -11
  139. package/dist/esm/color/index.js +11 -11
  140. package/dist/esm/color/parse.d.ts +2 -0
  141. package/dist/esm/color/parse.d.ts.map +1 -1
  142. package/dist/esm/color/parse.js +7 -0
  143. package/dist/esm/color/parse.js.map +1 -1
  144. package/dist/esm/compare/index.d.ts +76 -12
  145. package/dist/esm/compare/index.d.ts.map +1 -1
  146. package/dist/esm/compare/index.js +76 -12
  147. package/dist/esm/compare/index.js.map +1 -1
  148. package/dist/esm/drawing/registry.d.ts +28 -5
  149. package/dist/esm/drawing/registry.d.ts.map +1 -1
  150. package/dist/esm/drawing/registry.js +39 -3
  151. package/dist/esm/drawing/registry.js.map +1 -1
  152. package/dist/esm/index.d.ts +1 -1
  153. package/dist/esm/index.js +1 -1
  154. package/dist/esm/label/index.d.ts +265 -187
  155. package/dist/esm/label/index.d.ts.map +1 -1
  156. package/dist/esm/label/index.js +207 -177
  157. package/dist/esm/label/index.js.map +1 -1
  158. package/dist/esm/line/index.d.ts +247 -207
  159. package/dist/esm/line/index.d.ts.map +1 -1
  160. package/dist/esm/line/index.js +202 -194
  161. package/dist/esm/line/index.js.map +1 -1
  162. package/dist/esm/linefill/index.d.ts +61 -89
  163. package/dist/esm/linefill/index.d.ts.map +1 -1
  164. package/dist/esm/linefill/index.js +61 -89
  165. package/dist/esm/linefill/index.js.map +1 -1
  166. package/dist/esm/math/index.d.ts +49 -40
  167. package/dist/esm/math/index.d.ts.map +1 -1
  168. package/dist/esm/math/index.js +22 -9
  169. package/dist/esm/math/index.js.map +1 -1
  170. package/dist/esm/polyline/index.d.ts +57 -78
  171. package/dist/esm/polyline/index.d.ts.map +1 -1
  172. package/dist/esm/polyline/index.js +57 -78
  173. package/dist/esm/polyline/index.js.map +1 -1
  174. package/dist/esm/runtime/input-active.d.ts +2 -2
  175. package/dist/esm/runtime/input-active.js +2 -2
  176. package/dist/esm/runtime/series.d.ts +241 -161
  177. package/dist/esm/runtime/series.d.ts.map +1 -1
  178. package/dist/esm/runtime/series.js +241 -161
  179. package/dist/esm/runtime/series.js.map +1 -1
  180. package/dist/esm/script/api/alert.d.ts +37 -0
  181. package/dist/esm/script/api/alert.d.ts.map +1 -0
  182. package/dist/esm/script/api/alert.js +7 -0
  183. package/dist/esm/script/api/alert.js.map +1 -0
  184. package/dist/esm/script/api/calc.d.ts +232 -0
  185. package/dist/esm/script/api/calc.d.ts.map +1 -0
  186. package/dist/esm/script/api/calc.js +6 -0
  187. package/dist/esm/script/api/calc.js.map +1 -0
  188. package/dist/esm/script/api/color.d.ts +213 -0
  189. package/dist/esm/script/api/color.d.ts.map +1 -0
  190. package/dist/esm/script/api/color.js +6 -0
  191. package/dist/esm/script/api/color.js.map +1 -0
  192. package/dist/esm/script/api/context.d.ts +764 -0
  193. package/dist/esm/script/api/context.d.ts.map +1 -0
  194. package/dist/esm/script/api/context.js +7 -0
  195. package/dist/esm/script/api/context.js.map +1 -0
  196. package/dist/esm/script/api/log.d.ts +58 -0
  197. package/dist/esm/script/api/log.d.ts.map +1 -0
  198. package/dist/esm/script/api/log.js +6 -0
  199. package/dist/esm/script/api/log.js.map +1 -0
  200. package/dist/esm/script/api/strategy.d.ts +391 -0
  201. package/dist/esm/script/api/strategy.d.ts.map +1 -0
  202. package/dist/esm/script/api/strategy.js +7 -0
  203. package/dist/esm/script/api/strategy.js.map +1 -0
  204. package/dist/esm/script/api/ta.d.ts +1012 -0
  205. package/dist/esm/script/api/ta.d.ts.map +1 -0
  206. package/dist/esm/script/api/ta.js +6 -0
  207. package/dist/esm/script/api/ta.js.map +1 -0
  208. package/dist/esm/script/api/table.d.ts +479 -0
  209. package/dist/esm/script/api/table.d.ts.map +1 -0
  210. package/dist/esm/script/api/table.js +7 -0
  211. package/dist/esm/script/api/table.js.map +1 -0
  212. package/dist/esm/script/constants.d.ts +228 -83
  213. package/dist/esm/script/constants.d.ts.map +1 -1
  214. package/dist/esm/script/constants.js +110 -24
  215. package/dist/esm/script/constants.js.map +1 -1
  216. package/dist/esm/script/define.d.ts +94 -0
  217. package/dist/esm/script/define.d.ts.map +1 -0
  218. package/dist/esm/script/define.js +136 -0
  219. package/dist/esm/script/define.js.map +1 -0
  220. package/dist/esm/script/drawing-args.d.ts.map +1 -1
  221. package/dist/esm/script/drawing-args.js +2 -1
  222. package/dist/esm/script/drawing-args.js.map +1 -1
  223. package/dist/esm/script/formula.d.ts +53 -0
  224. package/dist/esm/script/formula.d.ts.map +1 -0
  225. package/dist/esm/script/formula.js +408 -0
  226. package/dist/esm/script/formula.js.map +1 -0
  227. package/dist/esm/script/globals.d.ts +10 -0
  228. package/dist/esm/script/globals.d.ts.map +1 -1
  229. package/dist/esm/script/globals.js.map +1 -1
  230. package/dist/esm/script/index.d.ts +1067 -1006
  231. package/dist/esm/script/index.d.ts.map +1 -1
  232. package/dist/esm/script/index.js +1096 -151
  233. package/dist/esm/script/index.js.map +1 -1
  234. package/dist/esm/script/json.d.ts +117 -0
  235. package/dist/esm/script/json.d.ts.map +1 -0
  236. package/dist/esm/script/json.js +375 -0
  237. package/dist/esm/script/json.js.map +1 -0
  238. package/dist/esm/str/index.d.ts +50 -75
  239. package/dist/esm/str/index.d.ts.map +1 -1
  240. package/dist/esm/str/index.js +51 -76
  241. package/dist/esm/str/index.js.map +1 -1
  242. package/dist/esm/strategy/index.d.ts +102 -1
  243. package/dist/esm/strategy/index.d.ts.map +1 -1
  244. package/dist/esm/strategy/index.js +1 -1
  245. package/dist/esm/strategy/index.js.map +1 -1
  246. package/dist/esm/table/index.d.ts +330 -49
  247. package/dist/esm/table/index.d.ts.map +1 -1
  248. package/dist/esm/table/index.js +372 -61
  249. package/dist/esm/table/index.js.map +1 -1
  250. package/dist/esm/text/index.d.ts +12 -14
  251. package/dist/esm/text/index.d.ts.map +1 -1
  252. package/dist/esm/text/index.js +12 -14
  253. package/dist/esm/text/index.js.map +1 -1
  254. package/dist/esm/types/index.d.ts +15 -8
  255. package/dist/esm/types/index.d.ts.map +1 -1
  256. package/dist/esm/types/index.js +15 -8
  257. package/dist/esm/types/index.js.map +1 -1
  258. package/docs/first-indicator.md +152 -0
  259. package/docs/guide.md +1185 -0
  260. package/docs/inventory.md +772 -0
  261. package/docs/no-code.md +207 -0
  262. package/docs/recipes.md +202 -0
  263. package/package.json +2 -1
  264. package/skills/oakscript/SKILL.md +8 -0
  265. package/skills/oakscript/reference/errors.md +3 -2
  266. package/src/box/index.ts +348 -289
  267. package/src/check/node.ts +1 -0
  268. package/src/check/preview.ts +307 -0
  269. package/src/color/index.ts +11 -11
  270. package/src/color/parse.ts +7 -0
  271. package/src/compare/index.ts +76 -12
  272. package/src/drawing/registry.ts +44 -5
  273. package/src/index.ts +1 -1
  274. package/src/label/index.ts +267 -189
  275. package/src/line/index.ts +248 -208
  276. package/src/linefill/index.ts +61 -89
  277. package/src/math/index.ts +51 -42
  278. package/src/polyline/index.ts +57 -78
  279. package/src/runtime/input-active.ts +2 -2
  280. package/src/runtime/series.ts +243 -163
  281. package/src/script/api/alert.ts +43 -0
  282. package/src/script/api/calc.ts +250 -0
  283. package/src/script/api/color.ts +245 -0
  284. package/src/script/api/context.ts +944 -0
  285. package/src/script/api/log.ts +60 -0
  286. package/src/script/api/strategy.ts +410 -0
  287. package/src/script/api/ta.ts +1115 -0
  288. package/src/script/api/table.ts +538 -0
  289. package/src/script/constants.ts +229 -25
  290. package/src/script/define.ts +221 -0
  291. package/src/script/drawing-args.ts +2 -1
  292. package/src/script/formula.ts +438 -0
  293. package/src/script/globals.ts +10 -0
  294. package/src/script/index.ts +1519 -239
  295. package/src/script/json.ts +457 -0
  296. package/src/str/index.ts +51 -76
  297. package/src/strategy/index.ts +102 -1
  298. package/src/table/index.ts +388 -62
  299. package/src/text/index.ts +12 -14
  300. package/src/types/index.ts +15 -8
@@ -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
- * Linefill objects fill the area between two lines with a color.
7
- * They have minimal computational value but automatically follow line movements
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
- * Creates a new linefill object that fills the area between two lines.
18
- *
19
- * @param line1 - First line object
20
- * @param line2 - Second line object
21
- * @param fillColor - Fill color (optional)
22
- * @returns New linefill object
23
- *
24
- * @remarks
25
- * - Automatically follows line movements (if lines are updated, fill updates too)
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
- * ```typescript
35
- * import { line, linefill } from 'oakscriptjs';
36
- *
37
- * // Create channel lines
38
- * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');
39
- * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');
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 reference.
82
- *
83
- * @param id - Linefill object
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
- * ```typescript
91
- * const channelFill = linefill.new(upperLine, lowerLine);
92
- *
93
- * // Later, retrieve and update the first line
94
- * const line1 = linefill.get_line1(channelFill);
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 reference.
104
- *
105
- * @param id - Linefill object
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
- * ```typescript
113
- * const channelFill = linefill.new(upperLine, lowerLine);
114
- *
115
- * // Later, retrieve and update the second line
116
- * const line2 = linefill.get_line2(channelFill);
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
- * Sets the fill color.
126
- *
127
- * @param id - Linefill object to modify
128
- * @param fillColor - New fill color
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
- * ```typescript
136
- * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');
137
- *
138
- * // Change color based on trend
139
- * if (bullish) {
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
- * Deletes the linefill object.
154
- *
155
- * @param id - Linefill object to delete
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
- * ```typescript
163
- * const channelFill = linefill.new(upperLine, lowerLine);
164
- * linefill.delete(channelFill);
165
- * // linefill.all() no longer contains it
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
- * All live linefills, in creation order (PineScript `linefill.all`). A new array.
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * ```typescript
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
- * PineScript's seeded generator: Java's linear congruential generator (`java.util.Random`), `nextDouble()`.
1044
- * Each generator draws one number per call.
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
- * ```typescript
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
- * ```typescript
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 value to the nearest mintick.
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 number to round or Series
1164
- * @param mintick - Optional mintick value (defaults to requiring syminfo context)
1165
- * @returns The number rounded to tick precision
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
- * ```typescript
1182
- * // Direct call with explicit mintick
1183
- * const rounded = math.round_to_mintick(1.2345, 0.01); // Returns: 1.23
1184
- * const rounded2 = math.round_to_mintick(1.2367, 0.01); // Returns: 1.24
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
- export const phi = 1.618033988749895; // Golden ratio
1270
- export const rphi = 0.6180339887498948; // Reciprocal of golden ratio: 1 / phi
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;