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/box/index.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  /**
2
- * Box namespace
3
- * Functions for creating and manipulating box drawing objects.
2
+ * Box namespace: functions that create, read, change and delete box drawings (`box.*`).
4
3
  *
5
4
  * @remarks
6
- * Box objects represent rectangular areas on the chart. The getter functions
7
- * (get_top, get_bottom, get_left, get_right) enable computational use cases like:
8
- * - Gap detection and tracking (detecting when price fills gaps)
9
- * - Range breakout analysis (detecting when price breaks out of consolidation)
10
- * - Rectangle pattern recognition
5
+ * A box is a rectangle between two x coordinates (left, right) and two prices (top, bottom), with an optional text
6
+ * inside. Its x coordinates are bar indexes (`xloc.bar_index`, the default), UNIX times in ms (`xloc.bar_time`) or
7
+ * percents of the pane's width (`xloc.pane`). The getters (`box.get_top()`...) let a script test whether the price
8
+ * entered or left a zone: gaps, ranges, supply and demand areas.
11
9
  *
12
10
  * @version 6
13
11
  */
@@ -19,20 +17,39 @@ type BoxXloc = 'bar_index' | 'bar_time' | 'pane';
19
17
  type BoxExtend = 'none' | 'left' | 'right' | 'both';
20
18
 
21
19
  /**
22
- * Creates a new box (PineScript `box.new`), with two chart points or with coordinates, in PineScript's
23
- * parameter order:
24
- *
25
- * - `box.new(top_left, bottom_right, border_color?, border_width?, border_style?, extend?, xloc?, bgcolor?,
26
- * text?, text_size?, text_color?, text_halign?, text_valign?, text_wrap?, text_font_family?,
27
- * force_overlay?, text_formatting?)`
28
- * - `box.new(left, top, right, bottom, border_color?, border_width?, border_style?, extend?, xloc?, ...)`
29
- *
30
- * With chart points, x is `point.index` for `bar_index` boxes and `point.time` for `bar_time` boxes.
31
- *
20
+ * Draws a box 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`. The arguments after the
22
+ * points can also be given by name in an object. Boxes above `max_boxes_count` (default 50) are deleted oldest first.
23
+ * @param top_left - Top-left corner (`chart.point.from_index(...)`, `chart.point.now()`...).
24
+ * @param bottom_right - Bottom-right corner.
25
+ * @param border_color - Colour of the border. Default: blue (#2962FF).
26
+ * @param border_width - Width of the border in pixels; 0 draws no border. Default: 1.
27
+ * @param border_style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`. Default: `line.style_solid`.
28
+ * @param extend - Extends the box sideways to the edge of the pane: `extend.none`, `extend.left`, `extend.right` or
29
+ * `extend.both`. Default: `extend.none`.
30
+ * @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
31
+ * @param bgcolor - Fill colour of the box. Default: blue (#2962FF).
32
+ * @param text - Text written inside the box; `\n` starts a new line. Default: none.
33
+ * @param text_size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in
34
+ * points. Default: `size.auto`.
35
+ * @param text_color - Text colour. Default: white.
36
+ * @param text_halign - Horizontal place of the text: `text.align_left`, `text.align_center` or `text.align_right`.
37
+ * Default: `text.align_center`.
38
+ * @param text_valign - Vertical place of the text: `text.align_top`, `text.align_center` or `text.align_bottom`.
39
+ * Default: `text.align_center`.
40
+ * @param text_wrap - `text.wrap_auto` wraps the text to the width of the box, `text.wrap_none` keeps each line whole.
41
+ * Default: `text.wrap_none`.
42
+ * @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.
43
+ * @param force_overlay - When true, the box is drawn on the price pane even if the script has its own pane.
44
+ * Default: false.
45
+ * @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
46
+ * Default: `text.format_none`.
47
+ * @returns The new box.
32
48
  * @example
33
- * ```typescript
34
- * // Gap box from bar 10 to 20, between 100 and 105, extended to the right
35
- * const gap = box.new(10, 105, 20, 100, '#2196F3', 1, 'solid', 'right');
49
+ * ```js
50
+ * eachBar((c) => {
51
+ * if (c.i === c.n - 1) box.new(chart.point.from_index(c.i - 20, c.get(high, 20)), chart.point.now(c.low));
52
+ * });
36
53
  * ```
37
54
  */
38
55
  export function new_box(
@@ -54,6 +71,46 @@ export function new_box(
54
71
  force_overlay?: boolean,
55
72
  text_formatting?: number
56
73
  ): Box;
74
+ /**
75
+ * Draws a box from its left, top, right and bottom and returns its handle, to change or delete it later.
76
+ * Inside `eachBar` a Series argument is read on the current bar; the arguments after the coordinates can also be
77
+ * given by name in an object. A bar index x is rounded down; it may be up to 500 bars after the last bar. Boxes
78
+ * above `max_boxes_count` (default 50) are deleted oldest first.
79
+ * @param left - x of the left side: a bar index, a UNIX time in ms (`xloc.bar_time`) or a percent of the pane's
80
+ * width (`xloc.pane`).
81
+ * @param top - Price of the top side.
82
+ * @param right - x of the right side, in the same unit as `left`.
83
+ * @param bottom - Price of the bottom side.
84
+ * @param border_color - Colour of the border. Default: blue (#2962FF).
85
+ * @param border_width - Width of the border in pixels; 0 draws no border. Default: 1.
86
+ * @param border_style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`. Default: `line.style_solid`.
87
+ * @param extend - Extends the box sideways to the edge of the pane: `extend.none`, `extend.left`, `extend.right` or
88
+ * `extend.both`. Default: `extend.none`.
89
+ * @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.
90
+ * @param bgcolor - Fill colour of the box. Default: blue (#2962FF).
91
+ * @param text - Text written inside the box; `\n` starts a new line. Default: none.
92
+ * @param text_size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in
93
+ * points. Default: `size.auto`.
94
+ * @param text_color - Text colour. Default: white.
95
+ * @param text_halign - Horizontal place of the text: `text.align_left`, `text.align_center` or `text.align_right`.
96
+ * Default: `text.align_center`.
97
+ * @param text_valign - Vertical place of the text: `text.align_top`, `text.align_center` or `text.align_bottom`.
98
+ * Default: `text.align_center`.
99
+ * @param text_wrap - `text.wrap_auto` wraps the text to the width of the box, `text.wrap_none` keeps each line whole.
100
+ * Default: `text.wrap_none`.
101
+ * @param text_font_family - `font.family_default` or `font.family_monospace`. Default: `font.family_default`.
102
+ * @param force_overlay - When true, the box is drawn on the price pane even if the script has its own pane.
103
+ * Default: false.
104
+ * @param text_formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
105
+ * Default: `text.format_none`.
106
+ * @returns The new box.
107
+ * @example
108
+ * ```js
109
+ * eachBar((c) => {
110
+ * if (c.i === c.n - 1) box.new(c.i - 20, c.get(high, 20), c.i, c.low, { bgcolor: color.new(color.blue, 85), text: "Range" });
111
+ * });
112
+ * ```
113
+ */
57
114
  export function new_box(
58
115
  left: number,
59
116
  top: number,
@@ -117,23 +174,15 @@ export function new_box(...args: unknown[]): Box {
117
174
  }
118
175
 
119
176
  /**
120
- * Returns the left border x coordinate.
121
- *
122
- * @param id - Box object
123
- * @returns Left border coordinate (bar index or timestamp)
124
- *
125
- * @remarks
126
- * **COMPUTATIONAL USE**: Calculate gap duration, validate range timeframes
127
- *
177
+ * Returns the x coordinate of the box's left side, for example to count how many bars a zone has been open.
178
+ * @param id - The box.
179
+ * @returns A bar index, a UNIX time in ms or a pane percent, by the box's xloc; NaN for a deleted box.
128
180
  * @example
129
- * ```typescript
130
- * const gap = box.new(10, 105, 20, 100);
131
- * const currentBar = 30;
132
- * const duration = currentBar - box.get_left(gap); // Returns 20
133
- *
134
- * if (duration > 50) {
135
- * console.log('Gap has been open for 50+ bars');
136
- * }
181
+ * ```js
182
+ * eachBar((c) => {
183
+ * const b = box.new(c.i - 10, c.get(high, 10), c.i, c.low);
184
+ * const age = c.i - box.get_left(b); // 10
185
+ * });
137
186
  * ```
138
187
  */
139
188
  export function get_left(id: Box): number {
@@ -141,18 +190,15 @@ export function get_left(id: Box): number {
141
190
  }
142
191
 
143
192
  /**
144
- * Returns the right border x coordinate.
145
- *
146
- * @param id - Box object
147
- * @returns Right border coordinate (bar index or timestamp)
148
- *
149
- * @remarks
150
- * **COMPUTATIONAL USE**: Calculate gap duration, update trailing edges
151
- *
193
+ * Returns the x coordinate of the box's right side.
194
+ * @param id - The box.
195
+ * @returns A bar index, a UNIX time in ms or a pane percent, by the box's xloc; NaN for a deleted box.
152
196
  * @example
153
- * ```typescript
154
- * const range = box.new(100, 155, 150, 145);
155
- * const width = box.get_right(range) - box.get_left(range); // Returns 50 bars
197
+ * ```js
198
+ * eachBar((c) => {
199
+ * const b = box.new(c.i - 10, c.get(high, 10), c.i, c.low);
200
+ * const bars = box.get_right(b) - box.get_left(b); // 10
201
+ * });
156
202
  * ```
157
203
  */
158
204
  export function get_right(id: Box): number {
@@ -160,23 +206,15 @@ export function get_right(id: Box): number {
160
206
  }
161
207
 
162
208
  /**
163
- * Returns the top border price level.
164
- *
165
- * @param id - Box object
166
- * @returns Top border price
167
- *
168
- * @remarks
169
- * **COMPUTATIONAL USE**: Detect breakouts above resistance, check gap fills
170
- *
209
+ * Returns the price of the box's top side, for example to test a breakout above a range.
210
+ * @param id - The box.
211
+ * @returns The top price; NaN for a deleted box.
171
212
  * @example
172
- * ```typescript
173
- * const gap = box.new(10, 105, 20, 100); // Bearish gap
174
- *
175
- * // Check if price has filled gap from below
176
- * const high = 106;
177
- * if (high > box.get_top(gap)) {
178
- * console.log('Gap completely filled!');
179
- * }
213
+ * ```js
214
+ * eachBar((c) => {
215
+ * const b = box.new(c.i - 10, c.get(high, 1), c.i - 1, c.get(low, 1));
216
+ * if (c.close > box.get_top(b)) label.new(c.i, c.high, "Breakout");
217
+ * });
180
218
  * ```
181
219
  */
182
220
  export function get_top(id: Box): number {
@@ -184,23 +222,15 @@ export function get_top(id: Box): number {
184
222
  }
185
223
 
186
224
  /**
187
- * Returns the bottom border price level.
188
- *
189
- * @param id - Box object
190
- * @returns Bottom border price
191
- *
192
- * @remarks
193
- * **COMPUTATIONAL USE**: Detect breakouts below support, check gap fills
194
- *
225
+ * Returns the price of the box's bottom side, for example to test a breakdown below a range.
226
+ * @param id - The box.
227
+ * @returns The bottom price; NaN for a deleted box.
195
228
  * @example
196
- * ```typescript
197
- * const gap = box.new(10, 105, 20, 100); // Bearish gap
198
- *
199
- * // Check if price has touched gap from above
200
- * const low = 104;
201
- * if (low < box.get_top(gap) && low > box.get_bottom(gap)) {
202
- * console.log('Price entered the gap!');
203
- * }
229
+ * ```js
230
+ * eachBar((c) => {
231
+ * const b = box.new(c.i - 10, c.get(high, 1), c.i - 1, c.get(low, 1));
232
+ * if (c.close < box.get_bottom(b)) label.new(c.i, c.low, "Breakdown", { style: label.style_label_up });
233
+ * });
204
234
  * ```
205
235
  */
206
236
  export function get_bottom(id: Box): number {
@@ -208,21 +238,16 @@ export function get_bottom(id: Box): number {
208
238
  }
209
239
 
210
240
  /**
211
- * Creates a copy of the box object.
212
- *
213
- * @param id - Box object to copy
214
- * @returns New box object with same properties
215
- *
216
- * @remarks
217
- * Creates a shallow copy of the box. Modifications to the copy won't affect the original.
218
- *
241
+ * Makes a new box with the same sides, colours and text as `id` (it counts toward `max_boxes_count`).
242
+ * Changing the copy does not change the original.
243
+ * @param id - The box to copy.
244
+ * @returns The new box.
219
245
  * @example
220
- * ```typescript
221
- * const originalBox = box.new(10, 105, 20, 100);
222
- * const copiedBox = box.copy(originalBox);
223
- *
224
- * // Modify copy without affecting original
225
- * copiedBox.top = 110;
246
+ * ```js
247
+ * eachBar((c) => {
248
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
249
+ * box.set_bgcolor(box.copy(b), color.new(color.red, 80)); // a red copy over the same bars
250
+ * });
226
251
  * ```
227
252
  */
228
253
  export function copy(id: Box): Box {
@@ -234,16 +259,17 @@ export function copy(id: Box): Box {
234
259
  // =============================================================================
235
260
 
236
261
  /**
237
- * Sets the left border x coordinate.
238
- *
239
- * @param id - Box object to modify
240
- * @param left - New left border coordinate
241
- * @returns Modified box object
242
- *
262
+ * Moves the box's left side. Does nothing on a deleted box.
263
+ * @param id - The box.
264
+ * @param left - New x: a bar index, a UNIX time in ms or a pane percent, by the box's xloc. A bar index is rounded
265
+ * down.
266
+ * @returns The same box.
243
267
  * @example
244
- * ```typescript
245
- * const box = box.new(10, 105, 20, 100);
246
- * box.set_left(box, 15); // Move left edge to bar 15
268
+ * ```js
269
+ * eachBar((c) => {
270
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
271
+ * box.set_left(b, c.i - 20);
272
+ * });
247
273
  * ```
248
274
  */
249
275
  export function set_left(id: Box, left: number): Box {
@@ -254,16 +280,17 @@ export function set_left(id: Box, left: number): Box {
254
280
  }
255
281
 
256
282
  /**
257
- * Sets the right border x coordinate.
258
- *
259
- * @param id - Box object to modify
260
- * @param right - New right border coordinate
261
- * @returns Modified box object
262
- *
283
+ * Moves the box's right side, for example to stretch a zone to the current bar. Does nothing on a deleted box.
284
+ * @param id - The box.
285
+ * @param right - New x: a bar index, a UNIX time in ms or a pane percent, by the box's xloc. A bar index is rounded
286
+ * down.
287
+ * @returns The same box.
263
288
  * @example
264
- * ```typescript
265
- * const box = box.new(10, 105, 20, 100);
266
- * box.set_right(box, 25); // Move right edge to bar 25
289
+ * ```js
290
+ * eachBar((c) => {
291
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
292
+ * box.set_right(b, c.i + 10); // reach 10 bars into the future
293
+ * });
267
294
  * ```
268
295
  */
269
296
  export function set_right(id: Box, right: number): Box {
@@ -274,16 +301,16 @@ export function set_right(id: Box, right: number): Box {
274
301
  }
275
302
 
276
303
  /**
277
- * Sets the top border price level.
278
- *
279
- * @param id - Box object to modify
280
- * @param top - New top border price
281
- * @returns Modified box object
282
- *
304
+ * Moves the box's top side. Does nothing on a deleted box.
305
+ * @param id - The box.
306
+ * @param top - New top price.
307
+ * @returns The same box.
283
308
  * @example
284
- * ```typescript
285
- * const box = box.new(10, 105, 20, 100);
286
- * box.set_top(box, 110); // Move top edge to price 110
309
+ * ```js
310
+ * eachBar((c) => {
311
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
312
+ * box.set_top(b, c.get(high, 10));
313
+ * });
287
314
  * ```
288
315
  */
289
316
  export function set_top(id: Box, top: number): Box {
@@ -293,16 +320,16 @@ export function set_top(id: Box, top: number): Box {
293
320
  }
294
321
 
295
322
  /**
296
- * Sets the bottom border price level.
297
- *
298
- * @param id - Box object to modify
299
- * @param bottom - New bottom border price
300
- * @returns Modified box object
301
- *
323
+ * Moves the box's bottom side. Does nothing on a deleted box.
324
+ * @param id - The box.
325
+ * @param bottom - New bottom price.
326
+ * @returns The same box.
302
327
  * @example
303
- * ```typescript
304
- * const box = box.new(10, 105, 20, 100);
305
- * box.set_bottom(box, 95); // Move bottom edge to price 95
328
+ * ```js
329
+ * eachBar((c) => {
330
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
331
+ * box.set_bottom(b, c.get(low, 10));
332
+ * });
306
333
  * ```
307
334
  */
308
335
  export function set_bottom(id: Box, bottom: number): Box {
@@ -312,17 +339,17 @@ export function set_bottom(id: Box, bottom: number): Box {
312
339
  }
313
340
 
314
341
  /**
315
- * Sets the left and top coordinates.
316
- *
317
- * @param id - Box object to modify
318
- * @param left - New left border coordinate
319
- * @param top - New top border price
320
- * @returns Modified box object
321
- *
342
+ * Moves the box's top-left corner (left side and top price). Does nothing on a deleted box.
343
+ * @param id - The box.
344
+ * @param left - New x of the left side, by the box's xloc. A bar index is rounded down.
345
+ * @param top - New top price.
346
+ * @returns The same box.
322
347
  * @example
323
- * ```typescript
324
- * const box = box.new(10, 105, 20, 100);
325
- * box.set_lefttop(box, 12, 108); // Move top-left corner
348
+ * ```js
349
+ * eachBar((c) => {
350
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
351
+ * box.set_lefttop(b, c.i - 20, c.get(high, 20));
352
+ * });
326
353
  * ```
327
354
  */
328
355
  export function set_lefttop(id: Box, left: number, top: number): Box {
@@ -334,17 +361,17 @@ export function set_lefttop(id: Box, left: number, top: number): Box {
334
361
  }
335
362
 
336
363
  /**
337
- * Sets the right and bottom coordinates.
338
- *
339
- * @param id - Box object to modify
340
- * @param right - New right border coordinate
341
- * @param bottom - New bottom border price
342
- * @returns Modified box object
343
- *
364
+ * Moves the box's bottom-right corner (right side and bottom price). Does nothing on a deleted box.
365
+ * @param id - The box.
366
+ * @param right - New x of the right side, by the box's xloc. A bar index is rounded down.
367
+ * @param bottom - New bottom price.
368
+ * @returns The same box.
344
369
  * @example
345
- * ```typescript
346
- * const box = box.new(10, 105, 20, 100);
347
- * box.set_rightbottom(box, 25, 98); // Move bottom-right corner
370
+ * ```js
371
+ * eachBar((c) => {
372
+ * const b = box.new(c.i - 10, c.high, c.i - 1, c.low);
373
+ * box.set_rightbottom(b, c.i, c.low);
374
+ * });
348
375
  * ```
349
376
  */
350
377
  export function set_rightbottom(id: Box, right: number, bottom: number): Box {
@@ -356,22 +383,20 @@ export function set_rightbottom(id: Box, right: number, bottom: number): Box {
356
383
  }
357
384
 
358
385
  /**
359
- * Sets the coordinate system for the box.
360
- *
361
- * @param id - Box object to modify
362
- * @param left - New left border coordinate
363
- * @param right - New right border coordinate
364
- * @param xloc - New coordinate system ('bar_index', 'bar_time' or 'pane')
365
- * @returns Modified box object
366
- *
367
- * @remarks
368
- * When changing xloc, you must provide appropriate x coordinates for the new system.
369
- *
386
+ * Changes what the box's x coordinates are and sets its left and right sides in that unit. Does nothing on a
387
+ * deleted box.
388
+ * @param id - The box.
389
+ * @param left - New x of the left side, in the unit of `xloc`.
390
+ * @param right - New x of the right side, in the unit of `xloc`.
391
+ * @param xloc - `xloc.bar_index` (bar indexes), `xloc.bar_time` (UNIX times in ms) or `xloc.pane` (percents of the
392
+ * pane's width).
393
+ * @returns The same box.
370
394
  * @example
371
- * ```typescript
372
- * const box = box.new(10, 105, 20, 100);
373
- * // Change to timestamp-based coordinates
374
- * box.set_xloc(box, 1609459200000, 1609545600000, 'bar_time');
395
+ * ```js
396
+ * eachBar((c) => {
397
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
398
+ * box.set_xloc(b, c.time - 3600000, c.time, xloc.bar_time);
399
+ * });
375
400
  * ```
376
401
  */
377
402
  export function set_xloc(id: Box, left: number, right: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Box {
@@ -383,16 +408,16 @@ export function set_xloc(id: Box, left: number, right: number, xloc: 'bar_index'
383
408
  }
384
409
 
385
410
  /**
386
- * Sets the horizontal extension mode.
387
- *
388
- * @param id - Box object to modify
389
- * @param extend - New extension mode
390
- * @returns Modified box object
391
- *
411
+ * Sets whether the box continues sideways to the edge of the pane. Does nothing on a deleted box.
412
+ * @param id - The box.
413
+ * @param extend - `extend.none`, `extend.left`, `extend.right` or `extend.both`.
414
+ * @returns The same box.
392
415
  * @example
393
- * ```typescript
394
- * const box = box.new(10, 105, 20, 100);
395
- * box.set_extend(box, 'right'); // Extend box to the right
416
+ * ```js
417
+ * eachBar((c) => {
418
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
419
+ * box.set_extend(b, extend.right);
420
+ * });
396
421
  * ```
397
422
  */
398
423
  export function set_extend(id: Box, extend: 'none' | 'left' | 'right' | 'both'): Box {
@@ -406,16 +431,16 @@ export function set_extend(id: Box, extend: 'none' | 'left' | 'right' | 'both'):
406
431
  // =============================================================================
407
432
 
408
433
  /**
409
- * Sets the border color.
410
- *
411
- * @param id - Box object to modify
412
- * @param borderColor - New border color
413
- * @returns Modified box object
414
- *
434
+ * Sets the colour of the box's border. Does nothing on a deleted box.
435
+ * @param id - The box.
436
+ * @param borderColor - New colour (`color.red`, `"#FF0000"`, `color.new(color.red, 50)`...).
437
+ * @returns The same box.
415
438
  * @example
416
- * ```typescript
417
- * const box = box.new(10, 105, 20, 100);
418
- * box.set_border_color(box, '#FF0000'); // Red border
439
+ * ```js
440
+ * eachBar((c) => {
441
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
442
+ * box.set_border_color(b, color.red);
443
+ * });
419
444
  * ```
420
445
  */
421
446
  export function set_border_color(id: Box, borderColor: color): Box {
@@ -425,16 +450,16 @@ export function set_border_color(id: Box, borderColor: color): Box {
425
450
  }
426
451
 
427
452
  /**
428
- * Sets the border width.
429
- *
430
- * @param id - Box object to modify
431
- * @param width - New border width in pixels
432
- * @returns Modified box object
433
- *
453
+ * Sets the width of the box's border. Does nothing on a deleted box.
454
+ * @param id - The box.
455
+ * @param width - New width in pixels; 0 draws no border.
456
+ * @returns The same box.
434
457
  * @example
435
- * ```typescript
436
- * const box = box.new(10, 105, 20, 100);
437
- * box.set_border_width(box, 2); // Thicker border
458
+ * ```js
459
+ * eachBar((c) => {
460
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
461
+ * box.set_border_width(b, 2);
462
+ * });
438
463
  * ```
439
464
  */
440
465
  export function set_border_width(id: Box, width: number): Box {
@@ -444,16 +469,16 @@ export function set_border_width(id: Box, width: number): Box {
444
469
  }
445
470
 
446
471
  /**
447
- * Sets the border style.
448
- *
449
- * @param id - Box object to modify
450
- * @param style - New border style
451
- * @returns Modified box object
452
- *
472
+ * Sets the style of the box's border. Does nothing on a deleted box.
473
+ * @param id - The box.
474
+ * @param style - `line.style_solid`, `line.style_dotted` or `line.style_dashed`.
475
+ * @returns The same box.
453
476
  * @example
454
- * ```typescript
455
- * const box = box.new(10, 105, 20, 100);
456
- * box.set_border_style(box, 'dashed'); // Dashed border
477
+ * ```js
478
+ * eachBar((c) => {
479
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
480
+ * box.set_border_style(b, line.style_dashed);
481
+ * });
457
482
  * ```
458
483
  */
459
484
  export function set_border_style(id: Box, style: 'solid' | 'dotted' | 'dashed'): Box {
@@ -463,16 +488,16 @@ export function set_border_style(id: Box, style: 'solid' | 'dotted' | 'dashed'):
463
488
  }
464
489
 
465
490
  /**
466
- * Sets the background fill color.
467
- *
468
- * @param id - Box object to modify
469
- * @param bgColor - New background color
470
- * @returns Modified box object
471
- *
491
+ * Sets the fill colour of the box. Does nothing on a deleted box.
492
+ * @param id - The box.
493
+ * @param bgColor - New fill colour; a transparent one (`color.new(color.green, 80)`) keeps the bars visible.
494
+ * @returns The same box.
472
495
  * @example
473
- * ```typescript
474
- * const box = box.new(10, 105, 20, 100);
475
- * box.set_bgcolor(box, '#00FF0030'); // Transparent green fill
496
+ * ```js
497
+ * eachBar((c) => {
498
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
499
+ * box.set_bgcolor(b, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));
500
+ * });
476
501
  * ```
477
502
  */
478
503
  export function set_bgcolor(id: Box, bgColor: color): Box {
@@ -486,16 +511,16 @@ export function set_bgcolor(id: Box, bgColor: color): Box {
486
511
  // =============================================================================
487
512
 
488
513
  /**
489
- * Sets the text content.
490
- *
491
- * @param id - Box object to modify
492
- * @param text - New text content
493
- * @returns Modified box object
494
- *
514
+ * Sets the text written inside the box. Does nothing on a deleted box.
515
+ * @param id - The box.
516
+ * @param text - New text; `\n` starts a new line.
517
+ * @returns The same box.
495
518
  * @example
496
- * ```typescript
497
- * const box = box.new(10, 105, 20, 100);
498
- * box.set_text(box, 'Gap Filled'); // Update text
519
+ * ```js
520
+ * eachBar((c) => {
521
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
522
+ * box.set_text(b, "Range " + str.tostring(c.high - c.low, "#.##"));
523
+ * });
499
524
  * ```
500
525
  */
501
526
  export function set_text(id: Box, text: string): Box {
@@ -505,16 +530,16 @@ export function set_text(id: Box, text: string): Box {
505
530
  }
506
531
 
507
532
  /**
508
- * Sets the text color.
509
- *
510
- * @param id - Box object to modify
511
- * @param textColor - New text color
512
- * @returns Modified box object
513
- *
533
+ * Sets the colour of the box's text. Does nothing on a deleted box.
534
+ * @param id - The box.
535
+ * @param textColor - New text colour.
536
+ * @returns The same box.
514
537
  * @example
515
- * ```typescript
516
- * const box = box.new(10, 105, 20, 100);
517
- * box.set_text_color(box, '#FFFFFF'); // White text
538
+ * ```js
539
+ * eachBar((c) => {
540
+ * const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
541
+ * box.set_text_color(b, color.black);
542
+ * });
518
543
  * ```
519
544
  */
520
545
  export function set_text_color(id: Box, textColor: color): Box {
@@ -524,16 +549,16 @@ export function set_text_color(id: Box, textColor: color): Box {
524
549
  }
525
550
 
526
551
  /**
527
- * Sets the text size.
528
- *
529
- * @param id - Box object to modify
530
- * @param size - New text size
531
- * @returns Modified box object
532
- *
552
+ * Sets the size of the box's text. Does nothing on a deleted box.
553
+ * @param id - The box.
554
+ * @param size - `size.tiny`, `size.small`, `size.normal`, `size.large`, `size.huge`, `size.auto`, or a size in points.
555
+ * @returns The same box.
533
556
  * @example
534
- * ```typescript
535
- * const box = box.new(10, 105, 20, 100);
536
- * box.set_text_size(box, 'large'); // Larger text
557
+ * ```js
558
+ * eachBar((c) => {
559
+ * const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
560
+ * box.set_text_size(b, size.large);
561
+ * });
537
562
  * ```
538
563
  */
539
564
  export function set_text_size(id: Box, size: string | number): Box {
@@ -543,16 +568,16 @@ export function set_text_size(id: Box, size: string | number): Box {
543
568
  }
544
569
 
545
570
  /**
546
- * Sets the horizontal text alignment.
547
- *
548
- * @param id - Box object to modify
549
- * @param align - New horizontal alignment
550
- * @returns Modified box object
551
- *
571
+ * Sets the horizontal place of the text inside the box. Does nothing on a deleted box.
572
+ * @param id - The box.
573
+ * @param align - `text.align_left`, `text.align_center` or `text.align_right`.
574
+ * @returns The same box.
552
575
  * @example
553
- * ```typescript
554
- * const box = box.new(10, 105, 20, 100);
555
- * box.set_text_halign(box, 'center'); // Center text horizontally
576
+ * ```js
577
+ * eachBar((c) => {
578
+ * const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
579
+ * box.set_text_halign(b, text.align_left);
580
+ * });
556
581
  * ```
557
582
  */
558
583
  export function set_text_halign(id: Box, align: 'left' | 'center' | 'right'): Box {
@@ -562,16 +587,16 @@ export function set_text_halign(id: Box, align: 'left' | 'center' | 'right'): Bo
562
587
  }
563
588
 
564
589
  /**
565
- * Sets the vertical text alignment.
566
- *
567
- * @param id - Box object to modify
568
- * @param align - New vertical alignment
569
- * @returns Modified box object
570
- *
590
+ * Sets the vertical place of the text inside the box. Does nothing on a deleted box.
591
+ * @param id - The box.
592
+ * @param align - `text.align_top`, `text.align_center` or `text.align_bottom`.
593
+ * @returns The same box.
571
594
  * @example
572
- * ```typescript
573
- * const box = box.new(10, 105, 20, 100);
574
- * box.set_text_valign(box, 'center'); // Center text vertically
595
+ * ```js
596
+ * eachBar((c) => {
597
+ * const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
598
+ * box.set_text_valign(b, text.align_top);
599
+ * });
575
600
  * ```
576
601
  */
577
602
  export function set_text_valign(id: Box, align: 'top' | 'center' | 'bottom'): Box {
@@ -581,16 +606,16 @@ export function set_text_valign(id: Box, align: 'top' | 'center' | 'bottom'): Bo
581
606
  }
582
607
 
583
608
  /**
584
- * Sets the text wrapping mode.
585
- *
586
- * @param id - Box object to modify
587
- * @param wrap - New text wrap mode
588
- * @returns Modified box object
589
- *
609
+ * Sets whether a long text wraps onto several lines to fit the width of the box. Does nothing on a deleted box.
610
+ * @param id - The box.
611
+ * @param wrap - `text.wrap_auto` (wrap to the box's width) or `text.wrap_none` (each line stays whole).
612
+ * @returns The same box.
590
613
  * @example
591
- * ```typescript
592
- * const box = box.new(10, 105, 20, 100);
593
- * box.set_text_wrap(box, 'auto'); // Enable text wrapping
614
+ * ```js
615
+ * eachBar((c) => {
616
+ * const b = box.new(c.i - 3, c.high, c.i, c.low, { text: "A long note about this zone" });
617
+ * box.set_text_wrap(b, text.wrap_auto);
618
+ * });
594
619
  * ```
595
620
  */
596
621
  export function set_text_wrap(id: Box, wrap: 'none' | 'auto'): Box {
@@ -600,16 +625,16 @@ export function set_text_wrap(id: Box, wrap: 'none' | 'auto'): Box {
600
625
  }
601
626
 
602
627
  /**
603
- * Sets the text font family.
604
- *
605
- * @param id - Box object to modify
606
- * @param font - New font family
607
- * @returns Modified box object
608
- *
628
+ * Sets the font of the box's text. Does nothing on a deleted box.
629
+ * @param id - The box.
630
+ * @param font - `font.family_default` or `font.family_monospace`.
631
+ * @returns The same box.
609
632
  * @example
610
- * ```typescript
611
- * const box = box.new(10, 105, 20, 100);
612
- * box.set_text_font_family(box, 'monospace'); // Monospace font
633
+ * ```js
634
+ * eachBar((c) => {
635
+ * const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "123.45" });
636
+ * box.set_text_font_family(b, font.family_monospace);
637
+ * });
613
638
  * ```
614
639
  */
615
640
  export function set_text_font_family(id: Box, font: 'default' | 'monospace'): Box {
@@ -619,19 +644,15 @@ export function set_text_font_family(id: Box, font: 'default' | 'monospace'): Bo
619
644
  }
620
645
 
621
646
  /**
622
- * Deletes the box object.
623
- *
624
- * @param id - Box object to delete
625
- *
626
- * @remarks
627
- * Removes the box from `box.all()`. As in PineScript, the deleted box is `na`: its getters
628
- * return NaN and its setters do nothing. Deleting it twice has no effect.
629
- *
647
+ * Removes the box from the chart and from `box.all`. Afterwards its getters return NaN and its setters do nothing;
648
+ * deleting it again does nothing.
649
+ * @param id - The box to delete.
630
650
  * @example
631
- * ```typescript
632
- * const box = box.new(10, 105, 20, 100);
633
- * box.delete(box);
634
- * // box.all() no longer contains it
651
+ * ```js
652
+ * eachBar((c) => {
653
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
654
+ * if (c.i < c.n - 1) box.delete(b); // keep only the box of the last bar
655
+ * });
635
656
  * ```
636
657
  */
637
658
  export function delete_box(id: Box): void {
@@ -645,14 +666,33 @@ function pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): num
645
666
  }
646
667
 
647
668
  /**
648
- * All live boxes, in creation order (PineScript `box.all`). A new array.
669
+ * Returns the boxes that are still on the chart, oldest first. The array is a copy.
670
+ * (In a script, `box.all` is read as a value, without a call.)
671
+ * @returns The live boxes in creation order.
672
+ * @example
673
+ * ```js
674
+ * eachBar((c) => {
675
+ * if (c.i === c.n - 1) for (const b of box.all) box.set_right(b, c.i);
676
+ * });
677
+ * ```
649
678
  */
650
679
  export function all(): Box[] {
651
680
  return allDrawings('box');
652
681
  }
653
682
 
654
683
  /**
655
- * Sets the left and top borders from a chart point (`point.index` or `point.time` by xloc, and `point.price`).
684
+ * Moves the box's top-left corner to a chart point: its `index` for a `xloc.bar_index` box, its `time` for a
685
+ * `xloc.bar_time` box (NaN when the point has none), and its `price`. Does nothing on a deleted box.
686
+ * @param id - The box.
687
+ * @param point - The new top-left corner.
688
+ * @returns The same box.
689
+ * @example
690
+ * ```js
691
+ * eachBar((c) => {
692
+ * const b = box.new(c.i - 10, c.high, c.i, c.low);
693
+ * box.set_top_left_point(b, chart.point.from_index(c.i - 20, c.get(high, 20)));
694
+ * });
695
+ * ```
656
696
  */
657
697
  export function set_top_left_point(id: Box, point: ChartPoint): Box {
658
698
  if (isDeleted(id)) return id;
@@ -662,7 +702,17 @@ export function set_top_left_point(id: Box, point: ChartPoint): Box {
662
702
  }
663
703
 
664
704
  /**
665
- * Sets the right and bottom borders from a chart point (`point.index` or `point.time` by xloc, and `point.price`).
705
+ * Moves the box's bottom-right corner to a chart point (see `box.set_top_left_point`). Does nothing on a deleted box.
706
+ * @param id - The box.
707
+ * @param point - The new bottom-right corner.
708
+ * @returns The same box.
709
+ * @example
710
+ * ```js
711
+ * eachBar((c) => {
712
+ * const b = box.new(c.i - 10, c.high, c.i - 1, c.low);
713
+ * box.set_bottom_right_point(b, chart.point.now(c.low));
714
+ * });
715
+ * ```
666
716
  */
667
717
  export function set_bottom_right_point(id: Box, point: ChartPoint): Box {
668
718
  if (isDeleted(id)) return id;
@@ -672,8 +722,17 @@ export function set_bottom_right_point(id: Box, point: ChartPoint): Box {
672
722
  }
673
723
 
674
724
  /**
675
- * Sets the text formatting: `text.format_none`, `text.format_bold`, `text.format_italic`,
676
- * or `text.format_bold + text.format_italic`.
725
+ * Makes the box's text bold, italic, both or plain. Does nothing on a deleted box.
726
+ * @param id - The box.
727
+ * @param formatting - `text.format_bold`, `text.format_italic`, their sum, or `text.format_none`.
728
+ * @returns The same box.
729
+ * @example
730
+ * ```js
731
+ * eachBar((c) => {
732
+ * const b = box.new(c.i - 10, c.high, c.i, c.low, { text: "Zone" });
733
+ * box.set_text_formatting(b, text.format_bold);
734
+ * });
735
+ * ```
677
736
  */
678
737
  export function set_text_formatting(id: Box, formatting: number): Box {
679
738
  if (isDeleted(id)) return id;