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
@@ -36,25 +36,41 @@ import type { Bar } from '../types/index.js';
36
36
  import type { ArrowData, BarColorData, BgColorData, BoxData, IndicatorResult, LabelData, LabelStyle, LineDrawingData, LinefillData, MarkerData, MarkerLocation, MarkerPosition, MarkerShape, MarkerSize, PineSize, PlotBarData, PlotCandleData, PolylineData, ShapeStyle, TableCellData, TableData, TableMergeData, TablePosition, TimeValue } from '../types/metadata.js';
37
37
  import type { ArrowConfig, BarColorConfig, CandleConfig, FillConfig, HLineConfig, InputConfig, InputCondition, PlotConfig, ShapeConfig } from '../runtime/types.js';
38
38
  import { BarData, Series } from '../runtime/series.js';
39
- import * as taSeries from '../ta-series.js';
40
- import * as colorCore from '../color/index.js';
39
+ import type { TaNamespace } from './api/ta.js';
40
+ import type { StrategyNamespace } from './api/strategy.js';
41
+ import type { BarmergeNamespace, BarstateNamespace, ChartNamespace, DividendsNamespace, EarningsNamespace, RequestNamespace, SessionNamespace, SplitsNamespace, SyminfoNamespace, TickerNamespace, TimeframeNamespace } from './api/context.js';
42
+ import type { CalcNamespace } from './api/calc.js';
43
+ import type { ColorNamespace } from './api/color.js';
44
+ import type { LogNamespace } from './api/log.js';
45
+ import type { AlertApi } from './api/alert.js';
46
+ import type { TableNamespace } from './api/table.js';
47
+ import * as pineConstants from './constants.js';
48
+ import * as compareCore from '../compare/index.js';
41
49
  import * as lineCore from '../line/index.js';
42
50
  import * as labelCore from '../label/index.js';
43
51
  import * as boxCore from '../box/index.js';
44
52
  import * as linefillCore from '../linefill/index.js';
45
53
  import * as polylineCore from '../polyline/index.js';
46
- import * as tableCore from '../table/index.js';
47
- import * as chartPointCore from '../chartpoint/index.js';
54
+ import * as textCore from '../text/index.js';
48
55
  import * as mathCore from '../math/index.js';
49
56
  import { type DrawingKind, type DrawingVariable } from '../drawing/registry.js';
50
57
  export { holdDrawing, releaseDrawing, type DrawingVariable } from '../drawing/registry.js';
51
58
  /**
52
- * A PineScript `var` variable of a drawing type (`var line l = na`): the object it refers to is not deleted by the
53
- * maximum count; assigning another object (or `undefined` for `na`) releases the one before. Its value is a
54
- * {@link persist} box: an incremental run puts it back with the drawings (#196). Declare it in the script body.
59
+ * A variable that holds one drawing (a line, label, box...) from bar to bar and keeps it alive: the object it holds is
60
+ * never deleted by the `max_*_count` limit of the script. Use it to create one object and move it, instead of a new
61
+ * object on each bar. Assigning another object (or `undefined` for na) releases the one before, which the limit can
62
+ * delete again. Declare it in the script body (outside the bar loops), then read and write `.value` in a bar loop.
63
+ * @param initial - The object held from the start. Default: none (`.value` is `undefined`).
64
+ * @returns A box whose `.value` is the held object, or `undefined`.
65
+ * @example
66
+ * ```js
67
+ * const level = varDrawing();
68
+ * eachBar((c) => {
69
+ * if (c.i === c.n - 1) level.value = line.new(c.i - 20, c.close, c.i, c.close, { color: color.orange });
70
+ * });
71
+ * ```
55
72
  */
56
- export declare function varDrawing<T extends object>(initial?: T): DrawingVariable<T>;
57
- import * as timeframeCore from '../timeframe/index.js';
73
+ export declare function varDrawing<T extends object = any>(initial?: T): DrawingVariable<T>;
58
74
  import * as strCore from '../str/index.js';
59
75
  import { type SessionSpec } from '../session/calendar.js';
60
76
  import { position } from '../types/index.js';
@@ -69,6 +85,8 @@ export interface ScriptRunResult {
69
85
  precision?: number;
70
86
  format?: string;
71
87
  scale?: 'right' | 'left' | 'none';
88
+ /** indicator(..., { pane }) when the script gives it (not PineScript); `overlay` is the pane it gave. */
89
+ pane?: 'price' | 'separate' | 'auto';
72
90
  };
73
91
  inputConfig: InputConfig[];
74
92
  plotConfig: PlotConfig[];
@@ -111,6 +129,11 @@ export interface ScriptRunResult {
111
129
  /** The script read `chart.left_visible_bar_time` or `chart.right_visible_bar_time`: it has to be calculated again when
112
130
  * the visible range of the chart changes. */
113
131
  usesVisibleRange: boolean;
132
+ /**
133
+ * Things the run did that a script usually does not mean, in plain words: drawings deleted because there were more
134
+ * than the maximum count (`indicator(max_labels_count)`...). Empty when there is nothing to say.
135
+ */
136
+ warnings: string[];
114
137
  }
115
138
  export interface AlertConditionConfig {
116
139
  id: string;
@@ -160,6 +183,30 @@ export interface ScriptOptions {
160
183
  * (see {@link executeIntrabar}). The host keeps one recorder for the main run of a backtest and its intrabar runs.
161
184
  */
162
185
  recorder?: StrategyRecorder;
186
+ /**
187
+ * Strict mode: mistakes that PineScript lets pass silently throw a {@link ScriptError} with a plain message: an input
188
+ * value of the wrong type, out of its range or not one of its options, an input name the script does not declare,
189
+ * an unknown option of plot() / hline() / plotshape() / plotchar() / bgcolor() / barcolor(), a text that is not a
190
+ * colour. Default false (PineScript behaviour); {@link defineIndicator} turns it on.
191
+ */
192
+ strict?: boolean;
193
+ /**
194
+ * Colours of the plots that give none: true for {@link DEFAULT_PALETTE} (each plot without a colour takes the next
195
+ * one), or a list of colours. Default false: every plot without a colour is blue, as in PineScript.
196
+ */
197
+ palette?: boolean | readonly string[];
198
+ /**
199
+ * The ids of the plots in `plotConfig` and `result.plots`: 'index' (default, as PineScript numbers them: plot0,
200
+ * plot1...) or 'title' (made from the title as the inputs' ids are: "Fast MA" gives fast_ma), which stay the same when
201
+ * plots are added or moved.
202
+ */
203
+ plotIds?: 'index' | 'title';
204
+ }
205
+ /** The colours given in turn to plots without a colour when `ScriptOptions.palette` is true. */
206
+ export declare const DEFAULT_PALETTE: readonly string[];
207
+ /** A mistake found in strict mode (see `ScriptOptions.strict`): the message says what to change. */
208
+ export declare class ScriptError extends Error {
209
+ constructor(message: string);
163
210
  }
164
211
  /**
165
212
  * Answers of the strategy engine recorded in the main run of a strategy, bar by bar, and its `varip` values: an
@@ -218,23 +265,28 @@ export interface IntrabarUpdate {
218
265
  fullRunReason: string | null;
219
266
  }
220
267
  /**
221
- * Runs a strategy once more on a bar, inside the bar (PineScript `calc_on_order_fills` and calculations on the
222
- * ticks of history bars): `bars` holds the bars up to that bar, the last one as it stands at the tick (its close is
223
- * the tick price, its high and low the extremes reached so far). The script's variables come back to their state at
224
- * the start of the bar (PineScript rollback), except `varip` ones. In strategy.eachBar(), the bars before replay the
225
- * engine's answers that the main run recorded (their order calls are dropped), and the bar itself calls
226
- * `options.engine` without processBar / processClose (the host is filling its orders). That bar is a confirmed
227
- * history bar (`barstate.isconfirmed`); `barstate.islast`, `last_bar_index` and `BarContext.n` keep the chart's last
228
- * bar. Strategy risk rules are not declared again, and the outputs (plots, drawings) are dropped. Re-entrant: the host
229
- * calls it inside the bar loop of the main run.
268
+ * Host-side: runs a strategy once more on one bar, inside the bar (calculation on order fills, or on the ticks of
269
+ * history bars). Scripts never call it. `bars` holds the bars up to that bar, the last one as it stands at the tick
270
+ * (its close is the tick price, its high and low the extremes reached so far). The script's variables come back to
271
+ * their state at the start of the bar, except `varip` ones. In strategy.eachBar(), the bars before replay the engine's
272
+ * answers that the main run recorded (their order calls are dropped), and the bar itself calls `options.engine`
273
+ * without processBar / processClose (the host is filling its orders). That bar is a confirmed history bar
274
+ * (`barstate.isconfirmed`); `barstate.islast`, `last_bar_index` and `BarContext.n` keep the chart's last bar. Risk
275
+ * rules are not declared again, and the outputs (plots, drawings) are dropped. Re-entrant: the host calls it inside
276
+ * the bar loop of the main run.
230
277
  *
231
- * Resumed runs (#206): the intrabar runs of a backtest (same recorder, script, inputs, chart and engine) keep the state
232
- * of the script as createScriptRun does, so a run calculates its bar only (and the bars since the previous intrabar
233
- * run), not all the bars before it; the order calls and `strategy.*` reads are the same as in a full run. The bars
234
- * before `options.bar` must be the main run's (the same on every call). A script that keeps state outside `persist()`
235
- * boxes (a `let` variable outside the callbacks that a callback changes), or uses a feature that is not resumed, gets
236
- * full runs (`fullRunReason`); the first resumed runs are also calculated in full and compared (`verify`). A resumed
237
- * run gives its order calls to the engine once it has ended.
278
+ * Resumed runs: the intrabar runs of a backtest (same recorder, script, inputs, chart and engine) keep the state of
279
+ * the script as createScriptRun does, so a run calculates its bar only (and the bars since the previous intrabar run);
280
+ * the order calls and `strategy.*` reads are the same as in a full run. The bars before `options.bar` must be the main
281
+ * run's (the same on every call). A script that keeps state outside `persist()` boxes, or uses a feature that is not
282
+ * resumed, gets full runs (`fullRunReason`); the first resumed runs are also calculated in full and compared
283
+ * (`verify`). A resumed run gives its order calls to the engine once it has ended.
284
+ * @param body - The script body, as given to executeScript().
285
+ * @param bars - The bars up to and including the bar calculated inside, oldest first.
286
+ * @param inputs - Input values by input id, as given to the main run.
287
+ * @param chart - The chart context of the main run.
288
+ * @param options - The bar, the chart's last bar index, the main run's engine and recorder, and the resume settings.
289
+ * @returns The first bar calculated, whether the run was resumed, and why the runs are full ones (or null).
238
290
  */
239
291
  export declare function executeIntrabar(body: () => void, bars: Bar[], inputs: Record<string, unknown>, chart: ChartContext, options: IntrabarOptions): IntrabarUpdate;
240
292
  /** The result of {@link ScriptRun.update}. */
@@ -262,7 +314,8 @@ export interface ScriptRun {
262
314
  readonly fullRunReason: string | null;
263
315
  }
264
316
  /**
265
- * A script that calculates only the newest bars on a live update (#196). The first update is a full run; it keeps,
317
+ * Host-side: a script that calculates only the newest bars on a live update. Scripts never call it. The first
318
+ * update is a full run; it keeps,
266
319
  * for the next one, what the script created (its Series, ta.* calls, eachBar() blocks, persist() boxes and plots) with
267
320
  * their state at the end of the last confirmed bar. An update whose bars are the same up to the forming bar of the
268
321
  * previous update (a new price of the forming bar, or new bars after it) runs the script again from that bar only;
@@ -274,36 +327,54 @@ export interface ScriptRun {
274
327
  * compared (`verify`): a difference makes the next updates full runs. Not resumed yet, so calculated in full: drawings,
275
328
  * request.security, strategies, varip, timenow, last_bar_index, BarContext.n, barstate.islastconfirmedhistory
276
329
  * (`fullRunReason` names the first one met).
330
+ * @param body - The script body, a function that runs the script's statements.
331
+ * @param inputs - Input values by input id. Default: `{}` (every input at its default).
332
+ * @param chart - The chart context (timeframe, time zone, session, symbol...); an update can give a new one.
333
+ * Default: `{}`.
334
+ * @param options - The executeScript() options, plus `verify` (resumed updates also run in full and compared).
335
+ * Default: `{}`.
336
+ * @returns A run: call `update(bars, chart?)` on each change of the bars; `fullRunReason` says why it does not resume.
277
337
  */
278
338
  export declare function createScriptRun(body: () => void, inputs?: Record<string, unknown>, chart?: ChartContext, options?: ScriptRunOptions): ScriptRun;
279
339
  /** A `varip` variable: `.value` reads and writes it. */
280
340
  export interface VaripVariable<T> {
341
+ /** The current value of the variable. */
281
342
  value: T;
282
343
  }
283
344
  /**
284
- * PineScript `varip`: a variable that keeps the changes made in the intrabar runs of a strategy (PineScript
285
- * rollback leaves it alone). A plain `let` variable of the script comes back to its value at the start of the bar
286
- * in each intrabar run; a `varip` one does not. Declare it once in the script body (outside the callbacks), in the
287
- * same order on each run; read and write it in strategy.eachBar(). Without intrabar runs it is a plain variable.
345
+ * A strategy variable that keeps the changes made while a bar is calculated again inside the bar (on order fills or
346
+ * ticks). A plain variable comes back to its value at the start of the bar on each of those runs; a `varip` one does
347
+ * not, so it can count fills or ticks. Declare it once in the script body (outside the callbacks), in the same order
348
+ * on each run; read and write `.value` in strategy.eachBar(). Without intrabar runs it is a plain variable.
349
+ * @param initial - The starting value.
350
+ * @returns A box whose `.value` reads and writes the variable.
351
+ * @example
352
+ * ```js
353
+ * const updatesInTrade = varip(0);
354
+ * strategy.eachBar((c) => {
355
+ * if (strategy.position_size !== 0) updatesInTrade.value += 1;
356
+ * });
357
+ * ```
288
358
  */
289
359
  export declare function varip<T>(initial: T): VaripVariable<T>;
290
360
  /** A `persist` variable: `.value` reads and writes it. */
291
361
  export interface PersistVariable<T> {
362
+ /** The current value of the variable. */
292
363
  value: T;
293
364
  }
294
365
  /**
295
- * PineScript `var` kept by the runtime (#196): a variable that keeps its value from one bar to the next. Declare it in
296
- * the script body (outside the callbacks), in the same order on each run, and read and write it in one eachBar()
297
- * callback. In a plain run it is a plain variable. In an incremental run (createScriptRun), the runtime keeps its value
298
- * at the end of the last confirmed bar and puts it back before the forming bar is calculated again: use it instead of
299
- * a `let` variable outside the callback, which a resumed run cannot put back.
300
- *
301
- * The run is calculated in full (not resumed) when the variable is read or written outside an eachBar() callback, by
302
- * two eachBar() blocks, or holds something else than plain data (numbers, strings, booleans, arrays, plain objects,
303
- * Map, Set).
304
- *
305
- * ```typescript
306
- * const dir = persist(0); // var dir = 0
366
+ * A variable that keeps its value from one bar to the next, kept by the runtime. Declare it in the script body
367
+ * (outside the callbacks), in the same order on each run, and read and write `.value` in one eachBar() callback. On a
368
+ * live chart the runtime saves its value at the end of the last confirmed bar and puts it back before the forming bar
369
+ * is calculated again, so only the newest bar is calculated: prefer it to a `let` variable outside the callback.
370
+ * The script is calculated in full on each update (same results, slower) when the variable is used outside an
371
+ * eachBar() callback, by two eachBar() blocks, or holds something else than plain data (numbers, strings, booleans,
372
+ * arrays, plain objects, Map, Set). Calling it inside a bar loop throws.
373
+ * @param initial - The value before the first bar.
374
+ * @returns A box whose `.value` reads and writes the variable.
375
+ * @example
376
+ * ```js
377
+ * const dir = persist(0);
307
378
  * const trend = eachBar((c) => {
308
379
  * if (c.close > c.get(close, 1)) dir.value = 1;
309
380
  * else if (c.close < c.get(close, 1)) dir.value = -1;
@@ -312,71 +383,117 @@ export interface PersistVariable<T> {
312
383
  * ```
313
384
  */
314
385
  export declare function persist<T>(initial: T): PersistVariable<T>;
386
+ /** Options of {@link indicator}. */
315
387
  export interface IndicatorOptions {
388
+ /** Short name shown in the chart legend. Default: the title. */
316
389
  shorttitle?: string;
317
- /** true: drawn on the price pane; false (default, as PineScript): in its own pane. */
390
+ /** true: drawn on the price pane; false: in its own pane below the chart. Default: false. */
318
391
  overlay?: boolean;
392
+ /** Number of decimals of the values shown in the legend and on the price scale. Default: the host's choice (the symbol's precision). */
319
393
  precision?: number;
394
+ /** Number format of the values: `format.price`, `format.volume`, `format.percent`, `format.mintick` or `format.inherit`. Default: `format.inherit`. */
320
395
  format?: string;
321
- /** The price scale: `scale.right`, `scale.left` or `scale.none` (recorded in `metadata.scale` for the host). */
396
+ /** The price scale the script uses: `scale.right`, `scale.left` or `scale.none`. Default: the host's choice. */
322
397
  scale?: 'right' | 'left' | 'none';
323
- /** Lines kept before the oldest are deleted (default 50; PineScript keeps up to 5 more). */
398
+ /** Most lines kept alive; above it the oldest are deleted (a few more may stay for a moment). Default: 50. */
324
399
  max_lines_count?: number;
325
- /** Labels kept before the oldest are deleted (default 50). */
400
+ /** Most labels kept alive; above it the oldest are deleted. Default: 50. */
326
401
  max_labels_count?: number;
327
- /** Boxes kept before the oldest are deleted (default 50). */
402
+ /** Most boxes kept alive; above it the oldest are deleted. Default: 50. */
328
403
  max_boxes_count?: number;
329
- /** Polylines kept before the oldest are deleted (default 50). */
404
+ /** Most polylines kept alive; above it the oldest are deleted. Default: 50. */
330
405
  max_polylines_count?: number;
406
+ /**
407
+ * Where the script is drawn, instead of `overlay` (give one of the two): 'price' (on the price pane), 'separate'
408
+ * (its own pane) or 'auto' (chosen from the plotted values: the price pane when they are prices, like an average;
409
+ * its own pane otherwise, like an RSI). Default: not set (`overlay` decides).
410
+ */
411
+ pane?: 'price' | 'separate' | 'auto';
331
412
  }
332
- /** PineScript `indicator()` — declares the script's metadata. */
413
+ /**
414
+ * Declares the script as an indicator: its title, its pane and how its values are shown. Call it once, at the top
415
+ * of the script (a script declares either `indicator()` or `strategy()`). A script without a declaration runs with
416
+ * the title "Untitled" in its own pane.
417
+ * @param title - Name of the script, shown in the legend and the settings.
418
+ * @param options - Pane, short title, number format and drawing limits. Default: `{}` (own pane).
419
+ * @example
420
+ * ```js
421
+ * indicator("My SMA", { overlay: true, precision: 2 });
422
+ * plot(ta.sma(close, 20), "SMA");
423
+ * ```
424
+ */
333
425
  export declare function indicator(title: string, options?: IndicatorOptions): void;
334
- /** Options of every `input.*` kind (PineScript `group`, `inline`, `tooltip`, `confirm`, `display`, `active`). */
426
+ /** Options of every `input.*` kind: where the input is listed in the settings and how it behaves. */
335
427
  export interface InputOptions {
336
- /** Group title: every input with the same `group` is listed under it, at the place of the group's first input. */
428
+ /** Group title: every input with the same `group` is listed under it, at the place of the group's first input. Default: no group. */
337
429
  group?: string;
338
- /** Inputs with the same `inline` id share one row of their group (ungrouped inputs share rows among themselves). */
430
+ /** Inputs with the same `inline` id share one row of their group (ungrouped inputs share rows among themselves). Default: a row of its own. */
339
431
  inline?: string;
340
- /** Help text shown next to the input. */
432
+ /** Help text shown next to the input. Default: none. */
341
433
  tooltip?: string;
342
- /** The host asks for the value when the script is added. */
434
+ /** true: the host asks for the value when the script is added to a chart. Default: false. */
343
435
  confirm?: boolean;
344
- /** Where the value is shown besides the settings: 'all', 'none', 'status_line', 'data_window'. */
436
+ /**
437
+ * Where the value is shown besides the settings: `display.all`, `display.none`, `display.status_line` or
438
+ * `display.data_window`. Default: 'none' for bool, color, time and text_area inputs, 'all' for the others.
439
+ */
345
440
  display?: InputConfig['display'];
346
441
  /**
347
- * PineScript `active`: false greys the input out in the settings (it keeps its value). A boolean as in
348
- * PineScript (`active: showMa`), or a condition on input ids that a host can apply without running the script
349
- * (`active: 'ma_1'`, `active: { input: 'type', ne: 'None' }`)
442
+ * false greys the input out in the settings (it keeps its value). A boolean (`active: showMa`), or a condition on
443
+ * input ids that a host can apply without running the script (`active: 'ma_1'`,
444
+ * `active: { input: 'type', ne: 'None' }`). Default: true.
350
445
  */
351
446
  active?: boolean | InputCondition;
447
+ /**
448
+ * The id of the input (letters, digits and _): the name of its value in the inputs given to the run. Default: made
449
+ * from the title ("Fast length" gives fast_length), which changes when the title changes.
450
+ */
451
+ id?: string;
352
452
  }
453
+ /** Options of `input.int()` and `input.float()`. */
353
454
  export interface NumericInputOptions extends InputOptions {
455
+ /** Smallest value the user can enter. Default: no minimum. */
354
456
  minval?: number;
457
+ /** Largest value the user can enter. Default: no maximum. */
355
458
  maxval?: number;
459
+ /** Step of the arrows of the number field. Default: the host's choice (1 for an int). */
356
460
  step?: number;
357
- /** The values to choose from (the host shows a drop-down list). */
461
+ /** The values to choose from (the host shows a drop-down list). Default: a free number field. */
358
462
  options?: number[];
359
463
  }
360
- /** A field of an enum made with `defineEnum()`: its name and title. `String(field)` is the title, as PineScript
361
- * `str.tostring()` of an enum field. */
464
+ /** A field of an enum made with `defineEnum()`: its name and title. `String(field)` is the title. */
362
465
  export interface EnumField {
466
+ /** The field's name, as written in `defineEnum()` (`"sma"`). */
363
467
  readonly name: string;
468
+ /** The field's title, shown in the settings (`"Simple"`); the name when the title was empty. */
364
469
  readonly title: string;
470
+ /** The title, so `String(field)` and `str.tostring(field)` give it. */
365
471
  toString(): string;
366
472
  }
473
+ /** Options of `input.enum()`. */
367
474
  export interface EnumInputOptions extends InputOptions {
368
- /** The fields to choose from (default: every field of the enum). */
475
+ /** The fields to choose from, all of the default's enum. Default: every field of the enum. */
369
476
  options?: EnumField[];
370
477
  }
371
478
  /**
372
- * PineScript `enum`: a set of named fields, each with a title (the name when the title is empty).
373
- * `const MaType = defineEnum({ sma: "Simple", ema: "Exponential" })`; `MaType.sma.title` is "Simple" and
374
- * `input.enum(MaType.sma, "Average")` returns `MaType.sma` or `MaType.ema`. Fields compare with `===`.
479
+ * Makes an enum: a fixed set of named fields, each with a title, for a choice list (`input.enum()`) or a state with
480
+ * a few values. Fields compare with `===`; `field.name` is the name, `field.title` and `String(field)` the title.
481
+ * @param fields - An object of field names and titles, e.g. `{ sma: "Simple", ema: "Exponential" }`; an empty title
482
+ * is the name.
483
+ * @returns A frozen object with one {@link EnumField} per name.
484
+ * @example
485
+ * ```js
486
+ * const MaType = defineEnum({ sma: "Simple", ema: "Exponential" });
487
+ * const maType = input.enum(MaType.sma, "Average");
488
+ * plot(maType === MaType.ema ? ta.ema(close, 20) : ta.sma(close, 20), "MA");
489
+ * ```
375
490
  */
376
491
  export declare function defineEnum<K extends string>(fields: Record<K, string>): {
377
492
  readonly [P in K]: EnumField;
378
493
  };
494
+ /** Options of `input.string()`, `input.timeframe()`, `input.session()` and `input.symbol()`. */
379
495
  export interface StringInputOptions extends InputOptions {
496
+ /** The values to choose from (the host shows a drop-down list). Default: a free text field (or the kind's own picker). */
380
497
  options?: string[];
381
498
  }
382
499
  /** Named arguments of an input: its options, with `title` (and `defval` when every argument is named). */
@@ -384,347 +501,522 @@ type InputArgs<O, D> = O & {
384
501
  title?: string;
385
502
  defval?: D;
386
503
  };
387
- /** PineScript `input.*` — declares an input AND returns its current value. The arguments after the default can be
388
- * named, as in PineScript: `input.int(14, "Length", { minval: 1 })`, `input.int(14, { title: "Length", minval: 1 })`,
389
- * `input.int({ defval: 14, title: "Length" })`. */
504
+ /**
505
+ * Script inputs: each `input.*` call declares a setting the user can change AND returns its current value (the
506
+ * user's value when there is one, else the default). The arguments after the default can be named:
507
+ * `input.int(14, "Length", { minval: 1 })`, `input.int(14, { title: "Length", minval: 1 })` or
508
+ * `input.int({ defval: 14, title: "Length" })`. The input id is the title in snake case ("Fast length" is
509
+ * `fast_length`); keep titles stable, a renamed input loses the user's value.
510
+ */
390
511
  export declare const input: {
512
+ /**
513
+ * Declares a whole-number setting (a length, a count) and returns its value, rounded to an integer.
514
+ * @param defval - Default value, or every argument by name (`{ defval, title, minval... }`).
515
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_int`).
516
+ * @param opts - `minval`, `maxval`, `step`, `options` (a choice list) and the common input options.
517
+ * @returns The current value: the user's value, else `defval`.
518
+ * @example
519
+ * ```js
520
+ * const length = input.int(14, "Length", { minval: 1, maxval: 500 });
521
+ * plot(ta.rsi(close, length), "RSI");
522
+ * ```
523
+ */
391
524
  int(defval: number | InputArgs<NumericInputOptions, number>, title?: string | InputArgs<NumericInputOptions, number>, opts?: NumericInputOptions): number;
525
+ /**
526
+ * Declares a decimal-number setting (a multiplier, a percent, a level) and returns its value.
527
+ * @param defval - Default value, or every argument by name (`{ defval, title, minval... }`).
528
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_float`).
529
+ * @param opts - `minval`, `maxval`, `step`, `options` (a choice list) and the common input options.
530
+ * @returns The current value: the user's value, else `defval`.
531
+ * @example
532
+ * ```js
533
+ * const mult = input.float(2.0, "Multiplier", { minval: 0.1, step: 0.1 });
534
+ * const [basis, upper, lower] = ta.bb(close, 20, mult);
535
+ * ```
536
+ */
392
537
  float(defval: number | InputArgs<NumericInputOptions, number>, title?: string | InputArgs<NumericInputOptions, number>, opts?: NumericInputOptions): number;
538
+ /**
539
+ * Declares an on / off setting (a checkbox) and returns its value. Shown only in the settings by default.
540
+ * @param defval - Default value, or every argument by name (`{ defval, title... }`).
541
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_bool`).
542
+ * @param opts - The common input options (`group`, `inline`, `tooltip`, `confirm`, `display`, `active`, `id`).
543
+ * @returns The current value: the user's value, else `defval`.
544
+ * @example
545
+ * ```js
546
+ * const showMa = input.bool(true, "Show MA");
547
+ * plot(ta.sma(close, 20), "MA", { display: showMa ? display.all : display.none });
548
+ * ```
549
+ */
393
550
  bool(defval: boolean | InputArgs<InputOptions, boolean>, title?: string | InputArgs<InputOptions, boolean>, opts?: InputOptions): boolean;
551
+ /**
552
+ * Declares a text setting and returns its value; with `options`, a drop-down list of choices.
553
+ * @param defval - Default value (one of `options` when they are given), or every argument by name.
554
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_string`).
555
+ * @param opts - `options` (a choice list) and the common input options.
556
+ * @returns The current value: the user's value, else `defval`.
557
+ * @example
558
+ * ```js
559
+ * const maType = input.string("EMA", "MA type", { options: ["SMA", "EMA"] });
560
+ * const ma = maType === "SMA" ? ta.sma(close, 20) : ta.ema(close, 20);
561
+ * ```
562
+ */
394
563
  string(defval: string | InputArgs<StringInputOptions, string>, title?: string | InputArgs<StringInputOptions, string>, opts?: StringInputOptions): string;
395
- /** Multi-line text (lines separated by a newline), e.g. a list a script parses (#184). */
564
+ /**
565
+ * Declares a multi-line text setting (lines separated by a newline) and returns its value, e.g. a list of levels
566
+ * the script parses. Shown only in the settings by default.
567
+ * @param defval - Default text, or every argument by name.
568
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_text_area`).
569
+ * @param opts - The common input options.
570
+ * @returns The current text: the user's text, else `defval`.
571
+ * @example
572
+ * ```js
573
+ * const text = input.text_area("100\n105\n110", "Levels");
574
+ * for (const lvl of text.split("\n")) hline(Number(lvl), "Level " + lvl);
575
+ * ```
576
+ */
396
577
  text_area(defval: string | InputArgs<InputOptions, string>, title?: string | InputArgs<InputOptions, string>, opts?: InputOptions): string;
397
578
  /**
398
- * Declares a colour input. As in PineScript, the default keeps an alpha of 2 decimals: an input default
399
- * `color.new(c, 90)` has the alpha byte 26 (25 in the script). A value given by the host is not changed.
579
+ * Declares a colour setting (a colour picker) and returns its value. The default's transparency is kept to 2
580
+ * decimals (`color.new(c, 90)` gives the alpha byte 26); a value given by the host is used as it is. Shown only in
581
+ * the settings by default.
582
+ * @param defval - Default colour (`color.blue`, `"#2962FF"`, `color.new(...)`), or every argument by name.
583
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_color`).
584
+ * @param opts - The common input options.
585
+ * @returns The current colour string: the user's colour, else `defval`.
586
+ * @example
587
+ * ```js
588
+ * const lineColor = input.color(color.teal, "Line colour");
589
+ * plot(ta.ema(close, 20), "EMA", { color: lineColor });
590
+ * ```
400
591
  */
401
592
  color(defval: string | InputArgs<InputOptions, string>, title?: string | InputArgs<InputOptions, string>, opts?: InputOptions): string;
402
- /** Declares a source input and returns it as a Series. */
593
+ /**
594
+ * Declares a source setting (the price a calculation reads) and returns it as a Series. The choices are `open`,
595
+ * `high`, `low`, `close`, `volume`, `hl2`, `hlc3`, `ohlc4`, `hlcc4`, and the outputs of other scripts on the chart
596
+ * when the host allows it (an unknown source gives `close`).
597
+ * @param defval - Default source, by name (`"close"`) or as the built-in Series (`close`), or every argument by
598
+ * name. Default: `"close"`.
599
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_source`).
600
+ * @param opts - The common input options.
601
+ * @returns The chosen source as a Series.
602
+ * @example
603
+ * ```js
604
+ * const src = input.source(close, "Source");
605
+ * plot(ta.sma(src, 20), "SMA");
606
+ * ```
607
+ */
403
608
  source(defval?: string | Series, title?: string | InputArgs<InputOptions, string | Series>, opts?: InputOptions): Series;
404
- /** Timeframe string ("60", "1D", "W"). As in PineScript, "" means the chart timeframe. */
609
+ /**
610
+ * Declares a timeframe setting (a timeframe picker) and returns its value, for `request.security()` or
611
+ * `timeframe.change()`.
612
+ * @param defval - Default timeframe: `"60"` (60 minutes), `"D"`, `"W"`, `"M"`...; `""` is the chart's timeframe.
613
+ * Or every argument by name.
614
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_timeframe`).
615
+ * @param opts - `options` (a choice list of timeframes) and the common input options.
616
+ * @returns The current timeframe string (`""`: the chart's timeframe).
617
+ * @example
618
+ * ```js
619
+ * const tf = input.timeframe("D", "Higher timeframe");
620
+ * const htfClose = request.security("", tf, () => close);
621
+ * ```
622
+ */
405
623
  timeframe(defval: string | InputArgs<StringInputOptions, string>, title?: string | InputArgs<StringInputOptions, string>, opts?: StringInputOptions): string;
406
- /** Session string ("0930-1600", "0930-1600:23456"). */
624
+ /**
625
+ * Declares a trading-hours setting and returns its value, a session string for `time()` or `inSession()`.
626
+ * @param defval - Default session: `"HHMM-HHMM"`, optionally followed by `:` and the days (1 = Sunday ...
627
+ * 7 = Saturday), e.g. `"0930-1600"` or `"0930-1600:23456"`. Or every argument by name.
628
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_session`).
629
+ * @param opts - `options` (a choice list of sessions) and the common input options.
630
+ * @returns The current session string.
631
+ * @example
632
+ * ```js
633
+ * const sess = input.session("0930-1600", "Session");
634
+ * bgcolor(color.when(na(time("", sess)).not(), color.new(color.blue, 90)));
635
+ * ```
636
+ */
407
637
  session(defval: string | InputArgs<StringInputOptions, string>, title?: string | InputArgs<StringInputOptions, string>, opts?: StringInputOptions): string;
408
- /** Ticker id ("NASDAQ:MSFT"), for `request.security` of another symbol (#180). */
638
+ /**
639
+ * Declares a symbol setting (a symbol search) and returns its value, a ticker id for `request.security()` of
640
+ * another symbol.
641
+ * @param defval - Default ticker id, `"EXCHANGE:TICKER"` (`"NASDAQ:MSFT"`), or every argument by name.
642
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_symbol`).
643
+ * @param opts - `options` (a choice list of symbols) and the common input options.
644
+ * @returns The current ticker id.
645
+ * @example
646
+ * ```js
647
+ * const other = input.symbol("NASDAQ:MSFT", "Compare with");
648
+ * plot(request.security(other, "", () => close), "Other close");
649
+ * ```
650
+ */
409
651
  symbol(defval: string | InputArgs<StringInputOptions, string>, title?: string | InputArgs<StringInputOptions, string>, opts?: StringInputOptions): string;
410
652
  /**
411
- * PineScript `input.price`: a price level, `InputConfig.type` `'price'` (a number field; with `confirm`, a host can
412
- * ask for it on the chart; an `inline` id shared with an `input.time` makes one point of both).
653
+ * Declares a price-level setting (a number field) and returns its value. With `confirm: true` the host can ask the
654
+ * user to pick it on the chart; an `inline` id shared with an `input.time()` makes one chart point of both.
655
+ * @param defval - Default price, or every argument by name.
656
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_float`).
657
+ * @param opts - The common input options.
658
+ * @returns The current price: the user's value, else `defval`.
659
+ * @example
660
+ * ```js
661
+ * const level = input.price(100, "Level", { confirm: true });
662
+ * hline(level, "Level");
663
+ * ```
413
664
  */
414
665
  price(defval: number | InputArgs<InputOptions, number>, title?: string | InputArgs<InputOptions, number>, opts?: InputOptions): number;
415
666
  /**
416
- * A field of an enum made with `defineEnum()`: `input.enum(MaType.sma, "Average")`. The host lists the fields by
417
- * title (`options`: only these fields) and stores the field name; the call returns the field.
667
+ * Declares a choice among the fields of an enum made with `defineEnum()` and returns the chosen field. The
668
+ * settings list the fields by title; the host stores the field's name.
669
+ * @param defval - Default field (`MaType.sma`), or every argument by name. It must be one of `options`.
670
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_enum`).
671
+ * @param opts - `options` (only these fields of the enum) and the common input options.
672
+ * @returns The chosen field; compare it with `===`.
673
+ * @example
674
+ * ```js
675
+ * const MaType = defineEnum({ sma: "Simple", ema: "Exponential" });
676
+ * const maType = input.enum(MaType.sma, "Average");
677
+ * const ma = maType === MaType.ema ? ta.ema(close, 20) : ta.sma(close, 20);
678
+ * ```
418
679
  */
419
680
  enum<F extends EnumField>(defval: F | InputArgs<EnumInputOptions, F>, title?: string | InputArgs<EnumInputOptions, F>, opts?: EnumInputOptions): F;
420
- /** Date and time as a UNIX time in milliseconds, e.g. `input.time(timestamp('2024-01-01'), 'Start')`. */
681
+ /**
682
+ * Declares a date-and-time setting and returns it as a UNIX time in milliseconds. With `confirm: true` the host
683
+ * can ask the user to pick it on the chart. Shown only in the settings by default.
684
+ * @param defval - Default time in ms, usually from `timestamp()`, or every argument by name.
685
+ * @param title - Label in the settings, or the options with `title` in them. Default: none (id `input_time`).
686
+ * @param opts - The common input options.
687
+ * @returns The current time in ms: the user's value, else `defval`.
688
+ * @example
689
+ * ```js
690
+ * const start = input.time(timestamp("2024-01-01"), "Start");
691
+ * bgcolor(color.when(time.gte(start), color.new(color.green, 90)));
692
+ * ```
693
+ */
421
694
  time(defval: number | InputArgs<InputOptions, number>, title?: string | InputArgs<InputOptions, number>, opts?: InputOptions): number;
422
695
  };
696
+ /**
697
+ * Opening price of each bar, as a Series. In a bar loop, `c.open` is the value of the current bar.
698
+ * @example
699
+ * ```js
700
+ * const body = close.sub(open);
701
+ * plot(body, "Body", { style: plot.style_columns });
702
+ * ```
703
+ */
423
704
  export declare const open: Series;
705
+ /**
706
+ * Highest price of each bar, as a Series. In a bar loop, `c.high` is the value of the current bar.
707
+ * @example
708
+ * ```js
709
+ * plot(ta.highest(high, 20), "20-bar high");
710
+ * ```
711
+ */
424
712
  export declare const high: Series;
713
+ /**
714
+ * Lowest price of each bar, as a Series. In a bar loop, `c.low` is the value of the current bar.
715
+ * @example
716
+ * ```js
717
+ * plot(ta.lowest(low, 20), "20-bar low");
718
+ * ```
719
+ */
425
720
  export declare const low: Series;
721
+ /**
722
+ * Closing price of each bar, as a Series (on the forming bar, the latest price). The usual source of indicators.
723
+ * In a bar loop, `c.close` is the value of the current bar.
724
+ * @example
725
+ * ```js
726
+ * plot(ta.sma(close, 20), "SMA");
727
+ * ```
728
+ */
426
729
  export declare const close: Series;
730
+ /**
731
+ * Traded volume of each bar, as a Series (NaN when the data has no volume). In a bar loop, `c.volume`.
732
+ * @example
733
+ * ```js
734
+ * plot(volume, "Volume", { style: plot.style_columns });
735
+ * ```
736
+ */
427
737
  export declare const volume: Series;
738
+ /**
739
+ * Median price of each bar, (high + low) / 2, as a Series.
740
+ * @example
741
+ * ```js
742
+ * plot(ta.sma(hl2, 10), "Median SMA");
743
+ * ```
744
+ */
428
745
  export declare const hl2: Series;
746
+ /**
747
+ * Typical price of each bar, (high + low + close) / 3, as a Series.
748
+ * @example
749
+ * ```js
750
+ * plot(ta.sma(hlc3, 20), "Typical SMA");
751
+ * ```
752
+ */
429
753
  export declare const hlc3: Series;
754
+ /**
755
+ * Average price of each bar, (open + high + low + close) / 4, as a Series.
756
+ * @example
757
+ * ```js
758
+ * plot(ohlc4, "OHLC average");
759
+ * ```
760
+ */
430
761
  export declare const ohlc4: Series;
762
+ /**
763
+ * Weighted close of each bar, (high + low + close + close) / 4, as a Series.
764
+ * @example
765
+ * ```js
766
+ * plot(ta.ema(hlcc4, 20), "Weighted close EMA");
767
+ * ```
768
+ */
431
769
  export declare const hlcc4: Series;
432
- /** PineScript `bar_index`: the index of each bar (0 on the first). In a bar loop, `c.i` is the same number. */
770
+ /**
771
+ * Index of each bar, as a Series: 0 on the oldest bar, then 1, 2... In a bar loop, `c.i` is the same number.
772
+ * @example
773
+ * ```js
774
+ * plotshape(bar_index.mod(10).eq(0), "Every 10 bars", { style: shape.circle });
775
+ * ```
776
+ */
433
777
  export declare const bar_index: Series;
434
- /** PineScript `last_bar_index`: the index of the last bar, on every bar. In a bar loop, `c.n - 1`. */
778
+ /**
779
+ * Index of the last bar of the chart, the same on every bar, as a Series. In a bar loop, `c.n - 1`.
780
+ * @example
781
+ * ```js
782
+ * bgcolor(color.when(bar_index.gte(last_bar_index.sub(9)), color.new(color.blue, 90)), { title: "Last 10 bars" });
783
+ * ```
784
+ */
435
785
  export declare const last_bar_index: Series;
436
- /** ta.* with the chart-implicit (bars-first) functions bound to the context,
437
- * so scripts call them like PineScript: `ta.tr(true)`, `ta.atr(14)`. */
438
- export declare const ta: {
439
- tr: (handleNa?: boolean) => Series;
440
- atr: (length: number) => Series;
441
- sar: (start?: number, inc?: number, max?: number) => Series;
442
- wpr: (length?: number) => Series;
443
- supertrend: (factor: number, atrLength: number) => [Series, Series];
444
- dmi: (diLength: number, adxSmoothing: number) => [Series, Series, Series];
445
- kc: (source: Series, length: number, mult: number, useTrueRange?: boolean) => [Series, Series, Series];
446
- kcw: (source: Series, length?: number, mult?: number, useTrueRange?: boolean) => Series;
447
- ichimoku: (conversionPeriods: number, basePeriods: number, laggingSpan2Periods: number, displacement: number) => [Series, Series, Series, Series, Series];
448
- /** `ta.highest(source, length)` or `ta.highest(length)` (source = high). */
449
- highest: (sourceOrLength: Series | number, length?: number | Series) => Series;
450
- /** `ta.lowest(source, length)` or `ta.lowest(length)` (source = low). */
451
- lowest: (sourceOrLength: Series | number, length?: number | Series) => Series;
452
- /** `ta.highestbars(source, length)` or `ta.highestbars(length)` (source = high); offsets are 0 or negative. */
453
- highestbars: (sourceOrLength: Series | number, length?: number | Series) => Series;
454
- /** `ta.lowestbars(source, length)` or `ta.lowestbars(length)` (source = low); offsets are 0 or negative. */
455
- lowestbars: (sourceOrLength: Series | number, length?: number | Series) => Series;
456
- /** `ta.vwap(source, anchor?, stdev_mult?)` with the chart volume; the default anchor is a new trading day
457
- * and the first bar: as in PineScript, the first loaded bars (a day in progress) have a value. On D / W / M
458
- * charts every bar is a new day (no time zone or session needed); on intraday charts it needs the chart context
459
- * (timeframe, time zone, session). */
460
- vwap: {
461
- (source: Series, anchor?: Series): Series;
462
- (source: Series, anchor: Series | undefined, stdev_mult: number): [Series, Series, Series];
463
- };
464
- /** `ta.vwma(source, length)` with the chart volume, as PineScript; a third argument gives another volume. */
465
- vwma: (source: Series, length: number, vol?: Series) => Series;
466
- /** `ta.mfi(source, length)` with the chart volume (PineScript takes 2 arguments). */
467
- mfi: (source: Series, length: number) => Series;
468
- /** `ta.pivothigh(source, leftbars, rightbars)` or `ta.pivothigh(leftbars, rightbars)` (source = high).
469
- * The value appears `rightbars` bars after the pivot bar, as in PineScript. */
470
- pivothigh: (sourceOrLeft: Series | number, leftOrRight: number | Series, rightbars?: number | Series) => Series;
471
- /** `ta.pivotlow(source, leftbars, rightbars)` or `ta.pivotlow(leftbars, rightbars)` (source = low). */
472
- pivotlow: (sourceOrLeft: Series | number, leftOrRight: number | Series, rightbars?: number | Series) => Series;
473
- obv: Series;
474
- pvt: Series;
475
- accdist: Series;
476
- nvi: Series;
477
- pvi: Series;
478
- iii: Series;
479
- wad: Series;
480
- wvad: Series;
481
- sma: (source: Series, length: number | Series) => Series;
482
- ema: (source: Series, length: number) => Series;
483
- rma: (source: Series, length: number) => Series;
484
- wma: (source: Series, length: number | Series) => Series;
485
- rsi: (source: Series, length: number | Series) => Series;
486
- change: (source: Series, length?: number) => Series;
487
- mom: (source: Series, length: number) => Series;
488
- roc: (source: Series, length: number) => Series;
489
- cum: (source: Series) => Series;
490
- stdev: (source: Series, length: number | Series, biased?: boolean) => Series;
491
- variance: (source: Series, length: number | Series, biased?: boolean) => Series;
492
- crossover: (a: Series, b: Series | number) => Series;
493
- crossunder: (a: Series, b: Series | number) => Series;
494
- cross: (a: Series, b: Series | number) => Series;
495
- barssince: (condition: Series) => Series;
496
- valuewhen: (condition: Series, source: Series, occurrence: number) => Series;
497
- macd: (source: Series, fastLength: number, slowLength: number, signalLength: number) => [Series, Series, Series];
498
- bb: (source: Series, length: number, mult: number) => [Series, Series, Series];
499
- hma: (source: Series, length: number) => Series;
500
- dev: (source: Series, length: number) => Series;
501
- cci: (source: Series, length: number) => Series;
502
- percentrank: (source: Series, length: number) => Series;
503
- median: (source: Series, length: number) => Series;
504
- linreg: (source: Series, length: number, offset?: number) => Series;
505
- correlation: (a: Series, b: Series, length: number) => Series;
506
- stoch: (source: Series, highSource: Series, lowSource: Series, length: number) => Series;
507
- rising(source: Series, length: number): Series;
508
- falling(source: Series, length: number): Series;
509
- vwapBands(source: Series, volume: Series, anchor: Series | undefined, stdev_mult: number): [Series, Series, Series];
510
- alma(source: Series, length?: number, offset?: number, sigma?: number, floor?: boolean): Series;
511
- zigzag(bars: Bar[], deviation?: number, depth?: number, backstep?: number): [Series, Series, Series];
512
- swma(source: Series): Series;
513
- tsi(source: Series, shortLength: number, longLength: number): Series;
514
- cmo(source: Series, length: number): Series;
515
- bbw(source: Series, length: number, mult: number): Series;
516
- range(source: Series, length: number): Series;
517
- max(source: Series): Series;
518
- min(source: Series): Series;
519
- cog(source: Series, length?: number): Series;
520
- mode(source: Series, length: number): Series;
521
- percentile_linear_interpolation(source: Series, length: number, percentage: number): Series;
522
- percentile_nearest_rank(source: Series, length: number, percentage: number): Series;
523
- rci(source: Series, length: number): Series;
524
- ta: {
525
- sma: typeof taSeries.sma;
526
- ema: typeof taSeries.ema;
527
- wma: typeof taSeries.wma;
528
- vwma: typeof taSeries.vwma;
529
- rma: typeof taSeries.rma;
530
- rsi: typeof taSeries.rsi;
531
- macd: typeof taSeries.macd;
532
- bb: typeof taSeries.bb;
533
- stdev: typeof taSeries.stdev;
534
- atr: typeof taSeries.atr;
535
- tr: typeof taSeries.tr;
536
- stoch: typeof taSeries.stoch;
537
- crossover: typeof taSeries.crossover;
538
- crossunder: typeof taSeries.crossunder;
539
- cross: typeof taSeries.cross;
540
- change: typeof taSeries.change;
541
- mom: typeof taSeries.mom;
542
- roc: typeof taSeries.roc;
543
- highest: typeof taSeries.highest;
544
- lowest: typeof taSeries.lowest;
545
- rising: typeof taSeries.rising;
546
- falling: typeof taSeries.falling;
547
- cum: typeof taSeries.cum;
548
- supertrend: typeof taSeries.supertrend;
549
- vwap: typeof taSeries.vwap;
550
- ichimoku: typeof taSeries.ichimoku;
551
- linreg: typeof taSeries.linreg;
552
- alma: typeof taSeries.alma;
553
- zigzag: typeof taSeries.zigzag;
554
- cci: typeof taSeries.cci;
555
- sar: typeof taSeries.sar;
556
- dev: typeof taSeries.dev;
557
- variance: typeof taSeries.variance;
558
- median: typeof taSeries.median;
559
- swma: typeof taSeries.swma;
560
- correlation: typeof taSeries.correlation;
561
- percentrank: typeof taSeries.percentrank;
562
- mfi: typeof taSeries.mfi;
563
- hma: typeof taSeries.hma;
564
- pivothigh: typeof taSeries.pivothigh;
565
- pivotlow: typeof taSeries.pivotlow;
566
- barssince: typeof taSeries.barssince;
567
- valuewhen: typeof taSeries.valuewhen;
568
- dmi: typeof taSeries.dmi;
569
- tsi: typeof taSeries.tsi;
570
- cmo: typeof taSeries.cmo;
571
- kc: typeof taSeries.kc;
572
- bbw: typeof taSeries.bbw;
573
- wpr: typeof taSeries.wpr;
574
- kcw: typeof taSeries.kcw;
575
- range: typeof taSeries.range;
576
- highestbars: typeof taSeries.highestbars;
577
- lowestbars: typeof taSeries.lowestbars;
578
- max: typeof taSeries.max;
579
- min: typeof taSeries.min;
580
- vwapBands: typeof taSeries.vwapBands;
581
- obv: typeof taSeries.obv;
582
- pvt: typeof taSeries.pvt;
583
- accdist: typeof taSeries.accdist;
584
- nvi: typeof taSeries.nvi;
585
- pvi: typeof taSeries.pvi;
586
- iii: typeof taSeries.iii;
587
- wad: typeof taSeries.wad;
588
- wvad: typeof taSeries.wvad;
589
- cog: typeof taSeries.cog;
590
- mode: typeof taSeries.mode;
591
- percentile_linear_interpolation: typeof taSeries.percentile_linear_interpolation;
592
- percentile_nearest_rank: typeof taSeries.percentile_nearest_rank;
593
- rci: typeof taSeries.rci;
594
- };
595
- };
596
- /** PineScript `fixnan(source)`: each `na` value becomes the previous non-`na` value.
597
- * Accepts a Series or a per-bar color array (`undefined` = `na`, as returned by `color.when`). */
786
+ /**
787
+ * Technical analysis: moving averages, oscillators, bands, crosses, pivots and volume indicators. Each function
788
+ * computes a whole Series in one call: call it before any `eachBar()` loop and read a bar's value with `c.get(x)`.
789
+ * @example
790
+ * ```js
791
+ * const fast = ta.ema(close, 12), slow = ta.ema(close, 26);
792
+ * plot(fast, "Fast"); plot(slow, "Slow");
793
+ * ```
794
+ */
795
+ export declare const ta: TaNamespace;
796
+ /**
797
+ * Fills the gaps of a Series: each na value (NaN) becomes the last value that was not na. Values before the first
798
+ * non-na value stay na; +/-Infinity is kept.
799
+ * @param source - The Series to fill.
800
+ * @returns A Series without gaps after its first value.
801
+ * @example
802
+ * ```js
803
+ * const pivot = fixnan(ta.pivothigh(5, 5));
804
+ * plot(pivot, "Last pivot high", { style: plot.style_stepline });
805
+ * ```
806
+ */
598
807
  export declare function fixnan(source: Series): Series;
808
+ /**
809
+ * Fills the gaps of a per-bar colour array: each na entry (`undefined`) becomes the last colour that was not na.
810
+ * @param source - One colour per bar, as made by `color.when()`.
811
+ * @returns A colour array without gaps after its first colour.
812
+ * @example
813
+ * ```js
814
+ * const trendColor = fixnan(color.when(ta.crossover(close, ta.sma(close, 20)), color.green));
815
+ * barcolor(trendColor);
816
+ * ```
817
+ */
599
818
  export declare function fixnan(source: Array<string | undefined>): Array<string | undefined>;
600
- /** PineScript `na(x)`. On a Series: a Series of 1 / 0, 1 where the value is na (NaN or +/-Infinity, #187). On a
601
- * single value (a number of a bar loop, a colour, a drawing): true when it is na. An empty text is na, as in
602
- * PineScript (`na("")`, `na(syminfo.basecurrency)` of a stock). */
819
+ /**
820
+ * Tells, bar by bar, whether a Series is na (NaN or +/-Infinity): a Series of 1 where it is, 0 elsewhere.
821
+ * @param x - The Series to test.
822
+ * @returns A Series of 1 / 0.
823
+ * @example
824
+ * ```js
825
+ * const ma = ta.sma(close, 50);
826
+ * bgcolor(color.when(na(ma), color.new(color.gray, 90)), { title: "Warming up" });
827
+ * ```
828
+ */
603
829
  export declare function na(x: Series): Series;
830
+ /**
831
+ * Tells whether one value is na: NaN, +/-Infinity, `undefined` or `null` (a colour or a drawing), a deleted drawing,
832
+ * or an empty text. Use it on the numbers of a bar loop.
833
+ * @param x - The value to test.
834
+ * @returns true when the value is na.
835
+ * @example
836
+ * ```js
837
+ * const ma = ta.sma(close, 50);
838
+ * eachBar((c) => { if (!na(c.get(ma)) && c.close > c.get(ma)) label.new(c.i, c.high, "Above"); });
839
+ * ```
840
+ */
604
841
  export declare function na(x: unknown): boolean;
605
- /** PineScript `nz(source, replacement)`; replacement defaults to 0. On a Series: each na value (NaN or +/-Infinity)
606
- * becomes the replacement of the same bar, a number or a Series (#187). On single values: the value or the
607
- * replacement. */
842
+ /**
843
+ * Replaces the na values of a Series (NaN or +/-Infinity) with a replacement, bar by bar, e.g. to start a sum at 0.
844
+ * @param source - The Series to clean.
845
+ * @param replacement - The value for the na bars: a number, or a Series (its value on the same bar). Default: 0.
846
+ * @returns A Series without na values (unless the replacement is na).
847
+ * @example
848
+ * ```js
849
+ * const change = nz(close.sub(close.offset(1)));
850
+ * plot(change, "Change", { style: plot.style_columns });
851
+ * ```
852
+ */
608
853
  export declare function nz(source: Series, replacement?: number | Series): Series;
854
+ /**
855
+ * Returns a value, or a replacement when it is na (NaN, +/-Infinity, `undefined`, `null`). Use it on the numbers of
856
+ * a bar loop.
857
+ * @param source - The value to check.
858
+ * @param replacement - The value returned when `source` is na. Default: 0.
859
+ * @returns `source`, or `replacement` when `source` is na.
860
+ * @example
861
+ * ```js
862
+ * const total = eachBar((c) => nz(c.prev()) + c.volume);
863
+ * plot(total, "Cumulative volume");
864
+ * ```
865
+ */
609
866
  export declare function nz<T>(source: T, replacement?: T): T;
610
- /** Per-bar color selection: truthy → colorTrue, else colorFalse.
611
- * colorFalse may be omitted (PineScript `na`): those bars get no color,
612
- * which bgcolor()/barcolor() skip. */
613
- declare function colorWhen(cond: Series, colorTrue: string, colorFalse: string): string[];
614
- declare function colorWhen(cond: Series, colorTrue: string, colorFalse?: string): Array<string | undefined>;
615
- type GradientColor = string | null | undefined;
616
- /** PineScript `color.from_gradient(value, bottom_value, top_value, bottom_color, top_color)`. With numbers and
617
- * colours: one colour. When an argument is a Series (or a colour is a per-bar array, as from `color.when`): the
618
- * colour of each bar, the rule of the number form applied to the values of that bar (#187), for
619
- * plot()/fill()/bgcolor()/barcolor(). */
620
- declare function fromGradient(value: number, bottom_value: number, top_value: number, bottom_color: GradientColor, top_color: GradientColor): string;
621
- declare function fromGradient(value: number | Series, bottom_value: number | Series, top_value: number | Series, bottom_color: GradientColor | readonly GradientColor[], top_color: GradientColor | readonly GradientColor[]): string | string[];
622
- /** color.* plus `when` — per-bar conditional colors for plot()/fill()/bgcolor()/barcolor(). */
623
- export declare const color: {
624
- new: typeof colorCore.new_color;
625
- from_gradient: typeof fromGradient;
626
- when: typeof colorWhen;
627
- rgb(red: import("../index.js").simple_int, green: import("../index.js").simple_int, blue: import("../index.js").simple_int, transp?: import("../index.js").simple_float): string;
628
- from_hex(hex: string, transp?: import("../index.js").simple_float): string;
629
- new_color(baseColor: import("../types/index.js").color | null | undefined, transp: import("../index.js").simple_float): string;
630
- r(clr: import("../types/index.js").color): import("../index.js").int;
631
- g(clr: import("../types/index.js").color): import("../index.js").int;
632
- b(clr: import("../types/index.js").color): import("../index.js").int;
633
- t(clr: import("../types/index.js").color | null | undefined): import("../index.js").float;
634
- aqua: "#00BCD4";
635
- black: "#363A45";
636
- blue: "#2962FF";
637
- fuchsia: "#E040FB";
638
- gray: "#787B86";
639
- green: "#4CAF50";
640
- lime: "#00E676";
641
- maroon: "#880E4F";
642
- navy: "#311B92";
643
- olive: "#808000";
644
- orange: "#FF9800";
645
- purple: "#9C27B0";
646
- red: "#F23645";
647
- silver: "#B2B5BE";
648
- teal: "#089981";
649
- white: "#FFFFFF";
650
- yellow: "#FDD835";
651
- };
867
+ /**
868
+ * Colours: named colours (`color.red`, `color.teal`...), `color.new` for transparency, `color.rgb`, gradients, and
869
+ * `color.when` to pick a colour per bar for `plot()`, `fill()`, `bgcolor()` and `barcolor()`.
870
+ * @example
871
+ * ```js
872
+ * const up = close.gt(open);
873
+ * plot(close, "Close", { color: color.when(up, color.green, color.red) });
874
+ * bgcolor(color.new(color.blue, 90));
875
+ * ```
876
+ */
877
+ export declare const color: ColorNamespace;
878
+ /** Options of {@link plot}. */
652
879
  export interface ScriptPlotOptions {
653
- /** Shift in bars (PineScript `offset`): the value of bar i is drawn on bar i + offset (negative: to the left). */
880
+ /** Shift in bars: the value of bar i is drawn on bar i + offset (negative: to the left). Default: 0. */
654
881
  offset?: number;
655
- /** Static color, or a per-bar color array from color.when(). */
882
+ /** One colour, or one colour per bar (`color.when()`, `undefined` = not drawn). Default: blue `#2962FF`. */
656
883
  color?: string | string[];
884
+ /** Line width in pixels. Default: 1. */
657
885
  linewidth?: number;
886
+ /** How the values are drawn: `plot.style_line`, `plot.style_histogram`, `plot.style_columns`... Default: `plot.style_line`. */
658
887
  style?: PlotConfig['style'];
659
- /** Line style (PineScript `linestyle`); default solid. A constant or an input value, not per bar. */
888
+ /** Dash pattern of the line: `plot.linestyle_solid`, `plot.linestyle_dashed` or `plot.linestyle_dotted` (one for all bars). Default: solid. */
660
889
  linestyle?: PlotConfig['linestyle'];
890
+ /** Where the plot shows: `display.all`, `display.none` (hidden, still listed), `display.pane`, `display.status_line`, `display.data_window`. Default: `display.all`. */
661
891
  display?: PlotConfig['display'];
892
+ /** Base level the histogram bars start from (`plot.style_histogram`). Default: 0. */
662
893
  histbase?: number;
663
- /** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
894
+ /** true: draw on the price pane even when the script has its own pane. Default: false. */
664
895
  force_overlay?: boolean;
665
- /** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
896
+ /** false: not listed in the style settings of the script. Default: true. */
666
897
  editable?: boolean;
667
898
  }
668
899
  /**
669
- * Titles of untitled outputs, as the PineScript compiler names them (reference metadata of a script whose outputs have
670
- * no title): the Style settings and the alert output lists show them.
900
+ * The titles an output gets when the script gives none (`plot` is "Plot", `hline` is "Level"...): the style settings
901
+ * and the alert lists show them.
671
902
  */
672
903
  export declare const DEFAULT_OUTPUT_TITLES: {
904
+ /** Title of a `plot()` without one. */
673
905
  readonly plot: "Plot";
906
+ /** Title of an `hline()` without one. */
674
907
  readonly hline: "Level";
908
+ /** Title of a `fill()` between two plots without one. */
675
909
  readonly plotFill: "Plots Background";
910
+ /** Title of a `fill()` between two hlines without one. */
676
911
  readonly hlineFill: "Hlines Background";
912
+ /** Title of a `plotshape()` without one. */
677
913
  readonly shape: "Shapes";
914
+ /** Title of a `plotchar()` without one. */
678
915
  readonly char: "Chars";
916
+ /** Title of a `plotarrow()` without one. */
679
917
  readonly arrow: "Arrows";
918
+ /** Title of a `bgcolor()` without one. */
680
919
  readonly bgcolor: "Background Color";
920
+ /** Title of a `barcolor()` without one. */
681
921
  readonly barcolor: "Bar Color";
922
+ /** Title of a `plotcandle()` without one. */
682
923
  readonly candle: "PlotCandle";
924
+ /** Title of a `plotbar()` without one. */
683
925
  readonly bar: "PlotBar";
684
926
  };
685
- /** PineScript `plot()` — declares the plot and supplies its data in one call. */
686
- declare function plotImpl(series: Series, title?: string, options?: ScriptPlotOptions): PlotHandle;
687
- /**
688
- * PineScript `plot()`, with the `plot.style_*` and `plot.linestyle_*` constants:
689
- * `plot(src, 'Level', { style: plot.style_stepline, linestyle: plot.linestyle_dashed })`.
690
- */
691
- export declare const plot: typeof plotImpl & {
692
- readonly style_line: "line";
693
- readonly style_linebr: "linebr";
694
- readonly style_stepline: "stepline";
695
- readonly style_steplinebr: "steplinebr";
696
- readonly style_stepline_diamond: "stepline_diamond";
697
- readonly style_histogram: "histogram";
698
- readonly style_columns: "columns";
699
- readonly style_area: "area";
700
- readonly style_areabr: "areabr";
701
- readonly style_circles: "circles";
702
- readonly style_cross: "cross";
703
- readonly linestyle_solid: "solid";
704
- readonly linestyle_dotted: "dotted";
705
- readonly linestyle_dashed: "dashed";
706
- };
927
+ /** The `plot()` function with its `plot.style_*` and `plot.linestyle_*` constants. */
928
+ export interface PlotFunction {
929
+ /**
930
+ * Draws a Series on the chart (a line by default, or a histogram, columns, area, circles...) and lists it in the
931
+ * legend and the settings. Bars whose value is na (NaN or +/-Infinity) are not drawn.
932
+ * @param source - The values to draw: a Series, or a number for the same value on every bar.
933
+ * @param title - Name of the plot in the legend, the settings and the alerts. Default: "Plot".
934
+ * @param options - Colour, width, style, line style, offset, display... Default: `{}` (a blue line).
935
+ * @returns A handle to pass to `fill()`.
936
+ */
937
+ (source: Series | number, title?: string, options?: ScriptPlotOptions): PlotHandle;
938
+ /** Style: a line through every value; na values are bridged. */
939
+ readonly style_line: 'line';
940
+ /** Style: a line with a gap where the value is na. */
941
+ readonly style_linebr: 'linebr';
942
+ /** Style: steps (horizontal then vertical moves); na values are bridged. */
943
+ readonly style_stepline: 'stepline';
944
+ /** Style: steps with a gap where the value is na. */
945
+ readonly style_steplinebr: 'steplinebr';
946
+ /** Style: steps with a diamond on each change. */
947
+ readonly style_stepline_diamond: 'stepline_diamond';
948
+ /** Style: a thin bar from the base line (`histbase`, default 0) to each value. */
949
+ readonly style_histogram: 'histogram';
950
+ /** Style: a wide column from the base line to each value. */
951
+ readonly style_columns: 'columns';
952
+ /** Style: a line with the area down to the base line filled. */
953
+ readonly style_area: 'area';
954
+ /** Style: a filled area with a gap where the value is na. */
955
+ readonly style_areabr: 'areabr';
956
+ /** Style: a dot on each value. */
957
+ readonly style_circles: 'circles';
958
+ /** Style: a cross on each value. */
959
+ readonly style_cross: 'cross';
960
+ /** Line style: solid. */
961
+ readonly linestyle_solid: 'solid';
962
+ /** Line style: dotted. */
963
+ readonly linestyle_dotted: 'dotted';
964
+ /** Line style: dashed. */
965
+ readonly linestyle_dashed: 'dashed';
966
+ }
967
+ /**
968
+ * Draws a Series on the chart and lists it in the legend and the settings; `plot.style_*` and `plot.linestyle_*`
969
+ * pick how it is drawn.
970
+ * @example
971
+ * ```js
972
+ * const fast = plot(ta.ema(close, 12), "Fast", { color: color.teal, linewidth: 2 });
973
+ * plot(ta.rsi(close, 14), "RSI", { style: plot.style_histogram });
974
+ * ```
975
+ */
976
+ export declare const plot: PlotFunction;
707
977
  export interface ScriptHLineOptions {
978
+ /** Colour of the line. Default: the host's (grey). */
708
979
  color?: string;
709
- /** Line style; default dashed (PineScript). */
980
+ /** Line style: `hline.style_solid`, `hline.style_dotted` or `hline.style_dashed`. Default: dashed. */
710
981
  linestyle?: HLineConfig['linestyle'];
982
+ /** Width of the line in pixels. Default: 1. */
711
983
  linewidth?: number;
712
- /** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
984
+ /** false: not listed in the style settings of the script. Default: true. */
713
985
  editable?: boolean;
714
986
  }
715
- /** PineScript `hline()` — a static horizontal level. Default line style: dashed (PineScript). */
716
- declare function hlineImpl(price: number, title?: string, options?: ScriptHLineOptions): PlotHandle;
717
- /** PineScript `hline()`, with the `hline.style_*` constants: `hline(0, 'Zero', { linestyle: hline.style_dotted })`. */
718
- export declare const hline: typeof hlineImpl & {
719
- readonly style_solid: "solid";
720
- readonly style_dotted: "dotted";
721
- readonly style_dashed: "dashed";
722
- };
987
+ /** The `hline()` function with its `hline.style_*` constants. */
988
+ export interface HlineFunction {
989
+ /**
990
+ * Draws a horizontal line at a fixed price (a level such as 70 / 30 on an oscillator).
991
+ * @param price - Price of the line.
992
+ * @param title - Name of the line in the settings. Default: "Level".
993
+ * @param options - Colour, line style and width. Default: `{}` (a dashed line).
994
+ * @returns A handle to pass to `fill()`.
995
+ */
996
+ (price: number, title?: string, options?: ScriptHLineOptions): PlotHandle;
997
+ /** Line style: solid. */
998
+ readonly style_solid: 'solid';
999
+ /** Line style: dotted. */
1000
+ readonly style_dotted: 'dotted';
1001
+ /** Line style: dashed (the default). */
1002
+ readonly style_dashed: 'dashed';
1003
+ }
1004
+ /**
1005
+ * Draws a horizontal line at a fixed price; `hline.style_*` picks its line style.
1006
+ * @example
1007
+ * ```js
1008
+ * const top = hline(70, "Overbought", { color: color.red });
1009
+ * const bottom = hline(30, "Oversold", { linestyle: hline.style_dotted });
1010
+ * fill(top, bottom, color.new(color.purple, 90));
1011
+ * ```
1012
+ */
1013
+ export declare const hline: HlineFunction;
723
1014
  export interface ScriptFillOptions {
724
- /** Static color, or a per-bar color array from color.when(). */
1015
+ /** Fill colour: one colour, or one per bar from `color.when()`. */
725
1016
  color?: string | string[];
1017
+ /** Name of the fill in the settings. Default: "Plots Background" / "Hlines Background". */
726
1018
  title?: string;
727
- /** False: not listed in the Style settings of the study (PineScript `editable`); default true. */
1019
+ /** false: not listed in the style settings of the script. Default: true. */
728
1020
  editable?: boolean;
729
1021
  }
730
1022
  /** A fill colour argument: a colour, na (null / undefined), or a per-bar array from color.when(). */
@@ -732,16 +1024,51 @@ export type ScriptFillColor = string | null | undefined | Array<string | null |
732
1024
  /** A gradient value argument: a number or a Series. */
733
1025
  export type ScriptFillValue = number | Series;
734
1026
  /**
735
- * PineScript `fill()`, with the three PineScript overloads (positional arguments), for two plots or two hlines:
736
- * - `fill(p1, p2, color?, title?, ...)`
737
- * - `fill(p1, p2, top_value, bottom_value, top_color, bottom_color, title?, ...)`: gradient fill; values and colours
738
- * can change per bar (a Series / a color.when() array)
739
- * - `fill(p1, p2, { color, title })`: options object (oakscriptjs form, kept for existing scripts)
740
- * `editable = false` keeps the fill out of the Style settings; `show_last`, `fillgaps` and `display` are accepted
741
- * and not used. Every fill has an id in `fillConfig` (the fills between plots also list it on their data).
1027
+ * Colours the space between two plots or two hlines, with an options object.
1028
+ * @param a - First plot or hline (the handle `plot()` / `hline()` returned).
1029
+ * @param b - Second plot or hline, of the same kind as `a`.
1030
+ * @param options - Colour (one, or one per bar from `color.when()`), title, editable. Default: `{}`.
1031
+ * @example
1032
+ * ```js
1033
+ * const upper = plot(ta.sma(high, 20), "Upper");
1034
+ * const lower = plot(ta.sma(low, 20), "Lower");
1035
+ * fill(upper, lower, { color: color.new(color.blue, 85), title: "Channel" });
1036
+ * ```
742
1037
  */
743
1038
  export declare function fill(a: PlotHandle, b: PlotHandle, options?: ScriptFillOptions): void;
1039
+ /**
1040
+ * Colours the space between two plots or two hlines with one colour (or one per bar).
1041
+ * @param a - First plot or hline (the handle `plot()` / `hline()` returned).
1042
+ * @param b - Second plot or hline, of the same kind as `a`.
1043
+ * @param color - Fill colour, or one per bar from `color.when()`; na (null) leaves a bar unfilled.
1044
+ * @param title - Name of the fill in the settings. Default: "Plots Background" / "Hlines Background".
1045
+ * @param rest - `editable` (false keeps it out of the settings); `show_last`, `fillgaps` and `display` are accepted
1046
+ * and not used.
1047
+ * @example
1048
+ * ```js
1049
+ * const top = hline(70), bottom = hline(30);
1050
+ * fill(top, bottom, color.new(color.purple, 90), "Zone");
1051
+ * ```
1052
+ */
744
1053
  export declare function fill(a: PlotHandle, b: PlotHandle, color: ScriptFillColor, title?: string, ...rest: unknown[]): void;
1054
+ /**
1055
+ * Colours the space between two plots with a gradient: `top_color` at `top_value`, `bottom_color` at
1056
+ * `bottom_value`; the values and colours may change from bar to bar.
1057
+ * @param a - First plot (the handle `plot()` returned).
1058
+ * @param b - Second plot.
1059
+ * @param top_value - Price of the top colour: a number or a Series.
1060
+ * @param bottom_value - Price of the bottom colour: a number or a Series.
1061
+ * @param top_color - Colour at the top, or one per bar.
1062
+ * @param bottom_color - Colour at the bottom, or one per bar.
1063
+ * @param title - Name of the fill in the settings. Default: "Plots Background".
1064
+ * @param rest - `editable` (false keeps it out of the settings); other arguments are accepted and not used.
1065
+ * @example
1066
+ * ```js
1067
+ * const basis = ta.sma(close, 20);
1068
+ * const p = plot(close), q = plot(basis);
1069
+ * fill(p, q, high, basis, color.green, color.new(color.green, 100));
1070
+ * ```
1071
+ */
745
1072
  export declare function fill(a: PlotHandle, b: PlotHandle, top_value: ScriptFillValue, bottom_value: ScriptFillValue, top_color: ScriptFillColor, bottom_color: ScriptFillColor, title?: string, ...rest: unknown[]): void;
746
1073
  export interface PlotShapeOptions {
747
1074
  style?: ShapeStyle;
@@ -762,21 +1089,46 @@ export interface PlotShapeOptions {
762
1089
  export interface PlotCharOptions extends Omit<PlotShapeOptions, 'style'> {
763
1090
  char?: string;
764
1091
  }
765
- /** PineScript `plotshape()` — a marker on each bar where the condition holds. */
1092
+ /**
1093
+ * Draws a shape (triangle, arrow, circle, label...) on each bar where the condition is true: buy and sell signals.
1094
+ * @param condition - Series that is true (non-zero) on the bars that get a shape. With `location.absolute`, its
1095
+ * value is the price of the shape.
1096
+ * @param title - Name of the shapes in the settings and the alerts. Default: "Shapes".
1097
+ * @param options - Shape (`shape.*`), place (`location.*`), colour, text, size (`size.*`), offset... Default: `{}`
1098
+ * (a cross above the bar).
1099
+ * @example
1100
+ * ```js
1101
+ * const up = ta.crossover(ta.ema(close, 9), ta.ema(close, 21));
1102
+ * plotshape(up, "Buy", { style: shape.triangleup, location: location.belowbar, color: color.green });
1103
+ * ```
1104
+ */
766
1105
  export declare function plotshape(condition: Series, title?: string, options?: PlotShapeOptions): void;
767
- /** PineScript `plotchar()` — a character marker on each bar where the condition holds. */
1106
+ /**
1107
+ * Draws a character (a letter, an emoji...) on each bar where the condition is true.
1108
+ * @param condition - Series that is true (non-zero) on the bars that get the character. With `location.absolute`,
1109
+ * its value is the price of the character.
1110
+ * @param title - Name of the characters in the settings and the alerts. Default: "Chars".
1111
+ * @param options - Character (`char`), place (`location.*`), colour, text, size (`size.*`), offset... Default: `{}`
1112
+ * (a star above the bar).
1113
+ * @example
1114
+ * ```js
1115
+ * const gapUp = open.gt(high.offset(1));
1116
+ * plotchar(gapUp, "Gap up", { char: "▲", location: location.abovebar, color: color.teal });
1117
+ * ```
1118
+ */
768
1119
  export declare function plotchar(condition: Series, title?: string, options?: PlotCharOptions): void;
769
1120
  export interface PlotArrowOptions {
770
- /** Color of the up arrows: a color or a per-bar array (default #00FF00, PineScript). */
1121
+ /** Colour of the up arrows: one colour or one per bar. Default: #00FF00. */
771
1122
  colorup?: string | Array<string | undefined>;
772
- /** Color of the down arrows: a color or a per-bar array (default #FF0000, PineScript). */
1123
+ /** Colour of the down arrows: one colour or one per bar. Default: #FF0000. */
773
1124
  colordown?: string | Array<string | undefined>;
774
- /** Display offset in bars (arrow shown at bar i + offset). */
1125
+ /** Moves the arrows by this many bars (the arrow of bar i is drawn on bar i + offset). Default: 0. */
775
1126
  offset?: number;
776
- /** Minimal arrow height in pixels (default 5). */
1127
+ /** Height of the smallest arrow, in pixels. Default: 5. */
777
1128
  minheight?: number;
778
- /** Maximal arrow height in pixels (default 100). */
1129
+ /** Height of the largest arrow, in pixels. Default: 100. */
779
1130
  maxheight?: number;
1131
+ /** Where the arrows are shown: `display.all`, `display.none`... Default: everywhere. */
780
1132
  display?: ArrowConfig['display'];
781
1133
  /** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
782
1134
  force_overlay?: boolean;
@@ -784,14 +1136,28 @@ export interface PlotArrowOptions {
784
1136
  editable?: boolean;
785
1137
  }
786
1138
  /**
787
- * PineScript `plotarrow()` — an up arrow below the bar for a positive value, a down arrow above the bar for a
788
- * negative value, nothing for 0 / na. The arrows go to `result.arrows` (value and color per bar), the declaration to
789
- * `arrowConfig`; the renderer scales the height with the absolute value between minheight and maxheight.
1139
+ * Draws an up arrow below the bar where the value is positive and a down arrow above it where it is negative;
1140
+ * nothing for 0 or na. The larger the value, the longer the arrow (between `minheight` and `maxheight`).
1141
+ * @param series - Series whose sign gives the arrow's direction and whose size gives its length.
1142
+ * @param title - Name of the arrows in the settings and the alerts. Default: "Arrows".
1143
+ * @param options - Colours, heights, offset, display. Default: `{}` (green up, red down).
1144
+ * @example
1145
+ * ```js
1146
+ * const change = close.sub(close.offset(1));
1147
+ * plotarrow(change, "Change", { colorup: color.teal, colordown: color.orange });
1148
+ * ```
790
1149
  */
791
1150
  export declare function plotarrow(series: Series, title?: string, options?: PlotArrowOptions): void;
792
1151
  /**
793
- * PineScript `bgcolor()` — per-bar background color. `force_overlay: true` colors the main chart pane even when the
794
- * script is not an overlay.
1152
+ * Colours the background of the script's pane behind each bar.
1153
+ * @param colors - One colour for every bar, or one per bar from `color.when()` (no colour on an na entry).
1154
+ * @param options - `offset` (bars to move the colours by), `title` (default "Background Color"), `force_overlay`
1155
+ * (true: colour the price chart's pane), `editable`. Default: `{}`.
1156
+ * @example
1157
+ * ```js
1158
+ * const rsi = ta.rsi(close, 14);
1159
+ * bgcolor(color.when(rsi.gt(70), color.new(color.red, 85)));
1160
+ * ```
795
1161
  */
796
1162
  export declare function bgcolor(colors: string | Array<string | undefined>, options?: {
797
1163
  offset?: number;
@@ -799,7 +1165,16 @@ export declare function bgcolor(colors: string | Array<string | undefined>, opti
799
1165
  force_overlay?: boolean;
800
1166
  editable?: boolean;
801
1167
  }): void;
802
- /** PineScript `barcolor()` — per-bar candle color override. */
1168
+ /**
1169
+ * Colours the chart's candles or bars, replacing their usual colours.
1170
+ * @param colors - One colour for every bar, or one per bar from `color.when()` (usual colour on an na entry).
1171
+ * @param options - `title` (default "Bar Color") and `editable`. Default: `{}`.
1172
+ * @example
1173
+ * ```js
1174
+ * const trendUp = close.gt(ta.sma(close, 50));
1175
+ * barcolor(color.when(trendUp, color.green, color.red));
1176
+ * ```
1177
+ */
803
1178
  export declare function barcolor(colors: string | Array<string | undefined>, options?: {
804
1179
  title?: string;
805
1180
  editable?: boolean;
@@ -807,12 +1182,13 @@ export declare function barcolor(colors: string | Array<string | undefined>, opt
807
1182
  /** A colour argument of plotcandle() / plotbar(): a colour, or per-bar colours (null / undefined entries are na). */
808
1183
  export type ScriptCandleColor = string | Array<string | null | undefined>;
809
1184
  export interface PlotCandleOptions {
810
- /** Body colour: a colour or a per-bar array (color.when); an na entry gives a transparent body */
1185
+ /** Body colour: one colour or one per bar (`color.when()`); an na entry gives a see-through body. Default: #2962FF. */
811
1186
  color?: ScriptCandleColor;
812
- /** Wick colour: a colour or a per-bar array */
1187
+ /** Wick colour: one colour or one per bar. Default: #737375. */
813
1188
  wickcolor?: ScriptCandleColor;
814
- /** Border colour: a colour or a per-bar array */
1189
+ /** Border colour: one colour or one per bar. Default: #000000. */
815
1190
  bordercolor?: ScriptCandleColor;
1191
+ /** Where the candles are shown: `display.all`, `display.none`... Default: everywhere. */
816
1192
  display?: CandleConfig['display'];
817
1193
  /** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
818
1194
  force_overlay?: boolean;
@@ -820,8 +1196,9 @@ export interface PlotCandleOptions {
820
1196
  editable?: boolean;
821
1197
  }
822
1198
  export interface PlotBarOptions {
823
- /** Bar colour: a colour or a per-bar array (color.when); an na entry gives a transparent bar */
1199
+ /** Bar colour: one colour or one per bar (`color.when()`); an na entry gives a see-through bar. Default: #2962FF. */
824
1200
  color?: ScriptCandleColor;
1201
+ /** Where the bars are shown: `display.all`, `display.none`... Default: everywhere. */
825
1202
  display?: CandleConfig['display'];
826
1203
  /** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */
827
1204
  force_overlay?: boolean;
@@ -833,18 +1210,41 @@ export interface PlotBarOptions {
833
1210
  * them (reference: body / bar #2962FF, wick #737375, border #000000; the wick and border do not follow the body).
834
1211
  */
835
1212
  export declare const DEFAULT_CANDLE_COLORS: {
1213
+ /** Body colour (and the colour of `plotbar()` bars). */
836
1214
  readonly color: "#2962FF";
1215
+ /** Wick colour. */
837
1216
  readonly wickColor: "#737375";
1217
+ /** Border colour. */
838
1218
  readonly borderColor: "#000000";
839
1219
  };
840
1220
  /**
841
- * PineScript `plotcandle(open, high, low, close, title?, { color, wickcolor, bordercolor, display, force_overlay })`:
842
- * candles in `result.plotCandles[id]`, the declaration in `candleConfig`. A bar with an na value has no candle.
1221
+ * Draws candles from four Series (for example the candles of another symbol, or smoothed prices). A bar where one of
1222
+ * the four values is na has no candle.
1223
+ * @param open - Open of each candle.
1224
+ * @param high - High of each candle.
1225
+ * @param low - Low of each candle.
1226
+ * @param close - Close of each candle.
1227
+ * @param title - Name of the candles in the settings. Default: "PlotCandle".
1228
+ * @param options - Body, wick and border colours, display, force_overlay, editable. Default: `{}`.
1229
+ * @example
1230
+ * ```js
1231
+ * const o = ta.ema(open, 5), h = ta.ema(high, 5), l = ta.ema(low, 5), c = ta.ema(close, 5);
1232
+ * plotcandle(o, h, l, c, "Smoothed", { color: color.when(c.gt(o), color.teal, color.red) });
1233
+ * ```
843
1234
  */
844
1235
  export declare function plotcandle(open: Series, high: Series, low: Series, close: Series, title?: string, options?: PlotCandleOptions): void;
845
1236
  /**
846
- * PineScript `plotbar(open, high, low, close, title?, { color, display, force_overlay })`: OHLC bars in
847
- * `result.plotBars[id]`, the declaration in `candleConfig`. A bar with an na value is not drawn.
1237
+ * Draws open-high-low-close bars from four Series. A bar where one of the four values is na is not drawn.
1238
+ * @param open - Open of each bar.
1239
+ * @param high - High of each bar.
1240
+ * @param low - Low of each bar.
1241
+ * @param close - Close of each bar.
1242
+ * @param title - Name of the bars in the settings. Default: "PlotBar".
1243
+ * @param options - Colour, display, force_overlay, editable. Default: `{}`.
1244
+ * @example
1245
+ * ```js
1246
+ * plotbar(open, high, low, close, "Bars", { color: color.when(close.gt(open), color.green, color.red) });
1247
+ * ```
848
1248
  */
849
1249
  export declare function plotbar(open: Series, high: Series, low: Series, close: Series, title?: string, options?: PlotBarOptions): void;
850
1250
  /**
@@ -868,6 +1268,20 @@ export interface BarContext {
868
1268
  /** This block's own previous output (PineScript self-reference, offset >= 1). */
869
1269
  prev(offset?: number): number;
870
1270
  }
1271
+ /**
1272
+ * Runs a function on every bar, oldest first, for logic that needs the bar's values one at a time (state, ifs,
1273
+ * loops). The function reads the bar through `c` (`c.close`, `c.get(series)`, `c.get(series, 1)` for one bar back)
1274
+ * and returns the bar's value of the Series that `eachBar` gives back (na when it returns nothing).
1275
+ * @param fn - Called once per bar with the bar's context; returns a number (or true / false) for that bar.
1276
+ * @returns Series of the values the function returned.
1277
+ * @example
1278
+ * ```js
1279
+ * const fast = ta.sma(close, 10);
1280
+ * let count = 0;
1281
+ * const streak = eachBar((c) => (count = c.get(close) > c.get(fast) ? count + 1 : 0));
1282
+ * plot(streak, "Bars above");
1283
+ * ```
1284
+ */
871
1285
  export declare function eachBar(fn: (c: BarContext) => number | boolean | void): Series;
872
1286
  /**
873
1287
  * Runs the strategy logic once per bar, in order, like {@link eachBar}. On each bar the engine first
@@ -924,7 +1338,7 @@ export type StrategyApi = ((title: string, options?: StrategyOptions) => void) &
924
1338
  * });
925
1339
  * ```
926
1340
  */
927
- export declare const strategy: StrategyApi;
1341
+ export declare const strategy: StrategyNamespace;
928
1342
  /** Types of chart PineScript tells apart (`chart.is_*`); every other type is 'standard'. */
929
1343
  export type ChartType = 'standard' | 'heikinashi' | 'renko' | 'kagi' | 'linebreak' | 'pnf' | 'range';
930
1344
  /**
@@ -992,6 +1406,8 @@ export interface ChartContext {
992
1406
  ticker?: string;
993
1407
  /** The chart's own symbol (PineScript `syminfo.main_tickerid`, the same inside `request.security`); default `tickerid` */
994
1408
  mainTickerid?: string;
1409
+ /** The chart's own timeframe (`timeframe.main_period`, the same inside `request.security`); default `timeframe` */
1410
+ mainTimeframe?: string;
995
1411
  /** Two-letter code of the country the symbol trades in (PineScript `syminfo.country`): "US", "IN" */
996
1412
  country?: string | null;
997
1413
  /** Contract a continuous future stands for (PineScript `syminfo.current_contract`): "ESZ2026" for CME_MINI:ES1! */
@@ -1151,143 +1567,200 @@ export declare class MissingSymbolDataError extends Error {
1151
1567
  * PineScript `timeframe.*`: the chart timeframe variables (from the chart context), and
1152
1568
  * `in_seconds(timeframe?)`, `from_seconds(seconds)`.
1153
1569
  */
1154
- export declare const timeframe: {
1155
- period: string;
1156
- main_period: string;
1157
- multiplier: number;
1158
- isintraday: boolean;
1159
- isdaily: boolean;
1160
- isweekly: boolean;
1161
- ismonthly: boolean;
1162
- isminutes: boolean;
1163
- isseconds: boolean;
1164
- isticks: boolean;
1165
- isdwm: boolean;
1166
- /** PineScript `timeframe.change(tf)`: 1 on bars that open a new `tf` period (0 on the first bar). */
1167
- change(tf: string): Series;
1168
- /** Seconds in `timeframe`; without it (or with "") the chart timeframe, as in PineScript. */
1169
- in_seconds(tf?: string): number;
1170
- from_seconds(seconds: import("../index.js").int): import("../index.js").simple_string;
1171
- info(timeframe: import("../index.js").simple_string): timeframeCore.TimeframeInfo;
1172
- };
1570
+ export declare const timeframe: TimeframeNamespace;
1173
1571
  /**
1174
1572
  * PineScript `syminfo.*`, from the chart context (inside `request.security`, the requested symbol's). A field the
1175
1573
  * symbol has none of is na ("" for a text); a field the host did not give throws.
1176
1574
  */
1177
- export declare const syminfo: {
1178
- readonly mintick: number;
1179
- readonly minmove: number;
1180
- readonly pricescale: number;
1181
- readonly pointvalue: number;
1182
- readonly mincontract: number;
1183
- readonly timezone: string;
1184
- readonly tickerid: string;
1185
- readonly main_tickerid: string;
1186
- readonly ticker: string;
1187
- readonly prefix: string;
1188
- readonly session: string;
1189
- readonly type: string;
1190
- readonly currency: string;
1191
- readonly basecurrency: string;
1192
- readonly root: string;
1193
- readonly description: string;
1194
- readonly country: string;
1195
- readonly current_contract: string;
1196
- readonly expiration_date: number;
1197
- readonly sector: string;
1198
- readonly industry: string;
1199
- readonly isin: string;
1200
- readonly volumetype: string;
1201
- readonly employees: number;
1202
- readonly shareholders: number;
1203
- readonly shares_outstanding_total: number;
1204
- readonly shares_outstanding_float: number;
1205
- readonly recommendations_buy: number;
1206
- readonly recommendations_buy_strong: number;
1207
- readonly recommendations_hold: number;
1208
- readonly recommendations_sell: number;
1209
- readonly recommendations_sell_strong: number;
1210
- readonly recommendations_total: number;
1211
- readonly recommendations_date: number;
1212
- readonly target_price_average: number;
1213
- readonly target_price_high: number;
1214
- readonly target_price_low: number;
1215
- readonly target_price_median: number;
1216
- readonly target_price_estimates: number;
1217
- readonly target_price_date: number;
1218
- };
1575
+ export declare const syminfo: SyminfoNamespace;
1219
1576
  /** A calendar function: `(time, timezone?)` on a UNIX time or on a Series of times. */
1220
1577
  interface CalendarFunction {
1578
+ /**
1579
+ * @param time - A time in UNIX milliseconds.
1580
+ * @param timezone - Time zone to read the time in: "America/New_York", "UTC+2"... Default: the exchange's.
1581
+ * @returns The calendar field of that time.
1582
+ */
1221
1583
  (time: number, timezone?: string): number;
1584
+ /**
1585
+ * @param time - A Series of times in UNIX milliseconds, e.g. `time`.
1586
+ * @param timezone - Time zone to read the times in: "America/New_York", "UTC+2"... Default: the exchange's.
1587
+ * @returns Series of the calendar field of each time.
1588
+ */
1222
1589
  (time: Series, timezone?: string): Series;
1223
1590
  }
1224
- /** PineScript `year(time, timezone?)`; the default time zone is the exchange time zone. */
1591
+ /**
1592
+ * The year of a time (2025...). Works on one time or on a Series of times (`year(time)` gives the value of each bar).
1593
+ * @example
1594
+ * ```js
1595
+ * const newYear = year(time).neq(year(time).offset(1));
1596
+ * bgcolor(color.when(newYear, color.new(color.blue, 80)));
1597
+ * ```
1598
+ */
1225
1599
  export declare const year: CalendarFunction;
1226
- /** PineScript `month(time, timezone?)`; the default time zone is the exchange time zone. */
1600
+ /**
1601
+ * The month of a time, 1 (January) to 12. Works on one time or on a Series of times (`month(time)` gives the value of each bar).
1602
+ * @example
1603
+ * ```js
1604
+ * const january = month(time).eq(1);
1605
+ * bgcolor(color.when(january, color.new(color.teal, 85)));
1606
+ * ```
1607
+ */
1227
1608
  export declare const month: CalendarFunction;
1228
- /** PineScript `weekofyear(time, timezone?)`; the default time zone is the exchange time zone. */
1609
+ /**
1610
+ * The week of the year of a time, 1 to 53. Works on one time or on a Series of times (`weekofyear(time)` gives the value of each bar).
1611
+ * @example
1612
+ * ```js
1613
+ * plot(weekofyear(time), "Week");
1614
+ * ```
1615
+ */
1229
1616
  export declare const weekofyear: CalendarFunction;
1230
- /** PineScript `dayofmonth(time, timezone?)`; the default time zone is the exchange time zone. */
1617
+ /**
1618
+ * The day of the month of a time, 1 to 31. Works on one time or on a Series of times (`dayofmonth(time)` gives the value of each bar).
1619
+ * @example
1620
+ * ```js
1621
+ * plot(dayofmonth(time, "UTC"), "Day of month");
1622
+ * ```
1623
+ */
1231
1624
  export declare const dayofmonth: CalendarFunction;
1232
- /** PineScript `dayofweek(time, timezone?)`; the default time zone is the exchange time zone. */
1233
- /** `dayofweek(time, timezone?)`, with the PineScript constants `dayofweek.sunday` (1) ... `dayofweek.saturday` (7). */
1234
- export declare const dayofweek: CalendarFunction & {
1235
- readonly sunday: 1;
1236
- readonly monday: 2;
1237
- readonly tuesday: 3;
1238
- readonly wednesday: 4;
1239
- readonly thursday: 5;
1240
- readonly friday: 6;
1241
- readonly saturday: 7;
1242
- };
1243
- /** PineScript `hour(time, timezone?)`; the default time zone is the exchange time zone. */
1625
+ /**
1626
+ * The day of the week of a time, 1 (Sunday) to 7 (Saturday), on one time or a Series of times; compare it with the
1627
+ * `dayofweek.monday`... constants.
1628
+ * @example
1629
+ * ```js
1630
+ * const monday = dayofweek(time).eq(dayofweek.monday);
1631
+ * bgcolor(color.when(monday, color.new(color.gray, 90)));
1632
+ * ```
1633
+ */
1634
+ export declare const dayofweek: CalendarFunction & typeof pineConstants.daysOfWeek;
1635
+ /**
1636
+ * The hour of a time, 0 to 23. Works on one time or on a Series of times (`hour(time)` gives the value of each bar).
1637
+ * @example
1638
+ * ```js
1639
+ * const morning = hour(time).lt(12);
1640
+ * bgcolor(color.when(morning, color.new(color.orange, 90)));
1641
+ * ```
1642
+ */
1244
1643
  export declare const hour: CalendarFunction;
1245
- /** PineScript `minute(time, timezone?)`; the default time zone is the exchange time zone. */
1644
+ /**
1645
+ * The minute of a time, 0 to 59. Works on one time or on a Series of times (`minute(time)` gives the value of each bar).
1646
+ * @example
1647
+ * ```js
1648
+ * plot(minute(time), "Minute");
1649
+ * ```
1650
+ */
1246
1651
  export declare const minute: CalendarFunction;
1247
- /** PineScript `second(time, timezone?)`; the default time zone is the exchange time zone. */
1652
+ /**
1653
+ * The second of a time, 0 to 59. Works on one time or on a Series of times (`second(time)` gives the value of each bar).
1654
+ * @example
1655
+ * ```js
1656
+ * plot(second(time), "Second");
1657
+ * ```
1658
+ */
1248
1659
  export declare const second: CalendarFunction;
1249
1660
  /**
1250
- * PineScript `timestamp`: date string (GMT+0 by default), `(timezone, year, month, day, ...)`, or
1251
- * `(year, month, day, ...)` in the exchange time zone.
1661
+ * The UNIX time (milliseconds) of a date written as text.
1662
+ * @param dateString - A date such as "2024-03-15", "2024-03-15T09:30" or "15 Mar 2024 09:30 GMT+1"; without a time
1663
+ * zone it is UTC.
1664
+ * @returns The time in UNIX milliseconds.
1665
+ * @example
1666
+ * ```js
1667
+ * const start = timestamp("2024-01-01");
1668
+ * bgcolor(color.when(time.gte(start), color.new(color.green, 92)));
1669
+ * ```
1252
1670
  */
1253
1671
  export declare function timestamp(dateString: string): number;
1672
+ /**
1673
+ * The UNIX time (milliseconds) of a date and time in a time zone.
1674
+ * @param timezone - Time zone: "America/New_York", "UTC+2"...
1675
+ * @param year - Year, e.g. 2024.
1676
+ * @param month - Month, 1 to 12.
1677
+ * @param day - Day of the month, 1 to 31.
1678
+ * @param hour - Hour, 0 to 23. Default: 0.
1679
+ * @param minute - Minute. Default: 0.
1680
+ * @param second - Second. Default: 0.
1681
+ * @returns The time in UNIX milliseconds.
1682
+ * @example
1683
+ * ```js
1684
+ * const open = timestamp("America/New_York", 2024, 3, 15, 9, 30);
1685
+ * ```
1686
+ */
1254
1687
  export declare function timestamp(timezone: string, year: number, month: number, day: number, hour?: number, minute?: number, second?: number): number;
1688
+ /**
1689
+ * The UNIX time (milliseconds) of a date and time in the exchange's time zone.
1690
+ * @param year - Year, e.g. 2024.
1691
+ * @param month - Month, 1 to 12.
1692
+ * @param day - Day of the month, 1 to 31.
1693
+ * @param hour - Hour, 0 to 23. Default: 0.
1694
+ * @param minute - Minute. Default: 0.
1695
+ * @param second - Second. Default: 0.
1696
+ * @returns The time in UNIX milliseconds.
1697
+ * @example
1698
+ * ```js
1699
+ * const from = timestamp(2024, 1, 1);
1700
+ * plotshape(time.eq(from), "Start");
1701
+ * ```
1702
+ */
1255
1703
  export declare function timestamp(year: number, month: number, day: number, hour?: number, minute?: number, second?: number): number;
1256
- /** Session test of PineScript `time(timeframe, session, timezone)`; the default time zone is the exchange time zone. */
1704
+ /**
1705
+ * Whether a time is inside a session (trading hours).
1706
+ * @param time - A time in UNIX milliseconds, e.g. `c.time` in `eachBar()`.
1707
+ * @param session - Session hours and days: "0930-1600", "0930-1600:23456" (Monday to Friday), "1800-0500" (overnight).
1708
+ * @param timezone - Time zone of the session hours. Default: the exchange's.
1709
+ * @returns true when the time is in the session.
1710
+ * @example
1711
+ * ```js
1712
+ * const regular = eachBar((c) => inSession(c.time, "0930-1600"));
1713
+ * bgcolor(color.when(regular, color.new(color.blue, 92)));
1714
+ * ```
1715
+ */
1257
1716
  export declare function inSession(time: number, session: string, timezone?: string): boolean;
1258
- /** PineScript `str.*`; `format_time` and the dates of `format` use the exchange time zone by default. */
1259
- export declare const str: {
1260
- tostring: typeof strCore.tostring;
1261
- format_time(time: number, format?: string, timezone?: string): string;
1262
- format(pattern: string, ...args: unknown[]): string;
1263
- length(str: import("../index.js").simple_string): import("../index.js").int;
1264
- tonumber(str: import("../index.js").simple_string): import("../index.js").float | null;
1265
- substring(str: import("../index.js").simple_string, begin: import("../index.js").simple_int, end?: import("../index.js").simple_int): string;
1266
- upper(str: import("../index.js").simple_string): string;
1267
- lower(str: import("../index.js").simple_string): string;
1268
- contains(source: import("../index.js").simple_string, str: import("../index.js").simple_string): import("../index.js").bool;
1269
- pos(source: import("../index.js").simple_string, str: import("../index.js").simple_string): import("../index.js").int;
1270
- replace(source: import("../index.js").simple_string, target: import("../index.js").simple_string, replacement: import("../index.js").simple_string, occurrence?: import("../index.js").simple_int): string;
1271
- replace_all(source: import("../index.js").simple_string, target: import("../index.js").simple_string, replacement: import("../index.js").simple_string): string;
1272
- split(str: import("../index.js").simple_string, separator: import("../index.js").simple_string): string[];
1273
- concat(...strings: import("../index.js").simple_string[]): string;
1274
- startswith(source: import("../index.js").simple_string, str: import("../index.js").simple_string): import("../index.js").bool;
1275
- endswith(source: import("../index.js").simple_string, str: import("../index.js").simple_string): import("../index.js").bool;
1276
- charAt(str: import("../index.js").simple_string, pos: import("../index.js").simple_int): string;
1277
- trim(str: import("../index.js").simple_string): string;
1278
- trimLeft(str: import("../index.js").simple_string): string;
1279
- trimRight(str: import("../index.js").simple_string): string;
1280
- match(source: import("../index.js").simple_string, regex: import("../index.js").simple_string): import("../index.js").simple_string | null;
1281
- repeat(source: import("../index.js").simple_string, count: import("../index.js").simple_int, separator?: import("../index.js").simple_string): string | null;
1282
- };
1717
+ /**
1718
+ * Text functions: `str.tostring` (a number as text), `str.format` (a pattern with values), `str.format_time` (a date),
1719
+ * search, replace, split, case... `str.format_time` and the dates of `str.format` use the exchange's time zone by
1720
+ * default.
1721
+ * @example
1722
+ * ```js
1723
+ * eachBar((c) => {
1724
+ * if (barstate.islast) log.info(str.format("Close {0} at {1}", c.get(close), str.format_time(c.get(time), "HH:mm")));
1725
+ * });
1726
+ * ```
1727
+ */
1728
+ export declare const str: typeof strCore;
1729
+ /**
1730
+ * The open time of the period of `tf` that holds each bar, in UNIX milliseconds; na on bars outside `session`.
1731
+ * @param tf - Timeframe of the periods: "D", "W", "60"... Default: the chart's.
1732
+ * @param session - Session hours, e.g. "0930-1600"; bars outside it give na. Default: the symbol's.
1733
+ * @param timezone - Time zone of the session hours. Default: the exchange's.
1734
+ * @returns Series of period open times.
1735
+ */
1283
1736
  declare function timeFunction(tf?: string, session?: string, timezone?: string): Series;
1737
+ /**
1738
+ * The close time of the period of `tf` that holds each bar, in UNIX milliseconds; na on bars outside `session`.
1739
+ * @param tf - Timeframe of the periods: "D", "W", "60"... Default: the chart's.
1740
+ * @param session - Session hours, e.g. "0930-1600"; bars outside it give na. Default: the symbol's.
1741
+ * @param timezone - Time zone of the session hours. Default: the exchange's.
1742
+ * @returns Series of period close times.
1743
+ */
1284
1744
  declare function timeCloseFunction(tf?: string, session?: string, timezone?: string): Series;
1285
1745
  /** PineScript `timenow`: the current time in ms, the same on every bar of a run (`ChartContext.now`). */
1286
1746
  export declare const timenow: Series;
1747
+ /**
1748
+ * The open time of each bar, in UNIX milliseconds (a Series). Called as `time(tf?, session?, timezone?)`: the open
1749
+ * time of the `tf` period that holds the bar, na outside `session`.
1750
+ * @example
1751
+ * ```js
1752
+ * const newDay = time("D").neq(time("D").offset(1));
1753
+ * bgcolor(color.when(newDay, color.new(color.gray, 85)));
1754
+ * ```
1755
+ */
1287
1756
  export declare const time: Series & typeof timeFunction;
1288
1757
  /**
1289
- * PineScript `time_close`: the bar close time in ms (a Series), and `time_close(timeframe?, session?, timezone?)`.
1290
- * Needs the chart timeframe and session.
1758
+ * The close time of each bar, in UNIX milliseconds (a Series). Called as `time_close(tf?, session?, timezone?)`: the
1759
+ * close time of the `tf` period that holds the bar, na outside `session`.
1760
+ * @example
1761
+ * ```js
1762
+ * plot(time_close.sub(time).div(60000), "Bar minutes");
1763
+ * ```
1291
1764
  */
1292
1765
  export declare const time_close: Series & typeof timeCloseFunction;
1293
1766
  /** PineScript `time_tradingday`: 00:00 UTC of the trading day of each bar, in ms. */
@@ -1299,42 +1772,16 @@ export declare const time_tradingday: Series;
1299
1772
  * it is a history bar, as in PineScript.
1300
1773
  * `islastconfirmedhistory` is the last bar when it is confirmed and not realtime, else the bar before it.
1301
1774
  */
1302
- export declare const barstate: {
1303
- readonly isfirst: Series;
1304
- readonly islast: Series;
1305
- readonly isconfirmed: Series;
1306
- readonly isrealtime: Series;
1307
- readonly ishistory: Series;
1308
- readonly isnew: Series;
1309
- readonly islastconfirmedhistory: Series;
1310
- };
1775
+ export declare const barstate: BarstateNamespace;
1311
1776
  /**
1312
1777
  * PineScript `session.*` (1 / 0 per bar) and the constants `session.regular` / `session.extended`.
1313
1778
  * First and last bars are per session period; market / pre / post market use the regular hours.
1314
1779
  */
1315
- export declare const session: {
1316
- regular: string;
1317
- extended: string;
1318
- readonly isfirstbar: Series;
1319
- readonly islastbar: Series;
1320
- readonly ismarket: Series;
1321
- readonly ispremarket: Series;
1322
- readonly ispostmarket: Series;
1323
- readonly isfirstbar_regular: Series;
1324
- readonly islastbar_regular: Series;
1325
- };
1780
+ export declare const session: SessionNamespace;
1326
1781
  /** PineScript `barmerge.*` constants of `request.security`. */
1327
- export declare const barmerge: {
1328
- readonly gaps_on: "gaps_on";
1329
- readonly gaps_off: "gaps_off";
1330
- readonly lookahead_on: "lookahead_on";
1331
- readonly lookahead_off: "lookahead_off";
1332
- };
1782
+ export declare const barmerge: BarmergeNamespace;
1333
1783
  /** PineScript `ticker.heikinashi(symbol)` / `ticker.standard(symbol)` for the chart symbol. */
1334
- export declare const ticker: {
1335
- heikinashi(symbol: string): string;
1336
- standard(symbol: string): string;
1337
- };
1784
+ export declare const ticker: TickerNamespace;
1338
1785
  /** What an expression of `request.security` may return. */
1339
1786
  export type SecurityValue = Series | number | boolean | Array<Series | number | boolean>;
1340
1787
  /** Named arguments of `request.security` (PineScript names). */
@@ -1358,18 +1805,6 @@ export interface SecurityLowerTfArgs<T extends SecurityValue = SecurityValue> {
1358
1805
  ignore_invalid_timeframe?: boolean;
1359
1806
  calc_bars_count?: number;
1360
1807
  }
1361
- /** `request.security` with PineScript's named arguments: `request.security(sym, "D", () => close, { lookahead: barmerge.lookahead_on })`. */
1362
- declare function securityCall<T extends SecurityValue>(...args: [symbol: string, timeframe: string, expression: () => T, gaps?: string, lookahead?: string, ignore_invalid_symbol?: boolean] | [symbol: string, timeframe: string, expression: () => T, args: SecurityArgs<T>] | [args: SecurityArgs<T> & {
1363
- symbol: string;
1364
- timeframe: string;
1365
- expression: () => T;
1366
- }]): T extends unknown[] ? Series[] : Series;
1367
- /** `request.security_lower_tf` with PineScript's named arguments. */
1368
- declare function securityLowerTfCall<T extends SecurityValue>(...args: [symbol: string, timeframe: string, expression: () => T, ignore_invalid_symbol?: boolean] | [symbol: string, timeframe: string, expression: () => T, args: SecurityLowerTfArgs<T>] | [args: SecurityLowerTfArgs<T> & {
1369
- symbol: string;
1370
- timeframe: string;
1371
- expression: () => T;
1372
- }]): T extends unknown[] ? number[][][] : number[][];
1373
1808
  /** Named arguments of `request.seed` (PineScript names). */
1374
1809
  export interface SeedArgs<T extends SecurityValue = SecurityValue> {
1375
1810
  source?: string;
@@ -1378,42 +1813,12 @@ export interface SeedArgs<T extends SecurityValue = SecurityValue> {
1378
1813
  ignore_invalid_symbol?: boolean;
1379
1814
  calc_bars_count?: number;
1380
1815
  }
1381
- /** `request.seed` with PineScript's named arguments. */
1382
- declare function seedCall<T extends SecurityValue>(...args: [source: string, symbol: string, expression: () => T, ignore_invalid_symbol?: boolean] | [source: string, symbol: string, expression: () => T, args: SeedArgs<T>] | [args: SeedArgs<T> & {
1383
- source: string;
1384
- symbol: string;
1385
- expression: () => T;
1386
- }]): T extends unknown[] ? Series[] : Series;
1387
1816
  /** PineScript `dividends.*`: the fields of `request.dividends` and the next announced dividend of the chart symbol. */
1388
- export declare const dividends: {
1389
- readonly net: "net";
1390
- readonly gross: "gross";
1391
- /** Amount of the next dividend (net), na when none is announced */
1392
- readonly future_amount: number;
1393
- /** Ex-date of the next dividend (ms) */
1394
- readonly future_ex_date: number;
1395
- /** Payment date of the next dividend (ms) */
1396
- readonly future_pay_date: number;
1397
- };
1817
+ export declare const dividends: DividendsNamespace;
1398
1818
  /** PineScript `splits.*`: the fields of `request.splits`. */
1399
- export declare const splits: {
1400
- readonly numerator: "numerator";
1401
- readonly denominator: "denominator";
1402
- };
1819
+ export declare const splits: SplitsNamespace;
1403
1820
  /** PineScript `earnings.*`: the fields of `request.earnings` and the next earnings release of the chart symbol. */
1404
- export declare const earnings: {
1405
- readonly actual: "actual";
1406
- readonly estimate: "estimate";
1407
- readonly standardized: "standardized";
1408
- /** Estimated earnings per share of the next release */
1409
- readonly future_eps: number;
1410
- /** Estimated revenue of the next release */
1411
- readonly future_revenue: number;
1412
- /** Time of the next release (ms) */
1413
- readonly future_time: number;
1414
- /** End of the fiscal period of the next release (ms) */
1415
- readonly future_period_end_time: number;
1416
- };
1821
+ export declare const earnings: EarningsNamespace;
1417
1822
  /** Named arguments of `request.dividends` / `request.earnings` (`request.splits` has no `currency`). */
1418
1823
  export interface EventRequestArgs {
1419
1824
  ticker?: string;
@@ -1423,34 +1828,17 @@ export interface EventRequestArgs {
1423
1828
  ignore_invalid_symbol?: boolean;
1424
1829
  currency?: string;
1425
1830
  }
1426
- type EventRequestCall = [ticker: string, field?: string, gaps?: string, lookahead?: string, ignore_invalid_symbol?: boolean, currency?: string] | [ticker: string, field: string, args: EventRequestArgs] | [ticker: string, args: EventRequestArgs] | [args: EventRequestArgs & {
1427
- ticker: string;
1428
- }];
1429
- /**
1430
- * PineScript `request.dividends(ticker, field, gaps, lookahead, ignore_invalid_symbol, currency)`: the dividend per
1431
- * share (`dividends.net`, default, or `dividends.gross`) as declared, from the bar after its ex-date's day (see
1432
- * `security/events`). na before the first dividend. The events come from `ChartContext.events`.
1433
- */
1434
- declare function dividendsCall(...args: EventRequestCall): Series;
1435
1831
  /**
1436
- * PineScript `request.splits(ticker, field, gaps, lookahead, ignore_invalid_symbol)`: the numerator
1437
- * (`splits.numerator`) or the denominator (`splits.denominator`) of the last split, from the bar after its day.
1438
- */
1439
- declare function splitsCall(...args: EventRequestCall): Series;
1440
- /**
1441
- * PineScript `request.earnings(ticker, field, gaps, lookahead, ignore_invalid_symbol, currency)`: earnings per share of
1442
- * the last release (`earnings.actual`, default, `earnings.estimate` or `earnings.standardized`), from the bar after the
1443
- * period of the chart timeframe it was published in (the next day on a daily chart).
1832
+ * Data from other symbols, timeframes and sources: `request.security` (another symbol or timeframe),
1833
+ * `request.security_lower_tf` (the lower-timeframe bars inside each bar), `request.seed` (a separately published data series),
1834
+ * dividends, splits and earnings. Call it before any `eachBar()` loop.
1835
+ * @example
1836
+ * ```js
1837
+ * const dailyClose = request.security("", "D", () => close);
1838
+ * plot(dailyClose, "Daily close");
1839
+ * ```
1444
1840
  */
1445
- declare function earningsCall(...args: EventRequestCall): Series;
1446
- export declare const request: {
1447
- security: typeof securityCall;
1448
- security_lower_tf: typeof securityLowerTfCall;
1449
- seed: typeof seedCall;
1450
- dividends: typeof dividendsCall;
1451
- splits: typeof splitsCall;
1452
- earnings: typeof earningsCall;
1453
- };
1841
+ export declare const request: RequestNamespace;
1454
1842
  /** PineScript `line.*`; `line.all` lists the live lines in creation order. */
1455
1843
  type Numeric = number | Series;
1456
1844
  /** A function whose number parameters also take a Series (read on the current bar inside a bar loop). */
@@ -1565,400 +1953,102 @@ export interface LinefillNewArgs {
1565
1953
  line2?: Line;
1566
1954
  color?: Colour;
1567
1955
  }
1568
- declare const lineNs: Omit<ScriptDrawing<{
1569
- style_solid: "solid";
1570
- style_dotted: "dotted";
1571
- style_dashed: "dashed";
1572
- style_arrow_left: "arrow_left";
1573
- style_arrow_right: "arrow_right";
1574
- style_arrow_both: "arrow_both";
1575
- new_line(first_point: ChartPoint, second_point: ChartPoint, xloc?: "bar_index" | "bar_time" | "pane", extend?: "none" | "left" | "right" | "both", lineColor?: import("../types/index.js").color, style?: "solid" | "dotted" | "dashed" | "arrow_left" | "arrow_right" | "arrow_both", width?: number, force_overlay?: boolean): Line;
1576
- new_line(x1: number, y1: number, x2: number, y2: number, xloc?: "bar_index" | "bar_time" | "pane", extend?: "none" | "left" | "right" | "both", lineColor?: import("../types/index.js").color, style?: "solid" | "dotted" | "dashed" | "arrow_left" | "arrow_right" | "arrow_both", width?: number, force_overlay?: boolean): Line;
1577
- get_price(id: Line, x: number): number;
1578
- get_x1(id: Line): number;
1579
- get_x2(id: Line): number;
1580
- get_y1(id: Line): number;
1581
- get_y2(id: Line): number;
1582
- copy(id: Line): Line;
1583
- set_x1(id: Line, x: number): Line;
1584
- set_x2(id: Line, x: number): Line;
1585
- set_y1(id: Line, y: number): Line;
1586
- set_y2(id: Line, y: number): Line;
1587
- set_xy1(id: Line, x: number, y: number): Line;
1588
- set_xy2(id: Line, x: number, y: number): Line;
1589
- set_xloc(id: Line, x1: number, x2: number, xloc: "bar_index" | "bar_time" | "pane"): Line;
1590
- set_extend(id: Line, extend: "none" | "left" | "right" | "both"): Line;
1591
- set_color(id: Line, lineColor: import("../types/index.js").color): Line;
1592
- set_style(id: Line, style: "solid" | "dotted" | "dashed" | "arrow_left" | "arrow_right" | "arrow_both"): Line;
1593
- set_width(id: Line, width: number): Line;
1594
- delete_line(id: Line): void;
1595
- all(): Line[];
1596
- set_first_point(id: Line, point: ChartPoint): Line;
1597
- set_second_point(id: Line, point: ChartPoint): Line;
1598
- new: typeof lineCore.new_line;
1599
- delete: typeof lineCore.delete_line;
1600
- }>, "all"> & {
1601
- readonly all: Line[];
1956
+ /** Wraps a drawing namespace and keeps its `all` getter (the live drawings in creation order). */
1957
+ /** A drawing namespace of scripts: the members of `T`, and `all`. */
1958
+ type DrawingNamespace<T, D> = Omit<ScriptDrawing<T>, 'all'> & {
1959
+ /** The live drawings of this kind, oldest first (a new array on each read). */
1960
+ readonly all: D[];
1602
1961
  };
1603
- /** PineScript `line.*` (with `line.style_*`); `line.all` lists the live lines in creation order. */
1962
+ declare const lineNs: DrawingNamespace<typeof lineCore & typeof pineConstants.lineStyles, Line>;
1963
+ /**
1964
+ * Lines between two chart points: `line.new()` draws one, `line.set_*` / `line.get_*` move and read it, `line.style_*`
1965
+ * are its styles, `line.all` lists the live lines.
1966
+ */
1604
1967
  export declare const line: typeof lineNs & {
1605
1968
  new: ((args: LineNewArgs) => Line) & ((x1: Numeric, y1: Numeric, x2: Numeric, y2: Numeric, args: LineNewArgs) => Line) & ((first_point: ChartPoint, second_point: ChartPoint, args: LineNewArgs) => Line);
1606
1969
  };
1607
- declare const labelNs: Omit<ScriptDrawing<{
1608
- style_none: "none";
1609
- style_xcross: "xcross";
1610
- style_cross: "cross";
1611
- style_triangleup: "triangleup";
1612
- style_triangledown: "triangledown";
1613
- style_flag: "flag";
1614
- style_circle: "circle";
1615
- style_arrowup: "arrowup";
1616
- style_arrowdown: "arrowdown";
1617
- style_label_up: "label_up";
1618
- style_label_down: "label_down";
1619
- style_label_left: "label_left";
1620
- style_label_right: "label_right";
1621
- style_label_lower_left: "label_lower_left";
1622
- style_label_lower_right: "label_lower_right";
1623
- style_label_upper_left: "label_upper_left";
1624
- style_label_upper_right: "label_upper_right";
1625
- style_label_center: "label_center";
1626
- style_square: "square";
1627
- style_diamond: "diamond";
1628
- style_text_outline: "text_outline";
1629
- new_label(point: ChartPoint, text?: string, xloc?: "bar_index" | "bar_time" | "pane", yloc?: "price" | "abovebar" | "belowbar", labelColor?: import("../types/index.js").color, style?: "none" | "xcross" | "cross" | "triangleup" | "triangledown" | "flag" | "circle" | "arrowup" | "arrowdown" | "label_up" | "label_down" | "label_left" | "label_right" | "label_lower_left" | "label_lower_right" | "label_upper_left" | "label_upper_right" | "label_center" | "square" | "diamond" | "text_outline", textcolor?: import("../types/index.js").color, size?: string | number, textalign?: "left" | "center" | "right", tooltip?: string, text_font_family?: "default" | "monospace", force_overlay?: boolean, text_formatting?: number): Label;
1630
- new_label(x: number, y: number, text?: string, xloc?: "bar_index" | "bar_time" | "pane", yloc?: "price" | "abovebar" | "belowbar", labelColor?: import("../types/index.js").color, style?: "none" | "xcross" | "cross" | "triangleup" | "triangledown" | "flag" | "circle" | "arrowup" | "arrowdown" | "label_up" | "label_down" | "label_left" | "label_right" | "label_lower_left" | "label_lower_right" | "label_upper_left" | "label_upper_right" | "label_center" | "square" | "diamond" | "text_outline", textcolor?: import("../types/index.js").color, size?: string | number, textalign?: "left" | "center" | "right", tooltip?: string, text_font_family?: "default" | "monospace", force_overlay?: boolean, text_formatting?: number): Label;
1631
- get_x(id: Label): number;
1632
- get_y(id: Label): number;
1633
- get_text(id: Label): string | undefined;
1634
- copy(id: Label): Label;
1635
- set_x(id: Label, x: number): Label;
1636
- set_y(id: Label, y: number): Label;
1637
- set_xy(id: Label, x: number, y: number): Label;
1638
- set_xloc(id: Label, x: number, xloc: "bar_index" | "bar_time" | "pane"): Label;
1639
- set_yloc(id: Label, yloc: "price" | "abovebar" | "belowbar"): Label;
1640
- set_text(id: Label, text: string): Label;
1641
- set_tooltip(id: Label, tooltip: string): Label;
1642
- set_color(id: Label, labelColor: import("../types/index.js").color): Label;
1643
- set_textcolor(id: Label, textColor: import("../types/index.js").color): Label;
1644
- set_style(id: Label, style: "none" | "xcross" | "cross" | "triangleup" | "triangledown" | "flag" | "circle" | "arrowup" | "arrowdown" | "label_up" | "label_down" | "label_left" | "label_right" | "label_lower_left" | "label_lower_right" | "label_upper_left" | "label_upper_right" | "label_center" | "square" | "diamond" | "text_outline"): Label;
1645
- set_size(id: Label, size: string | number): Label;
1646
- set_textalign(id: Label, align: "left" | "center" | "right"): Label;
1647
- set_text_font_family(id: Label, font: "default" | "monospace"): Label;
1648
- delete_label(id: Label): void;
1649
- all(): Label[];
1650
- set_point(id: Label, point: ChartPoint): Label;
1651
- set_text_formatting(id: Label, formatting: number): Label;
1652
- new: typeof labelCore.new_label;
1653
- delete: typeof labelCore.delete_label;
1654
- }>, "all"> & {
1655
- readonly all: Label[];
1656
- };
1657
- /** PineScript `label.*` (with `label.style_*`); `label.all` lists the live labels in creation order. */
1970
+ declare const labelNs: DrawingNamespace<typeof labelCore & typeof pineConstants.labelStyles, Label>;
1971
+ /**
1972
+ * Text boxes and shapes at a chart point: `label.new()` draws one, `label.set_*` / `label.get_*` change and read it,
1973
+ * `label.style_*` are its styles, `label.all` lists the live labels.
1974
+ */
1658
1975
  export declare const label: typeof labelNs & {
1659
1976
  new: ((args: LabelNewArgs) => Label) & ((x: Numeric, y: Numeric, args: LabelNewArgs) => Label) & ((x: Numeric, y: Numeric, text: string, args: LabelNewArgs) => Label) & ((point: ChartPoint, args: LabelNewArgs) => Label) & ((point: ChartPoint, text: string, args: LabelNewArgs) => Label);
1660
1977
  };
1661
- declare const boxNs: Omit<ScriptDrawing<{
1662
- new_box(top_left: ChartPoint, bottom_right: ChartPoint, border_color?: import("../types/index.js").color, border_width?: number, border_style?: "solid" | "dotted" | "dashed", extend?: "none" | "left" | "right" | "both", xloc?: "bar_index" | "bar_time" | "pane", bgcolor?: import("../types/index.js").color, text?: string, text_size?: string | number, text_color?: import("../types/index.js").color, text_halign?: "left" | "center" | "right", text_valign?: "top" | "center" | "bottom", text_wrap?: "none" | "auto", text_font_family?: "default" | "monospace", force_overlay?: boolean, text_formatting?: number): Box;
1663
- new_box(left: number, top: number, right: number, bottom: number, border_color?: import("../types/index.js").color, border_width?: number, border_style?: "solid" | "dotted" | "dashed", extend?: "none" | "left" | "right" | "both", xloc?: "bar_index" | "bar_time" | "pane", bgcolor?: import("../types/index.js").color, text?: string, text_size?: string | number, text_color?: import("../types/index.js").color, text_halign?: "left" | "center" | "right", text_valign?: "top" | "center" | "bottom", text_wrap?: "none" | "auto", text_font_family?: "default" | "monospace", force_overlay?: boolean, text_formatting?: number): Box;
1664
- get_left(id: Box): number;
1665
- get_right(id: Box): number;
1666
- get_top(id: Box): number;
1667
- get_bottom(id: Box): number;
1668
- copy(id: Box): Box;
1669
- set_left(id: Box, left: number): Box;
1670
- set_right(id: Box, right: number): Box;
1671
- set_top(id: Box, top: number): Box;
1672
- set_bottom(id: Box, bottom: number): Box;
1673
- set_lefttop(id: Box, left: number, top: number): Box;
1674
- set_rightbottom(id: Box, right: number, bottom: number): Box;
1675
- set_xloc(id: Box, left: number, right: number, xloc: "bar_index" | "bar_time" | "pane"): Box;
1676
- set_extend(id: Box, extend: "none" | "left" | "right" | "both"): Box;
1677
- set_border_color(id: Box, borderColor: import("../types/index.js").color): Box;
1678
- set_border_width(id: Box, width: number): Box;
1679
- set_border_style(id: Box, style: "solid" | "dotted" | "dashed"): Box;
1680
- set_bgcolor(id: Box, bgColor: import("../types/index.js").color): Box;
1681
- set_text(id: Box, text: string): Box;
1682
- set_text_color(id: Box, textColor: import("../types/index.js").color): Box;
1683
- set_text_size(id: Box, size: string | number): Box;
1684
- set_text_halign(id: Box, align: "left" | "center" | "right"): Box;
1685
- set_text_valign(id: Box, align: "top" | "center" | "bottom"): Box;
1686
- set_text_wrap(id: Box, wrap: "none" | "auto"): Box;
1687
- set_text_font_family(id: Box, font: "default" | "monospace"): Box;
1688
- delete_box(id: Box): void;
1689
- all(): Box[];
1690
- set_top_left_point(id: Box, point: ChartPoint): Box;
1691
- set_bottom_right_point(id: Box, point: ChartPoint): Box;
1692
- set_text_formatting(id: Box, formatting: number): Box;
1693
- new: typeof boxCore.new_box;
1694
- delete: typeof boxCore.delete_box;
1695
- }>, "all"> & {
1696
- readonly all: Box[];
1697
- };
1698
- /** PineScript `box.*`; `box.all` lists the live boxes in creation order. */
1978
+ declare const boxNs: DrawingNamespace<typeof boxCore, Box>;
1979
+ /**
1980
+ * Rectangles between two x coordinates and two prices, with optional text: `box.new()` draws one, `box.set_*` /
1981
+ * `box.get_*` change and read it, `box.all` lists the live boxes.
1982
+ */
1699
1983
  export declare const box: typeof boxNs & {
1700
1984
  new: ((args: BoxNewArgs) => Box) & ((left: Numeric, top: Numeric, right: Numeric, bottom: Numeric, args: BoxNewArgs) => Box) & ((top_left: ChartPoint, bottom_right: ChartPoint, args: BoxNewArgs) => Box);
1701
1985
  };
1702
- declare const linefillNs: Omit<ScriptDrawing<{
1703
- new_linefill(line1: Line, line2: Line, fillColor?: import("../types/index.js").color): Linefill;
1704
- get_line1(id: Linefill): Line;
1705
- get_line2(id: Linefill): Line;
1706
- set_color(id: Linefill, fillColor: import("../types/index.js").color): Linefill;
1707
- delete_linefill(id: Linefill): void;
1708
- all(): Linefill[];
1709
- new: typeof linefillCore.new_linefill;
1710
- delete: typeof linefillCore.delete_linefill;
1711
- }>, "all"> & {
1712
- readonly all: Linefill[];
1713
- };
1714
- /** PineScript `linefill.*`; `linefill.all` lists the live linefills in creation order. */
1986
+ declare const linefillNs: DrawingNamespace<typeof linefillCore, Linefill>;
1987
+ /**
1988
+ * Colour fills between two lines that follow the lines when they move: `linefill.new()`, `linefill.set_color()`,
1989
+ * `linefill.all`.
1990
+ */
1715
1991
  export declare const linefill: typeof linefillNs & {
1716
1992
  new: ((args: LinefillNewArgs) => Linefill) & ((line1: Line, line2: Line, args: LinefillNewArgs) => Linefill);
1717
1993
  };
1718
- declare const polylineNs: Omit<ScriptDrawing<{
1719
- new_polyline(points: ChartPoint[], curved?: boolean, closed?: boolean, xloc?: "bar_index" | "bar_time" | "pane", line_color?: import("../types/index.js").color, fill_color?: import("../types/index.js").color | null, line_style?: "solid" | "dotted" | "dashed", line_width?: number, force_overlay?: boolean): Polyline;
1720
- delete_polyline(id: Polyline): void;
1721
- get_all(): readonly Polyline[];
1722
- all(): Polyline[];
1723
- clear_all(): void;
1724
- reset_id_counter(): void;
1725
- new: typeof polylineCore.new_polyline;
1726
- delete: typeof polylineCore.delete_polyline;
1727
- }>, "all"> & {
1728
- readonly all: polylineCore.Polyline[];
1729
- };
1730
- /** PineScript `polyline.*`; `polyline.all` lists the live polylines in creation order. */
1994
+ declare const polylineNs: DrawingNamespace<typeof polylineCore, Polyline>;
1995
+ /**
1996
+ * Shapes through many chart points, straight or curved, open or closed and filled: `polyline.new()`,
1997
+ * `polyline.delete()`, `polyline.all`.
1998
+ */
1731
1999
  export declare const polyline: typeof polylineNs & {
1732
2000
  new: ((args: PolylineNewArgs) => Polyline) & ((points: ChartPoint[], args: PolylineNewArgs) => Polyline);
1733
2001
  };
1734
- declare const tableNs: Omit<ScriptDrawing<{
1735
- new_table(position: "top_left" | "top_center" | "top_right" | "middle_left" | "middle_center" | "middle_right" | "bottom_left" | "bottom_center" | "bottom_right", columns: number, rows: number, bgcolor?: import("../types/index.js").color, frame_color?: import("../types/index.js").color, frame_width?: number, border_color?: import("../types/index.js").color, border_width?: number, force_overlay?: boolean): Table;
1736
- cell(table_id: Table, column: number, row: number, text?: string, width?: number, height?: number, text_color?: import("../types/index.js").color, text_halign?: "left" | "right" | "center", text_valign?: "center" | "top" | "bottom", text_size?: string | number, bgcolor?: import("../types/index.js").color, tooltip?: string, text_font_family?: "default" | "monospace", text_formatting?: number): void;
1737
- merge_cells(table_id: Table, start_column: number, start_row: number, end_column: number, end_row: number): void;
1738
- clear(table_id: Table, start_column: number, start_row: number, end_column?: number, end_row?: number): void;
1739
- set_position(table_id: Table, position: "top_left" | "top_center" | "top_right" | "middle_left" | "middle_center" | "middle_right" | "bottom_left" | "bottom_center" | "bottom_right"): void;
1740
- delete_table(table_id: Table): void;
1741
- all(): Table[];
1742
- cell_set_text: (table_id: Table, column: number, row: number, value: string | undefined) => void;
1743
- cell_set_width: (table_id: Table, column: number, row: number, value: number | undefined) => void;
1744
- cell_set_height: (table_id: Table, column: number, row: number, value: number | undefined) => void;
1745
- cell_set_text_color: (table_id: Table, column: number, row: number, value: import("../types/index.js").color | undefined) => void;
1746
- cell_set_text_halign: (table_id: Table, column: number, row: number, value: "left" | "right" | "center" | undefined) => void;
1747
- cell_set_text_valign: (table_id: Table, column: number, row: number, value: "center" | "top" | "bottom" | undefined) => void;
1748
- cell_set_text_size: (table_id: Table, column: number, row: number, value: string | number | undefined) => void;
1749
- cell_set_bgcolor: (table_id: Table, column: number, row: number, value: import("../types/index.js").color | undefined) => void;
1750
- cell_set_tooltip: (table_id: Table, column: number, row: number, value: string | undefined) => void;
1751
- cell_set_text_font_family: (table_id: Table, column: number, row: number, value: "default" | "monospace" | undefined) => void;
1752
- cell_set_text_formatting: (table_id: Table, column: number, row: number, value: number | undefined) => void;
1753
- set_bgcolor: (table_id: Table, value: import("../types/index.js").color | undefined) => void;
1754
- set_frame_color: (table_id: Table, value: import("../types/index.js").color | undefined) => void;
1755
- set_frame_width: (table_id: Table, value: number | undefined) => void;
1756
- set_border_color: (table_id: Table, value: import("../types/index.js").color | undefined) => void;
1757
- set_border_width: (table_id: Table, value: number | undefined) => void;
1758
- new: typeof tableCore.new_table;
1759
- delete: typeof tableCore.delete_table;
1760
- }>, "all"> & {
1761
- readonly all: Table[];
1762
- };
1763
2002
  /**
1764
- * PineScript `table.*`; `table.all` lists the live tables in creation order. The live tables go to `result.tables`.
2003
+ * Tables fixed at a place of the pane, for values and dashboards: `table.new()` creates one, `table.cell()` fills it,
2004
+ * `table.all` lists the live tables. The live tables go to `result.tables`.
1765
2005
  */
1766
- export declare const table: typeof tableNs & {
1767
- new: ((args: TableNewArgs) => Table) & ((position: string, columns: number, rows: number, args: TableNewArgs) => Table);
1768
- cell: ((args: TableCellArgs) => void) & ((table_id: Table, column: number, row: number, args: TableCellArgs) => void) & ((table_id: Table, column: number, row: number, text: string, args: TableCellArgs) => void);
1769
- };
2006
+ export declare const table: TableNamespace;
1770
2007
  /** PineScript `position.*` constants (table positions). */
1771
2008
  export { position };
1772
- /** PineScript `text.format_*`, `text.align_*` and `text.wrap_*` constants. */
1773
- export declare const text: {
1774
- format_none: 0;
1775
- format_bold: 1;
1776
- format_italic: 2;
1777
- align_left: "left";
1778
- align_center: "center";
1779
- align_right: "right";
1780
- align_top: "top";
1781
- align_bottom: "bottom";
1782
- wrap_auto: "auto";
1783
- wrap_none: "none";
1784
- };
1785
- /** PineScript constant namespaces (`shape.triangleup`, `size.small`, `xloc.bar_time`, `extend.right`...): the strings
1786
- * the functions take. */
1787
- export declare const shape: {
1788
- readonly xcross: "xcross";
1789
- readonly cross: "cross";
1790
- readonly triangleup: "triangleup";
1791
- readonly triangledown: "triangledown";
1792
- readonly flag: "flag";
1793
- readonly circle: "circle";
1794
- readonly arrowup: "arrowup";
1795
- readonly arrowdown: "arrowdown";
1796
- readonly labelup: "labelup";
1797
- readonly labeldown: "labeldown";
1798
- readonly square: "square";
1799
- readonly diamond: "diamond";
1800
- }, location: {
1801
- readonly abovebar: "abovebar";
1802
- readonly belowbar: "belowbar";
1803
- readonly top: "top";
1804
- readonly bottom: "bottom";
1805
- readonly absolute: "absolute";
1806
- }, size: {
1807
- readonly auto: "auto";
1808
- readonly tiny: "tiny";
1809
- readonly small: "small";
1810
- readonly normal: "normal";
1811
- readonly large: "large";
1812
- readonly huge: "huge";
1813
- }, xloc: {
1814
- readonly bar_index: "bar_index";
1815
- readonly bar_time: "bar_time";
1816
- readonly pane: "pane";
1817
- }, yloc: {
1818
- readonly price: "price";
1819
- readonly abovebar: "abovebar";
1820
- readonly belowbar: "belowbar";
1821
- }, extend: {
1822
- readonly none: "none";
1823
- readonly left: "left";
1824
- readonly right: "right";
1825
- readonly both: "both";
1826
- }, display: {
1827
- readonly none: "none";
1828
- readonly all: "all";
1829
- readonly data_window: "data_window";
1830
- readonly status_line: "status_line";
1831
- readonly pane: "pane";
1832
- }, format: {
1833
- readonly inherit: "inherit";
1834
- readonly price: "price";
1835
- readonly volume: "volume";
1836
- readonly percent: "percent";
1837
- readonly mintick: "mintick";
1838
- }, font: {
1839
- readonly family_default: "default";
1840
- readonly family_monospace: "monospace";
1841
- }, scale: {
1842
- readonly right: "right";
1843
- readonly left: "left";
1844
- readonly none: "none";
1845
- }, order: {
1846
- readonly ascending: "ascending";
1847
- readonly descending: "descending";
1848
- }, currency: {
1849
- readonly NONE: "NONE";
1850
- readonly AED: "AED";
1851
- readonly ARS: "ARS";
1852
- readonly AUD: "AUD";
1853
- readonly BDT: "BDT";
1854
- readonly BHD: "BHD";
1855
- readonly BRL: "BRL";
1856
- readonly BTC: "BTC";
1857
- readonly CAD: "CAD";
1858
- readonly CHF: "CHF";
1859
- readonly CLP: "CLP";
1860
- readonly CNY: "CNY";
1861
- readonly COP: "COP";
1862
- readonly CZK: "CZK";
1863
- readonly DKK: "DKK";
1864
- readonly EGP: "EGP";
1865
- readonly ETH: "ETH";
1866
- readonly EUR: "EUR";
1867
- readonly GBP: "GBP";
1868
- readonly GEL: "GEL";
1869
- readonly HKD: "HKD";
1870
- readonly HUF: "HUF";
1871
- readonly IDR: "IDR";
1872
- readonly ILS: "ILS";
1873
- readonly INR: "INR";
1874
- readonly ISK: "ISK";
1875
- readonly JPY: "JPY";
1876
- readonly KES: "KES";
1877
- readonly KRW: "KRW";
1878
- readonly KWD: "KWD";
1879
- readonly LKR: "LKR";
1880
- readonly MAD: "MAD";
1881
- readonly MXN: "MXN";
1882
- readonly MYR: "MYR";
1883
- readonly NGN: "NGN";
1884
- readonly NOK: "NOK";
1885
- readonly NZD: "NZD";
1886
- readonly PEN: "PEN";
1887
- readonly PHP: "PHP";
1888
- readonly PKR: "PKR";
1889
- readonly PLN: "PLN";
1890
- readonly QAR: "QAR";
1891
- readonly RON: "RON";
1892
- readonly RSD: "RSD";
1893
- readonly RUB: "RUB";
1894
- readonly SAR: "SAR";
1895
- readonly SEK: "SEK";
1896
- readonly SGD: "SGD";
1897
- readonly THB: "THB";
1898
- readonly TND: "TND";
1899
- readonly TRY: "TRY";
1900
- readonly TWD: "TWD";
1901
- readonly USD: "USD";
1902
- readonly USDT: "USDT";
1903
- readonly VES: "VES";
1904
- readonly VND: "VND";
1905
- readonly ZAR: "ZAR";
1906
- }, adjustment: {
1907
- readonly none: "none";
1908
- readonly splits: "splits";
1909
- readonly dividends: "dividends";
1910
- };
2009
+ /** Text constants: `text.format_*` (bold, italic), `text.align_*` (alignment) and `text.wrap_*` (wrapping). */
2010
+ export declare const text: typeof textCore;
2011
+ export { shape, location, size, xloc, yloc, extend, display, format, font, scale, order, currency, adjustment } from './constants.js';
1911
2012
  /**
1912
2013
  * PineScript `chart.point.*`. `chart.point.now(price?)` is the point of the current bar
1913
2014
  * (index, time, and `price`, default the close), so it runs inside eachBar().
1914
2015
  */
1915
- export declare const chart: {
1916
- /** Chart foreground colour (PineScript `chart.fg_color`), from the chart context. */
1917
- readonly fg_color: string;
1918
- /** Chart background colour (PineScript `chart.bg_color`), from the chart context. */
1919
- readonly bg_color: string;
1920
- /** Time (ms) of the first bar in view (PineScript `chart.left_visible_bar_time`), from the chart context; without it,
1921
- * of the first bar. */
1922
- readonly left_visible_bar_time: number;
1923
- /** Time (ms) of the last bar in view (PineScript `chart.right_visible_bar_time`), from the chart context; without it,
1924
- * of the last bar. */
1925
- readonly right_visible_bar_time: number;
1926
- /** The chart is not one of the types below (PineScript `chart.is_standard`). */
1927
- readonly is_standard: boolean;
1928
- readonly is_heikinashi: boolean;
1929
- readonly is_renko: boolean;
1930
- readonly is_kagi: boolean;
1931
- readonly is_linebreak: boolean;
1932
- readonly is_pnf: boolean;
1933
- readonly is_range: boolean;
1934
- point: {
1935
- now(price?: number): ChartPoint;
1936
- new_point(time: number | null, index: number | null, price: number): ChartPoint;
1937
- from_time(time: number, price: number): ChartPoint;
1938
- from_index(index: number, price: number): ChartPoint;
1939
- copy(point: ChartPoint): ChartPoint;
1940
- new: typeof chartPointCore.new_point;
1941
- };
1942
- };
1943
- /** Wraps a plain value array (e.g. a side output accumulated inside eachBar)
1944
- * into a Series aligned with the current bars. */
2016
+ export declare const chart: ChartNamespace;
2017
+ /**
2018
+ * Makes a Series from an array of numbers, one per bar (oldest first), e.g. values collected inside `eachBar()`.
2019
+ * @param values - One value per bar; NaN is na.
2020
+ * @returns Series of the values.
2021
+ * @example
2022
+ * ```js
2023
+ * const ranges = [];
2024
+ * eachBar((c) => { ranges.push(c.high - c.low); });
2025
+ * plot(seriesOf(ranges), "Range");
2026
+ * ```
2027
+ */
1945
2028
  export declare function seriesOf(values: number[]): Series;
1946
- /** PineScript `alertcondition()` — collected for the host's alert engine. */
2029
+ /**
2030
+ * Declares a condition users can create an alert on (in the app's alert dialog). It does not send an alert itself.
2031
+ * @param condition - Series that is true (non-zero) on the bars where the alert fires.
2032
+ * @param title - Name of the condition in the alert dialog.
2033
+ * @param message - Default text of the alert. Default: the title.
2034
+ * @example
2035
+ * ```js
2036
+ * const cross = ta.crossover(close, ta.sma(close, 50));
2037
+ * alertcondition(cross, "Price above SMA 50", "Close crossed above its 50-bar average");
2038
+ * ```
2039
+ */
1947
2040
  export declare function alertcondition(condition: Series, title: string, message?: string): void;
1948
2041
  /**
1949
- * PineScript `alert(message, freq)`, with the `alert.freq_*` constants: the calls are collected per bar with their
1950
- * message and frequency (`result.alertCalls`) for the host's alert engine, which fires the ones made on the realtime
1951
- * bar. Called inside eachBar() / strategy.eachBar() it is a call on the current bar; at the top level of the script
1952
- * (which PineScript runs on every bar) it is a call on every bar, `message` then being a text or one text per bar
1953
- * (a bar whose text is na makes no call). Default frequency: `alert.freq_once_per_bar`.
1954
- */
1955
- declare function alertImpl(message: string | ReadonlyArray<string | undefined>, freq?: AlertFrequency): void;
1956
- /** PineScript `alert()` with the `alert.freq_*` constants: `alert('Crossed', alert.freq_once_per_bar_close)`. */
1957
- export declare const alert: typeof alertImpl & {
1958
- readonly freq_all: "all";
1959
- readonly freq_once_per_bar: "once_per_bar";
1960
- readonly freq_once_per_bar_close: "once_per_bar_close";
1961
- };
2042
+ * Sends an alert message while the script runs (to the alerts set on the script), with the `alert.freq_*`
2043
+ * constants for how often it may fire.
2044
+ * @example
2045
+ * ```js
2046
+ * eachBar((c) => {
2047
+ * if (c.get(close) > c.get(high, 1)) alert("New high", alert.freq_once_per_bar_close);
2048
+ * });
2049
+ * ```
2050
+ */
2051
+ export declare const alert: AlertApi;
1962
2052
  /** The level of a log message. */
1963
2053
  export type LogLevel = 'info' | 'warning' | 'error';
1964
2054
  /** One log.*() message: the bar it was made on (index, and time as given in the input bars), its level and text, and
@@ -1973,80 +2063,49 @@ export interface LogEntry {
1973
2063
  /** The most messages a run keeps: the newest ones. */
1974
2064
  export declare const MAX_LOG_ENTRIES = 10000;
1975
2065
  /**
1976
- * How the host finds the line of the script that called log.*(): `resolver` gets the stack of the call (an Error's
1977
- * `stack`) and gives the line in the script's own source. Null (the default): messages have no line.
2066
+ * Host-side: how the host finds the line of the script that called log.*(). Scripts never call it.
2067
+ * @param resolver - Gets the stack of the call (an Error's `stack`) and gives the line in the script's own source;
2068
+ * null (the default): messages have no line.
1978
2069
  */
1979
2070
  export declare function setLogLineResolver(resolver: ((stack: string) => number | undefined) | null): void;
1980
2071
  /**
1981
- * PineScript `log.info()`, `log.warning()` and `log.error()`: a message for the host's logs panel, made on the current
1982
- * bar inside eachBar() / strategy.eachBar(), on every bar at the top level of the script (which PineScript runs on
1983
- * every bar; `message` is then a text or one text per bar, a bar whose text is na makes no message). With arguments,
1984
- * `message` is a str.format() pattern (`log.info('close {0}', close)`), a Series argument giving its value on the bar.
1985
- * The messages of a run are in `result.logs`, by bar ({@link MAX_LOG_ENTRIES} newest kept).
2072
+ * Messages for the logs panel: `log.info`, `log.warning` and `log.error`. Inside `eachBar()` a call makes a message on
2073
+ * the current bar; at the top level, one message per bar. With arguments the message is a `str.format()` pattern.
2074
+ * @example
2075
+ * ```js
2076
+ * eachBar((c) => {
2077
+ * if (c.get(volume) > 2 * c.get(ta.sma(volume, 20))) log.info("Volume spike: {0}", c.get(volume));
2078
+ * });
2079
+ * ```
1986
2080
  */
1987
- export declare const log: {
1988
- info(message: string | ReadonlyArray<string | undefined>, ...args: unknown[]): void;
1989
- warning(message: string | ReadonlyArray<string | undefined>, ...args: unknown[]): void;
1990
- error(message: string | ReadonlyArray<string | undefined>, ...args: unknown[]): void;
1991
- };
2081
+ export declare const log: LogNamespace;
1992
2082
  export { Series, BarData };
1993
2083
  export { STRATEGY_DEFAULTS } from '../strategy/index.js';
1994
2084
  export type { StrategyCloseAllOptions, StrategyCloseOptions, StrategyCommissionType, StrategyDirection, StrategyEngine, StrategyEntryOptions, StrategyExitOptions, StrategyNumberVariable, StrategyOcaType, StrategyOptions, StrategyProperties, StrategyQtyType, StrategyRiskDirection, StrategyRiskRule, StrategyRiskValueType, StrategyTextVariable, StrategyTrade, StrategyVariable, } from '../strategy/index.js';
1995
- export declare const math: {
1996
- random: typeof mathCore.random;
1997
- round_to_mintick: typeof mathCore.round_to_mintick;
1998
- abs(value: Series): Series;
1999
- abs(value: import("../index.js").float): import("../index.js").float;
2000
- ceil(value: Series): Series;
2001
- ceil(value: import("../index.js").float): import("../index.js").int;
2002
- floor(value: Series): Series;
2003
- floor(value: import("../index.js").float): import("../index.js").int;
2004
- round(value: Series, precision?: import("../index.js").int): Series;
2005
- round(value: import("../index.js").float, precision?: import("../index.js").int): import("../index.js").float;
2006
- constant(value: import("../index.js").float): import("../index.js").float;
2007
- max(...values: (import("../index.js").float | Series)[]): import("../index.js").float | Series;
2008
- min(...values: (import("../index.js").float | Series)[]): import("../index.js").float | Series;
2009
- avg(...values: (import("../index.js").float | Series)[]): import("../index.js").float | Series;
2010
- sum(source: Series, length: import("../index.js").simple_int | ArrayLike<number> | Series): Series;
2011
- sum(source: import("../index.js").series_float, length: import("../index.js").simple_int | ArrayLike<number> | Series): import("../index.js").series_float;
2012
- sqrt(value: Series): Series;
2013
- sqrt(value: import("../index.js").float): import("../index.js").float;
2014
- pow(base: Series, exponent: import("../index.js").float): Series;
2015
- pow(base: import("../index.js").float, exponent: Series): Series;
2016
- pow(base: Series, exponent: Series): Series;
2017
- pow(base: import("../index.js").float, exponent: import("../index.js").float): import("../index.js").float;
2018
- exp(value: Series): Series;
2019
- exp(value: import("../index.js").float): import("../index.js").float;
2020
- log(value: Series): Series;
2021
- log(value: import("../index.js").float): import("../index.js").float;
2022
- log10(value: Series): Series;
2023
- log10(value: import("../index.js").float): import("../index.js").float;
2024
- sin(value: Series): Series;
2025
- sin(value: import("../index.js").float): import("../index.js").float;
2026
- cos(value: Series): Series;
2027
- cos(value: import("../index.js").float): import("../index.js").float;
2028
- tan(value: Series): Series;
2029
- tan(value: import("../index.js").float): import("../index.js").float;
2030
- asin(value: Series): Series;
2031
- asin(value: import("../index.js").float): import("../index.js").float;
2032
- acos(value: Series): Series;
2033
- acos(value: import("../index.js").float): import("../index.js").float;
2034
- atan(value: Series): Series;
2035
- atan(value: import("../index.js").float): import("../index.js").float;
2036
- toradians(degrees: Series): Series;
2037
- toradians(degrees: import("../index.js").float): import("../index.js").float;
2038
- todegrees(radians: Series): Series;
2039
- todegrees(radians: import("../index.js").float): import("../index.js").float;
2040
- seededRandom(seed: import("../index.js").int): (min?: import("../index.js").float, max?: import("../index.js").float) => import("../index.js").float;
2041
- resetRandom(): void;
2042
- sign(value: Series): Series;
2043
- sign(value: import("../index.js").float): import("../index.js").int;
2044
- pi: number;
2045
- e: number;
2046
- phi: 1.618033988749895;
2047
- rphi: 0.6180339887498948;
2048
- };
2049
- export * as compare from '../compare/index.js';
2085
+ /**
2086
+ * Math functions and constants for numbers and Series: rounding, min and max, powers and logarithms, trigonometry,
2087
+ * random numbers, `math.pi`... A Series argument gives a Series, numbers give a number. `math.round_to_mintick`
2088
+ * uses the symbol's tick size.
2089
+ * @example
2090
+ * ```js
2091
+ * const range = math.abs(close.sub(open));
2092
+ * plot(math.round(ta.sma(range, 10), 2), "Body");
2093
+ * ```
2094
+ */
2095
+ export declare const math: Omit<typeof mathCore, 'saveRandom' | 'restoreRandom'>;
2096
+ /**
2097
+ * Plain-English names for the most used calculations (`calc.average`, `calc.crossesAbove`...), beside the `ta.*` ones.
2098
+ * They take Series or numbers and give a Series; a condition gives 1 where true and 0 where false.
2099
+ */
2100
+ export declare const calc: CalcNamespace;
2101
+ /**
2102
+ * Comparisons of two numbers with a tolerance of 1e-10 (`compare.eq(0.1 + 0.2, 0.3)` is true), for the plain numbers
2103
+ * of a bar loop.
2104
+ */
2105
+ export declare const compare: typeof compareCore;
2050
2106
  export { isInputActive } from '../runtime/input-active.js';
2051
2107
  export type { Bar, IndicatorResult, TimeValue, InputConfig, InputCondition, PlotConfig, HLineConfig, FillConfig, ShapeConfig, ArrowConfig, BarColorConfig, CandleConfig, MarkerData, MarkerPosition, MarkerShape, ArrowData, BarColorData, BgColorData, PlotCandleData, PlotBarData, LabelData, LabelStyle, LineDrawingData, BoxData, LinefillData, PolylineData, TableData, TableCellData, TableMergeData, TablePosition, MarkerLocation, MarkerSize, PineSize, ShapeStyle, };
2108
+ export { defineIndicator, type DefineIndicatorOptions, type IndicatorCalculation, type IndicatorDefinition, type IndicatorLiveRun, } from './define.js';
2109
+ export { formula, evaluateFormula, FORMULA_FUNCTIONS, type FormulaVariables } from './formula.js';
2110
+ export { defineIndicatorFromJson, indicatorBodyFromJson, checkIndicatorJson, type IndicatorJson, type JsonInput, type JsonPlot, type JsonLevel, type JsonFill, type JsonSignal, type JsonColorRule, } from './json.js';
2052
2111
  //# sourceMappingURL=index.d.ts.map