oakscriptjs 0.24.0 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/README.md +25 -1
  2. package/bin/oakscript.mjs +10 -3
  3. package/dist/cjs/box/index.d.ts +348 -289
  4. package/dist/cjs/box/index.d.ts.map +1 -1
  5. package/dist/cjs/box/index.js.map +2 -2
  6. package/dist/cjs/check/node.d.ts.map +1 -1
  7. package/dist/cjs/check/node.js +1 -0
  8. package/dist/cjs/check/node.js.map +2 -2
  9. package/dist/cjs/check/preview.d.ts +31 -0
  10. package/dist/cjs/check/preview.d.ts.map +1 -0
  11. package/dist/cjs/check/preview.js +303 -0
  12. package/dist/cjs/check/preview.js.map +7 -0
  13. package/dist/cjs/color/index.d.ts +11 -11
  14. package/dist/cjs/color/index.js.map +1 -1
  15. package/dist/cjs/color/parse.d.ts +2 -0
  16. package/dist/cjs/color/parse.d.ts.map +1 -1
  17. package/dist/cjs/color/parse.js +6 -0
  18. package/dist/cjs/color/parse.js.map +2 -2
  19. package/dist/cjs/compare/index.d.ts +76 -12
  20. package/dist/cjs/compare/index.d.ts.map +1 -1
  21. package/dist/cjs/compare/index.js.map +2 -2
  22. package/dist/cjs/drawing/registry.d.ts +28 -5
  23. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  24. package/dist/cjs/drawing/registry.js +14 -0
  25. package/dist/cjs/drawing/registry.js.map +2 -2
  26. package/dist/cjs/index.d.ts +1 -1
  27. package/dist/cjs/index.js +1 -1
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/label/index.d.ts +265 -187
  30. package/dist/cjs/label/index.d.ts.map +1 -1
  31. package/dist/cjs/label/index.js +1 -1
  32. package/dist/cjs/label/index.js.map +2 -2
  33. package/dist/cjs/line/index.d.ts +247 -207
  34. package/dist/cjs/line/index.d.ts.map +1 -1
  35. package/dist/cjs/line/index.js.map +2 -2
  36. package/dist/cjs/linefill/index.d.ts +61 -89
  37. package/dist/cjs/linefill/index.d.ts.map +1 -1
  38. package/dist/cjs/linefill/index.js.map +2 -2
  39. package/dist/cjs/math/index.d.ts +49 -40
  40. package/dist/cjs/math/index.d.ts.map +1 -1
  41. package/dist/cjs/math/index.js.map +2 -2
  42. package/dist/cjs/polyline/index.d.ts +57 -78
  43. package/dist/cjs/polyline/index.d.ts.map +1 -1
  44. package/dist/cjs/polyline/index.js.map +2 -2
  45. package/dist/cjs/runtime/input-active.d.ts +2 -2
  46. package/dist/cjs/runtime/input-active.js.map +1 -1
  47. package/dist/cjs/runtime/series.d.ts +241 -161
  48. package/dist/cjs/runtime/series.d.ts.map +1 -1
  49. package/dist/cjs/runtime/series.js +223 -127
  50. package/dist/cjs/runtime/series.js.map +2 -2
  51. package/dist/cjs/script/api/alert.d.ts +37 -0
  52. package/dist/cjs/script/api/alert.d.ts.map +1 -0
  53. package/dist/cjs/script/api/alert.js +17 -0
  54. package/dist/cjs/script/api/alert.js.map +7 -0
  55. package/dist/cjs/script/api/calc.d.ts +232 -0
  56. package/dist/cjs/script/api/calc.d.ts.map +1 -0
  57. package/dist/cjs/script/api/calc.js +17 -0
  58. package/dist/cjs/script/api/calc.js.map +7 -0
  59. package/dist/cjs/script/api/color.d.ts +213 -0
  60. package/dist/cjs/script/api/color.d.ts.map +1 -0
  61. package/dist/cjs/script/api/color.js +17 -0
  62. package/dist/cjs/script/api/color.js.map +7 -0
  63. package/dist/cjs/script/api/context.d.ts +764 -0
  64. package/dist/cjs/script/api/context.d.ts.map +1 -0
  65. package/dist/cjs/script/api/context.js +17 -0
  66. package/dist/cjs/script/api/context.js.map +7 -0
  67. package/dist/cjs/script/api/log.d.ts +58 -0
  68. package/dist/cjs/script/api/log.d.ts.map +1 -0
  69. package/dist/cjs/script/api/log.js +17 -0
  70. package/dist/cjs/script/api/log.js.map +7 -0
  71. package/dist/cjs/script/api/strategy.d.ts +391 -0
  72. package/dist/cjs/script/api/strategy.d.ts.map +1 -0
  73. package/dist/cjs/script/api/strategy.js +17 -0
  74. package/dist/cjs/script/api/strategy.js.map +7 -0
  75. package/dist/cjs/script/api/ta.d.ts +1012 -0
  76. package/dist/cjs/script/api/ta.d.ts.map +1 -0
  77. package/dist/cjs/script/api/ta.js +17 -0
  78. package/dist/cjs/script/api/ta.js.map +7 -0
  79. package/dist/cjs/script/api/table.d.ts +479 -0
  80. package/dist/cjs/script/api/table.d.ts.map +1 -0
  81. package/dist/cjs/script/api/table.js +17 -0
  82. package/dist/cjs/script/api/table.js.map +7 -0
  83. package/dist/cjs/script/constants.d.ts +228 -83
  84. package/dist/cjs/script/constants.d.ts.map +1 -1
  85. package/dist/cjs/script/constants.js +87 -0
  86. package/dist/cjs/script/constants.js.map +2 -2
  87. package/dist/cjs/script/define.d.ts +94 -0
  88. package/dist/cjs/script/define.d.ts.map +1 -0
  89. package/dist/cjs/script/define.js +127 -0
  90. package/dist/cjs/script/define.js.map +7 -0
  91. package/dist/cjs/script/drawing-args.d.ts.map +1 -1
  92. package/dist/cjs/script/drawing-args.js +1 -1
  93. package/dist/cjs/script/drawing-args.js.map +2 -2
  94. package/dist/cjs/script/formula.d.ts +53 -0
  95. package/dist/cjs/script/formula.d.ts.map +1 -0
  96. package/dist/cjs/script/formula.js +402 -0
  97. package/dist/cjs/script/formula.js.map +7 -0
  98. package/dist/cjs/script/globals.d.ts +10 -0
  99. package/dist/cjs/script/globals.d.ts.map +1 -1
  100. package/dist/cjs/script/globals.js.map +1 -1
  101. package/dist/cjs/script/index.d.ts +1067 -1006
  102. package/dist/cjs/script/index.d.ts.map +1 -1
  103. package/dist/cjs/script/index.js +530 -60
  104. package/dist/cjs/script/index.js.map +3 -3
  105. package/dist/cjs/script/json.d.ts +117 -0
  106. package/dist/cjs/script/json.d.ts.map +1 -0
  107. package/dist/cjs/script/json.js +321 -0
  108. package/dist/cjs/script/json.js.map +7 -0
  109. package/dist/cjs/str/index.d.ts +50 -75
  110. package/dist/cjs/str/index.d.ts.map +1 -1
  111. package/dist/cjs/str/index.js +2 -2
  112. package/dist/cjs/str/index.js.map +2 -2
  113. package/dist/cjs/strategy/index.d.ts +102 -1
  114. package/dist/cjs/strategy/index.d.ts.map +1 -1
  115. package/dist/cjs/strategy/index.js.map +2 -2
  116. package/dist/cjs/table/index.d.ts +330 -49
  117. package/dist/cjs/table/index.d.ts.map +1 -1
  118. package/dist/cjs/table/index.js +55 -27
  119. package/dist/cjs/table/index.js.map +2 -2
  120. package/dist/cjs/text/index.d.ts +12 -14
  121. package/dist/cjs/text/index.d.ts.map +1 -1
  122. package/dist/cjs/text/index.js.map +2 -2
  123. package/dist/cjs/types/index.d.ts +15 -8
  124. package/dist/cjs/types/index.d.ts.map +1 -1
  125. package/dist/cjs/types/index.js +12 -3
  126. package/dist/cjs/types/index.js.map +2 -2
  127. package/dist/esm/box/index.d.ts +348 -289
  128. package/dist/esm/box/index.d.ts.map +1 -1
  129. package/dist/esm/box/index.js +276 -276
  130. package/dist/esm/box/index.js.map +1 -1
  131. package/dist/esm/check/node.d.ts.map +1 -1
  132. package/dist/esm/check/node.js +1 -0
  133. package/dist/esm/check/node.js.map +1 -1
  134. package/dist/esm/check/preview.d.ts +31 -0
  135. package/dist/esm/check/preview.d.ts.map +1 -0
  136. package/dist/esm/check/preview.js +296 -0
  137. package/dist/esm/check/preview.js.map +1 -0
  138. package/dist/esm/color/index.d.ts +11 -11
  139. package/dist/esm/color/index.js +11 -11
  140. package/dist/esm/color/parse.d.ts +2 -0
  141. package/dist/esm/color/parse.d.ts.map +1 -1
  142. package/dist/esm/color/parse.js +7 -0
  143. package/dist/esm/color/parse.js.map +1 -1
  144. package/dist/esm/compare/index.d.ts +76 -12
  145. package/dist/esm/compare/index.d.ts.map +1 -1
  146. package/dist/esm/compare/index.js +76 -12
  147. package/dist/esm/compare/index.js.map +1 -1
  148. package/dist/esm/drawing/registry.d.ts +28 -5
  149. package/dist/esm/drawing/registry.d.ts.map +1 -1
  150. package/dist/esm/drawing/registry.js +39 -3
  151. package/dist/esm/drawing/registry.js.map +1 -1
  152. package/dist/esm/index.d.ts +1 -1
  153. package/dist/esm/index.js +1 -1
  154. package/dist/esm/label/index.d.ts +265 -187
  155. package/dist/esm/label/index.d.ts.map +1 -1
  156. package/dist/esm/label/index.js +207 -177
  157. package/dist/esm/label/index.js.map +1 -1
  158. package/dist/esm/line/index.d.ts +247 -207
  159. package/dist/esm/line/index.d.ts.map +1 -1
  160. package/dist/esm/line/index.js +202 -194
  161. package/dist/esm/line/index.js.map +1 -1
  162. package/dist/esm/linefill/index.d.ts +61 -89
  163. package/dist/esm/linefill/index.d.ts.map +1 -1
  164. package/dist/esm/linefill/index.js +61 -89
  165. package/dist/esm/linefill/index.js.map +1 -1
  166. package/dist/esm/math/index.d.ts +49 -40
  167. package/dist/esm/math/index.d.ts.map +1 -1
  168. package/dist/esm/math/index.js +22 -9
  169. package/dist/esm/math/index.js.map +1 -1
  170. package/dist/esm/polyline/index.d.ts +57 -78
  171. package/dist/esm/polyline/index.d.ts.map +1 -1
  172. package/dist/esm/polyline/index.js +57 -78
  173. package/dist/esm/polyline/index.js.map +1 -1
  174. package/dist/esm/runtime/input-active.d.ts +2 -2
  175. package/dist/esm/runtime/input-active.js +2 -2
  176. package/dist/esm/runtime/series.d.ts +241 -161
  177. package/dist/esm/runtime/series.d.ts.map +1 -1
  178. package/dist/esm/runtime/series.js +241 -161
  179. package/dist/esm/runtime/series.js.map +1 -1
  180. package/dist/esm/script/api/alert.d.ts +37 -0
  181. package/dist/esm/script/api/alert.d.ts.map +1 -0
  182. package/dist/esm/script/api/alert.js +7 -0
  183. package/dist/esm/script/api/alert.js.map +1 -0
  184. package/dist/esm/script/api/calc.d.ts +232 -0
  185. package/dist/esm/script/api/calc.d.ts.map +1 -0
  186. package/dist/esm/script/api/calc.js +6 -0
  187. package/dist/esm/script/api/calc.js.map +1 -0
  188. package/dist/esm/script/api/color.d.ts +213 -0
  189. package/dist/esm/script/api/color.d.ts.map +1 -0
  190. package/dist/esm/script/api/color.js +6 -0
  191. package/dist/esm/script/api/color.js.map +1 -0
  192. package/dist/esm/script/api/context.d.ts +764 -0
  193. package/dist/esm/script/api/context.d.ts.map +1 -0
  194. package/dist/esm/script/api/context.js +7 -0
  195. package/dist/esm/script/api/context.js.map +1 -0
  196. package/dist/esm/script/api/log.d.ts +58 -0
  197. package/dist/esm/script/api/log.d.ts.map +1 -0
  198. package/dist/esm/script/api/log.js +6 -0
  199. package/dist/esm/script/api/log.js.map +1 -0
  200. package/dist/esm/script/api/strategy.d.ts +391 -0
  201. package/dist/esm/script/api/strategy.d.ts.map +1 -0
  202. package/dist/esm/script/api/strategy.js +7 -0
  203. package/dist/esm/script/api/strategy.js.map +1 -0
  204. package/dist/esm/script/api/ta.d.ts +1012 -0
  205. package/dist/esm/script/api/ta.d.ts.map +1 -0
  206. package/dist/esm/script/api/ta.js +6 -0
  207. package/dist/esm/script/api/ta.js.map +1 -0
  208. package/dist/esm/script/api/table.d.ts +479 -0
  209. package/dist/esm/script/api/table.d.ts.map +1 -0
  210. package/dist/esm/script/api/table.js +7 -0
  211. package/dist/esm/script/api/table.js.map +1 -0
  212. package/dist/esm/script/constants.d.ts +228 -83
  213. package/dist/esm/script/constants.d.ts.map +1 -1
  214. package/dist/esm/script/constants.js +110 -24
  215. package/dist/esm/script/constants.js.map +1 -1
  216. package/dist/esm/script/define.d.ts +94 -0
  217. package/dist/esm/script/define.d.ts.map +1 -0
  218. package/dist/esm/script/define.js +136 -0
  219. package/dist/esm/script/define.js.map +1 -0
  220. package/dist/esm/script/drawing-args.d.ts.map +1 -1
  221. package/dist/esm/script/drawing-args.js +2 -1
  222. package/dist/esm/script/drawing-args.js.map +1 -1
  223. package/dist/esm/script/formula.d.ts +53 -0
  224. package/dist/esm/script/formula.d.ts.map +1 -0
  225. package/dist/esm/script/formula.js +408 -0
  226. package/dist/esm/script/formula.js.map +1 -0
  227. package/dist/esm/script/globals.d.ts +10 -0
  228. package/dist/esm/script/globals.d.ts.map +1 -1
  229. package/dist/esm/script/globals.js.map +1 -1
  230. package/dist/esm/script/index.d.ts +1067 -1006
  231. package/dist/esm/script/index.d.ts.map +1 -1
  232. package/dist/esm/script/index.js +1096 -151
  233. package/dist/esm/script/index.js.map +1 -1
  234. package/dist/esm/script/json.d.ts +117 -0
  235. package/dist/esm/script/json.d.ts.map +1 -0
  236. package/dist/esm/script/json.js +375 -0
  237. package/dist/esm/script/json.js.map +1 -0
  238. package/dist/esm/str/index.d.ts +50 -75
  239. package/dist/esm/str/index.d.ts.map +1 -1
  240. package/dist/esm/str/index.js +51 -76
  241. package/dist/esm/str/index.js.map +1 -1
  242. package/dist/esm/strategy/index.d.ts +102 -1
  243. package/dist/esm/strategy/index.d.ts.map +1 -1
  244. package/dist/esm/strategy/index.js +1 -1
  245. package/dist/esm/strategy/index.js.map +1 -1
  246. package/dist/esm/table/index.d.ts +330 -49
  247. package/dist/esm/table/index.d.ts.map +1 -1
  248. package/dist/esm/table/index.js +372 -61
  249. package/dist/esm/table/index.js.map +1 -1
  250. package/dist/esm/text/index.d.ts +12 -14
  251. package/dist/esm/text/index.d.ts.map +1 -1
  252. package/dist/esm/text/index.js +12 -14
  253. package/dist/esm/text/index.js.map +1 -1
  254. package/dist/esm/types/index.d.ts +15 -8
  255. package/dist/esm/types/index.d.ts.map +1 -1
  256. package/dist/esm/types/index.js +15 -8
  257. package/dist/esm/types/index.js.map +1 -1
  258. package/docs/first-indicator.md +152 -0
  259. package/docs/guide.md +1185 -0
  260. package/docs/inventory.md +772 -0
  261. package/docs/no-code.md +207 -0
  262. package/docs/recipes.md +202 -0
  263. package/package.json +2 -1
  264. package/skills/oakscript/SKILL.md +8 -0
  265. package/skills/oakscript/reference/errors.md +3 -2
  266. package/src/box/index.ts +348 -289
  267. package/src/check/node.ts +1 -0
  268. package/src/check/preview.ts +307 -0
  269. package/src/color/index.ts +11 -11
  270. package/src/color/parse.ts +7 -0
  271. package/src/compare/index.ts +76 -12
  272. package/src/drawing/registry.ts +44 -5
  273. package/src/index.ts +1 -1
  274. package/src/label/index.ts +267 -189
  275. package/src/line/index.ts +248 -208
  276. package/src/linefill/index.ts +61 -89
  277. package/src/math/index.ts +51 -42
  278. package/src/polyline/index.ts +57 -78
  279. package/src/runtime/input-active.ts +2 -2
  280. package/src/runtime/series.ts +243 -163
  281. package/src/script/api/alert.ts +43 -0
  282. package/src/script/api/calc.ts +250 -0
  283. package/src/script/api/color.ts +245 -0
  284. package/src/script/api/context.ts +944 -0
  285. package/src/script/api/log.ts +60 -0
  286. package/src/script/api/strategy.ts +410 -0
  287. package/src/script/api/ta.ts +1115 -0
  288. package/src/script/api/table.ts +538 -0
  289. package/src/script/constants.ts +229 -25
  290. package/src/script/define.ts +221 -0
  291. package/src/script/drawing-args.ts +2 -1
  292. package/src/script/formula.ts +438 -0
  293. package/src/script/globals.ts +10 -0
  294. package/src/script/index.ts +1519 -239
  295. package/src/script/json.ts +457 -0
  296. package/src/str/index.ts +51 -76
  297. package/src/strategy/index.ts +102 -1
  298. package/src/table/index.ts +388 -62
  299. package/src/text/index.ts +12 -14
  300. package/src/types/index.ts +15 -8
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/line/index.ts"],
4
- "sourcesContent": ["/**\n * Line namespace\n * Functions for creating and manipulating line drawing objects.\n *\n * @remarks\n * While lines are primarily visual in PineScript, the line.get_price() function provides\n * computational value for algorithmic trading - calculating trend line breakouts,\n * support/resistance levels, and pattern recognition.\n *\n * @version 6\n */\n\nimport { all as allDrawings, checkBarIndex, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Line, color } from '../types/index.js';\n\ntype LineXloc = 'bar_index' | 'bar_time' | 'pane';\ntype LineExtend = 'none' | 'left' | 'right' | 'both';\ntype LineStyle = 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both';\n\n/**\n * Creates a new line (PineScript `line.new`), with two chart points or with coordinates:\n *\n * - `line.new(first_point, second_point, xloc?, extend?, color?, style?, width?, force_overlay?)`\n * - `line.new(x1, y1, x2, y2, xloc?, extend?, color?, style?, width?, force_overlay?)`\n *\n * With chart points, x is `point.index` for `bar_index` lines and `point.time` for `bar_time` lines.\n *\n * @example\n * ```typescript\n * // Create a trend line from bar 0 (price 100) to bar 50 (price 150)\n * const trendLine = line.new(0, 100, 50, 150, 'bar_index', 'right');\n * const fromPoints = line.new(chartPoint.from_index(0, 100), chartPoint.from_index(50, 150));\n *\n * // Calculate price at bar 75 (extrapolated)\n * const price = line.get_price(trendLine, 75); // Returns 175\n * ```\n */\nexport function new_line(\n first_point: ChartPoint,\n second_point: ChartPoint,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\nexport function new_line(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\nexport function new_line(...args: unknown[]): Line {\n let x1: number, y1: number, x2: number, y2: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const [p1, p2, ...others] = args as [ChartPoint, ChartPoint, ...unknown[]];\n const xloc = (others[0] as LineXloc | undefined) ?? 'bar_index';\n [x1, y1, x2, y2, rest] = [pointX(p1, xloc), p1.price, pointX(p2, xloc), p2.price, others];\n } else {\n [x1, y1, x2, y2] = args as [number, number, number, number];\n rest = args.slice(4);\n }\n const [xloc, extend, lineColor, style, width, force_overlay] = rest as [\n LineXloc?, LineExtend?, color?, LineStyle?, number?, boolean?,\n ];\n x1 = checkBarIndex('line.new', 'x1', x1, xloc);\n x2 = checkBarIndex('line.new', 'x2', x2, xloc);\n return register('line', {\n x1,\n y1,\n x2,\n y2,\n xloc: xloc ?? 'bar_index',\n extend: extend ?? 'none',\n color: lineColor,\n style: style || 'solid',\n width: width ?? 1,\n force_overlay: force_overlay ?? false,\n });\n}\n\n/**\n * Returns the price level of a line at a given bar index (PineScript `line.get_price`).\n *\n * @param id - Line object\n * @param x - Bar index to calculate price at\n * @returns Price level at the given bar index; NaN for a vertical line (x1 == x2) or a deleted line\n *\n * @remarks\n * As in PineScript (#174):\n * - the line is read as extended on both sides whatever its `extend`: a point before x1 or after x2 has a price\n * - the price is `y1 + (y2 - y1) * (x - x1) / (x2 - x1)`, in that order (bit for bit)\n * - a line placed with `xloc.bar_time` (or `xloc.pane`) throws \"'line.get_price' must be used with lines created using\n * 'xloc=xloc.bar_index'.\" (runtime error RE10119)\n *\n * @example\n * ```typescript\n * const trendLine = line.new(0, 100, 50, 150, 'bar_index', 'right');\n *\n * line.get_price(trendLine, 25); // 125\n * line.get_price(trendLine, 100); // 200\n * line.get_price(trendLine, -10); // 90: extended to the left too\n * ```\n */\nexport function get_price(id: Line, x: number): number {\n const { x1, y1, x2, y2, xloc } = id;\n if (xloc !== 'bar_index') {\n throw new Error(\"'line.get_price' must be used with lines created using 'xloc=xloc.bar_index'.\");\n }\n if (x2 === x1) return NaN;\n return y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);\n}\n\n/**\n * Returns the first point's x coordinate.\n *\n * @param id - Line object\n * @returns X coordinate of the first point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const x1 = line.get_x1(line); // Returns 10\n * ```\n */\nexport function get_x1(id: Line): number {\n return id.x1;\n}\n\n/**\n * Returns the second point's x coordinate.\n *\n * @param id - Line object\n * @returns X coordinate of the second point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const x2 = line.get_x2(line); // Returns 50\n * ```\n */\nexport function get_x2(id: Line): number {\n return id.x2;\n}\n\n/**\n * Returns the first point's y coordinate (price level).\n *\n * @param id - Line object\n * @returns Y coordinate (price) of the first point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const y1 = line.get_y1(line); // Returns 100\n * ```\n */\nexport function get_y1(id: Line): number {\n return id.y1;\n}\n\n/**\n * Returns the second point's y coordinate (price level).\n *\n * @param id - Line object\n * @returns Y coordinate (price) of the second point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const y2 = line.get_y2(line); // Returns 150\n * ```\n */\nexport function get_y2(id: Line): number {\n return id.y2;\n}\n\n/**\n * Creates a copy of the line object.\n *\n * @param id - Line object to copy\n * @returns New line object with same properties\n *\n * @remarks\n * Creates a shallow copy of the line. Modifications to the copy won't affect the original.\n *\n * @example\n * ```typescript\n * const originalLine = line.new(0, 100, 50, 150);\n * const copiedLine = line.copy(originalLine);\n *\n * // Modify copy without affecting original\n * copiedLine.y2 = 200;\n * ```\n */\nexport function copy(id: Line): Line {\n return register('line', { ...id });\n}\n\n/**\n * Sets the first point's x coordinate.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate (bar index or timestamp)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_x1(line, 10); // Move first point to bar 10\n * ```\n */\nexport function set_x1(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n return id;\n}\n\n/**\n * Sets the second point's x coordinate.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate (bar index or timestamp)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_x2(line, 60); // Move second point to bar 60\n * ```\n */\nexport function set_x2(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n return id;\n}\n\n/**\n * Sets the first point's y coordinate (price level).\n *\n * @param id - Line object to modify\n * @param y - New y coordinate (price)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_y1(line, 110); // Move first point to price 110\n * ```\n */\nexport function set_y1(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y1 = y;\n return id;\n}\n\n/**\n * Sets the second point's y coordinate (price level).\n *\n * @param id - Line object to modify\n * @param y - New y coordinate (price)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_y2(line, 160); // Move second point to price 160\n * ```\n */\nexport function set_y2(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y2 = y;\n return id;\n}\n\n/**\n * Sets both coordinates of the first point.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_xy1(line, 5, 105); // Move first point to (5, 105)\n * ```\n */\nexport function set_xy1(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n id.y1 = y;\n return id;\n}\n\n/**\n * Sets both coordinates of the second point.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_xy2(line, 60, 160); // Move second point to (60, 160)\n * ```\n */\nexport function set_xy2(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n id.y2 = y;\n return id;\n}\n\n/**\n * Sets the coordinate system for the line.\n *\n * @param id - Line object to modify\n * @param x1 - New first point x coordinate\n * @param x2 - New second point x coordinate\n * @param xloc - New coordinate system ('bar_index', 'bar_time' or 'pane')\n * @returns Modified line object\n *\n * @remarks\n * When changing xloc, you must provide appropriate x coordinates for the new system.\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * // Change to timestamp-based coordinates\n * line.set_xloc(line, 1609459200000, 1609545600000, 'bar_time');\n * ```\n */\nexport function set_xloc(id: Line, x1: number, x2: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Line {\n if (isDeleted(id)) return id;\n id.x1 = x1;\n id.x2 = x2;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets the extension mode of the line.\n *\n * @param id - Line object to modify\n * @param extend - New extension mode\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_extend(line, 'right'); // Extend line to the right\n * ```\n */\nexport function set_extend(id: Line, extend: 'none' | 'left' | 'right' | 'both'): Line {\n if (isDeleted(id)) return id;\n id.extend = extend;\n return id;\n}\n\n/**\n * Sets the line color.\n *\n * @param id - Line object to modify\n * @param color - New line color\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_color(line, '#FF0000'); // Change to red\n * ```\n */\nexport function set_color(id: Line, lineColor: color): Line {\n if (isDeleted(id)) return id;\n id.color = lineColor;\n return id;\n}\n\n/**\n * Sets the line style.\n *\n * @param id - Line object to modify\n * @param style - New line style\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_style(line, 'dashed'); // Change to dashed line\n * ```\n */\nexport function set_style(id: Line, style: 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both'): Line {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the line width.\n *\n * @param id - Line object to modify\n * @param width - New line width in pixels\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_width(line, 3); // Make line thicker\n * ```\n */\nexport function set_width(id: Line, width: number): Line {\n if (isDeleted(id)) return id;\n id.width = width;\n return id;\n}\n\n/**\n * Deletes the line object.\n *\n * @param id - Line object to delete\n *\n * @remarks\n * Removes the line from `line.all()`. As in PineScript, the deleted line is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect. Deleting a line also deletes the linefills that use it.\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.delete(line);\n * // line.all() no longer contains it\n * ```\n */\nexport function delete_line(id: Line): void {\n remove('line', id);\n}\n\n/** x coordinate of a chart point for an object's xloc (`na` when the point has no such coordinate). */\nfunction pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): number {\n const x = xloc === 'bar_time' ? point.time : point.index;\n return x ?? NaN;\n}\n\n/**\n * All live lines, in creation order (PineScript `line.all`). A new array: later changes do not affect it.\n */\nexport function all(): Line[] {\n return allDrawings('line');\n}\n\n/**\n * Sets the first point of the line from a chart point: `point.index` for `bar_index` lines,\n * `point.time` for `bar_time` lines (`na` when the point does not have it), and `point.price`.\n */\nexport function set_first_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x1 = pointX(point, id.xloc);\n id.y1 = point.price;\n return id;\n}\n\n/**\n * Sets the second point of the line from a chart point (see {@link set_first_point}).\n */\nexport function set_second_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x2 = pointX(point, id.xloc);\n id.y2 = point.price;\n return id;\n}\n\n// Alias to match PineScript API\nexport { new_line as new };\nexport { delete_line as delete };\n"],
5
- "mappings": "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",
4
+ "sourcesContent": ["/**\n * Line namespace: functions that create, read, change and delete line drawings (`line.*`).\n *\n * @remarks\n * A line joins two points. Its x coordinates are bar indexes (`xloc.bar_index`, the default), UNIX times in ms\n * (`xloc.bar_time`) or percents of the pane's width (`xloc.pane`); its y coordinates are prices. Besides drawing,\n * `line.get_price()` reads the price of a trend line on any bar, for breakout tests.\n *\n * @version 6\n */\n\nimport { all as allDrawings, checkBarIndex, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Line, color } from '../types/index.js';\n\ntype LineXloc = 'bar_index' | 'bar_time' | 'pane';\ntype LineExtend = 'none' | 'left' | 'right' | 'both';\ntype LineStyle = 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both';\n\n/**\n * Draws a line between two chart points and returns its handle, to change or delete it later.\n * With `xloc.bar_index` the x of a point is its `index`, with `xloc.bar_time` its `time`. Lines above\n * `max_lines_count` (default 50) are deleted oldest first.\n * @param first_point - Start of the line (`chart.point.from_index(...)`, `chart.point.now()`...).\n * @param second_point - End of the line.\n * @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.\n * @param extend - Extends the line past its points: `extend.none`, `extend.left`, `extend.right` or `extend.both`.\n * Default: `extend.none`.\n * @param lineColor - Line colour. Default: blue (#2962FF).\n * @param style - `line.style_solid`, `line.style_dotted`, `line.style_dashed`, `line.style_arrow_left`,\n * `line.style_arrow_right` or `line.style_arrow_both`. Default: `line.style_solid`.\n * @param width - Line width in pixels. Default: 1.\n * @param force_overlay - When true, the line is drawn on the price pane even if the script has its own pane.\n * Default: false.\n * @returns The new line.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) line.new(chart.point.from_index(c.i - 20, c.get(low, 20)), chart.point.now(c.high));\n * });\n * ```\n */\nexport function new_line(\n first_point: ChartPoint,\n second_point: ChartPoint,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\n/**\n * Draws a line from (x1, y1) to (x2, y2) and returns its handle, to change or delete it later.\n * Inside `eachBar` a Series argument is read on the current bar; the optional arguments can also be given by name in\n * an object after the coordinates. A bar index x is rounded down; it may be up to 500 bars after the last bar.\n * Lines above `max_lines_count` (default 50) are deleted oldest first.\n * @param x1 - x of the first point: a bar index, a UNIX time in ms (`xloc.bar_time`) or a percent of the pane's\n * width (`xloc.pane`).\n * @param y1 - Price of the first point.\n * @param x2 - x of the second point, in the same unit as `x1`.\n * @param y2 - Price of the second point.\n * @param xloc - What the x coordinates are: `xloc.bar_index`, `xloc.bar_time` or `xloc.pane`. Default: `xloc.bar_index`.\n * @param extend - Extends the line past its points: `extend.none`, `extend.left`, `extend.right` or `extend.both`.\n * Default: `extend.none`.\n * @param lineColor - Line colour. Default: blue (#2962FF).\n * @param style - `line.style_solid`, `line.style_dotted`, `line.style_dashed`, `line.style_arrow_left`,\n * `line.style_arrow_right` or `line.style_arrow_both`. Default: `line.style_solid`.\n * @param width - Line width in pixels. Default: 1.\n * @param force_overlay - When true, the line is drawn on the price pane even if the script has its own pane.\n * Default: false.\n * @returns The new line.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) line.new(c.i - 20, c.get(low, 20), c.i, c.low, { color: \"#2962FF\", extend: extend.right });\n * });\n * ```\n */\nexport function new_line(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\nexport function new_line(...args: unknown[]): Line {\n let x1: number, y1: number, x2: number, y2: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const [p1, p2, ...others] = args as [ChartPoint, ChartPoint, ...unknown[]];\n const xloc = (others[0] as LineXloc | undefined) ?? 'bar_index';\n [x1, y1, x2, y2, rest] = [pointX(p1, xloc), p1.price, pointX(p2, xloc), p2.price, others];\n } else {\n [x1, y1, x2, y2] = args as [number, number, number, number];\n rest = args.slice(4);\n }\n const [xloc, extend, lineColor, style, width, force_overlay] = rest as [\n LineXloc?, LineExtend?, color?, LineStyle?, number?, boolean?,\n ];\n x1 = checkBarIndex('line.new', 'x1', x1, xloc);\n x2 = checkBarIndex('line.new', 'x2', x2, xloc);\n return register('line', {\n x1,\n y1,\n x2,\n y2,\n xloc: xloc ?? 'bar_index',\n extend: extend ?? 'none',\n color: lineColor,\n style: style || 'solid',\n width: width ?? 1,\n force_overlay: force_overlay ?? false,\n });\n}\n\n/**\n * Returns the price of the line at a bar index, for example to test whether the close crossed a trend line.\n * The line is read as extended on both sides whatever its `extend`, so any bar has a price.\n * Only for lines placed with `xloc.bar_index`: other lines throw an error.\n * @param id - The line.\n * @param x - Bar index to read the price at.\n * @returns The price on the line at `x`; NaN for a vertical line (x1 equal to x2) or a deleted line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.get(high, 10), c.i - 1, c.get(high, 1));\n * if (c.close > line.get_price(l, c.i)) label.new(c.i, c.high, \"Break\");\n * });\n * ```\n */\nexport function get_price(id: Line, x: number): number {\n const { x1, y1, x2, y2, xloc } = id;\n if (xloc !== 'bar_index') {\n throw new Error(\"'line.get_price' must be used with lines created using 'xloc=xloc.bar_index'.\");\n }\n if (x2 === x1) return NaN;\n return y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);\n}\n\n/**\n * Returns the x coordinate of the line's first point.\n * @param id - The line.\n * @returns A bar index, a UNIX time in ms or a pane percent, by the line's xloc; NaN for a deleted line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);\n * const length = c.i - line.get_x1(l); // 10\n * });\n * ```\n */\nexport function get_x1(id: Line): number {\n return id.x1;\n}\n\n/**\n * Returns the x coordinate of the line's second point.\n * @param id - The line.\n * @returns A bar index, a UNIX time in ms or a pane percent, by the line's xloc; NaN for a deleted line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);\n * const bars = line.get_x2(l) - line.get_x1(l); // 10\n * });\n * ```\n */\nexport function get_x2(id: Line): number {\n return id.x2;\n}\n\n/**\n * Returns the price of the line's first point.\n * @param id - The line.\n * @returns The price of the first point; NaN for a deleted line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);\n * const rising = c.low > line.get_y1(l);\n * });\n * ```\n */\nexport function get_y1(id: Line): number {\n return id.y1;\n}\n\n/**\n * Returns the price of the line's second point.\n * @param id - The line.\n * @returns The price of the second point; NaN for a deleted line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);\n * const change = line.get_y2(l) - line.get_y1(l);\n * });\n * ```\n */\nexport function get_y2(id: Line): number {\n return id.y2;\n}\n\n/**\n * Makes a new line with the same points and style as `id` (it counts toward `max_lines_count`).\n * Changing the copy does not change the original.\n * @param id - The line to copy.\n * @returns The new line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.high, c.i, c.high);\n * line.set_y1(line.copy(l), c.low); // a second line from the same start bar, at the low\n * });\n * ```\n */\nexport function copy(id: Line): Line {\n return register('line', { ...id });\n}\n\n/**\n * Moves the x coordinate of the line's first point. Does nothing on a deleted line.\n * @param id - The line.\n * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_x1(l, c.i - 20);\n * });\n * ```\n */\nexport function set_x1(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n return id;\n}\n\n/**\n * Moves the x coordinate of the line's second point. Does nothing on a deleted line.\n * @param id - The line.\n * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_x2(l, c.i + 10); // reach 10 bars into the future\n * });\n * ```\n */\nexport function set_x2(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n return id;\n}\n\n/**\n * Moves the price of the line's first point. Does nothing on a deleted line.\n * @param id - The line.\n * @param y - New price.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_y1(l, c.get(low, 10));\n * });\n * ```\n */\nexport function set_y1(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y1 = y;\n return id;\n}\n\n/**\n * Moves the price of the line's second point. Does nothing on a deleted line.\n * @param id - The line.\n * @param y - New price.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_y2(l, c.high);\n * });\n * ```\n */\nexport function set_y2(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y2 = y;\n return id;\n}\n\n/**\n * Moves the line's first point (x and price). Does nothing on a deleted line.\n * @param id - The line.\n * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.\n * @param y - New price.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_xy1(l, c.i - 20, c.get(low, 20));\n * });\n * ```\n */\nexport function set_xy1(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n id.y1 = y;\n return id;\n}\n\n/**\n * Moves the line's second point (x and price). Does nothing on a deleted line.\n * @param id - The line.\n * @param x - New x: a bar index, a UNIX time in ms or a pane percent, by the line's xloc. A bar index is rounded down.\n * @param y - New price.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i - 1, c.low);\n * line.set_xy2(l, c.i, c.close);\n * });\n * ```\n */\nexport function set_xy2(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n id.y2 = y;\n return id;\n}\n\n/**\n * Changes what the line's x coordinates are and sets both of them in that unit. Does nothing on a deleted line.\n * @param id - The line.\n * @param x1 - New x of the first point, in the unit of `xloc`.\n * @param x2 - New x of the second point, in the unit of `xloc`.\n * @param xloc - `xloc.bar_index` (bar indexes), `xloc.bar_time` (UNIX times in ms) or `xloc.pane` (percents of the\n * pane's width).\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_xloc(l, c.time - 3600000, c.time, xloc.bar_time);\n * });\n * ```\n */\nexport function set_xloc(id: Line, x1: number, x2: number, xloc: 'bar_index' | 'bar_time' | 'pane'): Line {\n if (isDeleted(id)) return id;\n id.x1 = x1;\n id.x2 = x2;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets whether the line continues past its points. Does nothing on a deleted line.\n * @param id - The line.\n * @param extend - `extend.none`, `extend.left`, `extend.right` or `extend.both`.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.get(low, 10), c.i, c.low);\n * line.set_extend(l, extend.right);\n * });\n * ```\n */\nexport function set_extend(id: Line, extend: 'none' | 'left' | 'right' | 'both'): Line {\n if (isDeleted(id)) return id;\n id.extend = extend;\n return id;\n}\n\n/**\n * Sets the line colour. Does nothing on a deleted line.\n * @param id - The line.\n * @param lineColor - New colour (`color.red`, `\"#FF0000\"`, `color.new(color.red, 50)`...).\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.get(close, 10), c.i, c.close);\n * line.set_color(l, c.close > c.get(close, 10) ? color.green : color.red);\n * });\n * ```\n */\nexport function set_color(id: Line, lineColor: color): Line {\n if (isDeleted(id)) return id;\n id.color = lineColor;\n return id;\n}\n\n/**\n * Sets the line style (solid, dotted, dashed, or with arrow heads). Does nothing on a deleted line.\n * @param id - The line.\n * @param style - `line.style_solid`, `line.style_dotted`, `line.style_dashed`, `line.style_arrow_left`,\n * `line.style_arrow_right` or `line.style_arrow_both`.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_style(l, line.style_dashed);\n * });\n * ```\n */\nexport function set_style(id: Line, style: 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both'): Line {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the line width. Does nothing on a deleted line.\n * @param id - The line.\n * @param width - New width in pixels.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_width(l, 3);\n * });\n * ```\n */\nexport function set_width(id: Line, width: number): Line {\n if (isDeleted(id)) return id;\n id.width = width;\n return id;\n}\n\n/**\n * Removes the line from the chart and from `line.all`. The linefills that use it are deleted too.\n * Afterwards its getters return NaN and its setters do nothing; deleting it again does nothing.\n * @param id - The line to delete.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 1, c.get(close, 1), c.i, c.close);\n * if (c.i < c.n - 1) line.delete(l); // keep only the line of the last bar\n * });\n * ```\n */\nexport function delete_line(id: Line): void {\n remove('line', id);\n}\n\n/** x coordinate of a chart point for an object's xloc (`na` when the point has no such coordinate). */\nfunction pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time' | 'pane'): number {\n const x = xloc === 'bar_time' ? point.time : point.index;\n return x ?? NaN;\n}\n\n/**\n * Returns the lines that are still on the chart, oldest first. The array is a copy: later changes do not affect it.\n * (In a script, `line.all` is read as a value, without a call.)\n * @returns The live lines in creation order.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) for (const l of line.all) line.set_color(l, color.gray);\n * });\n * ```\n */\nexport function all(): Line[] {\n return allDrawings('line');\n}\n\n/**\n * Moves the line's first point to a chart point: its `index` for a `xloc.bar_index` line, its `time` for a\n * `xloc.bar_time` line (NaN when the point has none), and its `price`. Does nothing on a deleted line.\n * @param id - The line.\n * @param point - The new first point.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_first_point(l, chart.point.from_index(c.i - 20, c.get(low, 20)));\n * });\n * ```\n */\nexport function set_first_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x1 = pointX(point, id.xloc);\n id.y1 = point.price;\n return id;\n}\n\n/**\n * Moves the line's second point to a chart point (see `line.set_first_point`). Does nothing on a deleted line.\n * @param id - The line.\n * @param point - The new second point.\n * @returns The same line.\n * @example\n * ```js\n * eachBar((c) => {\n * const l = line.new(c.i - 10, c.low, c.i, c.low);\n * line.set_second_point(l, chart.point.now(c.high));\n * });\n * ```\n */\nexport function set_second_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x2 = pointX(point, id.xloc);\n id.y2 = point.price;\n return id;\n}\n\n// Script names: line.new / line.delete\nexport { new_line as new };\nexport { delete_line as delete };\n"],
5
+ "mappings": "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",
6
6
  "names": ["xloc", "allDrawings"]
7
7
  }
@@ -1,125 +1,97 @@
1
1
  /**
2
- * Linefill namespace
3
- * Functions for creating and manipulating linefill drawing objects.
2
+ * Linefill namespace: functions that fill the area between two lines (`linefill.*`).
4
3
  *
5
4
  * @remarks
6
- * Linefill objects fill the area between two lines with a color.
7
- * They have minimal computational value but automatically follow line movements
8
- * and provide a way to retrieve the underlying line references.
5
+ * A linefill colours the space between two lines and follows them when they move. It is deleted with either line,
6
+ * and two lines share one linefill.
9
7
  *
10
8
  * @version 6
11
9
  */
12
10
  import type { Linefill, Line, color } from '../types/index.js';
13
11
  /**
14
- * Creates a new linefill object that fills the area between two lines.
15
- *
16
- * @param line1 - First line object
17
- * @param line2 - Second line object
18
- * @param fillColor - Fill color (optional)
19
- * @returns New linefill object
20
- *
21
- * @remarks
22
- * - Automatically follows line movements (if lines are updated, fill updates too)
23
- * - Automatically deleted if either line is deleted
24
- * - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill
25
- * (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is
26
- * returned with the new colour instead of a new one; with several, the one created or returned last
27
- * - If both lines extend in same direction, fill extends too
28
- * - Purely visual in PineScript, but getters allow retrieving line references
29
- *
12
+ * Fills the area between two lines with a colour and returns the linefill's handle. The fill follows the lines when
13
+ * they move or extend, and is deleted when either line is deleted. Two lines have one linefill: when they already
14
+ * have one, that linefill gets the new colour and is returned instead of a new one. An `na` line gives `na`.
15
+ * The arguments can also be given by name in an object.
16
+ * @param line1 - The first line.
17
+ * @param line2 - The second line.
18
+ * @param fillColor - Fill colour; a transparent one (`color.new(color.blue, 85)`) keeps the bars visible.
19
+ * Default: none.
20
+ * @returns The linefill.
30
21
  * @example
31
- * ```typescript
32
- * import { line, linefill } from 'oakscriptjs';
33
- *
34
- * // Create channel lines
35
- * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');
36
- * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');
37
- *
38
- * // Fill channel with color
39
- * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue
22
+ * ```js
23
+ * eachBar((c) => {
24
+ * if (c.i !== c.n - 1) return;
25
+ * const top = line.new(c.i - 20, c.get(high, 20), c.i, c.high, { extend: extend.right });
26
+ * const bottom = line.new(c.i - 20, c.get(low, 20), c.i, c.low, { extend: extend.right });
27
+ * linefill.new(top, bottom, color.new(color.blue, 85));
28
+ * });
40
29
  * ```
41
30
  */
42
31
  export declare function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill;
43
32
  /**
44
- * Returns the first line reference.
45
- *
46
- * @param id - Linefill object
47
- * @returns First line object
48
- *
49
- * @remarks
50
- * Can be used to retrieve and manipulate the first line.
51
- *
33
+ * Returns the first line of a linefill, to read or move it.
34
+ * @param id - The linefill.
35
+ * @returns The first line given to `linefill.new()`.
52
36
  * @example
53
- * ```typescript
54
- * const channelFill = linefill.new(upperLine, lowerLine);
55
- *
56
- * // Later, retrieve and update the first line
57
- * const line1 = linefill.get_line1(channelFill);
58
- * line.set_y2(line1, 175); // Update upper line's second point
37
+ * ```js
38
+ * eachBar((c) => {
39
+ * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
40
+ * line.set_color(linefill.get_line1(lf), color.green);
41
+ * });
59
42
  * ```
60
43
  */
61
44
  export declare function get_line1(id: Linefill): Line;
62
45
  /**
63
- * Returns the second line reference.
64
- *
65
- * @param id - Linefill object
66
- * @returns Second line object
67
- *
68
- * @remarks
69
- * Can be used to retrieve and manipulate the second line.
70
- *
46
+ * Returns the second line of a linefill, to read or move it.
47
+ * @param id - The linefill.
48
+ * @returns The second line given to `linefill.new()`.
71
49
  * @example
72
- * ```typescript
73
- * const channelFill = linefill.new(upperLine, lowerLine);
74
- *
75
- * // Later, retrieve and update the second line
76
- * const line2 = linefill.get_line2(channelFill);
77
- * line.set_y2(line2, 145); // Update lower line's second point
50
+ * ```js
51
+ * eachBar((c) => {
52
+ * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
53
+ * line.set_color(linefill.get_line2(lf), color.red);
54
+ * });
78
55
  * ```
79
56
  */
80
57
  export declare function get_line2(id: Linefill): Line;
81
58
  /**
82
- * Sets the fill color.
83
- *
84
- * @param id - Linefill object to modify
85
- * @param fillColor - New fill color
86
- * @returns Modified linefill object
87
- *
88
- * @remarks
89
- * Useful for dynamically changing channel colors based on conditions.
90
- *
59
+ * Changes the fill colour. Does nothing on a deleted linefill.
60
+ * @param id - The linefill.
61
+ * @param fillColor - New fill colour.
62
+ * @returns The same linefill.
91
63
  * @example
92
- * ```typescript
93
- * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');
94
- *
95
- * // Change color based on trend
96
- * if (bullish) {
97
- * linefill.set_color(channelFill, '#00FF0020'); // Green
98
- * } else {
99
- * linefill.set_color(channelFill, '#FF000020'); // Red
100
- * }
64
+ * ```js
65
+ * eachBar((c) => {
66
+ * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
67
+ * linefill.set_color(lf, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));
68
+ * });
101
69
  * ```
102
70
  */
103
71
  export declare function set_color(id: Linefill, fillColor: color): Linefill;
104
72
  /**
105
- * Deletes the linefill object.
106
- *
107
- * @param id - Linefill object to delete
108
- *
109
- * @remarks
110
- * Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters
111
- * return NaN and its setters do nothing. Deleting it twice has no effect.
112
- *
73
+ * Removes the fill from the chart and from `linefill.all`; the two lines stay. Afterwards its setters do nothing;
74
+ * deleting it again does nothing.
75
+ * @param id - The linefill to delete.
113
76
  * @example
114
- * ```typescript
115
- * const channelFill = linefill.new(upperLine, lowerLine);
116
- * linefill.delete(channelFill);
117
- * // linefill.all() no longer contains it
77
+ * ```js
78
+ * eachBar((c) => {
79
+ * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));
80
+ * if (c.close < c.open) linefill.delete(lf);
81
+ * });
118
82
  * ```
119
83
  */
120
84
  export declare function delete_linefill(id: Linefill): void;
121
85
  /**
122
- * All live linefills, in creation order (PineScript `linefill.all`). A new array.
86
+ * Returns the linefills that are still on the chart, oldest first. The array is a copy.
87
+ * (In a script, `linefill.all` is read as a value, without a call.)
88
+ * @returns The live linefills in creation order.
89
+ * @example
90
+ * ```js
91
+ * eachBar((c) => {
92
+ * if (c.i === c.n - 1) for (const lf of linefill.all) linefill.set_color(lf, color.new(color.gray, 80));
93
+ * });
94
+ * ```
123
95
  */
124
96
  export declare function all(): Linefill[];
125
97
  export { new_linefill as new };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAoBlF;AAeD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,GAAG,QAAQ,CAIlE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAElD;AAGD;;GAEG;AACH,wBAAgB,GAAG,IAAI,QAAQ,EAAE,CAEhC;AAGD,OAAO,EAAE,YAAY,IAAI,GAAG,EAAE,CAAC;AAC/B,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAoBlF;AAeD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,GAAG,QAAQ,CAIlE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAElD;AAGD;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,IAAI,QAAQ,EAAE,CAEhC;AAGD,OAAO,EAAE,YAAY,IAAI,GAAG,EAAE,CAAC;AAC/B,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,CAAC"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/linefill/index.ts"],
4
- "sourcesContent": ["/**\n * Linefill namespace\n * Functions for creating and manipulating linefill drawing objects.\n *\n * @remarks\n * Linefill objects fill the area between two lines with a color.\n * They have minimal computational value but automatically follow line movements\n * and provide a way to retrieve the underlying line references.\n *\n * @version 6\n */\n\nimport { Stamped, all as allDrawings, isDeleted, liveFillsOf, register, remove } from '../drawing/registry.js';\nimport type { Linefill, Line, color } from '../types/index.js';\n\n/**\n * Creates a new linefill object that fills the area between two lines.\n *\n * @param line1 - First line object\n * @param line2 - Second line object\n * @param fillColor - Fill color (optional)\n * @returns New linefill object\n *\n * @remarks\n * - Automatically follows line movements (if lines are updated, fill updates too)\n * - Automatically deleted if either line is deleted\n * - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill\n * (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is\n * returned with the new colour instead of a new one; with several, the one created or returned last\n * - If both lines extend in same direction, fill extends too\n * - Purely visual in PineScript, but getters allow retrieving line references\n *\n * @example\n * ```typescript\n * import { line, linefill } from 'oakscriptjs';\n *\n * // Create channel lines\n * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');\n * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');\n *\n * // Fill channel with color\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue\n * ```\n */\nexport function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill {\n // PineScript: an na line gives an na linefill\n if (line1 === null || line1 === undefined || line2 === null || line2 === undefined) return null as unknown as Linefill;\n let found: Linefill | undefined;\n for (const fill of liveFillsOf(line1)) {\n const has = (l: Line): boolean => fill.line1 === l || fill.line2 === l;\n if (has(line2) && (!found || Touched.get(fill) > Touched.get(found))) found = fill;\n }\n if (found) {\n found.color = fillColor;\n Touched.set(found, ++touchCount);\n return found;\n }\n const fill = register('linefill', {\n line1,\n line2,\n color: fillColor\n });\n Touched.set(fill, ++touchCount);\n return fill;\n}\n\n/** Order in which the linefills were created or returned by `linefill.new` (the last one wins a lookup); 0 before. */\nclass Touched extends Stamped {\n #touch = 0;\n static get(fill: Linefill): number {\n return #touch in fill ? fill.#touch : 0;\n }\n static set(fill: Linefill, order: number): void {\n if (!(#touch in fill)) new Touched(fill);\n (fill as unknown as Touched).#touch = order;\n }\n}\nlet touchCount = 0;\n\n/**\n * Returns the first line reference.\n *\n * @param id - Linefill object\n * @returns First line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the first line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the first line\n * const line1 = linefill.get_line1(channelFill);\n * line.set_y2(line1, 175); // Update upper line's second point\n * ```\n */\nexport function get_line1(id: Linefill): Line {\n return id.line1;\n}\n\n/**\n * Returns the second line reference.\n *\n * @param id - Linefill object\n * @returns Second line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the second line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the second line\n * const line2 = linefill.get_line2(channelFill);\n * line.set_y2(line2, 145); // Update lower line's second point\n * ```\n */\nexport function get_line2(id: Linefill): Line {\n return id.line2;\n}\n\n/**\n * Sets the fill color.\n *\n * @param id - Linefill object to modify\n * @param fillColor - New fill color\n * @returns Modified linefill object\n *\n * @remarks\n * Useful for dynamically changing channel colors based on conditions.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');\n *\n * // Change color based on trend\n * if (bullish) {\n * linefill.set_color(channelFill, '#00FF0020'); // Green\n * } else {\n * linefill.set_color(channelFill, '#FF000020'); // Red\n * }\n * ```\n */\nexport function set_color(id: Linefill, fillColor: color): Linefill {\n if (isDeleted(id)) return id;\n id.color = fillColor;\n return id;\n}\n\n/**\n * Deletes the linefill object.\n *\n * @param id - Linefill object to delete\n *\n * @remarks\n * Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n * linefill.delete(channelFill);\n * // linefill.all() no longer contains it\n * ```\n */\nexport function delete_linefill(id: Linefill): void {\n remove('linefill', id);\n}\n\n\n/**\n * All live linefills, in creation order (PineScript `linefill.all`). A new array.\n */\nexport function all(): Linefill[] {\n return allDrawings('linefill');\n}\n\n// Alias to match PineScript API\nexport { new_linefill as new };\nexport { delete_linefill as delete };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAsF;AAgC/E,SAAS,aAAa,OAAa,OAAa,WAA6B;AAElF,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,QAAQ,UAAU,OAAW,QAAO;AAC3F,MAAI;AACJ,aAAWA,aAAQ,6BAAY,KAAK,GAAG;AACrC,UAAM,MAAM,CAAC,MAAqBA,MAAK,UAAU,KAAKA,MAAK,UAAU;AACrE,QAAI,IAAI,KAAK,MAAM,CAAC,SAAS,QAAQ,IAAIA,KAAI,IAAI,QAAQ,IAAI,KAAK,GAAI,SAAQA;AAAA,EAChF;AACA,MAAI,OAAO;AACT,UAAM,QAAQ;AACd,YAAQ,IAAI,OAAO,EAAE,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,WAAO,0BAAS,YAAY;AAAA,IAChC;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AACD,UAAQ,IAAI,MAAM,EAAE,UAAU;AAC9B,SAAO;AACT;AAGA,MAAM,gBAAgB,wBAAQ;AAAA,EAC5B,SAAS;AAAA,EACT,OAAO,IAAI,MAAwB;AACjC,WAAO,UAAU,OAAO,KAAK,SAAS;AAAA,EACxC;AAAA,EACA,OAAO,IAAI,MAAgB,OAAqB;AAC9C,QAAI,EAAE,UAAU,MAAO,KAAI,QAAQ,IAAI;AACvC,IAAC,KAA4B,SAAS;AAAA,EACxC;AACF;AACA,IAAI,aAAa;AAoBV,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAoBO,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAwBO,SAAS,UAAU,IAAc,WAA4B;AAClE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,QAAQ;AACX,SAAO;AACT;AAkBO,SAAS,gBAAgB,IAAoB;AAClD,8BAAO,YAAY,EAAE;AACvB;AAMO,SAAS,MAAkB;AAChC,aAAO,gBAAAC,KAAY,UAAU;AAC/B;",
4
+ "sourcesContent": ["/**\n * Linefill namespace: functions that fill the area between two lines (`linefill.*`).\n *\n * @remarks\n * A linefill colours the space between two lines and follows them when they move. It is deleted with either line,\n * and two lines share one linefill.\n *\n * @version 6\n */\n\nimport { Stamped, all as allDrawings, isDeleted, liveFillsOf, register, remove } from '../drawing/registry.js';\nimport type { Linefill, Line, color } from '../types/index.js';\n\n/**\n * Fills the area between two lines with a colour and returns the linefill's handle. The fill follows the lines when\n * they move or extend, and is deleted when either line is deleted. Two lines have one linefill: when they already\n * have one, that linefill gets the new colour and is returned instead of a new one. An `na` line gives `na`.\n * The arguments can also be given by name in an object.\n * @param line1 - The first line.\n * @param line2 - The second line.\n * @param fillColor - Fill colour; a transparent one (`color.new(color.blue, 85)`) keeps the bars visible.\n * Default: none.\n * @returns The linefill.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i !== c.n - 1) return;\n * const top = line.new(c.i - 20, c.get(high, 20), c.i, c.high, { extend: extend.right });\n * const bottom = line.new(c.i - 20, c.get(low, 20), c.i, c.low, { extend: extend.right });\n * linefill.new(top, bottom, color.new(color.blue, 85));\n * });\n * ```\n */\nexport function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill {\n // PineScript: an na line gives an na linefill\n if (line1 === null || line1 === undefined || line2 === null || line2 === undefined) return null as unknown as Linefill;\n let found: Linefill | undefined;\n for (const fill of liveFillsOf(line1)) {\n const has = (l: Line): boolean => fill.line1 === l || fill.line2 === l;\n if (has(line2) && (!found || Touched.get(fill) > Touched.get(found))) found = fill;\n }\n if (found) {\n found.color = fillColor;\n Touched.set(found, ++touchCount);\n return found;\n }\n const fill = register('linefill', {\n line1,\n line2,\n color: fillColor\n });\n Touched.set(fill, ++touchCount);\n return fill;\n}\n\n/** Order in which the linefills were created or returned by `linefill.new` (the last one wins a lookup); 0 before. */\nclass Touched extends Stamped {\n #touch = 0;\n static get(fill: Linefill): number {\n return #touch in fill ? fill.#touch : 0;\n }\n static set(fill: Linefill, order: number): void {\n if (!(#touch in fill)) new Touched(fill);\n (fill as unknown as Touched).#touch = order;\n }\n}\nlet touchCount = 0;\n\n/**\n * Returns the first line of a linefill, to read or move it.\n * @param id - The linefill.\n * @returns The first line given to `linefill.new()`.\n * @example\n * ```js\n * eachBar((c) => {\n * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));\n * line.set_color(linefill.get_line1(lf), color.green);\n * });\n * ```\n */\nexport function get_line1(id: Linefill): Line {\n return id.line1;\n}\n\n/**\n * Returns the second line of a linefill, to read or move it.\n * @param id - The linefill.\n * @returns The second line given to `linefill.new()`.\n * @example\n * ```js\n * eachBar((c) => {\n * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));\n * line.set_color(linefill.get_line2(lf), color.red);\n * });\n * ```\n */\nexport function get_line2(id: Linefill): Line {\n return id.line2;\n}\n\n/**\n * Changes the fill colour. Does nothing on a deleted linefill.\n * @param id - The linefill.\n * @param fillColor - New fill colour.\n * @returns The same linefill.\n * @example\n * ```js\n * eachBar((c) => {\n * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));\n * linefill.set_color(lf, c.close > c.open ? color.new(color.green, 80) : color.new(color.red, 80));\n * });\n * ```\n */\nexport function set_color(id: Linefill, fillColor: color): Linefill {\n if (isDeleted(id)) return id;\n id.color = fillColor;\n return id;\n}\n\n/**\n * Removes the fill from the chart and from `linefill.all`; the two lines stay. Afterwards its setters do nothing;\n * deleting it again does nothing.\n * @param id - The linefill to delete.\n * @example\n * ```js\n * eachBar((c) => {\n * const lf = linefill.new(line.new(c.i - 5, c.high, c.i, c.high), line.new(c.i - 5, c.low, c.i, c.low));\n * if (c.close < c.open) linefill.delete(lf);\n * });\n * ```\n */\nexport function delete_linefill(id: Linefill): void {\n remove('linefill', id);\n}\n\n\n/**\n * Returns the linefills that are still on the chart, oldest first. The array is a copy.\n * (In a script, `linefill.all` is read as a value, without a call.)\n * @returns The live linefills in creation order.\n * @example\n * ```js\n * eachBar((c) => {\n * if (c.i === c.n - 1) for (const lf of linefill.all) linefill.set_color(lf, color.new(color.gray, 80));\n * });\n * ```\n */\nexport function all(): Linefill[] {\n return allDrawings('linefill');\n}\n\n// Alias to match PineScript API\nexport { new_linefill as new };\nexport { delete_linefill as delete };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,sBAAsF;AAuB/E,SAAS,aAAa,OAAa,OAAa,WAA6B;AAElF,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,QAAQ,UAAU,OAAW,QAAO;AAC3F,MAAI;AACJ,aAAWA,aAAQ,6BAAY,KAAK,GAAG;AACrC,UAAM,MAAM,CAAC,MAAqBA,MAAK,UAAU,KAAKA,MAAK,UAAU;AACrE,QAAI,IAAI,KAAK,MAAM,CAAC,SAAS,QAAQ,IAAIA,KAAI,IAAI,QAAQ,IAAI,KAAK,GAAI,SAAQA;AAAA,EAChF;AACA,MAAI,OAAO;AACT,UAAM,QAAQ;AACd,YAAQ,IAAI,OAAO,EAAE,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,WAAO,0BAAS,YAAY;AAAA,IAChC;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AACD,UAAQ,IAAI,MAAM,EAAE,UAAU;AAC9B,SAAO;AACT;AAGA,MAAM,gBAAgB,wBAAQ;AAAA,EAC5B,SAAS;AAAA,EACT,OAAO,IAAI,MAAwB;AACjC,WAAO,UAAU,OAAO,KAAK,SAAS;AAAA,EACxC;AAAA,EACA,OAAO,IAAI,MAAgB,OAAqB;AAC9C,QAAI,EAAE,UAAU,MAAO,KAAI,QAAQ,IAAI;AACvC,IAAC,KAA4B,SAAS;AAAA,EACxC;AACF;AACA,IAAI,aAAa;AAcV,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAcO,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAeO,SAAS,UAAU,IAAc,WAA4B;AAClE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,QAAQ;AACX,SAAO;AACT;AAcO,SAAS,gBAAgB,IAAoB;AAClD,8BAAO,YAAY,EAAE;AACvB;AAcO,SAAS,MAAkB;AAChC,aAAO,gBAAAC,KAAY,UAAU;AAC/B;",
6
6
  "names": ["fill", "allDrawings"]
7
7
  }
@@ -29,7 +29,7 @@ import { Series } from '../runtime/series.js';
29
29
  * - If value is a Series, returns a Series; if value is a number, returns a number
30
30
  *
31
31
  * @example
32
- * ```typescript
32
+ * ```js
33
33
  * math.abs(5) // Returns: 5
34
34
  * math.abs(-5) // Returns: 5
35
35
  * math.abs(0) // Returns: 0
@@ -50,7 +50,7 @@ export declare function abs(value: float): float;
50
50
  * - If value is a Series, returns a Series; if value is a number, returns a number
51
51
  *
52
52
  * @example
53
- * ```typescript
53
+ * ```js
54
54
  * math.ceil(4.2) // Returns: 5
55
55
  * math.ceil(4.8) // Returns: 5
56
56
  * math.ceil(-4.2) // Returns: -4
@@ -72,7 +72,7 @@ export declare function ceil(value: float): int;
72
72
  * - If value is a Series, returns a Series; if value is a number, returns a number
73
73
  *
74
74
  * @example
75
- * ```typescript
75
+ * ```js
76
76
  * math.floor(4.2) // Returns: 4
77
77
  * math.floor(4.8) // Returns: 4
78
78
  * math.floor(-4.2) // Returns: -5
@@ -102,7 +102,7 @@ export declare function floor(value: float): int;
102
102
  * - an infinite value gives na
103
103
  *
104
104
  * @example
105
- * ```typescript
105
+ * ```js
106
106
  * math.round(4.2) // Returns: 4
107
107
  * math.round(4.5) // Returns: 5
108
108
  * math.round(-2.5) // Returns: -3
@@ -132,7 +132,7 @@ export declare function round(value: float, precision?: int): float;
132
132
  * - the same expression with a series operand (`close / 255`) is not rounded: do not wrap it
133
133
  *
134
134
  * @example
135
- * ```typescript
135
+ * ```js
136
136
  * // Pine: var const float i_255 = 1 / 255
137
137
  * const i_255 = math.constant(1 / 255) // 0.003921568627451 (JavaScript: 0.00392156862745098)
138
138
  * math.constant(1 / 7) // 0.1428571428571428 (JavaScript: 0.14285714285714285)
@@ -153,7 +153,7 @@ export declare function constant(value: float): float;
153
153
  * - If any argument is a Series, returns a Series; otherwise returns a number
154
154
  *
155
155
  * @example
156
- * ```typescript
156
+ * ```js
157
157
  * math.max(1, 2, 3) // Returns: 3
158
158
  * math.max(-1, -5, -2) // Returns: -1
159
159
  * math.max(10) // Returns: 10
@@ -174,7 +174,7 @@ export declare function max(...values: (float | Series)[]): float | Series;
174
174
  * - If any argument is a Series, returns a Series; otherwise returns a number
175
175
  *
176
176
  * @example
177
- * ```typescript
177
+ * ```js
178
178
  * math.min(1, 2, 3) // Returns: 1
179
179
  * math.min(-1, -5, -2) // Returns: -5
180
180
  * math.min(10) // Returns: 10
@@ -196,7 +196,7 @@ export declare function min(...values: (float | Series)[]): float | Series;
196
196
  * pending correction is subtracted before the division (math.avg(0.1, 0.2, 0.3) = 0.19999999999999998)
197
197
  *
198
198
  * @example
199
- * ```typescript
199
+ * ```js
200
200
  * math.avg(1, 2, 3) // Returns: 2
201
201
  * math.avg(10, 20) // Returns: 15
202
202
  * math.avg(5) // Returns: 5
@@ -221,7 +221,7 @@ export declare function avg(...values: (float | Series)[]): float | Series;
221
221
  * gives the sum of the last `length` earlier values
222
222
  *
223
223
  * @example
224
- * ```typescript
224
+ * ```js
225
225
  * math.sum([1, 2, 3, 4, 5], 3) // Returns: [NaN, NaN, 6, 9, 12]
226
226
  * // Explanation: [NaN, NaN, 1+2+3, 2+3+4, 3+4+5]
227
227
  * ```
@@ -240,7 +240,7 @@ export declare function sum(source: series_float, length: simple_int | ArrayLike
240
240
  * - If value is a Series, returns a Series; if value is a number, returns a number
241
241
  *
242
242
  * @example
243
- * ```typescript
243
+ * ```js
244
244
  * math.sqrt(9) // Returns: 3
245
245
  * math.sqrt(16) // Returns: 4
246
246
  * math.sqrt(2) // Returns: 1.414...
@@ -263,7 +263,7 @@ export declare function sqrt(value: float): float;
263
263
  * - If any argument is a Series, returns a Series; if all are numbers, returns a number
264
264
  *
265
265
  * @example
266
- * ```typescript
266
+ * ```js
267
267
  * math.pow(2, 3) // Returns: 8 (2³)
268
268
  * math.pow(10, 2) // Returns: 100
269
269
  * math.pow(5, 0) // Returns: 1
@@ -287,7 +287,7 @@ export declare function pow(base: float, exponent: float): float;
287
287
  * - If value is a Series, returns a Series; if value is a number, returns a number
288
288
  *
289
289
  * @example
290
- * ```typescript
290
+ * ```js
291
291
  * math.exp(0) // Returns: 1
292
292
  * math.exp(1) // Returns: 2.71828... (e)
293
293
  * math.exp(2) // Returns: 7.389...
@@ -311,7 +311,7 @@ export declare function exp(value: float): float;
311
311
  * - If value is a Series, returns a Series; if value is a number, returns a number
312
312
  *
313
313
  * @example
314
- * ```typescript
314
+ * ```js
315
315
  * math.log(1) // Returns: 0
316
316
  * math.log(Math.E) // Returns: 1
317
317
  * math.log(10) // Returns: 2.302...
@@ -334,7 +334,7 @@ export declare function log(value: float): float;
334
334
  * - If value is a Series, returns a Series; if value is a number, returns a number
335
335
  *
336
336
  * @example
337
- * ```typescript
337
+ * ```js
338
338
  * math.log10(10) // Returns: 1
339
339
  * math.log10(100) // Returns: 2
340
340
  * math.log10(1000) // Returns: 3
@@ -357,7 +357,7 @@ export declare function log10(value: float): float;
357
357
  * - If value is a Series, returns a Series; if value is a number, returns a number
358
358
  *
359
359
  * @example
360
- * ```typescript
360
+ * ```js
361
361
  * math.sin(0) // Returns: 0
362
362
  * math.sin(Math.PI / 2) // Returns: 1
363
363
  * math.sin(Math.PI) // Returns: 0 (approximately)
@@ -380,7 +380,7 @@ export declare function sin(value: float): float;
380
380
  * - If value is a Series, returns a Series; if value is a number, returns a number
381
381
  *
382
382
  * @example
383
- * ```typescript
383
+ * ```js
384
384
  * math.cos(0) // Returns: 1
385
385
  * math.cos(Math.PI / 2) // Returns: 0 (approximately)
386
386
  * math.cos(Math.PI) // Returns: -1
@@ -403,7 +403,7 @@ export declare function cos(value: float): float;
403
403
  * - If value is a Series, returns a Series; if value is a number, returns a number
404
404
  *
405
405
  * @example
406
- * ```typescript
406
+ * ```js
407
407
  * math.tan(0) // Returns: 0
408
408
  * math.tan(Math.PI / 4) // Returns: 1
409
409
  * math.tan(Math.PI / 6) // Returns: 0.577... (1/√3)
@@ -425,7 +425,7 @@ export declare function tan(value: float): float;
425
425
  * - If value is a Series, returns a Series; if value is a number, returns a number
426
426
  *
427
427
  * @example
428
- * ```typescript
428
+ * ```js
429
429
  * math.asin(0) // Returns: 0
430
430
  * math.asin(1) // Returns: 1.5707... (π/2)
431
431
  * math.asin(0.5) // Returns: 0.5235... (π/6)
@@ -448,7 +448,7 @@ export declare function asin(value: float): float;
448
448
  * - If value is a Series, returns a Series; if value is a number, returns a number
449
449
  *
450
450
  * @example
451
- * ```typescript
451
+ * ```js
452
452
  * math.acos(1) // Returns: 0
453
453
  * math.acos(0) // Returns: 1.5707... (π/2)
454
454
  * math.acos(0.5) // Returns: 1.0471... (π/3)
@@ -471,7 +471,7 @@ export declare function acos(value: float): float;
471
471
  * - If value is a Series, returns a Series; if value is a number, returns a number
472
472
  *
473
473
  * @example
474
- * ```typescript
474
+ * ```js
475
475
  * math.atan(0) // Returns: 0
476
476
  * math.atan(1) // Returns: 0.7853... (π/4)
477
477
  * math.atan(-1) // Returns: -0.7853... (-π/4)
@@ -493,7 +493,7 @@ export declare function atan(value: float): float;
493
493
  * - If degrees is a Series, returns a Series; if degrees is a number, returns a number
494
494
  *
495
495
  * @example
496
- * ```typescript
496
+ * ```js
497
497
  * math.toradians(0) // Returns: 0
498
498
  * math.toradians(90) // Returns: 1.5707... (π/2)
499
499
  * math.toradians(180) // Returns: 3.1415... (π)
@@ -515,7 +515,7 @@ export declare function toradians(degrees: float): float;
515
515
  * - If radians is a Series, returns a Series; if radians is a number, returns a number
516
516
  *
517
517
  * @example
518
- * ```typescript
518
+ * ```js
519
519
  * math.todegrees(0) // Returns: 0
520
520
  * math.todegrees(Math.PI / 2) // Returns: 90
521
521
  * math.todegrees(Math.PI) // Returns: 180
@@ -525,8 +525,17 @@ export declare function toradians(degrees: float): float;
525
525
  export declare function todegrees(radians: Series): Series;
526
526
  export declare function todegrees(radians: float): float;
527
527
  /**
528
- * PineScript's seeded generator: Java's linear congruential generator (`java.util.Random`), `nextDouble()`.
529
- * Each generator draws one number per call.
528
+ * Makes a repeatable random number generator: the same seed always gives the same sequence of numbers (the
529
+ * sequence of `math.random(min, max, seed)`). Each call of the generator draws the next number. In a script, prefer
530
+ * `math.random(min, max, seed)`.
531
+ * @param seed - Whole number that picks the sequence.
532
+ * @returns A function `(min?, max?)` that gives the next number, from `min` (included, default 0) to `max`
533
+ * (excluded, default 1).
534
+ * @example
535
+ * ```js
536
+ * const draw = math.seededRandom(42);
537
+ * const first = draw(0, 100);
538
+ * ```
530
539
  */
531
540
  export declare function seededRandom(seed: int): (min?: float, max?: float) => float;
532
541
  /** Starts every seeded sequence of `math.random` again (called at the start of a script run). */
@@ -551,7 +560,7 @@ export declare function restoreRandom(saved: Map<number, (min?: float, max?: flo
551
560
  * with the same seed use `callsite.random(seed)`
552
561
  *
553
562
  * @example
554
- * ```typescript
563
+ * ```js
555
564
  * math.random() // Returns: value between 0 and 1 (e.g., 0.234...)
556
565
  * math.random(0, 10) // Returns: value between 0 and 10 (e.g., 7.45...)
557
566
  * math.random(0, 1, 42) // Returns: 0.7275636800328681 on the first call, as PineScript
@@ -573,7 +582,7 @@ export declare function random(min?: float, max?: float, seed?: int): float;
573
582
  * - If value is a Series, returns a Series; if value is a number, returns a number
574
583
  *
575
584
  * @example
576
- * ```typescript
585
+ * ```js
577
586
  * math.sign(5) // Returns: 1
578
587
  * math.sign(-3) // Returns: -1
579
588
  * math.sign(0) // Returns: 0
@@ -584,15 +593,15 @@ export declare function random(min?: float, max?: float, seed?: int): float;
584
593
  export declare function sign(value: Series): Series;
585
594
  export declare function sign(value: float): int;
586
595
  /**
587
- * Rounds a value to the nearest mintick.
596
+ * Rounds a price to the nearest tick, the smallest price step of the symbol (`syminfo.mintick`). Use it for levels
597
+ * that must be real prices (a stop, a target).
588
598
  *
589
- * @param number - The number to round or Series
590
- * @param mintick - Optional mintick value (defaults to requiring syminfo context)
591
- * @returns The number rounded to tick precision
599
+ * @param number - The price to round: a number or a Series
600
+ * @param mintick - The tick size, e.g. 0.01. Default in a script: the chart symbol's tick (`syminfo.mintick`);
601
+ * called outside a script it is required (it throws without it)
602
+ * @returns The value rounded to the tick: a Series for a Series, a number for a number
592
603
  *
593
604
  * @remarks
594
- * - **PineScript v6 signature**: `math.round_to_mintick(number)` - uses implicit syminfo.mintick
595
- * - **JavaScript signature**: Requires explicit `mintick` OR use `createContext()` with syminfo
596
605
  * - Rounds to the nearest value divisible by mintick
597
606
  * - Returns NaN for NaN input
598
607
  * - If number is a Series, returns a Series; if number is a float, returns a float
@@ -604,20 +613,20 @@ export declare function sign(value: float): int;
604
613
  * (-1.075 -> -1.08, 1.005 -> 1.01, 2.675 -> 2.68 at mintick 0.01)
605
614
  *
606
615
  * @example
607
- * ```typescript
608
- * // Direct call with explicit mintick
609
- * const rounded = math.round_to_mintick(1.2345, 0.01); // Returns: 1.23
610
- * const rounded2 = math.round_to_mintick(1.2367, 0.01); // Returns: 1.24
611
- *
612
- * // Or use context API for cleaner syntax
613
- * const { math } = createContext({ syminfo: { mintick: 0.01 } });
614
- * const rounded = math.round_to_mintick(1.2345); // Returns: 1.23
616
+ * ```js
617
+ * const stop = math.round_to_mintick(low.mul(0.98));
618
+ * plot(stop, "Stop");
619
+ * math.round_to_mintick(1.2345, 0.01) // Returns: 1.23
615
620
  * ```
616
621
  */
617
622
  export declare function round_to_mintick(number: Series, mintick?: float): Series;
618
623
  export declare function round_to_mintick(number: float, mintick?: float): float;
624
+ /** Pi, the ratio of a circle's circumference to its diameter: 3.141592653589793. */
619
625
  export declare const pi: number;
626
+ /** Euler's number e, the base of natural logarithms (`math.log`): 2.718281828459045. */
620
627
  export declare const e: number;
628
+ /** The golden ratio: 1.618033988749895. */
621
629
  export declare const phi = 1.618033988749895;
630
+ /** The reciprocal of the golden ratio (1 / phi): 0.6180339887498948. */
622
631
  export declare const rphi = 0.6180339887498948;
623
632
  //# sourceMappingURL=index.d.ts.map