oakscriptjs 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/README.md +25 -1
  2. package/bin/oakscript.mjs +10 -3
  3. package/dist/cjs/box/index.d.ts +348 -289
  4. package/dist/cjs/box/index.d.ts.map +1 -1
  5. package/dist/cjs/box/index.js.map +2 -2
  6. package/dist/cjs/check/node.d.ts.map +1 -1
  7. package/dist/cjs/check/node.js +1 -0
  8. package/dist/cjs/check/node.js.map +2 -2
  9. package/dist/cjs/check/preview.d.ts +31 -0
  10. package/dist/cjs/check/preview.d.ts.map +1 -0
  11. package/dist/cjs/check/preview.js +303 -0
  12. package/dist/cjs/check/preview.js.map +7 -0
  13. package/dist/cjs/color/index.d.ts +11 -11
  14. package/dist/cjs/color/index.js.map +1 -1
  15. package/dist/cjs/color/parse.d.ts +2 -0
  16. package/dist/cjs/color/parse.d.ts.map +1 -1
  17. package/dist/cjs/color/parse.js +6 -0
  18. package/dist/cjs/color/parse.js.map +2 -2
  19. package/dist/cjs/compare/index.d.ts +76 -12
  20. package/dist/cjs/compare/index.d.ts.map +1 -1
  21. package/dist/cjs/compare/index.js.map +2 -2
  22. package/dist/cjs/drawing/registry.d.ts +28 -5
  23. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  24. package/dist/cjs/drawing/registry.js +14 -0
  25. package/dist/cjs/drawing/registry.js.map +2 -2
  26. package/dist/cjs/index.d.ts +1 -1
  27. package/dist/cjs/index.js +1 -1
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/label/index.d.ts +265 -187
  30. package/dist/cjs/label/index.d.ts.map +1 -1
  31. package/dist/cjs/label/index.js +1 -1
  32. package/dist/cjs/label/index.js.map +2 -2
  33. package/dist/cjs/line/index.d.ts +247 -207
  34. package/dist/cjs/line/index.d.ts.map +1 -1
  35. package/dist/cjs/line/index.js.map +2 -2
  36. package/dist/cjs/linefill/index.d.ts +61 -89
  37. package/dist/cjs/linefill/index.d.ts.map +1 -1
  38. package/dist/cjs/linefill/index.js.map +2 -2
  39. package/dist/cjs/math/index.d.ts +49 -40
  40. package/dist/cjs/math/index.d.ts.map +1 -1
  41. package/dist/cjs/math/index.js.map +2 -2
  42. package/dist/cjs/polyline/index.d.ts +57 -78
  43. package/dist/cjs/polyline/index.d.ts.map +1 -1
  44. package/dist/cjs/polyline/index.js.map +2 -2
  45. package/dist/cjs/runtime/input-active.d.ts +2 -2
  46. package/dist/cjs/runtime/input-active.js.map +1 -1
  47. package/dist/cjs/runtime/series.d.ts +241 -161
  48. package/dist/cjs/runtime/series.d.ts.map +1 -1
  49. package/dist/cjs/runtime/series.js +223 -127
  50. package/dist/cjs/runtime/series.js.map +2 -2
  51. package/dist/cjs/script/api/alert.d.ts +37 -0
  52. package/dist/cjs/script/api/alert.d.ts.map +1 -0
  53. package/dist/cjs/script/api/alert.js +17 -0
  54. package/dist/cjs/script/api/alert.js.map +7 -0
  55. package/dist/cjs/script/api/calc.d.ts +232 -0
  56. package/dist/cjs/script/api/calc.d.ts.map +1 -0
  57. package/dist/cjs/script/api/calc.js +17 -0
  58. package/dist/cjs/script/api/calc.js.map +7 -0
  59. package/dist/cjs/script/api/color.d.ts +213 -0
  60. package/dist/cjs/script/api/color.d.ts.map +1 -0
  61. package/dist/cjs/script/api/color.js +17 -0
  62. package/dist/cjs/script/api/color.js.map +7 -0
  63. package/dist/cjs/script/api/context.d.ts +764 -0
  64. package/dist/cjs/script/api/context.d.ts.map +1 -0
  65. package/dist/cjs/script/api/context.js +17 -0
  66. package/dist/cjs/script/api/context.js.map +7 -0
  67. package/dist/cjs/script/api/log.d.ts +58 -0
  68. package/dist/cjs/script/api/log.d.ts.map +1 -0
  69. package/dist/cjs/script/api/log.js +17 -0
  70. package/dist/cjs/script/api/log.js.map +7 -0
  71. package/dist/cjs/script/api/strategy.d.ts +391 -0
  72. package/dist/cjs/script/api/strategy.d.ts.map +1 -0
  73. package/dist/cjs/script/api/strategy.js +17 -0
  74. package/dist/cjs/script/api/strategy.js.map +7 -0
  75. package/dist/cjs/script/api/ta.d.ts +1012 -0
  76. package/dist/cjs/script/api/ta.d.ts.map +1 -0
  77. package/dist/cjs/script/api/ta.js +17 -0
  78. package/dist/cjs/script/api/ta.js.map +7 -0
  79. package/dist/cjs/script/api/table.d.ts +479 -0
  80. package/dist/cjs/script/api/table.d.ts.map +1 -0
  81. package/dist/cjs/script/api/table.js +17 -0
  82. package/dist/cjs/script/api/table.js.map +7 -0
  83. package/dist/cjs/script/constants.d.ts +228 -83
  84. package/dist/cjs/script/constants.d.ts.map +1 -1
  85. package/dist/cjs/script/constants.js +87 -0
  86. package/dist/cjs/script/constants.js.map +2 -2
  87. package/dist/cjs/script/define.d.ts +94 -0
  88. package/dist/cjs/script/define.d.ts.map +1 -0
  89. package/dist/cjs/script/define.js +127 -0
  90. package/dist/cjs/script/define.js.map +7 -0
  91. package/dist/cjs/script/drawing-args.d.ts.map +1 -1
  92. package/dist/cjs/script/drawing-args.js +1 -1
  93. package/dist/cjs/script/drawing-args.js.map +2 -2
  94. package/dist/cjs/script/formula.d.ts +53 -0
  95. package/dist/cjs/script/formula.d.ts.map +1 -0
  96. package/dist/cjs/script/formula.js +402 -0
  97. package/dist/cjs/script/formula.js.map +7 -0
  98. package/dist/cjs/script/globals.d.ts +10 -0
  99. package/dist/cjs/script/globals.d.ts.map +1 -1
  100. package/dist/cjs/script/globals.js.map +1 -1
  101. package/dist/cjs/script/index.d.ts +1065 -1006
  102. package/dist/cjs/script/index.d.ts.map +1 -1
  103. package/dist/cjs/script/index.js +530 -60
  104. package/dist/cjs/script/index.js.map +3 -3
  105. package/dist/cjs/script/json.d.ts +117 -0
  106. package/dist/cjs/script/json.d.ts.map +1 -0
  107. package/dist/cjs/script/json.js +321 -0
  108. package/dist/cjs/script/json.js.map +7 -0
  109. package/dist/cjs/str/index.d.ts +50 -75
  110. package/dist/cjs/str/index.d.ts.map +1 -1
  111. package/dist/cjs/str/index.js +2 -2
  112. package/dist/cjs/str/index.js.map +2 -2
  113. package/dist/cjs/strategy/index.d.ts +102 -1
  114. package/dist/cjs/strategy/index.d.ts.map +1 -1
  115. package/dist/cjs/strategy/index.js.map +2 -2
  116. package/dist/cjs/table/index.d.ts +330 -49
  117. package/dist/cjs/table/index.d.ts.map +1 -1
  118. package/dist/cjs/table/index.js +55 -27
  119. package/dist/cjs/table/index.js.map +2 -2
  120. package/dist/cjs/text/index.d.ts +12 -14
  121. package/dist/cjs/text/index.d.ts.map +1 -1
  122. package/dist/cjs/text/index.js.map +2 -2
  123. package/dist/cjs/types/index.d.ts +15 -8
  124. package/dist/cjs/types/index.d.ts.map +1 -1
  125. package/dist/cjs/types/index.js +12 -3
  126. package/dist/cjs/types/index.js.map +2 -2
  127. package/dist/esm/box/index.d.ts +348 -289
  128. package/dist/esm/box/index.d.ts.map +1 -1
  129. package/dist/esm/box/index.js +276 -276
  130. package/dist/esm/box/index.js.map +1 -1
  131. package/dist/esm/check/node.d.ts.map +1 -1
  132. package/dist/esm/check/node.js +1 -0
  133. package/dist/esm/check/node.js.map +1 -1
  134. package/dist/esm/check/preview.d.ts +31 -0
  135. package/dist/esm/check/preview.d.ts.map +1 -0
  136. package/dist/esm/check/preview.js +296 -0
  137. package/dist/esm/check/preview.js.map +1 -0
  138. package/dist/esm/color/index.d.ts +11 -11
  139. package/dist/esm/color/index.js +11 -11
  140. package/dist/esm/color/parse.d.ts +2 -0
  141. package/dist/esm/color/parse.d.ts.map +1 -1
  142. package/dist/esm/color/parse.js +7 -0
  143. package/dist/esm/color/parse.js.map +1 -1
  144. package/dist/esm/compare/index.d.ts +76 -12
  145. package/dist/esm/compare/index.d.ts.map +1 -1
  146. package/dist/esm/compare/index.js +76 -12
  147. package/dist/esm/compare/index.js.map +1 -1
  148. package/dist/esm/drawing/registry.d.ts +28 -5
  149. package/dist/esm/drawing/registry.d.ts.map +1 -1
  150. package/dist/esm/drawing/registry.js +39 -3
  151. package/dist/esm/drawing/registry.js.map +1 -1
  152. package/dist/esm/index.d.ts +1 -1
  153. package/dist/esm/index.js +1 -1
  154. package/dist/esm/label/index.d.ts +265 -187
  155. package/dist/esm/label/index.d.ts.map +1 -1
  156. package/dist/esm/label/index.js +207 -177
  157. package/dist/esm/label/index.js.map +1 -1
  158. package/dist/esm/line/index.d.ts +247 -207
  159. package/dist/esm/line/index.d.ts.map +1 -1
  160. package/dist/esm/line/index.js +202 -194
  161. package/dist/esm/line/index.js.map +1 -1
  162. package/dist/esm/linefill/index.d.ts +61 -89
  163. package/dist/esm/linefill/index.d.ts.map +1 -1
  164. package/dist/esm/linefill/index.js +61 -89
  165. package/dist/esm/linefill/index.js.map +1 -1
  166. package/dist/esm/math/index.d.ts +49 -40
  167. package/dist/esm/math/index.d.ts.map +1 -1
  168. package/dist/esm/math/index.js +22 -9
  169. package/dist/esm/math/index.js.map +1 -1
  170. package/dist/esm/polyline/index.d.ts +57 -78
  171. package/dist/esm/polyline/index.d.ts.map +1 -1
  172. package/dist/esm/polyline/index.js +57 -78
  173. package/dist/esm/polyline/index.js.map +1 -1
  174. package/dist/esm/runtime/input-active.d.ts +2 -2
  175. package/dist/esm/runtime/input-active.js +2 -2
  176. package/dist/esm/runtime/series.d.ts +241 -161
  177. package/dist/esm/runtime/series.d.ts.map +1 -1
  178. package/dist/esm/runtime/series.js +241 -161
  179. package/dist/esm/runtime/series.js.map +1 -1
  180. package/dist/esm/script/api/alert.d.ts +37 -0
  181. package/dist/esm/script/api/alert.d.ts.map +1 -0
  182. package/dist/esm/script/api/alert.js +7 -0
  183. package/dist/esm/script/api/alert.js.map +1 -0
  184. package/dist/esm/script/api/calc.d.ts +232 -0
  185. package/dist/esm/script/api/calc.d.ts.map +1 -0
  186. package/dist/esm/script/api/calc.js +6 -0
  187. package/dist/esm/script/api/calc.js.map +1 -0
  188. package/dist/esm/script/api/color.d.ts +213 -0
  189. package/dist/esm/script/api/color.d.ts.map +1 -0
  190. package/dist/esm/script/api/color.js +6 -0
  191. package/dist/esm/script/api/color.js.map +1 -0
  192. package/dist/esm/script/api/context.d.ts +764 -0
  193. package/dist/esm/script/api/context.d.ts.map +1 -0
  194. package/dist/esm/script/api/context.js +7 -0
  195. package/dist/esm/script/api/context.js.map +1 -0
  196. package/dist/esm/script/api/log.d.ts +58 -0
  197. package/dist/esm/script/api/log.d.ts.map +1 -0
  198. package/dist/esm/script/api/log.js +6 -0
  199. package/dist/esm/script/api/log.js.map +1 -0
  200. package/dist/esm/script/api/strategy.d.ts +391 -0
  201. package/dist/esm/script/api/strategy.d.ts.map +1 -0
  202. package/dist/esm/script/api/strategy.js +7 -0
  203. package/dist/esm/script/api/strategy.js.map +1 -0
  204. package/dist/esm/script/api/ta.d.ts +1012 -0
  205. package/dist/esm/script/api/ta.d.ts.map +1 -0
  206. package/dist/esm/script/api/ta.js +6 -0
  207. package/dist/esm/script/api/ta.js.map +1 -0
  208. package/dist/esm/script/api/table.d.ts +479 -0
  209. package/dist/esm/script/api/table.d.ts.map +1 -0
  210. package/dist/esm/script/api/table.js +7 -0
  211. package/dist/esm/script/api/table.js.map +1 -0
  212. package/dist/esm/script/constants.d.ts +228 -83
  213. package/dist/esm/script/constants.d.ts.map +1 -1
  214. package/dist/esm/script/constants.js +110 -24
  215. package/dist/esm/script/constants.js.map +1 -1
  216. package/dist/esm/script/define.d.ts +94 -0
  217. package/dist/esm/script/define.d.ts.map +1 -0
  218. package/dist/esm/script/define.js +136 -0
  219. package/dist/esm/script/define.js.map +1 -0
  220. package/dist/esm/script/drawing-args.d.ts.map +1 -1
  221. package/dist/esm/script/drawing-args.js +2 -1
  222. package/dist/esm/script/drawing-args.js.map +1 -1
  223. package/dist/esm/script/formula.d.ts +53 -0
  224. package/dist/esm/script/formula.d.ts.map +1 -0
  225. package/dist/esm/script/formula.js +408 -0
  226. package/dist/esm/script/formula.js.map +1 -0
  227. package/dist/esm/script/globals.d.ts +10 -0
  228. package/dist/esm/script/globals.d.ts.map +1 -1
  229. package/dist/esm/script/globals.js.map +1 -1
  230. package/dist/esm/script/index.d.ts +1065 -1006
  231. package/dist/esm/script/index.d.ts.map +1 -1
  232. package/dist/esm/script/index.js +1096 -151
  233. package/dist/esm/script/index.js.map +1 -1
  234. package/dist/esm/script/json.d.ts +117 -0
  235. package/dist/esm/script/json.d.ts.map +1 -0
  236. package/dist/esm/script/json.js +375 -0
  237. package/dist/esm/script/json.js.map +1 -0
  238. package/dist/esm/str/index.d.ts +50 -75
  239. package/dist/esm/str/index.d.ts.map +1 -1
  240. package/dist/esm/str/index.js +51 -76
  241. package/dist/esm/str/index.js.map +1 -1
  242. package/dist/esm/strategy/index.d.ts +102 -1
  243. package/dist/esm/strategy/index.d.ts.map +1 -1
  244. package/dist/esm/strategy/index.js +1 -1
  245. package/dist/esm/strategy/index.js.map +1 -1
  246. package/dist/esm/table/index.d.ts +330 -49
  247. package/dist/esm/table/index.d.ts.map +1 -1
  248. package/dist/esm/table/index.js +372 -61
  249. package/dist/esm/table/index.js.map +1 -1
  250. package/dist/esm/text/index.d.ts +12 -14
  251. package/dist/esm/text/index.d.ts.map +1 -1
  252. package/dist/esm/text/index.js +12 -14
  253. package/dist/esm/text/index.js.map +1 -1
  254. package/dist/esm/types/index.d.ts +15 -8
  255. package/dist/esm/types/index.d.ts.map +1 -1
  256. package/dist/esm/types/index.js +15 -8
  257. package/dist/esm/types/index.js.map +1 -1
  258. package/docs/first-indicator.md +152 -0
  259. package/docs/guide.md +1185 -0
  260. package/docs/inventory.md +772 -0
  261. package/docs/no-code.md +207 -0
  262. package/docs/recipes.md +202 -0
  263. package/package.json +2 -1
  264. package/skills/oakscript/SKILL.md +8 -0
  265. package/skills/oakscript/reference/errors.md +3 -2
  266. package/src/box/index.ts +348 -289
  267. package/src/check/node.ts +1 -0
  268. package/src/check/preview.ts +307 -0
  269. package/src/color/index.ts +11 -11
  270. package/src/color/parse.ts +7 -0
  271. package/src/compare/index.ts +76 -12
  272. package/src/drawing/registry.ts +44 -5
  273. package/src/index.ts +1 -1
  274. package/src/label/index.ts +267 -189
  275. package/src/line/index.ts +248 -208
  276. package/src/linefill/index.ts +61 -89
  277. package/src/math/index.ts +51 -42
  278. package/src/polyline/index.ts +57 -78
  279. package/src/runtime/input-active.ts +2 -2
  280. package/src/runtime/series.ts +243 -163
  281. package/src/script/api/alert.ts +43 -0
  282. package/src/script/api/calc.ts +250 -0
  283. package/src/script/api/color.ts +245 -0
  284. package/src/script/api/context.ts +944 -0
  285. package/src/script/api/log.ts +60 -0
  286. package/src/script/api/strategy.ts +410 -0
  287. package/src/script/api/ta.ts +1115 -0
  288. package/src/script/api/table.ts +538 -0
  289. package/src/script/constants.ts +229 -25
  290. package/src/script/define.ts +221 -0
  291. package/src/script/drawing-args.ts +2 -1
  292. package/src/script/formula.ts +438 -0
  293. package/src/script/globals.ts +10 -0
  294. package/src/script/index.ts +1517 -239
  295. package/src/script/json.ts +457 -0
  296. package/src/str/index.ts +51 -76
  297. package/src/strategy/index.ts +102 -1
  298. package/src/table/index.ts +388 -62
  299. package/src/text/index.ts +12 -14
  300. package/src/types/index.ts +15 -8
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/runtime/series.ts"],
4
- "sourcesContent": ["/**\n * @fileoverview Simplified Series class for lazy time-series computation\n * Represents a time-series of values with lazy evaluation\n * @module runtime/series\n */\n\nimport * as compare from '../compare/index.js';\nimport type { Bar } from '../types/index.js';\n\n/**\n * Function that computes a value for each bar\n */\nexport type SeriesExtractor = (bar: Bar, index: number, data: Bar[]) => number;\n\n/**\n * BarData - Versioned wrapper around Bar[] array for cache invalidation\n * \n * This class wraps a Bar[] array and tracks a version number that increments\n * whenever the data is mutated. Series objects reference this to detect when\n * their cached values need to be recomputed.\n * \n * @example\n * ```typescript\n * const barData = new BarData(bars);\n * const close = Series.fromBars(barData, 'close');\n * const values1 = close.toArray(); // Computes and caches\n * \n * barData.push(newBar); // Increments version\n * const values2 = close.toArray(); // Detects stale cache, recomputes\n * ```\n */\nexport class BarData {\n private _bars: Bar[];\n private _version: number = 0;\n\n /**\n * Create a new BarData wrapper\n * @param bars - Initial bar data (defaults to empty array)\n */\n constructor(bars: Bar[] = []) {\n this._bars = bars;\n }\n\n /**\n * Get the current version number\n * Version increments whenever data is mutated\n */\n get version(): number {\n return this._version;\n }\n\n /**\n * Get the underlying bar array\n * Note: Direct mutations to this array will NOT increment version\n * Use the provided mutation methods instead\n */\n get bars(): Bar[] {\n return this._bars;\n }\n\n /**\n * Get the number of bars\n */\n get length(): number {\n return this._bars.length;\n }\n\n /**\n * Add a new bar to the end\n * @param bar - Bar to add\n */\n push(bar: Bar): void {\n this._bars.push(bar);\n this._version++;\n }\n\n /**\n * Remove and return the last bar\n * @returns The removed bar, or undefined if empty\n */\n pop(): Bar | undefined {\n const bar = this._bars.pop();\n if (bar !== undefined) {\n this._version++;\n }\n return bar;\n }\n\n /**\n * Replace a bar at a specific index\n * @param index - Index to update\n * @param bar - New bar data\n */\n set(index: number, bar: Bar): void {\n if (index >= 0 && index < this._bars.length) {\n this._bars[index] = bar;\n this._version++;\n }\n }\n\n /**\n * Update the last bar (useful for real-time/streaming updates)\n * @param bar - New bar data\n */\n updateLast(bar: Bar): void {\n if (this._bars.length > 0) {\n this._bars[this._bars.length - 1] = bar;\n this._version++;\n }\n }\n\n /**\n * Replace all bars with new data\n * @param bars - New bar array\n */\n setAll(bars: Bar[]): void {\n this._bars = bars;\n this._version++;\n }\n\n /**\n * Manually increment version (for advanced use cases)\n * Call this after direct mutations to the bars array\n */\n invalidate(): void {\n this._version++;\n }\n\n /**\n * Get a bar at a specific index\n * @param index - Bar index\n * @returns Bar at that index, or undefined\n */\n at(index: number): Bar | undefined {\n return this._bars[index];\n }\n\n /**\n * Create a BarData from an existing Bar array\n * @param bars - Bar array\n * @returns New BarData instance\n */\n static from(bars: Bar[]): BarData {\n return new BarData(bars);\n }\n}\n\n/**\n * Series - represents a time-series of values with lazy evaluation\n *\n * Series are lazy - they don't compute values until needed.\n * Operations on Series return new Series with composed extractors.\n *\n * Now supports automatic cache invalidation via BarData versioning\n * and memory-efficient closure chain breaking via materialize().\n *\n * @example\n * ```typescript\n * // Basic usage (backward compatible)\n * const close = Series.fromBars(bars, 'close');\n * const open = Series.fromBars(bars, 'open');\n * const range = close.sub(open); // Creates new Series, doesn't compute yet\n * const values = range.toArray(); // Now computes for all bars\n * \n * // With automatic cache invalidation\n * const barData = new BarData(bars);\n * const close = Series.fromBars(barData, 'close');\n * const values1 = close.toArray(); // Computes and caches\n * barData.push(newBar); // Version increments\n * const values2 = close.toArray(); // Detects stale cache, recomputes\n * \n * // Breaking closure chains for memory efficiency\n * const complex = a.add(b).mul(c).div(d).sub(e);\n * const materialized = complex.materialize(); // Breaks closure chain\n * ```\n */\n/** Largest history reference of a script series (PineScript max_bars_back limit). */\nexport const MAX_BARS_BACK = 5000;\n\n/** PineScript's runtime error RE10008 text. */\nexport function historyError(bar: number, barsBack: number): string {\n return (\n `Error on bar ${bar}: The script attempts to reference historical data that is too far from the current bar ` +\n `(${barsBack} bars back). The history-referencing length for the expression must be a value between 0 and ${MAX_BARS_BACK}.`\n );\n}\n\n/**\n * Hooks of an incremental script run (#196, set by the script runtime during a run only): a Series created by the\n * script gets a slot, and toArray() reuses the values of the previous run up to the first bar that changed.\n * @internal\n */\nexport interface SeriesRunHooks {\n created(series: Series): void;\n /** The values of the previous run (indexes below `from` are kept; the array is reused), or null to compute every bar */\n prefix(series: Series, bars: readonly Bar[]): { values: number[]; from: number } | null;\n computed(series: Series, values: number[]): void;\n}\n\nlet runHooks: SeriesRunHooks | null = null;\n\n/** @internal */\nexport function setSeriesRunHooks(hooks: SeriesRunHooks | null): void {\n runHooks = hooks;\n}\n\nexport class Series {\n private extractor: SeriesExtractor;\n private dataSource: BarData;\n private cached: number[] | null = null;\n private cachedVersion: number = -1;\n\n /**\n * Create a new Series\n *\n * @param data - Bar data (Bar[] or BarData)\n * @param extractor - Function to extract/compute value for each bar\n */\n /**\n * True for PineScript's built-in price variables (open, high, low, close, volume, hl2...): their history covers\n * every bar, so references further than 5000 bars back are allowed (measured: close[bar_index] runs).\n */\n fullHistory = false;\n\n constructor(data: Bar[] | BarData, extractor: SeriesExtractor) {\n // Support both Bar[] and BarData for backward compatibility\n this.dataSource = data instanceof BarData ? data : new BarData(data);\n this.extractor = extractor;\n runHooks?.created(this);\n }\n\n /**\n * Get the underlying bar data\n * @returns Bar array\n */\n get bars(): Bar[] {\n return this.dataSource.bars;\n }\n\n /**\n * Get the underlying BarData source\n * @returns BarData instance\n */\n get barData(): BarData {\n return this.dataSource;\n }\n\n // ============================================\n // Static Factory Methods\n // ============================================\n\n /**\n * Create Series from bar data by extracting a specific field\n * @param bars - Bar data (Bar[] or BarData)\n * @param field - Field to extract ('open', 'high', 'low', 'close', 'volume')\n * @returns Series with extracted field values\n */\n static fromBars(bars: Bar[] | BarData, field: 'open' | 'high' | 'low' | 'close' | 'volume'): Series {\n const series = new Series(bars, (bar) => bar[field] ?? NaN);\n series.fullHistory = true;\n return series;\n }\n\n /**\n * Create a constant series (same value for all bars)\n * @param bars - Bar data (Bar[] or BarData)\n * @param value - Constant value\n * @returns Series with constant value\n */\n static constant(bars: Bar[] | BarData, value: number): Series {\n return new Series(bars, () => value);\n }\n\n /**\n * Create series from array of values\n * @param bars - Bar data (Bar[] or BarData) for time alignment\n * @param values - Array of values\n * @returns Series\n * @throws When read on other bars with a different length than `values` (e.g. a series computed on the\n * chart bars and read inside a `request.security` expression, which runs on the higher-timeframe bars)\n */\n static fromArray(bars: Bar[] | BarData, values: number[]): Series {\n const origin = bars instanceof BarData ? bars.bars : bars;\n return new Series(bars, (_bar, i, data) => {\n if (data !== origin && data.length !== values.length) {\n throw new Error(\n `Series values were computed on other bars (${values.length} values, ${data.length} bars). ` +\n 'Inside request.security(), compute the series inside the expression, e.g. () => ta.ema(close, 10).'\n );\n }\n return values[i] ?? NaN;\n });\n }\n\n // ============================================\n // Arithmetic Operations\n // ============================================\n\n /**\n * Add two series or a series and a number\n * @param other - Series or number to add\n * @returns New Series representing the sum\n */\n add(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a + b;\n });\n }\n\n /**\n * Subtract two series or subtract a number from a series\n * @param other - Series or number to subtract\n * @returns New Series representing the difference\n */\n sub(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a - b;\n });\n }\n\n /**\n * Multiply two series or a series by a number\n * @param other - Series or number to multiply\n * @returns New Series representing the product\n */\n mul(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a * b;\n });\n }\n\n /**\n * Raise the series to a power (PineScript math.pow on a series)\n * @param exponent - Series or number exponent\n * @returns New Series representing base ** exponent\n */\n pow(exponent: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof exponent === 'number' ? exponent : exponent.extractor(bar, i, data);\n return Math.pow(a, b);\n });\n }\n\n /**\n * Divide two series or a series by a number\n * @param other - Series or number to divide by\n * @returns New Series representing the quotient\n */\n div(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a / b; // PineScript: x / 0 is +/-Infinity (na() is true for it), 0 / 0 is na\n });\n }\n\n /**\n * Modulo operation\n * @param other - Series or number for modulo\n * @returns New Series representing the remainder\n */\n mod(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return b !== 0 ? a % b : NaN;\n });\n }\n\n /**\n * Negation\n * @returns New Series with negated values\n */\n neg(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n return -this.extractor(bar, i, data);\n });\n }\n\n // ============================================\n // Comparison Operations (PineScript operators: tolerance 1e-10, false with na; see src/compare)\n // ============================================\n\n /**\n * Greater than comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n gt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.gt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Greater than or equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n gte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ge(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Less than comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n lt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.lt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Less than or equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n lte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.le(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Equality comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n eq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.eq(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Not equal comparison\n * @param other - Series or number to compare\n * @returns New Series with 1 where true, 0 where false\n */\n neq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ne(a, b) ? 1 : 0;\n });\n }\n\n // ============================================\n // Logical Operations (for boolean series)\n // ============================================\n\n /**\n * Logical AND\n * @param other - Series or number (truthy/falsy)\n * @returns New Series with 1 where both true, 0 otherwise\n */\n and(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a && b ? 1 : 0;\n });\n }\n\n /**\n * Logical OR\n * @param other - Series or number (truthy/falsy)\n * @returns New Series with 1 where either true, 0 otherwise\n */\n or(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a || b ? 1 : 0;\n });\n }\n\n /**\n * Logical NOT\n * @returns New Series with inverted boolean values\n */\n not(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n return !a ? 1 : 0;\n });\n }\n\n // ============================================\n // Conditional Selection\n // ============================================\n\n /**\n * Bar-by-bar conditional selection (ternary operator for Series)\n * Uses this Series as the condition (truthy = nonzero, falsy = zero/NaN)\n *\n * @param trueValue - Value or Series to use when condition is truthy\n * @param falseValue - Value or Series to use when condition is falsy\n * @returns New Series with bar-by-bar selected values\n *\n * @example\n * ```typescript\n * // PineScript: result = condition ? trueVal : falseVal\n * const result = condition.iff(trueVal, falseVal);\n *\n * // Example: RSI formula uses ternary for edge cases\n * // rsi = down == 0 ? 100 : up == 0 ? 0 : formula\n * const rsi = down.eq(0).iff(100, up.eq(0).iff(0, formula));\n * ```\n */\n iff(trueValue: Series | number, falseValue: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const condition = this.extractor(bar, i, data);\n // Truthy: nonzero and not NaN\n const isTruthy = condition !== 0 && !Number.isNaN(condition);\n\n if (isTruthy) {\n return typeof trueValue === 'number' ? trueValue : trueValue.extractor(bar, i, data);\n } else {\n return typeof falseValue === 'number' ? falseValue : falseValue.extractor(bar, i, data);\n }\n });\n }\n\n // ============================================\n // Offset/History\n // ============================================\n\n /**\n * Access previous bars (like close[1] in PineScript)\n * @param offset - Number of bars back (0 or more)\n * @returns New Series with offset values\n * @throws RangeError when `offset` is negative\n */\n offset(offset: number): Series {\n if (offset < 0) throw new RangeError(`Series.offset(${offset}): the offset cannot be negative (it would read a future bar).`);\n // PineScript runtime error RE10008: a script series keeps at most 5000 bars of history\n if (offset > MAX_BARS_BACK && !this.fullHistory) throw new Error(historyError(0, Math.floor(offset)));\n return new Series(this.dataSource, (_bar, i, data) => {\n const targetIndex = i - offset;\n if (targetIndex < 0 || targetIndex >= data.length) {\n return NaN;\n }\n return this.extractor(data[targetIndex]!, targetIndex, data);\n });\n }\n\n // ============================================\n // Computation & Access\n // ============================================\n\n /**\n * Compute all values for the series\n * \n * Now includes automatic cache invalidation:\n * - Checks if dataSource version has changed since cache was computed\n * - Recomputes if version mismatch detected\n * - Stores version when cache is created\n * \n * @returns Array of computed values\n */\n toArray(): number[] {\n // Check if cache is valid by comparing versions\n if (this.cached !== null && this.cachedVersion === this.dataSource.version) {\n return this.cached;\n }\n\n // Recompute and update cache\n const bars = this.dataSource.bars;\n const prefix = runHooks?.prefix(this, bars) ?? null;\n if (prefix) {\n // the run's own array of the previous run: its first values are kept, the newest computed in place\n const n = bars.length;\n const values = prefix.values;\n const from = Math.min(prefix.from, n);\n values.length = n;\n for (let i = from; i < n; i++) values[i] = this.extractor(bars[i]!, i, bars);\n this.cached = values;\n } else {\n this.cached = bars.map((bar, i) => this.extractor(bar, i, bars));\n }\n this.cachedVersion = this.dataSource.version;\n runHooks?.computed(this, this.cached);\n return this.cached;\n }\n\n /**\n * Materialize this Series by eagerly computing values and breaking closure chain\n * \n * This method addresses the closure chain memory leak issue:\n * - Computes all values immediately\n * - Creates a new Series that stores values directly\n * - Breaks references to parent Series objects\n * - Useful for complex expressions to free intermediate Series memory\n * \n * @example\n * ```typescript\n * // Without materialize: keeps a, b, c, d in memory via closures\n * const result = a.add(b).mul(c).div(d).sub(e);\n * \n * // With materialize: breaks chain, frees a, b, c memory\n * const result = a.add(b).mul(c).materialize().div(d).sub(e);\n * ```\n * \n * @returns New Series with computed values and no closure dependencies\n */\n materialize(): Series {\n const values = this.toArray();\n // Create a copy of values to ensure no shared references\n const valuesCopy = [...values];\n return Series.fromArray(this.dataSource, valuesCopy);\n }\n\n /**\n * Invalidate cache (when data changes)\n * \n * Note: With BarData versioning, manual invalidation is rarely needed.\n * The cache is automatically invalidated when the underlying BarData changes.\n * This method is kept for backward compatibility and advanced use cases.\n * \n * @internal\n */\n _invalidate(): void {\n this.cached = null;\n this.cachedVersion = -1;\n }\n\n /**\n * Compute all values (alias for toArray)\n * @returns Array of computed values\n * @internal\n */\n _compute(): number[] {\n return this.toArray();\n }\n\n /**\n * Get value at specific index\n * @param index - Bar index\n * @returns Value at that index\n */\n get(index: number): number {\n const values = this.toArray();\n return values[index] ?? NaN;\n }\n\n /**\n * Get the last value (most recent bar)\n * @returns Most recent value\n */\n last(): number {\n const values = this.toArray();\n return values[values.length - 1] ?? NaN;\n }\n\n /**\n * Get number of values\n * @returns Length of series\n */\n length(): number {\n return this.dataSource.length;\n }\n\n /**\n * Convert series to time-value pairs for charting\n * @returns Array of { time, value } objects\n */\n /**\n * A Series holds the values of all the bars, so JavaScript operators cannot use it: without this guard\n * `close - open` is NaN, `close > open` false and `` `${rsi}` `` \"[object Object]\", with no error. The\n * conversion throws instead, with the Series method or bar-loop read to use.\n */\n [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): never {\n if (hint === 'string') {\n throw new TypeError(\n 'A Series is not a text: read the value of one bar inside eachBar(), e.g. str.tostring(c.get(rsi)), ' +\n 'or pass the Series itself to plot() / plotshape().'\n );\n }\n throw new TypeError(\n 'JavaScript operators (+ - * / % ** < > <= >= ==) do not work on a Series: use its methods, ' +\n 'a.add(b) a.sub(b) a.mul(b) a.div(b) a.mod(b) a.pow(b) a.neg(), a.gt(b) a.gte(b) a.lt(b) a.lte(b) a.eq(b) a.neq(b), ' +\n 'a.and(b) a.or(b) a.not(), cond.iff(x, y), a.offset(1) for a[1]; or read numbers inside eachBar() with c.get(a).'\n );\n }\n\n toTimeValuePairs(): Array<{ time: any; value: number }> {\n const values = this.toArray();\n const bars = this.dataSource.bars;\n return bars.map((bar, i) => ({\n time: bar.time,\n value: values[i]!\n })).filter(point => !Number.isNaN(point.value));\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,cAAyB;AAyBlB,MAAM,QAAQ;AAAA,EACX;AAAA,EACA,WAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,YAAY,OAAc,CAAC,GAAG;AAC5B,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,UAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAc;AAChB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAiB;AACnB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,KAAgB;AACnB,SAAK,MAAM,KAAK,GAAG;AACnB,SAAK;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAuB;AACrB,UAAM,MAAM,KAAK,MAAM,IAAI;AAC3B,QAAI,QAAQ,QAAW;AACrB,WAAK;AAAA,IACP;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAe,KAAgB;AACjC,QAAI,SAAS,KAAK,QAAQ,KAAK,MAAM,QAAQ;AAC3C,WAAK,MAAM,KAAK,IAAI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ACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,cAAoB;AAClB,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAqB;AACnB,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAuB;AACzB,UAAM,SAAS,KAAK,QAAQ;AAC5B,WAAO,OAAO,KAAK,KAAK;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAe;AACb,UAAM,SAAS,KAAK,QAAQ;AAC5B,WAAO,OAAO,OAAO,SAAS,CAAC,KAAK;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAiB;AACf,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,CAAC,OAAO,WAAW,EAAE,MAA8C;AACjE,QAAI,SAAS,UAAU;AACrB,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AAAA,EAEA,mBAAwD;AACtD,UAAM,SAAS,KAAK,QAAQ;AAC5B,UAAM,OAAO,KAAK,WAAW;AAC7B,WAAO,KAAK,IAAI,CAAC,KAAK,OAAO;AAAA,MAC3B,MAAM,IAAI;AAAA,MACV,OAAO,OAAO,CAAC;AAAA,IACjB,EAAE,EAAE,OAAO,WAAS,CAAC,OAAO,MAAM,MAAM,KAAK,CAAC;AAAA,EAChD;AACF;",
4
+ "sourcesContent": ["/**\n * @fileoverview Simplified Series class for lazy time-series computation\n * Represents a time-series of values with lazy evaluation\n * @module runtime/series\n */\n\nimport * as compare from '../compare/index.js';\nimport type { Bar } from '../types/index.js';\n\n/**\n * Function that computes a value for each bar\n */\nexport type SeriesExtractor = (bar: Bar, index: number, data: Bar[]) => number;\n\n/**\n * Host-side: an array of bars with a version number that grows on every change, so the Series made on it know when\n * their cached values are stale. Scripts do not use it: their Series are made on the chart's bars.\n *\n * @example\n * ```typescript\n * const barData = new BarData(bars);\n * const close = Series.fromBars(barData, 'close');\n * const values1 = close.toArray(); // Computes and caches\n * \n * barData.push(newBar); // Increments version\n * const values2 = close.toArray(); // Detects stale cache, recomputes\n * ```\n */\nexport class BarData {\n private _bars: Bar[];\n private _version: number = 0;\n\n /**\n * Create a new BarData wrapper\n * @param bars - Initial bar data (defaults to empty array)\n */\n constructor(bars: Bar[] = []) {\n this._bars = bars;\n }\n\n /**\n * Get the current version number\n * Version increments whenever data is mutated\n */\n get version(): number {\n return this._version;\n }\n\n /**\n * Get the underlying bar array\n * Note: Direct mutations to this array will NOT increment version\n * Use the provided mutation methods instead\n */\n get bars(): Bar[] {\n return this._bars;\n }\n\n /**\n * Get the number of bars\n */\n get length(): number {\n return this._bars.length;\n }\n\n /**\n * Add a new bar to the end\n * @param bar - Bar to add\n */\n push(bar: Bar): void {\n this._bars.push(bar);\n this._version++;\n }\n\n /**\n * Remove and return the last bar\n * @returns The removed bar, or undefined if empty\n */\n pop(): Bar | undefined {\n const bar = this._bars.pop();\n if (bar !== undefined) {\n this._version++;\n }\n return bar;\n }\n\n /**\n * Replace a bar at a specific index\n * @param index - Index to update\n * @param bar - New bar data\n */\n set(index: number, bar: Bar): void {\n if (index >= 0 && index < this._bars.length) {\n this._bars[index] = bar;\n this._version++;\n }\n }\n\n /**\n * Update the last bar (useful for real-time/streaming updates)\n * @param bar - New bar data\n */\n updateLast(bar: Bar): void {\n if (this._bars.length > 0) {\n this._bars[this._bars.length - 1] = bar;\n this._version++;\n }\n }\n\n /**\n * Replace all bars with new data\n * @param bars - New bar array\n */\n setAll(bars: Bar[]): void {\n this._bars = bars;\n this._version++;\n }\n\n /**\n * Manually increment version (for advanced use cases)\n * Call this after direct mutations to the bars array\n */\n invalidate(): void {\n this._version++;\n }\n\n /**\n * Get a bar at a specific index\n * @param index - Bar index\n * @returns Bar at that index, or undefined\n */\n at(index: number): Bar | undefined {\n return this._bars[index];\n }\n\n /**\n * Create a BarData from an existing Bar array\n * @param bars - Bar array\n * @returns New BarData instance\n */\n static from(bars: Bar[]): BarData {\n return new BarData(bars);\n }\n}\n\n/** Largest history reference of a script series (PineScript max_bars_back limit). */\nexport const MAX_BARS_BACK = 5000;\n\n/** PineScript's runtime error RE10008 text. */\nexport function historyError(bar: number, barsBack: number): string {\n return (\n `Error on bar ${bar}: The script attempts to reference historical data that is too far from the current bar ` +\n `(${barsBack} bars back). The history-referencing length for the expression must be a value between 0 and ${MAX_BARS_BACK}.`\n );\n}\n\n/**\n * Hooks of an incremental script run (#196, set by the script runtime during a run only): a Series created by the\n * script gets a slot, and toArray() reuses the values of the previous run up to the first bar that changed.\n * @internal\n */\nexport interface SeriesRunHooks {\n created(series: Series): void;\n /** The values of the previous run (indexes below `from` are kept; the array is reused), or null to compute every bar */\n prefix(series: Series, bars: readonly Bar[]): { values: number[]; from: number } | null;\n computed(series: Series, values: number[]): void;\n}\n\nlet runHooks: SeriesRunHooks | null = null;\n\n/** @internal */\nexport function setSeriesRunHooks(hooks: SeriesRunHooks | null): void {\n runHooks = hooks;\n}\n\n/**\n * A series: one number per bar, oldest bar first, NaN where the value is missing (na). `close`, `open`, `high`,\n * `low`, `volume`, the `ta.*` results and `input.source()` are Series.\n *\n * JavaScript operators do not work on a Series (`close - open` throws): use its methods, which work on all the bars\n * at once and return a new Series. The other operand can be a Series or a plain number. Comparisons and logic give\n * a Series of 1 (true) and 0 (false). Inside `eachBar()`, read the number of the current bar with `c.get(series)`.\n * Values are computed when first read, then kept.\n *\n * @example\n * ```js\n * const body = close.sub(open);\n * const up = close.gt(open);\n * plot(up.iff(body, body.neg()), \"Body size\");\n * ```\n */\nexport class Series {\n private extractor: SeriesExtractor;\n private dataSource: BarData;\n private cached: number[] | null = null;\n private cachedVersion: number = -1;\n\n /**\n * True for the built-in price series (`open`, `high`, `low`, `close`, `volume`, `hl2`...): their history covers\n * every bar, so `offset()` may reach further than 5000 bars back.\n */\n fullHistory = false;\n\n /**\n * Makes a Series that computes its value on each bar with a function. Scripts rarely need it: Series come from the\n * builtins, `ta.*` and the Series methods.\n * @param data - The bars the series is aligned to (an array of bars, or a {@link BarData}).\n * @param extractor - Gives the value of bar `index`: `(bar, index, bars) => number`; NaN for na.\n * @example\n * ```js\n * const range = new Series(close.bars, (bar) => bar.high - bar.low);\n * ```\n */\n constructor(data: Bar[] | BarData, extractor: SeriesExtractor) {\n // Support both Bar[] and BarData for backward compatibility\n this.dataSource = data instanceof BarData ? data : new BarData(data);\n this.extractor = extractor;\n runHooks?.created(this);\n }\n\n /** The bars this series is aligned to (`{ time, open, high, low, close, volume }`, oldest first). */\n get bars(): Bar[] {\n return this.dataSource.bars;\n }\n\n /** The {@link BarData} holding the bars this series is aligned to. */\n get barData(): BarData {\n return this.dataSource;\n }\n\n // ============================================\n // Static Factory Methods\n // ============================================\n\n /**\n * Makes the Series of one field of the bars (the price series). In a script, use the globals `open`, `high`, `low`,\n * `close`, `volume` instead.\n * @param bars - The bars (an array of bars, or a {@link BarData}).\n * @param field - `'open'`, `'high'`, `'low'`, `'close'` or `'volume'`.\n * @returns A Series of that field; NaN where a bar does not have it.\n * @example\n * ```js\n * const myClose = Series.fromBars(close.bars, \"close\");\n * ```\n */\n static fromBars(bars: Bar[] | BarData, field: 'open' | 'high' | 'low' | 'close' | 'volume'): Series {\n const series = new Series(bars, (bar) => bar[field] ?? NaN);\n series.fullHistory = true;\n return series;\n }\n\n /**\n * Makes a Series with the same value on every bar. The Series methods also take plain numbers, so a script seldom\n * needs it.\n * @param bars - The bars to align to (an array of bars, or a {@link BarData}).\n * @param value - The value of every bar (NaN for na).\n * @returns A Series of `value`.\n * @example\n * ```js\n * const level = Series.constant(close.bars, 50);\n * ```\n */\n static constant(bars: Bar[] | BarData, value: number): Series {\n return new Series(bars, () => value);\n }\n\n /**\n * Makes a Series from an array with one value per bar, oldest first. In a script, `seriesOf(values)` does the same\n * on the chart bars.\n * @param bars - The bars the values belong to (an array of bars, or a {@link BarData}).\n * @param values - One number per bar, oldest first; a missing value reads as NaN.\n * @returns A Series of the values.\n * @throws When read on other bars with a different length than `values` (e.g. a series computed on the\n * chart bars and read inside a `request.security` expression, which runs on the other timeframe's bars).\n * @example\n * ```js\n * const doubled = Series.fromArray(close.bars, close.toArray().map((v) => v * 2));\n * ```\n */\n static fromArray(bars: Bar[] | BarData, values: number[]): Series {\n const origin = bars instanceof BarData ? bars.bars : bars;\n return new Series(bars, (_bar, i, data) => {\n if (data !== origin && data.length !== values.length) {\n throw new Error(\n `Series values were computed on other bars (${values.length} values, ${data.length} bars). ` +\n 'Inside request.security(), compute the series inside the expression, e.g. () => ta.ema(close, 10).'\n );\n }\n return values[i] ?? NaN;\n });\n }\n\n // ============================================\n // Arithmetic Operations\n // ============================================\n\n /**\n * Adds a Series or a number to this series, bar by bar (the `+` of two values). NaN on either side gives NaN.\n * @param other - Series or number to add.\n * @returns A Series of the sums.\n * @example\n * ```js\n * const mid = high.add(low).div(2);\n * ```\n */\n add(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a + b;\n });\n }\n\n /**\n * Subtracts a Series or a number from this series, bar by bar (the `-` of two values). NaN on either side gives NaN.\n * @param other - Series or number to subtract.\n * @returns A Series of the differences.\n * @example\n * ```js\n * const body = close.sub(open);\n * ```\n */\n sub(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a - b;\n });\n }\n\n /**\n * Multiplies this series by a Series or a number, bar by bar (the `*` of two values). NaN on either side gives NaN.\n * @param other - Series or number to multiply by.\n * @returns A Series of the products.\n * @example\n * ```js\n * const upper = ta.sma(close, 20).mul(1.02);\n * ```\n */\n mul(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a * b;\n });\n }\n\n /**\n * Raises this series to a power, bar by bar (`math.pow` on a series). NaN on either side gives NaN; a negative base\n * with a fractional exponent gives NaN.\n * @param exponent - Series or number exponent.\n * @returns A Series of `this ** exponent`.\n * @example\n * ```js\n * const squared = close.sub(ta.sma(close, 20)).pow(2);\n * ```\n */\n pow(exponent: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof exponent === 'number' ? exponent : exponent.extractor(bar, i, data);\n return Math.pow(a, b);\n });\n }\n\n /**\n * Divides this series by a Series or a number, bar by bar (the `/` of two values). A division by 0 gives\n * +/-Infinity (which `na()` treats as na), 0 / 0 and NaN on either side give NaN.\n * @param other - Series or number to divide by.\n * @returns A Series of the quotients.\n * @example\n * ```js\n * const range = high.sub(low);\n * const ratio = range.gt(0).iff(close.sub(open).div(range), 0);\n * ```\n */\n div(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a / b; // PineScript: x / 0 is +/-Infinity (na() is true for it), 0 / 0 is na\n });\n }\n\n /**\n * Remainder of the division of this series by a Series or a number, bar by bar (the `%` of two values). The\n * remainder has the sign of this series; a divisor of 0 and NaN on either side give NaN.\n * @param other - Series or number to divide by.\n * @returns A Series of the remainders.\n * @example\n * ```js\n * const everyFifth = bar_index.mod(5).eq(0);\n * ```\n */\n mod(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return b !== 0 ? a % b : NaN;\n });\n }\n\n /**\n * Changes the sign of every value (the unary `-`). NaN stays NaN.\n * @returns A Series of the opposite values.\n * @example\n * ```js\n * const drop = close.sub(close.offset(1)).neg();\n * ```\n */\n neg(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n return -this.extractor(bar, i, data);\n });\n }\n\n // ============================================\n // Comparison Operations (PineScript operators: tolerance 1e-10, false with na; see src/compare)\n // ============================================\n\n /**\n * Tests whether this series is above a Series or a number, bar by bar (`a > b`).\n * Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.\n * @param other - Series or number to compare with.\n * @returns A Series of 1 where it is true, 0 where it is false.\n * @example\n * ```js\n * const up = close.gt(open);\n * ```\n */\n gt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.gt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Tests whether this series is above or equal to a Series or a number, bar by bar (`a >= b`).\n * Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.\n * @param other - Series or number to compare with.\n * @returns A Series of 1 where it is true, 0 where it is false.\n * @example\n * ```js\n * const atOrAbove = close.gte(ta.sma(close, 50));\n * ```\n */\n gte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ge(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Tests whether this series is below a Series or a number, bar by bar (`a < b`).\n * Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.\n * @param other - Series or number to compare with.\n * @returns A Series of 1 where it is true, 0 where it is false.\n * @example\n * ```js\n * const oversold = ta.rsi(close, 14).lt(30);\n * ```\n */\n lt(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.lt(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Tests whether this series is below or equal to a Series or a number, bar by bar (`a <= b`).\n * Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.\n * @param other - Series or number to compare with.\n * @returns A Series of 1 where it is true, 0 where it is false.\n * @example\n * ```js\n * const atOrBelow = low.lte(ta.lowest(low, 20).offset(1));\n * ```\n */\n lte(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.le(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Tests whether this series equals a Series or a number, bar by bar (`a == b`).\n * Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.\n * @param other - Series or number to compare with.\n * @returns A Series of 1 where it is true, 0 where it is false.\n * @example\n * ```js\n * const doji = close.eq(open);\n * ```\n */\n eq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.eq(a, b) ? 1 : 0;\n });\n }\n\n /**\n * Tests whether this series differs from a Series or a number, bar by bar (`a != b`).\n * Values closer than 1e-10 count as equal, and a NaN on either side gives 0 (false), never NaN.\n * @param other - Series or number to compare with.\n * @returns A Series of 1 where it is true, 0 where it is false.\n * @example\n * ```js\n * const moved = close.neq(close.offset(1));\n * ```\n */\n neq(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return compare.ne(a, b) ? 1 : 0;\n });\n }\n\n // ============================================\n // Logical Operations (for boolean series)\n // ============================================\n\n /**\n * Logical \"and\" of two conditions, bar by bar. A value is true when it is not 0 and not NaN.\n * @param other - The other condition: a Series or a number.\n * @returns A Series of 1 where both are true, 0 elsewhere.\n * @example\n * ```js\n * const strongUp = close.gt(open).and(volume.gt(ta.sma(volume, 20)));\n * ```\n */\n and(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a && b ? 1 : 0;\n });\n }\n\n /**\n * Logical \"or\" of two conditions, bar by bar. A value is true when it is not 0 and not NaN.\n * @param other - The other condition: a Series or a number.\n * @returns A Series of 1 where at least one is true, 0 elsewhere.\n * @example\n * ```js\n * const extreme = ta.rsi(close, 14).gt(70).or(ta.rsi(close, 14).lt(30));\n * ```\n */\n or(other: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n const b = typeof other === 'number' ? other : other.extractor(bar, i, data);\n return a || b ? 1 : 0;\n });\n }\n\n /**\n * Logical \"not\" of a condition, bar by bar: true (not 0, not NaN) becomes 0, and 0 or NaN becomes 1.\n * @returns A Series of 1 where this series is false, 0 where it is true.\n * @example\n * ```js\n * const notUp = close.gt(open).not();\n * ```\n */\n not(): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const a = this.extractor(bar, i, data);\n return !a ? 1 : 0;\n });\n }\n\n // ============================================\n // Conditional Selection\n // ============================================\n\n /**\n * Picks one of two values on each bar, with this series as the condition (the `cond ? x : y` of a series). The\n * condition is true when it is not 0 and not NaN; 0 and NaN pick `falseValue`.\n * @param trueValue - Series or number used where the condition is true.\n * @param falseValue - Series or number used where the condition is false.\n * @returns A Series of the picked values.\n * @example\n * ```js\n * const range = high.sub(low);\n * const ratio = range.gt(0).iff(close.sub(open).div(range), 0);\n * plot(ratio, \"Body / range\");\n * ```\n */\n iff(trueValue: Series | number, falseValue: Series | number): Series {\n return new Series(this.dataSource, (bar, i, data) => {\n const condition = this.extractor(bar, i, data);\n // Truthy: nonzero and not NaN\n const isTruthy = condition !== 0 && !Number.isNaN(condition);\n\n if (isTruthy) {\n return typeof trueValue === 'number' ? trueValue : trueValue.extractor(bar, i, data);\n } else {\n return typeof falseValue === 'number' ? falseValue : falseValue.extractor(bar, i, data);\n }\n });\n }\n\n // ============================================\n // Offset/History\n // ============================================\n\n /**\n * Shifts the series back in time: on each bar, the value `offset` bars earlier (`close.offset(1)` is the previous\n * close). The first `offset` bars, which have no earlier bar, get NaN.\n * @param offset - Number of bars back: 0 (the series itself) or more, a whole number. A series computed by the\n * script can look back at most 5000 bars; the price series (`close`, `high`...) any number.\n * @returns A Series of the earlier values.\n * @throws RangeError when `offset` is negative (it would read a future bar); an error past 5000 bars.\n * @example\n * ```js\n * const change = close.sub(close.offset(1));\n * const higherHigh = high.gt(high.offset(1));\n * ```\n */\n offset(offset: number): Series {\n if (offset < 0) throw new RangeError(`Series.offset(${offset}): the offset cannot be negative (it would read a future bar).`);\n // PineScript runtime error RE10008: a script series keeps at most 5000 bars of history\n if (offset > MAX_BARS_BACK && !this.fullHistory) throw new Error(historyError(0, Math.floor(offset)));\n return new Series(this.dataSource, (_bar, i, data) => {\n const targetIndex = i - offset;\n if (targetIndex < 0 || targetIndex >= data.length) {\n return NaN;\n }\n return this.extractor(data[targetIndex]!, targetIndex, data);\n });\n }\n\n // ============================================\n // Computation & Access\n // ============================================\n\n /**\n * Gives the values of all the bars as a plain array, oldest bar first (NaN for na). The values are computed on the\n * first read and kept until the bars change; the array is shared, so copy it before changing it.\n * @returns One number per bar, oldest first.\n * @example\n * ```js\n * const values = ta.sma(close, 20).toArray();\n * const shifted = seriesOf(values.map((v) => v * 1.01));\n * ```\n */\n toArray(): number[] {\n // Check if cache is valid by comparing versions\n if (this.cached !== null && this.cachedVersion === this.dataSource.version) {\n return this.cached;\n }\n\n // Recompute and update cache\n const bars = this.dataSource.bars;\n const prefix = runHooks?.prefix(this, bars) ?? null;\n if (prefix) {\n // the run's own array of the previous run: its first values are kept, the newest computed in place\n const n = bars.length;\n const values = prefix.values;\n const from = Math.min(prefix.from, n);\n values.length = n;\n for (let i = from; i < n; i++) values[i] = this.extractor(bars[i]!, i, bars);\n this.cached = values;\n } else {\n this.cached = bars.map((bar, i) => this.extractor(bar, i, bars));\n }\n this.cachedVersion = this.dataSource.version;\n runHooks?.computed(this, this.cached);\n return this.cached;\n }\n\n /**\n * Computes the values now and returns a Series that stores them, without links to the series it was built from.\n * Use it on a long chain of methods to compute it once and free the steps in between.\n * @returns A Series of the same values, stored.\n * @example\n * ```js\n * const spread = high.sub(low).div(close).mul(100).materialize();\n * ```\n */\n materialize(): Series {\n const values = this.toArray();\n // Create a copy of values to ensure no shared references\n const valuesCopy = [...values];\n return Series.fromArray(this.dataSource, valuesCopy);\n }\n\n /**\n * Invalidate cache (when data changes)\n * \n * Note: With BarData versioning, manual invalidation is rarely needed.\n * The cache is automatically invalidated when the underlying BarData changes.\n * This method is kept for backward compatibility and advanced use cases.\n * \n * @internal\n */\n _invalidate(): void {\n this.cached = null;\n this.cachedVersion = -1;\n }\n\n /**\n * Compute all values (alias for toArray)\n * @returns Array of computed values\n * @internal\n */\n _compute(): number[] {\n return this.toArray();\n }\n\n /**\n * Reads the value of one bar by its position: 0 is the oldest bar, `bar_index` counts the same way. This is not\n * the \"bars back\" of `offset()`: inside a bar loop, read the current bar with `c.get(series)` and earlier bars with\n * `c.get(series, k)`.\n * @param index - Bar position, 0 for the oldest bar.\n * @returns The value of that bar; NaN when there is no such bar.\n * @example\n * ```js\n * const firstClose = close.get(0);\n * ```\n */\n get(index: number): number {\n const values = this.toArray();\n return values[index] ?? NaN;\n }\n\n /**\n * Reads the value of the newest bar.\n * @returns The value of the last bar; NaN when there are no bars.\n * @example\n * ```js\n * const lastRsi = ta.rsi(close, 14).last();\n * ```\n */\n last(): number {\n const values = this.toArray();\n return values[values.length - 1] ?? NaN;\n }\n\n /**\n * Gives the number of bars of the series (a method, not a property).\n * @returns The number of bars.\n * @example\n * ```js\n * const bars = close.length();\n * ```\n */\n length(): number {\n return this.dataSource.length;\n }\n\n /**\n * A Series holds the values of all the bars, so JavaScript operators cannot use it: without this guard\n * `close - open` is NaN, `close > open` false and `` `${rsi}` `` \"[object Object]\", with no error. The\n * conversion throws instead, with the Series method or bar-loop read to use.\n */\n [Symbol.toPrimitive](hint: 'number' | 'string' | 'default'): never {\n if (hint === 'string') {\n throw new TypeError(\n 'A Series is not a text: read the value of one bar inside eachBar(), e.g. str.tostring(c.get(rsi)), ' +\n 'or pass the Series itself to plot() / plotshape().'\n );\n }\n throw new TypeError(\n 'JavaScript operators (+ - * / % ** < > <= >= ==) do not work on a Series: use its methods, ' +\n 'a.add(b) a.sub(b) a.mul(b) a.div(b) a.mod(b) a.pow(b) a.neg(), a.gt(b) a.gte(b) a.lt(b) a.lte(b) a.eq(b) a.neq(b), ' +\n 'a.and(b) a.or(b) a.not(), cond.iff(x, y), a.offset(1) for a[1]; or read numbers inside eachBar() with c.get(a).'\n );\n }\n\n /**\n * Gives the values as `{ time, value }` points for a chart line, oldest first, leaving out the NaN bars.\n * @returns The points; `time` is the bar time, in the unit of the bars.\n * @example\n * ```js\n * const points = ta.sma(close, 20).toTimeValuePairs();\n * ```\n */\n toTimeValuePairs(): Array<{ time: any; value: number }> {\n const values = this.toArray();\n const bars = this.dataSource.bars;\n return bars.map((bar, i) => ({\n time: bar.time,\n value: values[i]!\n })).filter(point => !Number.isNaN(point.value));\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,cAAyB;AAsBlB,MAAM,QAAQ;AAAA,EACX;AAAA,EACA,WAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3B,YAAY,OAAc,CAAC,GAAG;AAC5B,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,UAAkB;AACpB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAc;AAChB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAiB;AACnB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,KAAgB;AACnB,SAAK,MAAM,KAAK,GAAG;AACnB,SAAK;AA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AAS,KAAK,QAAQ;AAC5B,WAAO,OAAO,OAAO,SAAS,CAAC,KAAK;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,SAAiB;AACf,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,CAAC,OAAO,WAAW,EAAE,MAA8C;AACjE,QAAI,SAAS,UAAU;AACrB,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,mBAAwD;AACtD,UAAM,SAAS,KAAK,QAAQ;AAC5B,UAAM,OAAO,KAAK,WAAW;AAC7B,WAAO,KAAK,IAAI,CAAC,KAAK,OAAO;AAAA,MAC3B,MAAM,IAAI;AAAA,MACV,OAAO,OAAO,CAAC;AAAA,IACjB,EAAE,EAAE,OAAO,WAAS,CAAC,OAAO,MAAM,MAAM,KAAK,CAAC;AAAA,EAChD;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @fileoverview The documented type of the `alert` global of the script API: the `alert()` call and its
3
+ * `alert.freq_*` constants.
4
+ * @module script/api/alert
5
+ */
6
+ /**
7
+ * `alert(message, freq)` sends an alert message to the app's alert engine, which fires the calls made on the live
8
+ * (realtime) bar; `alert.freq_all`, `alert.freq_once_per_bar` and `alert.freq_once_per_bar_close` choose how often
9
+ * it may fire.
10
+ */
11
+ export interface AlertApi {
12
+ /**
13
+ * Sends an alert message. Inside `eachBar()` / `strategy.eachBar()` it is a call on the current bar (put it in an
14
+ * `if`); at the top level of the script it is a call on every bar. The app fires the calls of the live bar for
15
+ * the alerts that the user created on the script.
16
+ * @param message - The alert text. At the top level it can also be an array with one text per bar; a bar whose
17
+ * text is `undefined` makes no call.
18
+ * @param freq - How often the alert may fire: `alert.freq_all` (on every call), `alert.freq_once_per_bar` (the
19
+ * first call of each bar) or `alert.freq_once_per_bar_close` (when the bar closes). Another value throws.
20
+ * Default: `alert.freq_once_per_bar`.
21
+ * @example
22
+ * ```js
23
+ * const up = ta.crossover(close, ta.sma(close, 20));
24
+ * eachBar((c) => {
25
+ * if (c.get(up) === 1) alert("Close crossed above the average", alert.freq_once_per_bar_close);
26
+ * });
27
+ * ```
28
+ */
29
+ (message: string | ReadonlyArray<string | undefined>, freq?: 'all' | 'once_per_bar' | 'once_per_bar_close'): void;
30
+ /** Frequency for `alert()`: the alert fires on every call, several times per bar if need be. */
31
+ readonly freq_all: 'all';
32
+ /** Frequency for `alert()`: the alert fires on the first call of a bar only. The default. */
33
+ readonly freq_once_per_bar: 'once_per_bar';
34
+ /** Frequency for `alert()`: the alert fires only when the bar closes, if the call was made on it. */
35
+ readonly freq_once_per_bar_close: 'once_per_bar_close';
36
+ }
37
+ //# sourceMappingURL=alert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alert.d.ts","sourceRoot":"","sources":["../../../../src/script/api/alert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;;;;;;;;;;OAgBG;IACH,CACE,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,EACnD,IAAI,CAAC,EAAE,KAAK,GAAG,cAAc,GAAG,oBAAoB,GACnD,IAAI,CAAC;IAER,gGAAgG;IAChG,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;IAEzB,6FAA6F;IAC7F,QAAQ,CAAC,iBAAiB,EAAE,cAAc,CAAC;IAE3C,qGAAqG;IACrG,QAAQ,CAAC,uBAAuB,EAAE,oBAAoB,CAAC;CACxD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var alert_exports = {};
16
+ module.exports = __toCommonJS(alert_exports);
17
+ //# sourceMappingURL=alert.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/script/api/alert.ts"],
4
+ "sourcesContent": ["/**\n * @fileoverview The documented type of the `alert` global of the script API: the `alert()` call and its\n * `alert.freq_*` constants.\n * @module script/api/alert\n */\n\n/**\n * `alert(message, freq)` sends an alert message to the app's alert engine, which fires the calls made on the live\n * (realtime) bar; `alert.freq_all`, `alert.freq_once_per_bar` and `alert.freq_once_per_bar_close` choose how often\n * it may fire.\n */\nexport interface AlertApi {\n /**\n * Sends an alert message. Inside `eachBar()` / `strategy.eachBar()` it is a call on the current bar (put it in an\n * `if`); at the top level of the script it is a call on every bar. The app fires the calls of the live bar for\n * the alerts that the user created on the script.\n * @param message - The alert text. At the top level it can also be an array with one text per bar; a bar whose\n * text is `undefined` makes no call.\n * @param freq - How often the alert may fire: `alert.freq_all` (on every call), `alert.freq_once_per_bar` (the\n * first call of each bar) or `alert.freq_once_per_bar_close` (when the bar closes). Another value throws.\n * Default: `alert.freq_once_per_bar`.\n * @example\n * ```js\n * const up = ta.crossover(close, ta.sma(close, 20));\n * eachBar((c) => {\n * if (c.get(up) === 1) alert(\"Close crossed above the average\", alert.freq_once_per_bar_close);\n * });\n * ```\n */\n (\n message: string | ReadonlyArray<string | undefined>,\n freq?: 'all' | 'once_per_bar' | 'once_per_bar_close'\n ): void;\n\n /** Frequency for `alert()`: the alert fires on every call, several times per bar if need be. */\n readonly freq_all: 'all';\n\n /** Frequency for `alert()`: the alert fires on the first call of a bar only. The default. */\n readonly freq_once_per_bar: 'once_per_bar';\n\n /** Frequency for `alert()`: the alert fires only when the bar closes, if the call was made on it. */\n readonly freq_once_per_bar_close: 'once_per_bar_close';\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,232 @@
1
+ /**
2
+ * @fileoverview The documented type of the `calc` namespace of the script API (plain-English calculations).
3
+ * @module script/api/calc
4
+ */
5
+ import type { Series } from '../../runtime/series.js';
6
+ /**
7
+ * Plain-English names for the most used calculations, beside the `ta.*` functions: averages, crosses, comparisons,
8
+ * changes, highs and lows. Each function takes Series or numbers and computes a whole Series in one call, so call it
9
+ * at the top level of the script, before any `eachBar()` loop (inside a loop it throws). A condition comes back as a
10
+ * Series of 1 (true) and 0 (false). A length or a number of bars is a whole number, 1 or more.
11
+ */
12
+ export interface CalcNamespace {
13
+ /**
14
+ * Moving average of the last `length` values, of the kind you choose. Use it to smooth a price or any Series.
15
+ * `NaN` on the first bars, until the window is full.
16
+ * @param source - Values to average: a Series such as `close`, or a number.
17
+ * @param length - Number of bars in the window: a whole number, 1 or more.
18
+ * @param kind - 'simple', 'exponential', 'weighted', 'smoothed' (the average of `ta.rsi`), 'hull' or
19
+ * 'volume-weighted' (weighted by `volume`). Another text throws. Default: 'simple'.
20
+ * @returns Series of the averages.
21
+ * @example
22
+ * ```js
23
+ * const fast = calc.average(close, 9, 'exponential');
24
+ * plot(fast, "Fast average");
25
+ * ```
26
+ */
27
+ average(source: Series | number, length: number, kind?: string): Series;
28
+ /**
29
+ * Tests whether `a` crosses above `b`: 1 on the bar where `a` goes from at or below `b` to above it, else 0.
30
+ * Use it for buy signals such as a fast average crossing a slow one.
31
+ * @param a - The line that crosses: a Series or a number.
32
+ * @param b - The line it crosses: a Series or a level.
33
+ * @returns Series of 1 on the crossing bars, 0 elsewhere.
34
+ * @example
35
+ * ```js
36
+ * const up = calc.crossesAbove(calc.average(close, 9), calc.average(close, 21));
37
+ * plotshape(up, "Up", { style: shape.triangleup, location: location.belowbar });
38
+ * ```
39
+ */
40
+ crossesAbove(a: Series | number, b: Series | number): Series;
41
+ /**
42
+ * Tests whether `a` crosses below `b`: 1 on the bar where `a` goes from at or above `b` to below it, else 0.
43
+ * @param a - The line that crosses: a Series or a number.
44
+ * @param b - The line it crosses: a Series or a level.
45
+ * @returns Series of 1 on the crossing bars, 0 elsewhere.
46
+ * @example
47
+ * ```js
48
+ * const down = calc.crossesBelow(ta.rsi(close, 14), 70);
49
+ * plotshape(down, "Down", { style: shape.triangledown, location: location.abovebar });
50
+ * ```
51
+ */
52
+ crossesBelow(a: Series | number, b: Series | number): Series;
53
+ /**
54
+ * Tests whether `a` and `b` cross, in either direction: 1 on the bar where they swap sides, else 0.
55
+ * @param a - The first line: a Series or a number.
56
+ * @param b - The second line: a Series or a number.
57
+ * @returns Series of 1 on the crossing bars, 0 elsewhere.
58
+ * @example
59
+ * ```js
60
+ * const crossed = calc.crosses(close, calc.average(close, 50));
61
+ * bgcolor(color.when(crossed, color.new(color.yellow, 80)));
62
+ * ```
63
+ */
64
+ crosses(a: Series | number, b: Series | number): Series;
65
+ /**
66
+ * Tests whether `a` is above `b` on each bar. Values closer than 1e-10 count as equal; a NaN on either side
67
+ * gives 0.
68
+ * @param a - The value tested: a Series or a number.
69
+ * @param b - The value it is compared with: a Series or a number.
70
+ * @returns Series of 1 where `a` is above `b`, 0 elsewhere.
71
+ * @example
72
+ * ```js
73
+ * const uptrend = calc.above(close, calc.average(close, 200));
74
+ * ```
75
+ */
76
+ above(a: Series | number, b: Series | number): Series;
77
+ /**
78
+ * Tests whether `a` is below `b` on each bar. Values closer than 1e-10 count as equal; a NaN on either side
79
+ * gives 0.
80
+ * @param a - The value tested: a Series or a number.
81
+ * @param b - The value it is compared with: a Series or a number.
82
+ * @returns Series of 1 where `a` is below `b`, 0 elsewhere.
83
+ * @example
84
+ * ```js
85
+ * const oversold = calc.below(ta.rsi(close, 14), 30);
86
+ * ```
87
+ */
88
+ below(a: Series | number, b: Series | number): Series;
89
+ /**
90
+ * Tests whether `value` is between two limits on each bar, both limits included. A NaN gives 0.
91
+ * @param value - The value tested: a Series or a number.
92
+ * @param lowLimit - The lower limit: a Series or a number.
93
+ * @param highLimit - The upper limit: a Series or a number.
94
+ * @returns Series of 1 where `lowLimit <= value <= highLimit`, 0 elsewhere.
95
+ * @example
96
+ * ```js
97
+ * const neutral = calc.between(ta.rsi(close, 14), 40, 60);
98
+ * ```
99
+ */
100
+ between(value: Series | number, lowLimit: Series | number, highLimit: Series | number): Series;
101
+ /**
102
+ * The value from `bars` bars before, on each bar (`calc.previous(close)` is the previous close). The first bars,
103
+ * which have no earlier bar, get `NaN`.
104
+ * @param source - A Series or a number.
105
+ * @param bars - How many bars back: a whole number, 1 or more. Default: 1.
106
+ * @returns Series of the earlier values.
107
+ * @example
108
+ * ```js
109
+ * const gapUp = calc.above(open, calc.previous(high));
110
+ * ```
111
+ */
112
+ previous(source: Series | number, bars?: number): Series;
113
+ /**
114
+ * The difference between the value and the value `bars` bars before (`close - close 1 bar ago`). `NaN` on the
115
+ * first bars.
116
+ * @param source - A Series or a number.
117
+ * @param bars - How many bars back: a whole number, 1 or more. Default: 1.
118
+ * @returns Series of the differences, in the units of the source.
119
+ * @example
120
+ * ```js
121
+ * plot(calc.change(close, 5), "5-bar change", { style: plot.style_histogram });
122
+ * ```
123
+ */
124
+ change(source: Series | number, bars?: number): Series;
125
+ /**
126
+ * The change in percent since `bars` bars before: `(value - earlier) / earlier * 100`. `NaN` on the first bars;
127
+ * an earlier value of 0 gives an infinite or `NaN` result.
128
+ * @param source - A Series or a number.
129
+ * @param bars - How many bars back: a whole number, 1 or more. Default: 1.
130
+ * @returns Series of the changes in percent (5 means +5 %).
131
+ * @example
132
+ * ```js
133
+ * const roc = calc.percentChange(close, 10);
134
+ * plot(roc, "10-bar change %");
135
+ * ```
136
+ */
137
+ percentChange(source: Series | number, bars?: number): Series;
138
+ /**
139
+ * The highest value of the last `length` bars, the current bar included.
140
+ * @param source - A Series such as `high`, or a number.
141
+ * @param length - Number of bars in the window: a whole number, 1 or more.
142
+ * @returns Series of the highest values.
143
+ * @example
144
+ * ```js
145
+ * plot(calc.highest(high, 20), "20-bar high");
146
+ * ```
147
+ */
148
+ highest(source: Series | number, length: number): Series;
149
+ /**
150
+ * The lowest value of the last `length` bars, the current bar included.
151
+ * @param source - A Series such as `low`, or a number.
152
+ * @param length - Number of bars in the window: a whole number, 1 or more.
153
+ * @returns Series of the lowest values.
154
+ * @example
155
+ * ```js
156
+ * plot(calc.lowest(low, 20), "20-bar low");
157
+ * ```
158
+ */
159
+ lowest(source: Series | number, length: number): Series;
160
+ /**
161
+ * Tests whether the value rose on each of the last `bars` bars (each bar above the one before it).
162
+ * @param source - A Series or a number.
163
+ * @param bars - How many rises in a row: a whole number, 1 or more. Default: 1.
164
+ * @returns Series of 1 where the value rose on each of those bars, 0 elsewhere.
165
+ * @example
166
+ * ```js
167
+ * const climbing = calc.isRising(calc.average(close, 20), 3);
168
+ * ```
169
+ */
170
+ isRising(source: Series | number, bars?: number): Series;
171
+ /**
172
+ * Tests whether the value fell on each of the last `bars` bars (each bar below the one before it).
173
+ * @param source - A Series or a number.
174
+ * @param bars - How many falls in a row: a whole number, 1 or more. Default: 1.
175
+ * @returns Series of 1 where the value fell on each of those bars, 0 elsewhere.
176
+ * @example
177
+ * ```js
178
+ * const sliding = calc.isFalling(close, 3);
179
+ * ```
180
+ */
181
+ isFalling(source: Series | number, bars?: number): Series;
182
+ /**
183
+ * Standard deviation of the last `length` values (dividing by `length`): how far the values spread around their
184
+ * mean. `NaN` until the window is full.
185
+ * @param source - A Series or a number.
186
+ * @param length - Number of bars in the window: a whole number, 1 or more.
187
+ * @returns Series of the deviations, in the units of the source.
188
+ * @example
189
+ * ```js
190
+ * const spread = calc.standardDeviation(close, 20);
191
+ * plot(calc.average(close, 20).add(spread.mul(2)), "Upper band");
192
+ * ```
193
+ */
194
+ standardDeviation(source: Series | number, length: number): Series;
195
+ /**
196
+ * Picks one of two values on each bar: `whenTrue` where the condition holds, `whenFalse` elsewhere. A condition
197
+ * holds when it is not 0 and not NaN.
198
+ * @param condition - The condition: a Series of 1 / 0, or a number.
199
+ * @param whenTrue - Value used where the condition holds: a Series or a number.
200
+ * @param whenFalse - Value used elsewhere: a Series or a number.
201
+ * @returns Series of the picked values.
202
+ * @example
203
+ * ```js
204
+ * const body = calc.ifElse(calc.above(close, open), close.sub(open), 0);
205
+ * plot(body, "Up body");
206
+ * ```
207
+ */
208
+ ifElse(condition: Series | number, whenTrue: Series | number, whenFalse: Series | number): Series;
209
+ /**
210
+ * Tests whether every condition holds on each bar (a logical "and"). A condition holds when it is not 0 and not
211
+ * NaN. Give at least one condition.
212
+ * @param conditions - The conditions: Series of 1 / 0, or numbers.
213
+ * @returns Series of 1 where all of them hold, 0 elsewhere.
214
+ * @example
215
+ * ```js
216
+ * const buy = calc.all(calc.above(close, open), calc.below(ta.rsi(close, 14), 40));
217
+ * ```
218
+ */
219
+ all(...conditions: Array<Series | number>): Series;
220
+ /**
221
+ * Tests whether at least one condition holds on each bar (a logical "or"). A condition holds when it is not 0 and
222
+ * not NaN. Give at least one condition.
223
+ * @param conditions - The conditions: Series of 1 / 0, or numbers.
224
+ * @returns Series of 1 where one of them holds, 0 elsewhere.
225
+ * @example
226
+ * ```js
227
+ * const extreme = calc.any(calc.above(ta.rsi(close, 14), 70), calc.below(ta.rsi(close, 14), 30));
228
+ * ```
229
+ */
230
+ any(...conditions: Array<Series | number>): Series;
231
+ }
232
+ //# sourceMappingURL=calc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calc.d.ts","sourceRoot":"","sources":["../../../../src/script/api/calc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAA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AEvD;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE9D;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzD;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAExD;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzD;;;;;;;;;OASG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE1D;;;;;;;;;;;OAWG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAEnE;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAElG;;;;;;;;;OASG;IACH,GAAG,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;IAEnD;;;;;;;;;OASG;IACH,GAAG,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;CACpD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var calc_exports = {};
16
+ module.exports = __toCommonJS(calc_exports);
17
+ //# sourceMappingURL=calc.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/script/api/calc.ts"],
4
+ "sourcesContent": ["/**\n * @fileoverview The documented type of the `calc` namespace of the script API (plain-English calculations).\n * @module script/api/calc\n */\n\nimport type { Series } from '../../runtime/series.js';\n\n/**\n * Plain-English names for the most used calculations, beside the `ta.*` functions: averages, crosses, comparisons,\n * changes, highs and lows. Each function takes Series or numbers and computes a whole Series in one call, so call it\n * at the top level of the script, before any `eachBar()` loop (inside a loop it throws). A condition comes back as a\n * Series of 1 (true) and 0 (false). A length or a number of bars is a whole number, 1 or more.\n */\nexport interface CalcNamespace {\n /**\n * Moving average of the last `length` values, of the kind you choose. Use it to smooth a price or any Series.\n * `NaN` on the first bars, until the window is full.\n * @param source - Values to average: a Series such as `close`, or a number.\n * @param length - Number of bars in the window: a whole number, 1 or more.\n * @param kind - 'simple', 'exponential', 'weighted', 'smoothed' (the average of `ta.rsi`), 'hull' or\n * 'volume-weighted' (weighted by `volume`). Another text throws. Default: 'simple'.\n * @returns Series of the averages.\n * @example\n * ```js\n * const fast = calc.average(close, 9, 'exponential');\n * plot(fast, \"Fast average\");\n * ```\n */\n average(source: Series | number, length: number, kind?: string): Series;\n\n /**\n * Tests whether `a` crosses above `b`: 1 on the bar where `a` goes from at or below `b` to above it, else 0.\n * Use it for buy signals such as a fast average crossing a slow one.\n * @param a - The line that crosses: a Series or a number.\n * @param b - The line it crosses: a Series or a level.\n * @returns Series of 1 on the crossing bars, 0 elsewhere.\n * @example\n * ```js\n * const up = calc.crossesAbove(calc.average(close, 9), calc.average(close, 21));\n * plotshape(up, \"Up\", { style: shape.triangleup, location: location.belowbar });\n * ```\n */\n crossesAbove(a: Series | number, b: Series | number): Series;\n\n /**\n * Tests whether `a` crosses below `b`: 1 on the bar where `a` goes from at or above `b` to below it, else 0.\n * @param a - The line that crosses: a Series or a number.\n * @param b - The line it crosses: a Series or a level.\n * @returns Series of 1 on the crossing bars, 0 elsewhere.\n * @example\n * ```js\n * const down = calc.crossesBelow(ta.rsi(close, 14), 70);\n * plotshape(down, \"Down\", { style: shape.triangledown, location: location.abovebar });\n * ```\n */\n crossesBelow(a: Series | number, b: Series | number): Series;\n\n /**\n * Tests whether `a` and `b` cross, in either direction: 1 on the bar where they swap sides, else 0.\n * @param a - The first line: a Series or a number.\n * @param b - The second line: a Series or a number.\n * @returns Series of 1 on the crossing bars, 0 elsewhere.\n * @example\n * ```js\n * const crossed = calc.crosses(close, calc.average(close, 50));\n * bgcolor(color.when(crossed, color.new(color.yellow, 80)));\n * ```\n */\n crosses(a: Series | number, b: Series | number): Series;\n\n /**\n * Tests whether `a` is above `b` on each bar. Values closer than 1e-10 count as equal; a NaN on either side\n * gives 0.\n * @param a - The value tested: a Series or a number.\n * @param b - The value it is compared with: a Series or a number.\n * @returns Series of 1 where `a` is above `b`, 0 elsewhere.\n * @example\n * ```js\n * const uptrend = calc.above(close, calc.average(close, 200));\n * ```\n */\n above(a: Series | number, b: Series | number): Series;\n\n /**\n * Tests whether `a` is below `b` on each bar. Values closer than 1e-10 count as equal; a NaN on either side\n * gives 0.\n * @param a - The value tested: a Series or a number.\n * @param b - The value it is compared with: a Series or a number.\n * @returns Series of 1 where `a` is below `b`, 0 elsewhere.\n * @example\n * ```js\n * const oversold = calc.below(ta.rsi(close, 14), 30);\n * ```\n */\n below(a: Series | number, b: Series | number): Series;\n\n /**\n * Tests whether `value` is between two limits on each bar, both limits included. A NaN gives 0.\n * @param value - The value tested: a Series or a number.\n * @param lowLimit - The lower limit: a Series or a number.\n * @param highLimit - The upper limit: a Series or a number.\n * @returns Series of 1 where `lowLimit <= value <= highLimit`, 0 elsewhere.\n * @example\n * ```js\n * const neutral = calc.between(ta.rsi(close, 14), 40, 60);\n * ```\n */\n between(value: Series | number, lowLimit: Series | number, highLimit: Series | number): Series;\n\n /**\n * The value from `bars` bars before, on each bar (`calc.previous(close)` is the previous close). The first bars,\n * which have no earlier bar, get `NaN`.\n * @param source - A Series or a number.\n * @param bars - How many bars back: a whole number, 1 or more. Default: 1.\n * @returns Series of the earlier values.\n * @example\n * ```js\n * const gapUp = calc.above(open, calc.previous(high));\n * ```\n */\n previous(source: Series | number, bars?: number): Series;\n\n /**\n * The difference between the value and the value `bars` bars before (`close - close 1 bar ago`). `NaN` on the\n * first bars.\n * @param source - A Series or a number.\n * @param bars - How many bars back: a whole number, 1 or more. Default: 1.\n * @returns Series of the differences, in the units of the source.\n * @example\n * ```js\n * plot(calc.change(close, 5), \"5-bar change\", { style: plot.style_histogram });\n * ```\n */\n change(source: Series | number, bars?: number): Series;\n\n /**\n * The change in percent since `bars` bars before: `(value - earlier) / earlier * 100`. `NaN` on the first bars;\n * an earlier value of 0 gives an infinite or `NaN` result.\n * @param source - A Series or a number.\n * @param bars - How many bars back: a whole number, 1 or more. Default: 1.\n * @returns Series of the changes in percent (5 means +5 %).\n * @example\n * ```js\n * const roc = calc.percentChange(close, 10);\n * plot(roc, \"10-bar change %\");\n * ```\n */\n percentChange(source: Series | number, bars?: number): Series;\n\n /**\n * The highest value of the last `length` bars, the current bar included.\n * @param source - A Series such as `high`, or a number.\n * @param length - Number of bars in the window: a whole number, 1 or more.\n * @returns Series of the highest values.\n * @example\n * ```js\n * plot(calc.highest(high, 20), \"20-bar high\");\n * ```\n */\n highest(source: Series | number, length: number): Series;\n\n /**\n * The lowest value of the last `length` bars, the current bar included.\n * @param source - A Series such as `low`, or a number.\n * @param length - Number of bars in the window: a whole number, 1 or more.\n * @returns Series of the lowest values.\n * @example\n * ```js\n * plot(calc.lowest(low, 20), \"20-bar low\");\n * ```\n */\n lowest(source: Series | number, length: number): Series;\n\n /**\n * Tests whether the value rose on each of the last `bars` bars (each bar above the one before it).\n * @param source - A Series or a number.\n * @param bars - How many rises in a row: a whole number, 1 or more. Default: 1.\n * @returns Series of 1 where the value rose on each of those bars, 0 elsewhere.\n * @example\n * ```js\n * const climbing = calc.isRising(calc.average(close, 20), 3);\n * ```\n */\n isRising(source: Series | number, bars?: number): Series;\n\n /**\n * Tests whether the value fell on each of the last `bars` bars (each bar below the one before it).\n * @param source - A Series or a number.\n * @param bars - How many falls in a row: a whole number, 1 or more. Default: 1.\n * @returns Series of 1 where the value fell on each of those bars, 0 elsewhere.\n * @example\n * ```js\n * const sliding = calc.isFalling(close, 3);\n * ```\n */\n isFalling(source: Series | number, bars?: number): Series;\n\n /**\n * Standard deviation of the last `length` values (dividing by `length`): how far the values spread around their\n * mean. `NaN` until the window is full.\n * @param source - A Series or a number.\n * @param length - Number of bars in the window: a whole number, 1 or more.\n * @returns Series of the deviations, in the units of the source.\n * @example\n * ```js\n * const spread = calc.standardDeviation(close, 20);\n * plot(calc.average(close, 20).add(spread.mul(2)), \"Upper band\");\n * ```\n */\n standardDeviation(source: Series | number, length: number): Series;\n\n /**\n * Picks one of two values on each bar: `whenTrue` where the condition holds, `whenFalse` elsewhere. A condition\n * holds when it is not 0 and not NaN.\n * @param condition - The condition: a Series of 1 / 0, or a number.\n * @param whenTrue - Value used where the condition holds: a Series or a number.\n * @param whenFalse - Value used elsewhere: a Series or a number.\n * @returns Series of the picked values.\n * @example\n * ```js\n * const body = calc.ifElse(calc.above(close, open), close.sub(open), 0);\n * plot(body, \"Up body\");\n * ```\n */\n ifElse(condition: Series | number, whenTrue: Series | number, whenFalse: Series | number): Series;\n\n /**\n * Tests whether every condition holds on each bar (a logical \"and\"). A condition holds when it is not 0 and not\n * NaN. Give at least one condition.\n * @param conditions - The conditions: Series of 1 / 0, or numbers.\n * @returns Series of 1 where all of them hold, 0 elsewhere.\n * @example\n * ```js\n * const buy = calc.all(calc.above(close, open), calc.below(ta.rsi(close, 14), 40));\n * ```\n */\n all(...conditions: Array<Series | number>): Series;\n\n /**\n * Tests whether at least one condition holds on each bar (a logical \"or\"). A condition holds when it is not 0 and\n * not NaN. Give at least one condition.\n * @param conditions - The conditions: Series of 1 / 0, or numbers.\n * @returns Series of 1 where one of them holds, 0 elsewhere.\n * @example\n * ```js\n * const extreme = calc.any(calc.above(ta.rsi(close, 14), 70), calc.below(ta.rsi(close, 14), 30));\n * ```\n */\n any(...conditions: Array<Series | number>): Series;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }