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
@@ -0,0 +1,1115 @@
1
+ /**
2
+ * @fileoverview The documented type of the `ta` namespace of the script API (technical analysis).
3
+ * @module script/api/ta
4
+ */
5
+
6
+ import type { Series } from '../../runtime/series.js';
7
+
8
+ /**
9
+ * Technical analysis functions and values of the script API: moving averages, oscillators, bands, crosses,
10
+ * pivots and volume indicators.
11
+ *
12
+ * Each function computes a whole Series (one value per bar) in one call, so call it at the top level of the
13
+ * script, before any `eachBar()` loop, and read the value of a bar with `c.get(series)` inside the loop. Missing
14
+ * values (`na`) are `NaN`. Conditions come back as Series of 1 (true) and 0 (false).
15
+ */
16
+ export interface TaNamespace {
17
+ // ── Moving averages ────────────────────────────────────────────────────────
18
+
19
+ /**
20
+ * Simple moving average: the mean of the last `length` values. Use it to smooth a price or any Series.
21
+ * Missing values are skipped (the window holds the last `length` valid values); `NaN` until `length` values exist.
22
+ * @param source - Series to average, e.g. `close`.
23
+ * @param length - Number of values in the window (a fraction is truncated). A Series gives one length per bar.
24
+ * @returns Series of the averages.
25
+ * @example
26
+ * ```js
27
+ * const ma = ta.sma(close, 20);
28
+ * plot(ma, "SMA 20", { color: color.blue });
29
+ * ```
30
+ */
31
+ sma(source: Series, length: number | Series): Series;
32
+
33
+ /**
34
+ * Exponential moving average with the smoothing factor `2 / (length + 1)`: recent values weigh more than in
35
+ * `ta.sma`. The first value is the simple average of the first `length` valid values; `NaN` before it, and on a
36
+ * bar whose source is missing.
37
+ * @param source - Series to average.
38
+ * @param length - Number of bars of the average (at least 1).
39
+ * @returns Series of the averages.
40
+ * @example
41
+ * ```js
42
+ * const fast = ta.ema(close, 12);
43
+ * plot(fast, "Fast EMA");
44
+ * ```
45
+ */
46
+ ema(source: Series, length: number): Series;
47
+
48
+ /**
49
+ * Running moving average (Wilder's smoothing) with the smoothing factor `1 / length`, the average used by
50
+ * `ta.rsi` and `ta.atr`. Starts with the simple average of the first `length` valid values; `NaN` before it.
51
+ * @param source - Series to average.
52
+ * @param length - Number of bars of the average (at least 1).
53
+ * @returns Series of the averages.
54
+ * @example
55
+ * ```js
56
+ * const avgRange = ta.rma(high.sub(low), 14);
57
+ * plot(avgRange, "Average range");
58
+ * ```
59
+ */
60
+ rma(source: Series, length: number): Series;
61
+
62
+ /**
63
+ * Weighted moving average: the newest value has the weight `length`, the one before `length - 1`, and so on
64
+ * down to 1. `NaN` on a bar whose source is missing and until `length` valid values exist.
65
+ * @param source - Series to average.
66
+ * @param length - Number of values in the window (at least 1). A Series gives one length per bar.
67
+ * @returns Series of the averages.
68
+ * @example
69
+ * ```js
70
+ * const wma = ta.wma(close, 10);
71
+ * plot(wma, "WMA 10");
72
+ * ```
73
+ */
74
+ wma(source: Series, length: number | Series): Series;
75
+
76
+ /**
77
+ * Hull moving average: a weighted average of `2 * wma(source, length / 2) - wma(source, length)` over
78
+ * `sqrt(length)` bars, smooth with little lag.
79
+ * @param source - Series to average.
80
+ * @param length - Number of bars (at least 1).
81
+ * @returns Series of the averages.
82
+ * @example
83
+ * ```js
84
+ * const hull = ta.hma(close, 21);
85
+ * plot(hull, "HMA");
86
+ * ```
87
+ */
88
+ hma(source: Series, length: number): Series;
89
+
90
+ /**
91
+ * Arnaud Legoux moving average: a moving average whose weights follow a bell curve placed toward the newest
92
+ * values, smooth with little lag. `NaN` on the first `length - 1` bars and when the window holds a missing value.
93
+ * @param source - Series to average.
94
+ * @param length - Number of bars in the window. Default: 9.
95
+ * @param offset - Where the peak of the weights sits, from 0 (oldest bar) to 1 (newest bar). Default: 0.85.
96
+ * @param sigma - Width of the bell curve: a higher value gives flatter weights. Default: 6.
97
+ * @param floor - When true, the peak position `offset * (length - 1)` is rounded down to a whole bar.
98
+ * Default: false.
99
+ * @returns Series of the averages.
100
+ * @example
101
+ * ```js
102
+ * const alma = ta.alma(close, 9, 0.85, 6);
103
+ * plot(alma, "ALMA");
104
+ * ```
105
+ */
106
+ alma(source: Series, length?: number, offset?: number, sigma?: number, floor?: boolean): Series;
107
+
108
+ /**
109
+ * Symmetrically weighted moving average over 4 bars with the weights 1, 2, 2, 1 (newest to oldest).
110
+ * `NaN` on the first 3 bars and when one of the 4 values is missing.
111
+ * @param source - Series to average.
112
+ * @returns Series of the averages.
113
+ * @example
114
+ * ```js
115
+ * plot(ta.swma(close), "SWMA");
116
+ * ```
117
+ */
118
+ swma(source: Series): Series;
119
+
120
+ /**
121
+ * Volume-weighted moving average: `sma(source * volume, length) / sma(volume, length)`, so bars with more
122
+ * volume weigh more. Uses the chart volume unless a third argument gives another one.
123
+ * @param source - Series to average.
124
+ * @param length - Number of bars (at least 1).
125
+ * @param vol - Volume Series to weigh with. Default: the chart `volume`.
126
+ * @returns Series of the averages (`NaN` where the summed volume is 0).
127
+ * @example
128
+ * ```js
129
+ * const vwma = ta.vwma(close, 20);
130
+ * plot(vwma, "VWMA");
131
+ * ```
132
+ */
133
+ vwma(source: Series, length: number, vol?: Series): Series;
134
+
135
+ /**
136
+ * Volume-weighted average price with the chart volume, restarted on each anchor bar. Without an anchor it
137
+ * restarts on each new trading day (on daily, weekly and monthly charts every bar starts again).
138
+ * @param source - Price Series to average, usually `hlc3`.
139
+ * @param anchor - Series that is non-zero on the bars where the sums restart, e.g.
140
+ * `timeframe.change("W")`. Default: a new trading day.
141
+ * @returns Series of the average price since the last anchor.
142
+ * @example
143
+ * ```js
144
+ * const vwap = ta.vwap(hlc3);
145
+ * plot(vwap, "VWAP", { color: color.orange });
146
+ * ```
147
+ */
148
+ vwap(source: Series, anchor?: Series): Series;
149
+ /**
150
+ * Volume-weighted average price with bands at a multiple of the volume-weighted standard deviation.
151
+ * @param source - Price Series to average, usually `hlc3`.
152
+ * @param anchor - Series that is non-zero on the bars where the sums restart, or `undefined` for a new trading
153
+ * day.
154
+ * @param stdev_mult - Distance of the bands from the average, in standard deviations.
155
+ * @returns Tuple `[vwap, upper, lower]` of Series.
156
+ * @example
157
+ * ```js
158
+ * const [vwap, upper, lower] = ta.vwap(hlc3, undefined, 2);
159
+ * plot(upper, "Upper");
160
+ * plot(lower, "Lower");
161
+ * ```
162
+ */
163
+ vwap(source: Series, anchor: Series | undefined, stdev_mult: number): [Series, Series, Series];
164
+
165
+ /**
166
+ * Volume-weighted average price with bands, with an explicit volume. Same as `ta.vwap(source, anchor,
167
+ * stdev_mult)` with another volume Series; without an anchor the sums never restart.
168
+ * @param source - Price Series to average.
169
+ * @param volume - Volume Series to weigh with.
170
+ * @param anchor - Series that is non-zero on the bars where the sums restart, or `undefined` for no restart.
171
+ * @param stdev_mult - Distance of the bands from the average, in standard deviations.
172
+ * @returns Tuple `[vwap, upper, lower]` of Series.
173
+ * @example
174
+ * ```js
175
+ * const [vwap, upper, lower] = ta.vwapBands(hlc3, volume, timeframe.change("D"), 1);
176
+ * plot(vwap, "VWAP");
177
+ * ```
178
+ */
179
+ vwapBands(
180
+ source: Series,
181
+ volume: Series,
182
+ anchor: Series | undefined,
183
+ stdev_mult: number
184
+ ): [Series, Series, Series];
185
+
186
+ // ── Oscillators and momentum ───────────────────────────────────────────────
187
+
188
+ /**
189
+ * Relative strength index, from 0 to 100: the share of the average gains in the average gains and losses
190
+ * over `length` bars (Wilder's smoothing). Above 70 is often read as overbought, below 30 as oversold.
191
+ * @param source - Series to measure, e.g. `close`.
192
+ * @param length - Number of bars of the averages (at least 1).
193
+ * @returns Series of values from 0 to 100.
194
+ * @example
195
+ * ```js
196
+ * const rsi = ta.rsi(close, 14);
197
+ * plot(rsi, "RSI");
198
+ * hline(70, "Overbought");
199
+ * ```
200
+ */
201
+ rsi(source: Series, length: number): Series;
202
+ /**
203
+ * Relative strength index from two averages you computed yourself: `100 - 100 / (1 + up / down)`; 100 when
204
+ * `down` is 0, 0 when `up` is 0.
205
+ * @param up - Average of the upward changes.
206
+ * @param down - Average of the downward changes.
207
+ * @returns Series of values from 0 to 100.
208
+ * @example
209
+ * ```js
210
+ * const up = ta.rma(ta.change(close).mul(close.gt(close.offset(1))), 14);
211
+ * const down = ta.rma(ta.change(close).neg().mul(close.lt(close.offset(1))), 14);
212
+ * plot(ta.rsi(up, down), "RSI");
213
+ * ```
214
+ */
215
+ rsi(up: Series, down: Series): Series;
216
+
217
+ /**
218
+ * Moving average convergence divergence: the gap between a fast and a slow exponential average, its own
219
+ * average (the signal line) and the difference of the two (the histogram).
220
+ * @param source - Series to measure, e.g. `close`.
221
+ * @param fastLength - Length of the fast exponential average, e.g. 12.
222
+ * @param slowLength - Length of the slow exponential average, e.g. 26.
223
+ * @param signalLength - Length of the exponential average of the MACD line, e.g. 9.
224
+ * @returns Tuple `[macdLine, signalLine, histogram]` of Series.
225
+ * @example
226
+ * ```js
227
+ * const [macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9);
228
+ * plot(hist, "Histogram", { style: plot.style_columns });
229
+ * plot(macdLine, "MACD");
230
+ * ```
231
+ */
232
+ macd(
233
+ source: Series,
234
+ fastLength: number,
235
+ slowLength: number,
236
+ signalLength: number
237
+ ): [Series, Series, Series];
238
+
239
+ /**
240
+ * Stochastic %K, from 0 to 100: where `source` sits in the range between the lowest `low` and the highest
241
+ * `high` of the last `length` bars. Smooth it with `ta.sma` for the %D line. A bar where it cannot be computed
242
+ * keeps the previous value.
243
+ * @param source - Series to place in the range, usually `close`.
244
+ * @param highSource - Series of highs, usually `high`.
245
+ * @param lowSource - Series of lows, usually `low`.
246
+ * @param length - Number of bars of the range (at least 1).
247
+ * @returns Series of values from 0 to 100.
248
+ * @example
249
+ * ```js
250
+ * const k = ta.sma(ta.stoch(close, high, low, 14), 3);
251
+ * plot(k, "%K");
252
+ * plot(ta.sma(k, 3), "%D");
253
+ * ```
254
+ */
255
+ stoch(source: Series, highSource: Series, lowSource: Series, length: number): Series;
256
+
257
+ /**
258
+ * Commodity channel index: `(source - sma) / (0.015 * mean deviation)` over `length` bars. Readings above
259
+ * +100 or below -100 mark strong moves. A flat window keeps the previous value.
260
+ * @param source - Series to measure, usually `hlc3`.
261
+ * @param length - Number of bars (at least 1).
262
+ * @returns Series of index values (unbounded).
263
+ * @example
264
+ * ```js
265
+ * const cci = ta.cci(hlc3, 20);
266
+ * plot(cci, "CCI");
267
+ * ```
268
+ */
269
+ cci(source: Series, length: number): Series;
270
+
271
+ /**
272
+ * Money flow index, from 0 to 100: a volume-weighted version of the RSI built from the chart volume. Above 80
273
+ * is often read as overbought, below 20 as oversold.
274
+ * @param source - Price Series, usually `hlc3`.
275
+ * @param length - Number of bars (at least 1).
276
+ * @returns Series of values from 0 to 100.
277
+ * @example
278
+ * ```js
279
+ * const mfi = ta.mfi(hlc3, 14);
280
+ * plot(mfi, "MFI");
281
+ * ```
282
+ */
283
+ mfi(source: Series, length: number): Series;
284
+
285
+ /**
286
+ * Williams %R, from -100 to 0: where the close sits in the high-low range of the last `length` bars
287
+ * (0 = at the highest high, -100 = at the lowest low). Uses the chart high, low and close.
288
+ * @param length - Number of bars (at least 1). Default: 14.
289
+ * @returns Series of values from -100 to 0 (`NaN` when the range is 0).
290
+ * @example
291
+ * ```js
292
+ * const wpr = ta.wpr(14);
293
+ * plot(wpr, "%R");
294
+ * ```
295
+ */
296
+ wpr(length?: number): Series;
297
+
298
+ /**
299
+ * True strength index, from -1 to 1: the bar-to-bar change smoothed twice with exponential averages, divided
300
+ * by the change size smoothed the same way. Not multiplied by 100.
301
+ * @param source - Series to measure, e.g. `close`.
302
+ * @param shortLength - Length of the second (short) smoothing.
303
+ * @param longLength - Length of the first (long) smoothing.
304
+ * @returns Series of values from -1 to 1 (`NaN` when the source does not move).
305
+ * @example
306
+ * ```js
307
+ * const tsi = ta.tsi(close, 13, 25);
308
+ * plot(tsi, "TSI");
309
+ * ```
310
+ */
311
+ tsi(source: Series, shortLength: number, longLength: number): Series;
312
+
313
+ /**
314
+ * Chande momentum oscillator, from -100 to 100: `100 * (sum of gains - sum of losses) / (sum of gains + sum
315
+ * of losses)` over the last `length` bars.
316
+ * @param source - Series to measure, e.g. `close`.
317
+ * @param length - Number of bars (at least 1).
318
+ * @returns Series of values from -100 to 100 (`NaN` when every change in the window is 0).
319
+ * @example
320
+ * ```js
321
+ * const cmo = ta.cmo(close, 9);
322
+ * plot(cmo, "CMO");
323
+ * ```
324
+ */
325
+ cmo(source: Series, length: number): Series;
326
+
327
+ /**
328
+ * Center of gravity oscillator: `-sum(source[i] * (i + 1)) / sum(source)` over the last `length` bars
329
+ * (`i` = 0 for the newest bar). Turns tend to show early.
330
+ * @param source - Series to measure, e.g. `close`.
331
+ * @param length - Number of bars (at least 1). Default: 10.
332
+ * @returns Series of oscillator values (`NaN` when the window holds a missing value).
333
+ * @example
334
+ * ```js
335
+ * const cog = ta.cog(close, 10);
336
+ * plot(cog, "COG");
337
+ * ```
338
+ */
339
+ cog(source: Series, length?: number): Series;
340
+
341
+ /**
342
+ * Rank correlation index, from -100 to 100: how steadily the source rose (+100) or fell (-100) over the
343
+ * last `length` bars, from the rank order of the values. The first value is on bar `length`.
344
+ * @param source - Series to measure, e.g. `close`.
345
+ * @param length - Number of bars (at least 1).
346
+ * @returns Series of values from -100 to 100.
347
+ * @example
348
+ * ```js
349
+ * const rci = ta.rci(close, 9);
350
+ * plot(rci, "RCI");
351
+ * ```
352
+ */
353
+ rci(source: Series, length: number): Series;
354
+
355
+ /**
356
+ * Momentum: `source - source[length]`, the change over `length` bars. `NaN` on the first `length` bars.
357
+ * @param source - Series to measure.
358
+ * @param length - Number of bars back (at least 1).
359
+ * @returns Series of differences.
360
+ * @example
361
+ * ```js
362
+ * const mom = ta.mom(close, 10);
363
+ * plot(mom, "Momentum");
364
+ * ```
365
+ */
366
+ mom(source: Series, length: number): Series;
367
+
368
+ /**
369
+ * Rate of change in percent: `100 * (source - source[length]) / source[length]`. `NaN` on the first `length`
370
+ * bars.
371
+ * @param source - Series to measure.
372
+ * @param length - Number of bars back (at least 1).
373
+ * @returns Series of percentages (5 means +5%).
374
+ * @example
375
+ * ```js
376
+ * const roc = ta.roc(close, 9);
377
+ * plot(roc, "ROC");
378
+ * ```
379
+ */
380
+ roc(source: Series, length: number): Series;
381
+
382
+ /**
383
+ * Change over `length` bars: `source - source[length]`. With the default length, the difference from the
384
+ * previous bar. `NaN` on the first `length` bars.
385
+ * @param source - Series to measure.
386
+ * @param length - Number of bars back (at least 1). Default: 1.
387
+ * @returns Series of differences.
388
+ * @example
389
+ * ```js
390
+ * const diff = ta.change(close);
391
+ * plot(diff, "Change", { style: plot.style_histogram });
392
+ * ```
393
+ */
394
+ change(source: Series, length?: number): Series;
395
+
396
+ // ── Volatility and bands ───────────────────────────────────────────────────
397
+
398
+ /**
399
+ * True range of each bar: the largest of `high - low`, `|high - previous close|` and `|low - previous close|`.
400
+ * Uses the chart high, low and close.
401
+ * @param handleNa - What to return when the previous close is missing (the first bar): true gives
402
+ * `high - low`, false gives `NaN`. Default: false.
403
+ * @returns Series of true ranges, in price units.
404
+ * @example
405
+ * ```js
406
+ * const range = ta.tr(true);
407
+ * plot(range, "True range");
408
+ * ```
409
+ */
410
+ tr(handleNa?: boolean): Series;
411
+
412
+ /**
413
+ * Average true range: the running moving average (`ta.rma`) of the true range over `length` bars, a measure
414
+ * of volatility in price units. Uses the chart high, low and close.
415
+ * @param length - Number of bars (at least 1).
416
+ * @returns Series of average ranges.
417
+ * @example
418
+ * ```js
419
+ * const atr = ta.atr(14);
420
+ * plot(close.sub(atr.mul(2)), "Stop");
421
+ * ```
422
+ */
423
+ atr(length: number): Series;
424
+
425
+ /**
426
+ * Bollinger Bands: a simple moving average with bands `mult` standard deviations above and below it.
427
+ * @param source - Series to measure, e.g. `close`.
428
+ * @param length - Number of bars of the average and the deviation.
429
+ * @param mult - Distance of the bands, in standard deviations, e.g. 2.
430
+ * @returns Tuple `[middle, upper, lower]` of Series.
431
+ * @example
432
+ * ```js
433
+ * const [middle, upper, lower] = ta.bb(close, 20, 2);
434
+ * fill(plot(upper, "Upper"), plot(lower, "Lower"), { color: color.new(color.blue, 90) });
435
+ * ```
436
+ */
437
+ bb(source: Series, length: number, mult: number): [Series, Series, Series];
438
+
439
+ /**
440
+ * Bollinger Bands width in percent of the middle band: `100 * (upper - lower) / middle`. Low values mark
441
+ * quiet markets.
442
+ * @param source - Series to measure, e.g. `close`.
443
+ * @param length - Number of bars of the average and the deviation.
444
+ * @param mult - Distance of the bands, in standard deviations.
445
+ * @returns Series of widths in percent (`NaN` when the middle band is 0).
446
+ * @example
447
+ * ```js
448
+ * const width = ta.bbw(close, 20, 2);
449
+ * plot(width, "BB width");
450
+ * ```
451
+ */
452
+ bbw(source: Series, length: number, mult: number): Series;
453
+
454
+ /**
455
+ * Keltner Channels: an exponential average of `source` with bands at `mult` times the exponential average
456
+ * of the true range (or of `high - low`) above and below it. Uses the chart high, low and close.
457
+ * @param source - Series of the middle line, e.g. `close`.
458
+ * @param length - Number of bars of the averages.
459
+ * @param mult - Multiplier of the range for the bands.
460
+ * @param useTrueRange - True: the bands use the true range; false: `high - low`. Default: true.
461
+ * @returns Tuple `[middle, upper, lower]` of Series.
462
+ * @example
463
+ * ```js
464
+ * const [middle, upper, lower] = ta.kc(close, 20, 1.5);
465
+ * plot(upper, "Upper");
466
+ * plot(lower, "Lower");
467
+ * ```
468
+ */
469
+ kc(
470
+ source: Series,
471
+ length: number,
472
+ mult: number,
473
+ useTrueRange?: boolean
474
+ ): [Series, Series, Series];
475
+
476
+ /**
477
+ * Keltner Channels width as a ratio of the middle line: `(upper - lower) / middle` (0.05 is a width of 5%).
478
+ * Uses the chart high, low and close.
479
+ * @param source - Series of the middle line, e.g. `close`.
480
+ * @param length - Number of bars of the averages. Default: 20.
481
+ * @param mult - Multiplier of the range for the bands. Default: 2.
482
+ * @param useTrueRange - True: the bands use the true range; false: `high - low`. Default: true.
483
+ * @returns Series of ratios.
484
+ * @example
485
+ * ```js
486
+ * const width = ta.kcw(close, 20, 2);
487
+ * plot(width, "KC width");
488
+ * ```
489
+ */
490
+ kcw(source: Series, length?: number, mult?: number, useTrueRange?: boolean): Series;
491
+
492
+ /**
493
+ * Standard deviation over the last `length` values: how far the values spread around their mean. Missing
494
+ * values are skipped; `NaN` until `length` values exist.
495
+ * @param source - Series to measure.
496
+ * @param length - Number of values in the window. A Series gives one length per bar.
497
+ * @param biased - True divides by `length` (whole population); false by `length - 1` (sample). Default: true.
498
+ * @returns Series of deviations, in the units of the source.
499
+ * @example
500
+ * ```js
501
+ * const sd = ta.stdev(close, 20);
502
+ * plot(sd, "Std dev");
503
+ * ```
504
+ */
505
+ stdev(source: Series, length: number | Series, biased?: boolean): Series;
506
+
507
+ /**
508
+ * Variance over the last `length` values: the mean of the squared distances to the mean (the square of
509
+ * `ta.stdev`). Missing values are skipped; `NaN` until `length` values exist.
510
+ * @param source - Series to measure.
511
+ * @param length - Number of values in the window. A Series gives one length per bar.
512
+ * @param biased - True divides by `length` (whole population); false by `length - 1` (sample). Default: true.
513
+ * @returns Series of variances.
514
+ * @example
515
+ * ```js
516
+ * const v = ta.variance(close, 20);
517
+ * plot(v, "Variance");
518
+ * ```
519
+ */
520
+ variance(source: Series, length: number | Series, biased?: boolean): Series;
521
+
522
+ /**
523
+ * Mean absolute deviation: the average distance of the last `length` values from their simple average.
524
+ * `NaN` when one of these values is missing.
525
+ * @param source - Series to measure.
526
+ * @param length - Number of bars (at least 1).
527
+ * @returns Series of deviations, in the units of the source.
528
+ * @example
529
+ * ```js
530
+ * const md = ta.dev(close, 20);
531
+ * plot(md, "Mean deviation");
532
+ * ```
533
+ */
534
+ dev(source: Series, length: number): Series;
535
+
536
+ /**
537
+ * Parabolic SAR (stop and reverse): a trailing level below the price in an up trend and above it in a down
538
+ * trend, which flips when the price crosses it. Uses the chart high, low and close. `NaN` on the first bar.
539
+ * @param start - Starting acceleration factor. Default: 0.02.
540
+ * @param inc - Step added to the acceleration on each new extreme. Default: 0.02.
541
+ * @param max - Largest acceleration factor. Default: 0.2.
542
+ * @returns Series of stop levels, in price units.
543
+ * @example
544
+ * ```js
545
+ * const sar = ta.sar(0.02, 0.02, 0.2);
546
+ * plot(sar, "SAR", { style: plot.style_cross });
547
+ * ```
548
+ */
549
+ sar(start?: number, inc?: number, max?: number): Series;
550
+
551
+ /**
552
+ * Supertrend: a trailing line at `factor` average true ranges from the middle of the bar, below the price in an
553
+ * up trend and above it in a down trend. Uses the chart high, low and close.
554
+ * @param factor - Multiplier of the average true range, e.g. 3.
555
+ * @param atrLength - Number of bars of the average true range, e.g. 10.
556
+ * @returns Tuple `[supertrend, direction]`: the line, and the direction (-1 in an up trend, 1 in a down trend).
557
+ * @example
558
+ * ```js
559
+ * const [line, direction] = ta.supertrend(3, 10);
560
+ * plot(line, "Supertrend", { color: color.when(direction.lt(0), color.green, color.red) });
561
+ * ```
562
+ */
563
+ supertrend(factor: number, atrLength: number): [Series, Series];
564
+
565
+ /**
566
+ * Directional movement index: the plus and minus directional indicators and the average directional index
567
+ * (trend strength, 0 to 100). Uses the chart high, low and close.
568
+ * @param diLength - Number of bars of the directional indicators, e.g. 14.
569
+ * @param adxSmoothing - Number of bars of the ADX smoothing, e.g. 14.
570
+ * @returns Tuple `[plusDI, minusDI, adx]` of Series.
571
+ * @example
572
+ * ```js
573
+ * const [plusDI, minusDI, adx] = ta.dmi(14, 14);
574
+ * plot(adx, "ADX");
575
+ * ```
576
+ */
577
+ dmi(diLength: number, adxSmoothing: number): [Series, Series, Series];
578
+
579
+ /**
580
+ * Ichimoku cloud lines, computed from the chart high, low and close. The two leading spans are already moved
581
+ * `displacement` bars forward (their value on a bar comes from `displacement` bars earlier), and the lagging
582
+ * span is moved `displacement` bars back (its value on a bar is the close `displacement` bars later, so the last
583
+ * `displacement` bars are `NaN`).
584
+ * @param conversionPeriods - Bars of the conversion line (midpoint of the high-low range), e.g. 9.
585
+ * @param basePeriods - Bars of the base line, e.g. 26.
586
+ * @param laggingSpan2Periods - Bars of the second leading span, e.g. 52.
587
+ * @param displacement - Number of bars the spans are moved, e.g. 26.
588
+ * @returns Tuple `[conversion, base, leadA, leadB, lagging]` of Series.
589
+ * @example
590
+ * ```js
591
+ * const [conversion, base, leadA, leadB] = ta.ichimoku(9, 26, 52, 26);
592
+ * fill(plot(leadA, "Lead A"), plot(leadB, "Lead B"), { color: color.new(color.teal, 85) });
593
+ * ```
594
+ */
595
+ ichimoku(
596
+ conversionPeriods: number,
597
+ basePeriods: number,
598
+ laggingSpan2Periods: number,
599
+ displacement: number
600
+ ): [Series, Series, Series, Series, Series];
601
+
602
+ // ── Crosses and conditions ─────────────────────────────────────────────────
603
+
604
+ /**
605
+ * Crossover: 1 on the bar where `a` moves above `b` (it was at or below `b` on the last bar where both had a
606
+ * value), 0 elsewhere.
607
+ * @param a - Series that crosses.
608
+ * @param b - Series or fixed level it crosses.
609
+ * @returns Series of 1 / 0.
610
+ * @example
611
+ * ```js
612
+ * const buy = ta.crossover(ta.ema(close, 9), ta.ema(close, 21));
613
+ * plotshape(buy, "Buy", { style: shape.triangleup, location: location.belowbar });
614
+ * ```
615
+ */
616
+ crossover(a: Series, b: Series | number): Series;
617
+
618
+ /**
619
+ * Crossunder: 1 on the bar where `a` moves below `b` (it was at or above `b` on the last bar where both had a
620
+ * value), 0 elsewhere.
621
+ * @param a - Series that crosses.
622
+ * @param b - Series or fixed level it crosses.
623
+ * @returns Series of 1 / 0.
624
+ * @example
625
+ * ```js
626
+ * const exitSignal = ta.crossunder(ta.rsi(close, 14), 70);
627
+ * plotshape(exitSignal, "Exit", { style: shape.xcross, location: location.abovebar });
628
+ * ```
629
+ */
630
+ crossunder(a: Series, b: Series | number): Series;
631
+
632
+ /**
633
+ * Cross in either direction: 1 on the bar where `a` moves to the other side of `b` (bars where they are equal
634
+ * do not count as a side), 0 elsewhere.
635
+ * @param a - First Series.
636
+ * @param b - Second Series or a fixed level.
637
+ * @returns Series of 1 / 0.
638
+ * @example
639
+ * ```js
640
+ * const [macdLine, signalLine] = ta.macd(close, 12, 26, 9);
641
+ * bgcolor(color.when(ta.cross(macdLine, signalLine), color.new(color.gray, 85)));
642
+ * ```
643
+ */
644
+ cross(a: Series, b: Series | number): Series;
645
+
646
+ /**
647
+ * Rising: 1 when the source went up on each of the last `length` bars, 0 otherwise.
648
+ * @param source - Series to test.
649
+ * @param length - Number of rises in a row needed (at least 1).
650
+ * @returns Series of 1 / 0.
651
+ * @example
652
+ * ```js
653
+ * const up3 = ta.rising(close, 3);
654
+ * bgcolor(color.when(up3, color.new(color.green, 85)));
655
+ * ```
656
+ */
657
+ rising(source: Series, length: number): Series;
658
+
659
+ /**
660
+ * Falling: 1 when the source went down on each of the last `length` bars, 0 otherwise.
661
+ * @param source - Series to test.
662
+ * @param length - Number of falls in a row needed (at least 1).
663
+ * @returns Series of 1 / 0.
664
+ * @example
665
+ * ```js
666
+ * const down3 = ta.falling(close, 3);
667
+ * bgcolor(color.when(down3, color.new(color.red, 85)));
668
+ * ```
669
+ */
670
+ falling(source: Series, length: number): Series;
671
+
672
+ /**
673
+ * Bars since a condition: 0 on a bar where the condition is 1, then 1, 2, 3... until it is 1 again. `NaN`
674
+ * until the condition was first true.
675
+ * @param condition - Series of 1 / 0 (only the value 1 counts as true).
676
+ * @returns Series of bar counts.
677
+ * @example
678
+ * ```js
679
+ * const sinceCross = ta.barssince(ta.crossover(close, ta.sma(close, 50)));
680
+ * plot(sinceCross, "Bars since cross");
681
+ * ```
682
+ */
683
+ barssince(condition: Series): Series;
684
+
685
+ /**
686
+ * Value when a condition was true: on each bar, the value `source` had on the bar of the `occurrence`-th most
687
+ * recent bar where the condition was 1. `NaN` while there were not enough such bars.
688
+ * @param condition - Series of 1 / 0 (only the value 1 counts as true).
689
+ * @param source - Series whose value is taken.
690
+ * @param occurrence - Which true bar, counting back: 0 is the most recent, 1 the one before, and so on.
691
+ * @returns Series of the remembered values.
692
+ * @example
693
+ * ```js
694
+ * const lastCrossLow = ta.valuewhen(ta.crossover(close, ta.sma(close, 20)), low, 0);
695
+ * plot(lastCrossLow, "Low at last cross");
696
+ * ```
697
+ */
698
+ valuewhen(condition: Series, source: Series, occurrence: number): Series;
699
+
700
+ // ── Window statistics ──────────────────────────────────────────────────────
701
+
702
+ /**
703
+ * Highest value of the last `length` bars of the chart `high`.
704
+ * @param length - Number of bars. A Series gives one length per bar.
705
+ * @returns Series of the highest highs (`NaN` on the first `length - 1` bars).
706
+ * @example
707
+ * ```js
708
+ * const top = ta.highest(20);
709
+ * plot(top, "20-bar high");
710
+ * ```
711
+ */
712
+ highest(length: number): Series;
713
+ /**
714
+ * Highest value of the last `length` values of a Series, e.g. a 20-bar high for a breakout. Missing values are
715
+ * skipped; `NaN` on the first `length - 1` bars.
716
+ * @param source - Series to search.
717
+ * @param length - Number of bars (a fraction is truncated). A Series gives one length per bar.
718
+ * @returns Series of the highest values.
719
+ * @example
720
+ * ```js
721
+ * const top = ta.highest(close, 20);
722
+ * plotshape(close.gte(top), "New high", { location: location.abovebar });
723
+ * ```
724
+ */
725
+ highest(source: Series, length: number | Series): Series;
726
+
727
+ /**
728
+ * Lowest value of the last `length` bars of the chart `low`.
729
+ * @param length - Number of bars. A Series gives one length per bar.
730
+ * @returns Series of the lowest lows (`NaN` on the first `length - 1` bars).
731
+ * @example
732
+ * ```js
733
+ * const bottom = ta.lowest(20);
734
+ * plot(bottom, "20-bar low");
735
+ * ```
736
+ */
737
+ lowest(length: number): Series;
738
+ /**
739
+ * Lowest value of the last `length` values of a Series. Missing values are skipped; `NaN` on the first
740
+ * `length - 1` bars.
741
+ * @param source - Series to search.
742
+ * @param length - Number of bars (a fraction is truncated). A Series gives one length per bar.
743
+ * @returns Series of the lowest values.
744
+ * @example
745
+ * ```js
746
+ * const bottom = ta.lowest(close, 20);
747
+ * plot(bottom, "20-bar low of close");
748
+ * ```
749
+ */
750
+ lowest(source: Series, length: number | Series): Series;
751
+
752
+ /**
753
+ * Offset to the bar with the highest chart `high` of the last `length` bars: 0 for the current bar, -1 for the
754
+ * bar before, and so on (always 0 or negative).
755
+ * @param length - Number of bars. A Series gives one length per bar.
756
+ * @returns Series of offsets (`NaN` on the first `length - 1` bars).
757
+ * @example
758
+ * ```js
759
+ * const ago = ta.highestbars(20);
760
+ * plot(ago, "Bars since 20-bar high");
761
+ * ```
762
+ */
763
+ highestbars(length: number): Series;
764
+ /**
765
+ * Offset to the bar with the highest value of the last `length` values of a Series: 0 for the current bar,
766
+ * -1 for the bar before, and so on (always 0 or negative; the newest bar wins a tie).
767
+ * @param source - Series to search.
768
+ * @param length - Number of bars. A Series gives one length per bar.
769
+ * @returns Series of offsets (`NaN` on the first `length - 1` bars).
770
+ * @example
771
+ * ```js
772
+ * const ago = ta.highestbars(close, 20);
773
+ * plot(ago, "Offset of highest close");
774
+ * ```
775
+ */
776
+ highestbars(source: Series, length: number | Series): Series;
777
+
778
+ /**
779
+ * Offset to the bar with the lowest chart `low` of the last `length` bars: 0 for the current bar, -1 for the
780
+ * bar before, and so on (always 0 or negative).
781
+ * @param length - Number of bars. A Series gives one length per bar.
782
+ * @returns Series of offsets (`NaN` on the first `length - 1` bars).
783
+ * @example
784
+ * ```js
785
+ * const ago = ta.lowestbars(20);
786
+ * plot(ago, "Bars since 20-bar low");
787
+ * ```
788
+ */
789
+ lowestbars(length: number): Series;
790
+ /**
791
+ * Offset to the bar with the lowest value of the last `length` values of a Series: 0 for the current bar,
792
+ * -1 for the bar before, and so on (always 0 or negative; the newest bar wins a tie).
793
+ * @param source - Series to search.
794
+ * @param length - Number of bars. A Series gives one length per bar.
795
+ * @returns Series of offsets (`NaN` on the first `length - 1` bars).
796
+ * @example
797
+ * ```js
798
+ * const ago = ta.lowestbars(close, 20);
799
+ * plot(ago, "Offset of lowest close");
800
+ * ```
801
+ */
802
+ lowestbars(source: Series, length: number | Series): Series;
803
+
804
+ /**
805
+ * Range of the last `length` values: highest minus lowest. Missing values are skipped; `NaN` until `length`
806
+ * values exist.
807
+ * @param source - Series to measure.
808
+ * @param length - Number of values (at least 1).
809
+ * @returns Series of ranges, in the units of the source.
810
+ * @example
811
+ * ```js
812
+ * const width = ta.range(close, 20);
813
+ * plot(width, "20-bar range");
814
+ * ```
815
+ */
816
+ range(source: Series, length: number): Series;
817
+
818
+ /**
819
+ * All-time highest value: the highest value of the source from the first bar up to each bar. Missing values
820
+ * are skipped.
821
+ * @param source - Series to search.
822
+ * @returns Series of running highest values (`NaN` until the first value).
823
+ * @example
824
+ * ```js
825
+ * plot(ta.max(high), "All-time high");
826
+ * ```
827
+ */
828
+ max(source: Series): Series;
829
+
830
+ /**
831
+ * All-time lowest value: the lowest value of the source from the first bar up to each bar. Missing values
832
+ * are skipped.
833
+ * @param source - Series to search.
834
+ * @returns Series of running lowest values (`NaN` until the first value).
835
+ * @example
836
+ * ```js
837
+ * plot(ta.min(low), "All-time low");
838
+ * ```
839
+ */
840
+ min(source: Series): Series;
841
+
842
+ /**
843
+ * Median of the last `length` values (the mean of the two middle values for an even length). Missing values
844
+ * are skipped; `NaN` until `length` values exist.
845
+ * @param source - Series to measure.
846
+ * @param length - Number of values (at least 1).
847
+ * @returns Series of medians.
848
+ * @example
849
+ * ```js
850
+ * plot(ta.median(close, 20), "Median");
851
+ * ```
852
+ */
853
+ median(source: Series, length: number): Series;
854
+
855
+ /**
856
+ * Mode of the last `length` values: the most frequent value (the smallest one when several are as frequent).
857
+ * Missing values are skipped; `NaN` until `length` values exist.
858
+ * @param source - Series to measure.
859
+ * @param length - Number of values (at least 1).
860
+ * @returns Series of modes.
861
+ * @example
862
+ * ```js
863
+ * plot(ta.mode(close, 20), "Mode");
864
+ * ```
865
+ */
866
+ mode(source: Series, length: number): Series;
867
+
868
+ /**
869
+ * Percentile of the last `length` values, interpolated between the two nearest ranks (so the result may not be
870
+ * one of the values). `NaN` on the first `length - 1` bars.
871
+ * @param source - Series to measure.
872
+ * @param length - Number of bars (at least 1).
873
+ * @param percentage - Percentile to return, from 0 to 100 (50 is the median).
874
+ * @returns Series of percentile values.
875
+ * @example
876
+ * ```js
877
+ * const p90 = ta.percentile_linear_interpolation(close, 50, 90);
878
+ * plot(p90, "90th percentile");
879
+ * ```
880
+ */
881
+ percentile_linear_interpolation(source: Series, length: number, percentage: number): Series;
882
+
883
+ /**
884
+ * Percentile of the last `length` values by the nearest rank: always one of the values in the window.
885
+ * `NaN` on the first `length - 1` bars.
886
+ * @param source - Series to measure.
887
+ * @param length - Number of bars (at least 1).
888
+ * @param percentage - Percentile to return, from 0 to 100 (100 is the largest value).
889
+ * @returns Series of percentile values.
890
+ * @example
891
+ * ```js
892
+ * const p10 = ta.percentile_nearest_rank(close, 50, 10);
893
+ * plot(p10, "10th percentile");
894
+ * ```
895
+ */
896
+ percentile_nearest_rank(source: Series, length: number, percentage: number): Series;
897
+
898
+ /**
899
+ * Percent rank, from 0 to 100: the share of the previous `length` values that are at or below the current
900
+ * value. `NaN` on the first `length` bars.
901
+ * @param source - Series to measure.
902
+ * @param length - Number of previous bars to compare with (at least 1).
903
+ * @returns Series of values from 0 to 100.
904
+ * @example
905
+ * ```js
906
+ * const rank = ta.percentrank(close, 100);
907
+ * plot(rank, "Percent rank");
908
+ * ```
909
+ */
910
+ percentrank(source: Series, length: number): Series;
911
+
912
+ /**
913
+ * Correlation coefficient of two Series over the last `length` bars, from -1 (move in opposite directions) to
914
+ * 1 (move together).
915
+ * @param a - First Series.
916
+ * @param b - Second Series.
917
+ * @param length - Number of bars (at least 1).
918
+ * @returns Series of values from -1 to 1 (`NaN` when one Series is flat over the window).
919
+ * @example
920
+ * ```js
921
+ * const corr = ta.correlation(close, volume, 20);
922
+ * plot(corr, "Price / volume correlation");
923
+ * ```
924
+ */
925
+ correlation(a: Series, b: Series, length: number): Series;
926
+
927
+ /**
928
+ * Linear regression: the least-squares line through the last `length` values, read on the current bar (or
929
+ * `offset` bars back along the line). `NaN` when the window holds a missing value.
930
+ * @param source - Series to fit.
931
+ * @param length - Number of bars (at least 1).
932
+ * @param offset - Bars back along the line where it is read: 0 is the current bar, a negative value projects
933
+ * ahead. Default: 0.
934
+ * @returns Series of fitted values.
935
+ * @example
936
+ * ```js
937
+ * const fit = ta.linreg(close, 50);
938
+ * plot(fit, "Regression");
939
+ * ```
940
+ */
941
+ linreg(source: Series, length: number, offset?: number): Series;
942
+
943
+ /**
944
+ * Cumulative sum of the source from the first bar. A missing value adds nothing and gives `NaN` on its own
945
+ * bar only.
946
+ * @param source - Series to add up.
947
+ * @returns Series of running totals.
948
+ * @example
949
+ * ```js
950
+ * const totalVolume = ta.cum(volume);
951
+ * plot(totalVolume, "Cumulative volume");
952
+ * ```
953
+ */
954
+ cum(source: Series): Series;
955
+
956
+ // ── Pivots and zigzag ──────────────────────────────────────────────────────
957
+
958
+ /**
959
+ * Pivot high of the chart `high`: a bar higher than the `rightbars` bars after it and at least as high as the
960
+ * `leftbars` bars before it. The value appears `rightbars` bars after the pivot bar, when it is confirmed;
961
+ * `NaN` on the other bars.
962
+ * @param leftbars - Bars to the left of the pivot.
963
+ * @param rightbars - Bars to the right of the pivot.
964
+ * @returns Series of the pivot high price on the confirming bar, `NaN` elsewhere.
965
+ * @example
966
+ * ```js
967
+ * const ph = ta.pivothigh(5, 5);
968
+ * plot(ph, "Pivot high", { style: plot.style_circles, offset: -5 });
969
+ * ```
970
+ */
971
+ pivothigh(leftbars: number, rightbars: number | Series): Series;
972
+ /**
973
+ * Pivot high of a Series: a value higher than the `rightbars` values after it and at least as high as the
974
+ * `leftbars` values before it. The value appears `rightbars` bars after the pivot bar; `NaN` on the other bars.
975
+ * @param source - Series to search.
976
+ * @param leftbars - Bars to the left of the pivot. A Series gives one length per bar.
977
+ * @param rightbars - Bars to the right of the pivot. A Series gives one length per bar.
978
+ * @returns Series of the pivot value on the confirming bar, `NaN` elsewhere.
979
+ * @example
980
+ * ```js
981
+ * const ph = ta.pivothigh(close, 3, 3);
982
+ * plot(ph, "Pivot high", { style: plot.style_circles, offset: -3 });
983
+ * ```
984
+ */
985
+ pivothigh(source: Series, leftbars: number | Series, rightbars: number | Series): Series;
986
+
987
+ /**
988
+ * Pivot low of the chart `low`: a bar lower than the `rightbars` bars after it and at most as low as the
989
+ * `leftbars` bars before it. The value appears `rightbars` bars after the pivot bar, when it is confirmed;
990
+ * `NaN` on the other bars.
991
+ * @param leftbars - Bars to the left of the pivot.
992
+ * @param rightbars - Bars to the right of the pivot.
993
+ * @returns Series of the pivot low price on the confirming bar, `NaN` elsewhere.
994
+ * @example
995
+ * ```js
996
+ * const pl = ta.pivotlow(5, 5);
997
+ * plot(pl, "Pivot low", { style: plot.style_circles, offset: -5 });
998
+ * ```
999
+ */
1000
+ pivotlow(leftbars: number, rightbars: number | Series): Series;
1001
+ /**
1002
+ * Pivot low of a Series: a value lower than the `rightbars` values after it and at most as low as the
1003
+ * `leftbars` values before it. The value appears `rightbars` bars after the pivot bar; `NaN` on the other bars.
1004
+ * @param source - Series to search.
1005
+ * @param leftbars - Bars to the left of the pivot. A Series gives one length per bar.
1006
+ * @param rightbars - Bars to the right of the pivot. A Series gives one length per bar.
1007
+ * @returns Series of the pivot value on the confirming bar, `NaN` elsewhere.
1008
+ * @example
1009
+ * ```js
1010
+ * const pl = ta.pivotlow(close, 3, 3);
1011
+ * plot(pl, "Pivot low", { style: plot.style_circles, offset: -3 });
1012
+ * ```
1013
+ */
1014
+ pivotlow(source: Series, leftbars: number | Series, rightbars: number | Series): Series;
1015
+
1016
+ /**
1017
+ * ZigZag of the chart: the turning points of the price that are at least `deviation` percent apart, found on the
1018
+ * chart's highs and lows. The last point may move as new bars come in.
1019
+ * @param deviation - Smallest move between two points, in percent. Default: 5.
1020
+ * @param depth - Bars at the start used to find the first point. Default: 10.
1021
+ * @param backstep - Bars a new high or low must beat, and bars a point must wait before it is confirmed.
1022
+ * Default: 3.
1023
+ * @returns Tuple `[price, direction, isPivot]` of Series: the point price on point bars (`NaN` elsewhere), the
1024
+ * direction (1 up, -1 down, 0 before the first point) and 1 / 0 on point bars.
1025
+ * @example
1026
+ * ```js
1027
+ * const [points, direction, isPivot] = ta.zigzag(5, 10, 3);
1028
+ * plot(points, "ZigZag", { style: plot.style_circles });
1029
+ * ```
1030
+ */
1031
+ zigzag(deviation?: number, depth?: number, backstep?: number): [Series, Series, Series];
1032
+
1033
+ // ── Volume values of the chart (read them, do not call them) ───────────────
1034
+
1035
+ /**
1036
+ * On-balance volume of the chart: a running total that adds the volume on up closes and subtracts it on down
1037
+ * closes. A Series, not a function: read it as `ta.obv`.
1038
+ * @example
1039
+ * ```js
1040
+ * plot(ta.obv, "OBV");
1041
+ * ```
1042
+ */
1043
+ readonly obv: Series;
1044
+
1045
+ /**
1046
+ * Price-volume trend of the chart: a running total of the close change in fraction of the previous close
1047
+ * times the volume. A Series, not a function.
1048
+ * @example
1049
+ * ```js
1050
+ * plot(ta.pvt, "PVT");
1051
+ * ```
1052
+ */
1053
+ readonly pvt: Series;
1054
+
1055
+ /**
1056
+ * Accumulation / distribution of the chart: a running total of
1057
+ * `((close - low) - (high - close)) / (high - low) * volume`. Bars with `high == low` add nothing. A Series,
1058
+ * not a function.
1059
+ * @example
1060
+ * ```js
1061
+ * plot(ta.accdist, "Accumulation / distribution");
1062
+ * ```
1063
+ */
1064
+ readonly accdist: Series;
1065
+
1066
+ /**
1067
+ * Negative volume index of the chart: starts at 1 and follows the close change only on bars where the volume
1068
+ * falls. A Series, not a function.
1069
+ * @example
1070
+ * ```js
1071
+ * plot(ta.nvi, "NVI");
1072
+ * ```
1073
+ */
1074
+ readonly nvi: Series;
1075
+
1076
+ /**
1077
+ * Positive volume index of the chart: starts at 1 and follows the close change only on bars where the volume
1078
+ * rises. A Series, not a function.
1079
+ * @example
1080
+ * ```js
1081
+ * plot(ta.pvi, "PVI");
1082
+ * ```
1083
+ */
1084
+ readonly pvi: Series;
1085
+
1086
+ /**
1087
+ * Intraday intensity index of the chart: `(2 * close - high - low) / (high - low) * volume` on each bar
1088
+ * (`NaN` where `high == low`). A Series, not a function.
1089
+ * @example
1090
+ * ```js
1091
+ * plot(ta.iii, "III", { style: plot.style_histogram });
1092
+ * ```
1093
+ */
1094
+ readonly iii: Series;
1095
+
1096
+ /**
1097
+ * Williams accumulation / distribution of the chart: a running total of the close move beyond the previous
1098
+ * close (against the low on up closes, the high on down closes). A Series, not a function.
1099
+ * @example
1100
+ * ```js
1101
+ * plot(ta.wad, "WAD");
1102
+ * ```
1103
+ */
1104
+ readonly wad: Series;
1105
+
1106
+ /**
1107
+ * Williams variable accumulation / distribution of the chart: `(close - open) / (high - low) * volume` on each
1108
+ * bar (`NaN` where `high == low`). A Series, not a function.
1109
+ * @example
1110
+ * ```js
1111
+ * plot(ta.wvad, "WVAD", { style: plot.style_histogram });
1112
+ * ```
1113
+ */
1114
+ readonly wvad: Series;
1115
+ }