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