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.
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 +1065 -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 +1065 -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 +1517 -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,125 +1,97 @@
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
  */
12
10
  import type { Linefill, Line, color } from '../types/index.js';
13
11
  /**
14
- * Creates a new linefill object that fills the area between two lines.
15
- *
16
- * @param line1 - First line object
17
- * @param line2 - Second line object
18
- * @param fillColor - Fill color (optional)
19
- * @returns New linefill object
20
- *
21
- * @remarks
22
- * - Automatically follows line movements (if lines are updated, fill updates too)
23
- * - Automatically deleted if either line is deleted
24
- * - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill
25
- * (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is
26
- * returned with the new colour instead of a new one; with several, the one created or returned last
27
- * - If both lines extend in same direction, fill extends too
28
- * - Purely visual in PineScript, but getters allow retrieving line references
29
- *
12
+ * Fills the area between two lines with a colour and returns the linefill's handle. The fill follows the lines when
13
+ * they move or extend, and is deleted when either line is deleted. Two lines have one linefill: when they already
14
+ * have one, that linefill gets the new colour and is returned instead of a new one. An `na` line gives `na`.
15
+ * The arguments can also be given by name in an object.
16
+ * @param line1 - The first line.
17
+ * @param line2 - The second line.
18
+ * @param fillColor - Fill colour; a transparent one (`color.new(color.blue, 85)`) keeps the bars visible.
19
+ * Default: none.
20
+ * @returns The linefill.
30
21
  * @example
31
- * ```typescript
32
- * import { line, linefill } from 'oakscriptjs';
33
- *
34
- * // Create channel lines
35
- * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');
36
- * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');
37
- *
38
- * // Fill channel with color
39
- * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue
22
+ * ```js
23
+ * eachBar((c) => {
24
+ * if (c.i !== c.n - 1) return;
25
+ * const top = line.new(c.i - 20, c.get(high, 20), c.i, c.high, { extend: extend.right });
26
+ * const bottom = line.new(c.i - 20, c.get(low, 20), c.i, c.low, { extend: extend.right });
27
+ * linefill.new(top, bottom, color.new(color.blue, 85));
28
+ * });
40
29
  * ```
41
30
  */
42
31
  export declare function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill;
43
32
  /**
44
- * Returns the first line reference.
45
- *
46
- * @param id - Linefill object
47
- * @returns First line object
48
- *
49
- * @remarks
50
- * Can be used to retrieve and manipulate the first line.
51
- *
33
+ * Returns the first line of a linefill, to read or move it.
34
+ * @param id - The linefill.
35
+ * @returns The first line given to `linefill.new()`.
52
36
  * @example
53
- * ```typescript
54
- * const channelFill = linefill.new(upperLine, lowerLine);
55
- *
56
- * // Later, retrieve and update the first line
57
- * const line1 = linefill.get_line1(channelFill);
58
- * line.set_y2(line1, 175); // Update upper line's second point
37
+ * ```js
38
+ * eachBar((c) => {
39
+ * 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));
40
+ * line.set_color(linefill.get_line1(lf), color.green);
41
+ * });
59
42
  * ```
60
43
  */
61
44
  export declare function get_line1(id: Linefill): Line;
62
45
  /**
63
- * Returns the second line reference.
64
- *
65
- * @param id - Linefill object
66
- * @returns Second line object
67
- *
68
- * @remarks
69
- * Can be used to retrieve and manipulate the second line.
70
- *
46
+ * Returns the second line of a linefill, to read or move it.
47
+ * @param id - The linefill.
48
+ * @returns The second line given to `linefill.new()`.
71
49
  * @example
72
- * ```typescript
73
- * const channelFill = linefill.new(upperLine, lowerLine);
74
- *
75
- * // Later, retrieve and update the second line
76
- * const line2 = linefill.get_line2(channelFill);
77
- * line.set_y2(line2, 145); // Update lower line's second point
50
+ * ```js
51
+ * eachBar((c) => {
52
+ * 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));
53
+ * line.set_color(linefill.get_line2(lf), color.red);
54
+ * });
78
55
  * ```
79
56
  */
80
57
  export declare function get_line2(id: Linefill): Line;
81
58
  /**
82
- * Sets the fill color.
83
- *
84
- * @param id - Linefill object to modify
85
- * @param fillColor - New fill color
86
- * @returns Modified linefill object
87
- *
88
- * @remarks
89
- * Useful for dynamically changing channel colors based on conditions.
90
- *
59
+ * Changes the fill colour. Does nothing on a deleted linefill.
60
+ * @param id - The linefill.
61
+ * @param fillColor - New fill colour.
62
+ * @returns The same linefill.
91
63
  * @example
92
- * ```typescript
93
- * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');
94
- *
95
- * // Change color based on trend
96
- * if (bullish) {
97
- * linefill.set_color(channelFill, '#00FF0020'); // Green
98
- * } else {
99
- * linefill.set_color(channelFill, '#FF000020'); // Red
100
- * }
64
+ * ```js
65
+ * eachBar((c) => {
66
+ * 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));
67
+ * linefill.set_color(lf, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));
68
+ * });
101
69
  * ```
102
70
  */
103
71
  export declare function set_color(id: Linefill, fillColor: color): Linefill;
104
72
  /**
105
- * Deletes the linefill object.
106
- *
107
- * @param id - Linefill object to delete
108
- *
109
- * @remarks
110
- * Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters
111
- * return NaN and its setters do nothing. Deleting it twice has no effect.
112
- *
73
+ * Removes the fill from the chart and from `linefill.all`; the two lines stay. Afterwards its setters do nothing;
74
+ * deleting it again does nothing.
75
+ * @param id - The linefill to delete.
113
76
  * @example
114
- * ```typescript
115
- * const channelFill = linefill.new(upperLine, lowerLine);
116
- * linefill.delete(channelFill);
117
- * // linefill.all() no longer contains it
77
+ * ```js
78
+ * eachBar((c) => {
79
+ * 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));
80
+ * if (c.close < c.open) linefill.delete(lf);
81
+ * });
118
82
  * ```
119
83
  */
120
84
  export declare function delete_linefill(id: Linefill): void;
121
85
  /**
122
- * All live linefills, in creation order (PineScript `linefill.all`). A new array.
86
+ * Returns the linefills that are still on the chart, oldest first. The array is a copy.
87
+ * (In a script, `linefill.all` is read as a value, without a call.)
88
+ * @returns The live linefills in creation order.
89
+ * @example
90
+ * ```js
91
+ * eachBar((c) => {
92
+ * if (c.i === c.n - 1) for (const lf of linefill.all) linefill.set_color(lf, color.new(color.gray, 80));
93
+ * });
94
+ * ```
123
95
  */
124
96
  export declare function all(): Linefill[];
125
97
  export { new_linefill as new };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAU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;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,GAAG,QAAQ,CAIlE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAElD;AAGD;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,IAAI,QAAQ,EAAE,CAEhC;AAGD,OAAO,EAAE,YAAY,IAAI,GAAG,EAAE,CAAC;AAC/B,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,CAAC"}
@@ -1,42 +1,31 @@
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
  */
12
10
  import { Stamped, all as allDrawings, isDeleted, liveFillsOf, register, remove } from '../drawing/registry.js';
13
11
  /**
14
- * Creates a new linefill object that fills the area between two lines.
15
- *
16
- * @param line1 - First line object
17
- * @param line2 - Second line object
18
- * @param fillColor - Fill color (optional)
19
- * @returns New linefill object
20
- *
21
- * @remarks
22
- * - Automatically follows line movements (if lines are updated, fill updates too)
23
- * - Automatically deleted if either line is deleted
24
- * - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill
25
- * (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is
26
- * returned with the new colour instead of a new one; with several, the one created or returned last
27
- * - If both lines extend in same direction, fill extends too
28
- * - Purely visual in PineScript, but getters allow retrieving line references
29
- *
12
+ * Fills the area between two lines with a colour and returns the linefill's handle. The fill follows the lines when
13
+ * they move or extend, and is deleted when either line is deleted. Two lines have one linefill: when they already
14
+ * have one, that linefill gets the new colour and is returned instead of a new one. An `na` line gives `na`.
15
+ * The arguments can also be given by name in an object.
16
+ * @param line1 - The first line.
17
+ * @param line2 - The second line.
18
+ * @param fillColor - Fill colour; a transparent one (`color.new(color.blue, 85)`) keeps the bars visible.
19
+ * Default: none.
20
+ * @returns The linefill.
30
21
  * @example
31
- * ```typescript
32
- * import { line, linefill } from 'oakscriptjs';
33
- *
34
- * // Create channel lines
35
- * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');
36
- * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');
37
- *
38
- * // Fill channel with color
39
- * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue
22
+ * ```js
23
+ * eachBar((c) => {
24
+ * if (c.i !== c.n - 1) return;
25
+ * const top = line.new(c.i - 20, c.get(high, 20), c.i, c.high, { extend: extend.right });
26
+ * const bottom = line.new(c.i - 20, c.get(low, 20), c.i, c.low, { extend: extend.right });
27
+ * linefill.new(top, bottom, color.new(color.blue, 85));
28
+ * });
40
29
  * ```
41
30
  */
42
31
  export function new_linefill(line1, line2, fillColor) {
@@ -76,67 +65,46 @@ class Touched extends Stamped {
76
65
  }
77
66
  let touchCount = 0;
78
67
  /**
79
- * Returns the first line reference.
80
- *
81
- * @param id - Linefill object
82
- * @returns First line object
83
- *
84
- * @remarks
85
- * Can be used to retrieve and manipulate the first line.
86
- *
68
+ * Returns the first line of a linefill, to read or move it.
69
+ * @param id - The linefill.
70
+ * @returns The first line given to `linefill.new()`.
87
71
  * @example
88
- * ```typescript
89
- * const channelFill = linefill.new(upperLine, lowerLine);
90
- *
91
- * // Later, retrieve and update the first line
92
- * const line1 = linefill.get_line1(channelFill);
93
- * line.set_y2(line1, 175); // Update upper line's second point
72
+ * ```js
73
+ * eachBar((c) => {
74
+ * 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));
75
+ * line.set_color(linefill.get_line1(lf), color.green);
76
+ * });
94
77
  * ```
95
78
  */
96
79
  export function get_line1(id) {
97
80
  return id.line1;
98
81
  }
99
82
  /**
100
- * Returns the second line reference.
101
- *
102
- * @param id - Linefill object
103
- * @returns Second line object
104
- *
105
- * @remarks
106
- * Can be used to retrieve and manipulate the second line.
107
- *
83
+ * Returns the second line of a linefill, to read or move it.
84
+ * @param id - The linefill.
85
+ * @returns The second line given to `linefill.new()`.
108
86
  * @example
109
- * ```typescript
110
- * const channelFill = linefill.new(upperLine, lowerLine);
111
- *
112
- * // Later, retrieve and update the second line
113
- * const line2 = linefill.get_line2(channelFill);
114
- * line.set_y2(line2, 145); // Update lower line's second point
87
+ * ```js
88
+ * eachBar((c) => {
89
+ * 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));
90
+ * line.set_color(linefill.get_line2(lf), color.red);
91
+ * });
115
92
  * ```
116
93
  */
117
94
  export function get_line2(id) {
118
95
  return id.line2;
119
96
  }
120
97
  /**
121
- * Sets the fill color.
122
- *
123
- * @param id - Linefill object to modify
124
- * @param fillColor - New fill color
125
- * @returns Modified linefill object
126
- *
127
- * @remarks
128
- * Useful for dynamically changing channel colors based on conditions.
129
- *
98
+ * Changes the fill colour. Does nothing on a deleted linefill.
99
+ * @param id - The linefill.
100
+ * @param fillColor - New fill colour.
101
+ * @returns The same linefill.
130
102
  * @example
131
- * ```typescript
132
- * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');
133
- *
134
- * // Change color based on trend
135
- * if (bullish) {
136
- * linefill.set_color(channelFill, '#00FF0020'); // Green
137
- * } else {
138
- * linefill.set_color(channelFill, '#FF000020'); // Red
139
- * }
103
+ * ```js
104
+ * eachBar((c) => {
105
+ * 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));
106
+ * linefill.set_color(lf, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));
107
+ * });
140
108
  * ```
141
109
  */
142
110
  export function set_color(id, fillColor) {
@@ -146,26 +114,30 @@ export function set_color(id, fillColor) {
146
114
  return id;
147
115
  }
148
116
  /**
149
- * Deletes the linefill object.
150
- *
151
- * @param id - Linefill object to delete
152
- *
153
- * @remarks
154
- * Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters
155
- * return NaN and its setters do nothing. Deleting it twice has no effect.
156
- *
117
+ * Removes the fill from the chart and from `linefill.all`; the two lines stay. Afterwards its setters do nothing;
118
+ * deleting it again does nothing.
119
+ * @param id - The linefill to delete.
157
120
  * @example
158
- * ```typescript
159
- * const channelFill = linefill.new(upperLine, lowerLine);
160
- * linefill.delete(channelFill);
161
- * // linefill.all() no longer contains it
121
+ * ```js
122
+ * eachBar((c) => {
123
+ * 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));
124
+ * if (c.close < c.open) linefill.delete(lf);
125
+ * });
162
126
  * ```
163
127
  */
164
128
  export function delete_linefill(id) {
165
129
  remove('linefill', id);
166
130
  }
167
131
  /**
168
- * All live linefills, in creation order (PineScript `linefill.all`). A new array.
132
+ * Returns the linefills that are still on the chart, oldest first. The array is a copy.
133
+ * (In a script, `linefill.all` is read as a value, without a call.)
134
+ * @returns The live linefills in creation order.
135
+ * @example
136
+ * ```js
137
+ * eachBar((c) => {
138
+ * if (c.i === c.n - 1) for (const lf of linefill.all) linefill.set_color(lf, color.new(color.gray, 80));
139
+ * });
140
+ * ```
169
141
  */
170
142
  export function all() {
171
143
  return allDrawings('linefill');
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE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