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
package/src/index.ts CHANGED
@@ -232,7 +232,7 @@ export type { LightweightSeriesDefinitions } from './runtime/adapters/Lightweigh
232
232
  export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
233
233
 
234
234
  // Version
235
- export const VERSION = '0.24.0';
235
+ export const VERSION = '0.25.1';
236
236
 
237
237
  /**
238
238
  * Library information
@@ -1,11 +1,10 @@
1
1
  /**
2
- * Label namespace
3
- * Functions for creating and manipulating label drawing objects.
2
+ * Label namespace: functions that create, read, change and delete label drawings (`label.*`).
4
3
  *
5
4
  * @remarks
6
- * Labels are primarily used for annotations and marking points on the chart.
7
- * They have limited computational value compared to lines and boxes, but getters
8
- * allow retrieving position and text for conditional logic.
5
+ * A label is a text box or a shape at one point of the chart: a bar index (`xloc.bar_index`, the default), a UNIX
6
+ * time in ms (`xloc.bar_time`) or a percent of the pane's width (`xloc.pane`), and a price, or above / below the bar
7
+ * with `yloc.abovebar` / `yloc.belowbar`.
9
8
  *
10
9
  * @version 6
11
10
  */
@@ -18,19 +17,34 @@ type LabelYloc = 'price' | 'abovebar' | 'belowbar';
18
17
  type LabelStyle = NonNullable<Label['style']>;
19
18
 
20
19
  /**
21
- * Creates a new label (PineScript `label.new`), with a chart point or with coordinates:
22
- *
23
- * - `label.new(point, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,
24
- * text_font_family?, force_overlay?, text_formatting?)`
25
- * - `label.new(x, y, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,
26
- * text_font_family?, force_overlay?, text_formatting?)`
27
- *
28
- * With a chart point, x is `point.index` for `bar_index` labels and `point.time` for `bar_time` labels.
29
- *
20
+ * Draws a label at a chart point and returns its handle, to change or delete it later.
21
+ * With `xloc.bar_index` the x of the point is its `index`, with `xloc.bar_time` its `time`. Labels above
22
+ * `max_labels_count` (default 50) are deleted oldest first.
23
+ * @param point - Where the label points (`chart.point.now()`, `chart.point.from_index(...)`...).
24
+ * @param text - Text of the label; `\n` starts a new line. Default: "".
25
+ * @param xloc - What the x coordinate is: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
26
+ * @param yloc - `yloc.price` (at the point's price), `yloc.abovebar` or `yloc.belowbar` (above the high / below the
27
+ * low of the bar). Default: `yloc.price`.
28
+ * @param labelColor - Colour of the label box or shape. Default: blue (#2962FF).
29
+ * @param style - `label.style_label_down`, `label.style_label_up`, `label.style_label_left`... or a shape style
30
+ * (`label.style_circle`, `label.style_triangleup`...). Default: `label.style_label_down`.
31
+ * @param textcolor - Text colour. Default: white.
32
+ * @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.
33
+ * Default: `size.normal`.
34
+ * @param textalign - Alignment of the text lines: `text.align_left`, `text.align_center` or `text.align_right`.
35
+ * Default: `text.align_center`.
36
+ * @param tooltip - Text shown when the pointer is over the label. Default: none.
37
+ * @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.
38
+ * @param force_overlay - When true, the label is drawn on the price pane even if the script has its own pane.
39
+ * Default: false.
40
+ * @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
41
+ * Default: `text.format_none`.
42
+ * @returns The new label.
30
43
  * @example
31
- * ```typescript
32
- * const signal = label.new(10, 105.5, 'BUY');
33
- * const atPoint = label.new(chartPoint.from_index(10, 105.5), 'BUY');
44
+ * ```js
45
+ * eachBar((c) => {
46
+ * if (c.i === c.n - 1) label.new(chart.point.now(c.high), "Last", { style: label.style_label_down });
47
+ * });
34
48
  * ```
35
49
  */
36
50
  export function new_label(
@@ -48,6 +62,39 @@ export function new_label(
48
62
  force_overlay?: boolean,
49
63
  text_formatting?: number
50
64
  ): Label;
65
+ /**
66
+ * Draws a label at (x, y) and returns its handle, to change or delete it later.
67
+ * Inside `eachBar` a Series argument is read on the current bar; the optional arguments can also be given by name in
68
+ * an object after the coordinates. A bar index x is rounded down. Labels above `max_labels_count` (default 50) are
69
+ * deleted oldest first.
70
+ * @param x - A bar index, a UNIX time in ms (`xloc.bar_time`) or a percent of the pane's width (`xloc.pane`).
71
+ * @param y - Price of the label (not used with `yloc.abovebar` / `yloc.belowbar`).
72
+ * @param text - Text of the label; `\n` starts a new line. Default: "".
73
+ * @param xloc - What the x coordinate is: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
74
+ * @param yloc - `yloc.price` (at `y`), `yloc.abovebar` or `yloc.belowbar` (above the high / below the low of the
75
+ * bar). Default: `yloc.price`.
76
+ * @param labelColor - Colour of the label box or shape. Default: blue (#2962FF).
77
+ * @param style - `label.style_label_down`, `label.style_label_up`, `label.style_label_left`... or a shape style
78
+ * (`label.style_circle`, `label.style_triangleup`...). Default: `label.style_label_down`.
79
+ * @param textcolor - Text colour. Default: white.
80
+ * @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.
81
+ * Default: `size.normal`.
82
+ * @param textalign - Alignment of the text lines: `text.align_left`, `text.align_center` or `text.align_right`.
83
+ * Default: `text.align_center`.
84
+ * @param tooltip - Text shown when the pointer is over the label. Default: none.
85
+ * @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.
86
+ * @param force_overlay - When true, the label is drawn on the price pane even if the script has its own pane.
87
+ * Default: false.
88
+ * @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
89
+ * Default: `text.format_none`.
90
+ * @returns The new label.
91
+ * @example
92
+ * ```js
93
+ * eachBar((c) => {
94
+ * if (c.i === c.n - 1) label.new(c.i, c.high, "Last", { color: color.gray, textcolor: color.white });
95
+ * });
96
+ * ```
97
+ */
51
98
  export function new_label(
52
99
  x: number,
53
100
  y: number,
@@ -86,7 +133,7 @@ export function new_label(...args: unknown[]): Label {
86
133
  y,
87
134
  xloc: xloc ?? 'bar_index',
88
135
  yloc: yloc ?? 'price',
89
- // PineScript: a label without text has the text "" (label.get_text gives "")
136
+ // a label without text has the text "" (label.get_text gives "")
90
137
  text: text ?? '',
91
138
  tooltip,
92
139
  color: labelColor,
@@ -101,15 +148,15 @@ export function new_label(...args: unknown[]): Label {
101
148
  }
102
149
 
103
150
  /**
104
- * Returns the x coordinate.
105
- *
106
- * @param id - Label object
107
- * @returns X coordinate (bar index or timestamp)
108
- *
151
+ * Returns the x coordinate of the label.
152
+ * @param id - The label.
153
+ * @returns A bar index, a UNIX time in ms or a pane percent, by the label's xloc; NaN for a deleted label.
109
154
  * @example
110
- * ```typescript
111
- * const label = label.new(50, 155.5, 'Pivot');
112
- * const x = label.get_x(label); // Returns 50
155
+ * ```js
156
+ * eachBar((c) => {
157
+ * const lb = label.new(c.i - 5, c.high, "Pivot");
158
+ * const age = c.i - label.get_x(lb); // 5
159
+ * });
113
160
  * ```
114
161
  */
115
162
  export function get_x(id: Label): number {
@@ -117,15 +164,15 @@ export function get_x(id: Label): number {
117
164
  }
118
165
 
119
166
  /**
120
- * Returns the y coordinate (price level).
121
- *
122
- * @param id - Label object
123
- * @returns Y coordinate (price)
124
- *
167
+ * Returns the price of the label.
168
+ * @param id - The label.
169
+ * @returns The label's price; NaN for a deleted label.
125
170
  * @example
126
- * ```typescript
127
- * const label = label.new(50, 155.5, 'Pivot');
128
- * const y = label.get_y(label); // Returns 155.5
171
+ * ```js
172
+ * eachBar((c) => {
173
+ * const lb = label.new(c.i, c.high, "High");
174
+ * const above = c.close > label.get_y(lb);
175
+ * });
129
176
  * ```
130
177
  */
131
178
  export function get_y(id: Label): number {
@@ -133,15 +180,15 @@ export function get_y(id: Label): number {
133
180
  }
134
181
 
135
182
  /**
136
- * Returns the label text content.
137
- *
138
- * @param id - Label object
139
- * @returns Text content (or undefined if no text)
140
- *
183
+ * Returns the text of the label.
184
+ * @param id - The label.
185
+ * @returns The label text ("" when it was created without one).
141
186
  * @example
142
- * ```typescript
143
- * const label = label.new(50, 155.5, 'Pivot High');
144
- * const text = label.get_text(label); // Returns 'Pivot High'
187
+ * ```js
188
+ * eachBar((c) => {
189
+ * const lb = label.new(c.i, c.high, "Up");
190
+ * if (label.get_text(lb) === "Up") label.set_color(lb, color.green);
191
+ * });
145
192
  * ```
146
193
  */
147
194
  export function get_text(id: Label): string | undefined {
@@ -149,21 +196,16 @@ export function get_text(id: Label): string | undefined {
149
196
  }
150
197
 
151
198
  /**
152
- * Creates a copy of the label object.
153
- *
154
- * @param id - Label object to copy
155
- * @returns New label object with same properties
156
- *
157
- * @remarks
158
- * Creates a shallow copy of the label. Modifications to the copy won't affect the original.
159
- *
199
+ * Makes a new label with the same position, text and style as `id` (it counts toward `max_labels_count`).
200
+ * Changing the copy does not change the original.
201
+ * @param id - The label to copy.
202
+ * @returns The new label.
160
203
  * @example
161
- * ```typescript
162
- * const original = label.new(50, 155.5, 'Pivot');
163
- * const copied = label.copy(original);
164
- *
165
- * // Modify copy without affecting original
166
- * copied.text = 'New Text';
204
+ * ```js
205
+ * eachBar((c) => {
206
+ * const lb = label.new(c.i, c.high, "Mark");
207
+ * label.set_y(label.copy(lb), c.low); // the same label at the low
208
+ * });
167
209
  * ```
168
210
  */
169
211
  export function copy(id: Label): Label {
@@ -175,16 +217,16 @@ export function copy(id: Label): Label {
175
217
  // =============================================================================
176
218
 
177
219
  /**
178
- * Sets the x coordinate.
179
- *
180
- * @param id - Label object to modify
181
- * @param x - New x coordinate
182
- * @returns Modified label object
183
- *
220
+ * Moves the label to another x. Does nothing on a deleted label.
221
+ * @param id - The label.
222
+ * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the label's xloc. A bar index is rounded down.
223
+ * @returns The same label.
184
224
  * @example
185
- * ```typescript
186
- * const label = label.new(50, 155.5, 'Pivot');
187
- * label.set_x(label, 55); // Move to bar 55
225
+ * ```js
226
+ * eachBar((c) => {
227
+ * const lb = label.new(c.i, c.high, "Next");
228
+ * label.set_x(lb, c.i + 5);
229
+ * });
188
230
  * ```
189
231
  */
190
232
  export function set_x(id: Label, x: number): Label {
@@ -195,16 +237,16 @@ export function set_x(id: Label, x: number): Label {
195
237
  }
196
238
 
197
239
  /**
198
- * Sets the y coordinate (price level).
199
- *
200
- * @param id - Label object to modify
201
- * @param y - New y coordinate
202
- * @returns Modified label object
203
- *
240
+ * Moves the label to another price. Does nothing on a deleted label.
241
+ * @param id - The label.
242
+ * @param y - New price.
243
+ * @returns The same label.
204
244
  * @example
205
- * ```typescript
206
- * const label = label.new(50, 155.5, 'Pivot');
207
- * label.set_y(label, 160); // Move to price 160
245
+ * ```js
246
+ * eachBar((c) => {
247
+ * const lb = label.new(c.i, c.high, "Low");
248
+ * label.set_y(lb, c.low);
249
+ * });
208
250
  * ```
209
251
  */
210
252
  export function set_y(id: Label, y: number): Label {
@@ -214,17 +256,17 @@ export function set_y(id: Label, y: number): Label {
214
256
  }
215
257
 
216
258
  /**
217
- * Sets both x and y coordinates.
218
- *
219
- * @param id - Label object to modify
220
- * @param x - New x coordinate
221
- * @param y - New y coordinate
222
- * @returns Modified label object
223
- *
259
+ * Moves the label to another x and price. Does nothing on a deleted label.
260
+ * @param id - The label.
261
+ * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the label's xloc. A bar index is rounded down.
262
+ * @param y - New price.
263
+ * @returns The same label.
224
264
  * @example
225
- * ```typescript
226
- * const label = label.new(50, 155.5, 'Pivot');
227
- * label.set_xy(label, 60, 160); // Move to (60, 160)
265
+ * ```js
266
+ * eachBar((c) => {
267
+ * const lb = label.new(c.i - 1, c.get(close, 1), "Close");
268
+ * label.set_xy(lb, c.i, c.close);
269
+ * });
228
270
  * ```
229
271
  */
230
272
  export function set_xy(id: Label, x: number, y: number): Label {
@@ -236,20 +278,18 @@ export function set_xy(id: Label, x: number, y: number): Label {
236
278
  }
237
279
 
238
280
  /**
239
- * Sets the x-axis coordinate system.
240
- *
241
- * @param id - Label object to modify
242
- * @param x - New x coordinate
243
- * @param xloc - New coordinate system
244
- * @returns Modified label object
245
- *
246
- * @remarks
247
- * When changing xloc, you must provide an appropriate x coordinate for the new system.
248
- *
281
+ * Changes what the label's x coordinate is and sets it in that unit. Does nothing on a deleted label.
282
+ * @param id - The label.
283
+ * @param x - New x, in the unit of `xloc`.
284
+ * @param xloc - `xloc.bar_index` (bar index), `xloc.bar_time` (UNIX time in ms) or `xloc.pane` (percent of the
285
+ * pane's width).
286
+ * @returns The same label.
249
287
  * @example
250
- * ```typescript
251
- * const label = label.new(50, 155.5, 'Pivot');
252
- * label.set_xloc(label, 1609459200000, 'bar_time'); // Change to timestamp
288
+ * ```js
289
+ * eachBar((c) => {
290
+ * const lb = label.new(c.i, c.high, "Now");
291
+ * label.set_xloc(lb, c.time, xloc.bar_time);
292
+ * });
253
293
  * ```
254
294
  */
255
295
  export function set_xloc(id: Label, x: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Label {
@@ -260,8 +300,18 @@ export function set_xloc(id: Label, x: number, xloc: 'bar_index' | 'bar_time' |
260
300
  }
261
301
 
262
302
  /**
263
- * Sets the y-location mode of the label (PineScript `label.set_yloc(id, yloc)`): `price` uses the
264
- * label's y, `abovebar` / `belowbar` place it above / below the bar.
303
+ * Sets how the label is placed vertically. Does nothing on a deleted label.
304
+ * @param id - The label.
305
+ * @param yloc - `yloc.price` (at the label's price), `yloc.abovebar` (above the bar's high) or `yloc.belowbar`
306
+ * (below the bar's low).
307
+ * @returns The same label.
308
+ * @example
309
+ * ```js
310
+ * eachBar((c) => {
311
+ * const lb = label.new(c.i, c.close, "Buy", { style: label.style_label_up });
312
+ * label.set_yloc(lb, yloc.belowbar);
313
+ * });
314
+ * ```
265
315
  */
266
316
  export function set_yloc(id: Label, yloc: 'price' | 'abovebar' | 'belowbar'): Label {
267
317
  if (isDeleted(id)) return id;
@@ -274,16 +324,16 @@ export function set_yloc(id: Label, yloc: 'price' | 'abovebar' | 'belowbar'): La
274
324
  // =============================================================================
275
325
 
276
326
  /**
277
- * Sets the text content.
278
- *
279
- * @param id - Label object to modify
280
- * @param text - New text content
281
- * @returns Modified label object
282
- *
327
+ * Sets the text of the label. Does nothing on a deleted label.
328
+ * @param id - The label.
329
+ * @param text - New text; `\n` starts a new line.
330
+ * @returns The same label.
283
331
  * @example
284
- * ```typescript
285
- * const label = label.new(50, 155.5, 'Pivot');
286
- * label.set_text(label, 'Updated Text');
332
+ * ```js
333
+ * eachBar((c) => {
334
+ * const lb = label.new(c.i, c.high, "");
335
+ * label.set_text(lb, str.tostring(c.close, "#.##"));
336
+ * });
287
337
  * ```
288
338
  */
289
339
  export function set_text(id: Label, text: string): Label {
@@ -293,16 +343,16 @@ export function set_text(id: Label, text: string): Label {
293
343
  }
294
344
 
295
345
  /**
296
- * Sets the tooltip text.
297
- *
298
- * @param id - Label object to modify
299
- * @param tooltip - New tooltip text
300
- * @returns Modified label object
301
- *
346
+ * Sets the text shown when the pointer is over the label. Does nothing on a deleted label.
347
+ * @param id - The label.
348
+ * @param tooltip - New tooltip text.
349
+ * @returns The same label.
302
350
  * @example
303
- * ```typescript
304
- * const label = label.new(50, 155.5, 'Pivot');
305
- * label.set_tooltip(label, 'Resistance level formed at 155.5');
351
+ * ```js
352
+ * eachBar((c) => {
353
+ * const lb = label.new(c.i, c.high, "H");
354
+ * label.set_tooltip(lb, "High " + str.tostring(c.high));
355
+ * });
306
356
  * ```
307
357
  */
308
358
  export function set_tooltip(id: Label, tooltip: string): Label {
@@ -316,16 +366,16 @@ export function set_tooltip(id: Label, tooltip: string): Label {
316
366
  // =============================================================================
317
367
 
318
368
  /**
319
- * Sets the label color (border and arrow).
320
- *
321
- * @param id - Label object to modify
322
- * @param labelColor - New color
323
- * @returns Modified label object
324
- *
369
+ * Sets the colour of the label box or shape. Does nothing on a deleted label.
370
+ * @param id - The label.
371
+ * @param labelColor - New colour (`color.red`, `"#FF0000"`, `color.new(color.red, 50)`...).
372
+ * @returns The same label.
325
373
  * @example
326
- * ```typescript
327
- * const label = label.new(50, 155.5, 'Pivot');
328
- * label.set_color(label, '#FF0000'); // Red label
374
+ * ```js
375
+ * eachBar((c) => {
376
+ * const lb = label.new(c.i, c.high, "Bar");
377
+ * label.set_color(lb, c.close > c.open ? color.green : color.red);
378
+ * });
329
379
  * ```
330
380
  */
331
381
  export function set_color(id: Label, labelColor: color): Label {
@@ -335,16 +385,16 @@ export function set_color(id: Label, labelColor: color): Label {
335
385
  }
336
386
 
337
387
  /**
338
- * Sets the text color.
339
- *
340
- * @param id - Label object to modify
341
- * @param textColor - New text color
342
- * @returns Modified label object
343
- *
388
+ * Sets the text colour of the label. Does nothing on a deleted label.
389
+ * @param id - The label.
390
+ * @param textColor - New text colour.
391
+ * @returns The same label.
344
392
  * @example
345
- * ```typescript
346
- * const label = label.new(50, 155.5, 'Pivot');
347
- * label.set_textcolor(label, '#FFFFFF'); // White text
393
+ * ```js
394
+ * eachBar((c) => {
395
+ * const lb = label.new(c.i, c.high, "Note", { style: label.style_none });
396
+ * label.set_textcolor(lb, color.orange);
397
+ * });
348
398
  * ```
349
399
  */
350
400
  export function set_textcolor(id: Label, textColor: color): Label {
@@ -354,16 +404,20 @@ export function set_textcolor(id: Label, textColor: color): Label {
354
404
  }
355
405
 
356
406
  /**
357
- * Sets the label style.
358
- *
359
- * @param id - Label object to modify
360
- * @param style - New label style
361
- * @returns Modified label object
362
- *
407
+ * Sets the label style: a box with a tip on one side, a box centred on the point, a shape, or text only.
408
+ * Does nothing on a deleted label.
409
+ * @param id - The label.
410
+ * @param style - A `label.style_*` constant: `label.style_label_down`, `label.style_label_up`,
411
+ * `label.style_label_left`, `label.style_label_right`, `label.style_label_center`, the corner styles
412
+ * (`label.style_label_lower_left`...), the shapes (`label.style_circle`, `label.style_xcross`...),
413
+ * `label.style_text_outline` or `label.style_none`.
414
+ * @returns The same label.
363
415
  * @example
364
- * ```typescript
365
- * const label = label.new(50, 155.5, 'Pivot');
366
- * label.set_style(label, 'label_down'); // Arrow pointing down
416
+ * ```js
417
+ * eachBar((c) => {
418
+ * const lb = label.new(c.i, c.low, "Low");
419
+ * label.set_style(lb, label.style_label_up);
420
+ * });
367
421
  * ```
368
422
  */
369
423
  export function set_style(
@@ -379,16 +433,16 @@ export function set_style(
379
433
  }
380
434
 
381
435
  /**
382
- * Sets the label size.
383
- *
384
- * @param id - Label object to modify
385
- * @param size - New size
386
- * @returns Modified label object
387
- *
436
+ * Sets the size of the label text (and of its shape for the shape styles). Does nothing on a deleted label.
437
+ * @param id - The label.
438
+ * @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.
439
+ * @returns The same label.
388
440
  * @example
389
- * ```typescript
390
- * const label = label.new(50, 155.5, 'Pivot');
391
- * label.set_size(label, 'large'); // Larger label
441
+ * ```js
442
+ * eachBar((c) => {
443
+ * const lb = label.new(c.i, c.high, "Big");
444
+ * label.set_size(lb, size.large);
445
+ * });
392
446
  * ```
393
447
  */
394
448
  export function set_size(id: Label, size: string | number): Label {
@@ -398,16 +452,16 @@ export function set_size(id: Label, size: string | number): Label {
398
452
  }
399
453
 
400
454
  /**
401
- * Sets the text alignment.
402
- *
403
- * @param id - Label object to modify
404
- * @param align - New text alignment
405
- * @returns Modified label object
406
- *
455
+ * Sets how the lines of a multi-line text are aligned. Does nothing on a deleted label.
456
+ * @param id - The label.
457
+ * @param align - `text.align_left`, `text.align_center` or `text.align_right`.
458
+ * @returns The same label.
407
459
  * @example
408
- * ```typescript
409
- * const label = label.new(50, 155.5, 'Pivot');
410
- * label.set_textalign(label, 'center'); // Center-aligned text
460
+ * ```js
461
+ * eachBar((c) => {
462
+ * const lb = label.new(c.i, c.high, "Open\nClose");
463
+ * label.set_textalign(lb, text.align_left);
464
+ * });
411
465
  * ```
412
466
  */
413
467
  export function set_textalign(id: Label, align: 'left' | 'center' | 'right'): Label {
@@ -417,16 +471,16 @@ export function set_textalign(id: Label, align: 'left' | 'center' | 'right'): La
417
471
  }
418
472
 
419
473
  /**
420
- * Sets the text font family.
421
- *
422
- * @param id - Label object to modify
423
- * @param font - New font family
424
- * @returns Modified label object
425
- *
474
+ * Sets the font family of the label text. Does nothing on a deleted label.
475
+ * @param id - The label.
476
+ * @param font - `font.family_default` or `font.family_monospace`.
477
+ * @returns The same label.
426
478
  * @example
427
- * ```typescript
428
- * const label = label.new(50, 155.5, 'Pivot');
429
- * label.set_text_font_family(label, 'monospace');
479
+ * ```js
480
+ * eachBar((c) => {
481
+ * const lb = label.new(c.i, c.high, str.tostring(c.close, "0.00"));
482
+ * label.set_text_font_family(lb, font.family_monospace);
483
+ * });
430
484
  * ```
431
485
  */
432
486
  export function set_text_font_family(id: Label, font: 'default' | 'monospace'): Label {
@@ -436,19 +490,15 @@ export function set_text_font_family(id: Label, font: 'default' | 'monospace'):
436
490
  }
437
491
 
438
492
  /**
439
- * Deletes the label object.
440
- *
441
- * @param id - Label object to delete
442
- *
443
- * @remarks
444
- * Removes the label from `label.all()`. As in PineScript, the deleted label is `na`: its getters
445
- * return NaN and its setters do nothing. Deleting it twice has no effect.
446
- *
493
+ * Removes the label from the chart and from `label.all`. Afterwards its getters return NaN and its setters do
494
+ * nothing; deleting it again does nothing.
495
+ * @param id - The label to delete.
447
496
  * @example
448
- * ```typescript
449
- * const label = label.new(50, 155.5, 'Pivot');
450
- * label.delete(label);
451
- * // label.all() no longer contains it
497
+ * ```js
498
+ * eachBar((c) => {
499
+ * const lb = label.new(c.i, c.high, "Last");
500
+ * if (c.i < c.n - 1) label.delete(lb); // keep only the label of the last bar
501
+ * });
452
502
  * ```
453
503
  */
454
504
  export function delete_label(id: Label): void {
@@ -462,15 +512,33 @@ function pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): num
462
512
  }
463
513
 
464
514
  /**
465
- * All live labels, in creation order (PineScript `label.all`). A new array.
515
+ * Returns the labels that are still on the chart, oldest first. The array is a copy.
516
+ * (In a script, `label.all` is read as a value, without a call.)
517
+ * @returns The live labels in creation order.
518
+ * @example
519
+ * ```js
520
+ * eachBar((c) => {
521
+ * if (c.i === c.n - 1) for (const lb of label.all) label.set_textcolor(lb, color.yellow);
522
+ * });
523
+ * ```
466
524
  */
467
525
  export function all(): Label[] {
468
526
  return allDrawings('label');
469
527
  }
470
528
 
471
529
  /**
472
- * Sets the label position from a chart point: `point.index` for `bar_index` labels, `point.time`
473
- * for `bar_time` labels, and `point.price`.
530
+ * Moves the label to a chart point: its `index` for a `xloc.bar_index` label, its `time` for a `xloc.bar_time` label
531
+ * (NaN when the point has none), and its `price`. Does nothing on a deleted label.
532
+ * @param id - The label.
533
+ * @param point - The new position.
534
+ * @returns The same label.
535
+ * @example
536
+ * ```js
537
+ * eachBar((c) => {
538
+ * const lb = label.new(c.i, c.high, "Here");
539
+ * label.set_point(lb, chart.point.now(c.low));
540
+ * });
541
+ * ```
474
542
  */
475
543
  export function set_point(id: Label, point: ChartPoint): Label {
476
544
  if (isDeleted(id)) return id;
@@ -480,8 +548,18 @@ export function set_point(id: Label, point: ChartPoint): Label {
480
548
  }
481
549
 
482
550
  /**
483
- * Sets the text formatting: `text.format_none`, `text.format_bold`, `text.format_italic`,
484
- * or `text.format_bold + text.format_italic`.
551
+ * Makes the label text bold and / or italic. Does nothing on a deleted label.
552
+ * @param id - The label.
553
+ * @param formatting - `text.format_none`, `text.format_bold`, `text.format_italic`, or
554
+ * `text.format_bold + text.format_italic`.
555
+ * @returns The same label.
556
+ * @example
557
+ * ```js
558
+ * eachBar((c) => {
559
+ * const lb = label.new(c.i, c.high, "Signal");
560
+ * label.set_text_formatting(lb, text.format_bold);
561
+ * });
562
+ * ```
485
563
  */
486
564
  export function set_text_formatting(id: Label, formatting: number): Label {
487
565
  if (isDeleted(id)) return id;
@@ -489,6 +567,6 @@ export function set_text_formatting(id: Label, formatting: number): Label {
489
567
  return id;
490
568
  }
491
569
 
492
- // Alias to match PineScript API
570
+ // Script names: label.new / label.delete
493
571
  export { new_label as new };
494
572
  export { delete_label as delete };