oakscriptjs 0.8.1 → 0.9.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 (544) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -9
  3. package/dist/cjs/array/index.d.ts +701 -0
  4. package/dist/cjs/array/index.d.ts.map +1 -0
  5. package/dist/cjs/array/index.js +392 -0
  6. package/dist/cjs/array/index.js.map +7 -0
  7. package/dist/cjs/box/index.d.ts +444 -0
  8. package/dist/cjs/box/index.d.ts.map +1 -0
  9. package/dist/cjs/box/index.js +246 -0
  10. package/dist/cjs/box/index.js.map +7 -0
  11. package/dist/cjs/callsite/index.d.ts +61 -0
  12. package/dist/cjs/callsite/index.d.ts.map +1 -0
  13. package/dist/cjs/callsite/index.js +65 -0
  14. package/dist/cjs/callsite/index.js.map +7 -0
  15. package/dist/cjs/chartpoint/index.d.ts +90 -0
  16. package/dist/cjs/chartpoint/index.d.ts.map +1 -0
  17. package/dist/cjs/chartpoint/index.js +56 -0
  18. package/dist/cjs/chartpoint/index.js.map +7 -0
  19. package/dist/cjs/color/index.d.ts +285 -0
  20. package/dist/cjs/color/index.d.ts.map +1 -0
  21. package/dist/cjs/color/index.js +143 -0
  22. package/dist/cjs/color/index.js.map +7 -0
  23. package/dist/cjs/compare/index.d.ts +26 -0
  24. package/dist/cjs/compare/index.d.ts.map +1 -0
  25. package/dist/cjs/compare/index.js +50 -0
  26. package/dist/cjs/compare/index.js.map +7 -0
  27. package/dist/cjs/drawing/registry.d.ts +42 -0
  28. package/dist/cjs/drawing/registry.d.ts.map +1 -0
  29. package/dist/cjs/drawing/registry.js +87 -0
  30. package/dist/cjs/drawing/registry.js.map +7 -0
  31. package/dist/cjs/index.d.ts +85 -0
  32. package/dist/cjs/index.d.ts.map +1 -0
  33. package/dist/cjs/index.js +184 -0
  34. package/dist/cjs/index.js.map +7 -0
  35. package/dist/cjs/indicator.d.ts +117 -0
  36. package/dist/cjs/indicator.d.ts.map +1 -0
  37. package/dist/cjs/indicator.js +74 -0
  38. package/dist/cjs/indicator.js.map +7 -0
  39. package/dist/cjs/input.d.ts +196 -0
  40. package/dist/cjs/input.d.ts.map +1 -0
  41. package/dist/cjs/input.js +197 -0
  42. package/dist/cjs/input.js.map +7 -0
  43. package/dist/cjs/label/index.d.ts +303 -0
  44. package/dist/cjs/label/index.d.ts.map +1 -0
  45. package/dist/cjs/label/index.js +190 -0
  46. package/dist/cjs/label/index.js.map +7 -0
  47. package/dist/cjs/lib/index.d.ts +8 -0
  48. package/dist/cjs/lib/index.d.ts.map +1 -0
  49. package/dist/cjs/lib/index.js +19 -0
  50. package/dist/cjs/lib/index.js.map +7 -0
  51. package/dist/{lib → cjs/lib}/zigzag/index.d.ts +4 -1
  52. package/dist/cjs/lib/zigzag/index.d.ts.map +1 -0
  53. package/dist/cjs/lib/zigzag/index.js +27 -0
  54. package/dist/cjs/lib/zigzag/index.js.map +7 -0
  55. package/dist/cjs/lib/zigzag/zigzag.d.ts +100 -0
  56. package/dist/cjs/lib/zigzag/zigzag.d.ts.map +1 -0
  57. package/dist/cjs/lib/zigzag/zigzag.js +207 -0
  58. package/dist/cjs/lib/zigzag/zigzag.js.map +7 -0
  59. package/dist/cjs/line/index.d.ts +342 -0
  60. package/dist/cjs/line/index.d.ts.map +1 -0
  61. package/dist/cjs/line/index.js +193 -0
  62. package/dist/cjs/line/index.js.map +7 -0
  63. package/dist/cjs/linefill/index.d.ts +124 -0
  64. package/dist/cjs/linefill/index.d.ts.map +1 -0
  65. package/dist/cjs/linefill/index.js +56 -0
  66. package/dist/cjs/linefill/index.js.map +7 -0
  67. package/dist/cjs/map/index.d.ts +69 -0
  68. package/dist/cjs/map/index.d.ts.map +1 -0
  69. package/dist/cjs/map/index.js +80 -0
  70. package/dist/cjs/map/index.js.map +7 -0
  71. package/dist/cjs/math/index.d.ts +560 -0
  72. package/dist/cjs/math/index.d.ts.map +1 -0
  73. package/dist/cjs/math/index.js +441 -0
  74. package/dist/cjs/math/index.js.map +7 -0
  75. package/dist/cjs/matrix/index.d.ts +1231 -0
  76. package/dist/cjs/matrix/index.d.ts.map +1 -0
  77. package/dist/cjs/matrix/index.js +1200 -0
  78. package/dist/cjs/matrix/index.js.map +7 -0
  79. package/dist/cjs/package.json +1 -0
  80. package/dist/cjs/plot.d.ts +76 -0
  81. package/dist/cjs/plot.d.ts.map +1 -0
  82. package/dist/cjs/plot.js +51 -0
  83. package/dist/cjs/plot.js.map +7 -0
  84. package/dist/cjs/polyline/index.d.ts +115 -0
  85. package/dist/cjs/polyline/index.d.ts.map +1 -0
  86. package/dist/cjs/polyline/index.js +76 -0
  87. package/dist/cjs/polyline/index.js.map +7 -0
  88. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.d.ts +86 -0
  89. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.d.ts.map +1 -0
  90. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.js +141 -0
  91. package/dist/cjs/runtime/adapters/LightweightChartsAdapter.js.map +7 -0
  92. package/dist/cjs/runtime/adapters/SimpleInputAdapter.d.ts +59 -0
  93. package/dist/cjs/runtime/adapters/SimpleInputAdapter.d.ts.map +1 -0
  94. package/dist/cjs/runtime/adapters/SimpleInputAdapter.js +117 -0
  95. package/dist/cjs/runtime/adapters/SimpleInputAdapter.js.map +7 -0
  96. package/dist/{runtime → cjs/runtime}/index.d.ts +12 -5
  97. package/dist/cjs/runtime/index.d.ts.map +1 -0
  98. package/dist/cjs/runtime/index.js +49 -0
  99. package/dist/cjs/runtime/index.js.map +7 -0
  100. package/dist/cjs/runtime/inputs.d.ts +91 -0
  101. package/dist/cjs/runtime/inputs.d.ts.map +1 -0
  102. package/dist/cjs/runtime/inputs.js +262 -0
  103. package/dist/cjs/runtime/inputs.js.map +7 -0
  104. package/dist/cjs/runtime/runtime.d.ts +70 -0
  105. package/dist/cjs/runtime/runtime.d.ts.map +1 -0
  106. package/dist/cjs/runtime/runtime.js +148 -0
  107. package/dist/cjs/runtime/runtime.js.map +7 -0
  108. package/dist/cjs/runtime/series.d.ts +362 -0
  109. package/dist/cjs/runtime/series.d.ts.map +1 -0
  110. package/dist/cjs/runtime/series.js +560 -0
  111. package/dist/cjs/runtime/series.js.map +7 -0
  112. package/dist/cjs/runtime/types.d.ts +282 -0
  113. package/dist/cjs/runtime/types.d.ts.map +1 -0
  114. package/dist/cjs/runtime/types.js +17 -0
  115. package/dist/cjs/runtime/types.js.map +7 -0
  116. package/dist/cjs/script/index.d.ts +987 -0
  117. package/dist/cjs/script/index.d.ts.map +1 -0
  118. package/dist/cjs/script/index.js +1169 -0
  119. package/dist/cjs/script/index.js.map +7 -0
  120. package/dist/cjs/security/resample.d.ts +63 -0
  121. package/dist/cjs/security/resample.d.ts.map +1 -0
  122. package/dist/cjs/security/resample.js +84 -0
  123. package/dist/cjs/security/resample.js.map +7 -0
  124. package/dist/cjs/session/bars.d.ts +80 -0
  125. package/dist/cjs/session/bars.d.ts.map +1 -0
  126. package/dist/cjs/session/bars.js +219 -0
  127. package/dist/cjs/session/bars.js.map +7 -0
  128. package/dist/cjs/session/calendar.d.ts +70 -0
  129. package/dist/cjs/session/calendar.d.ts.map +1 -0
  130. package/dist/cjs/session/calendar.js +164 -0
  131. package/dist/cjs/session/calendar.js.map +7 -0
  132. package/dist/cjs/str/dateformat.d.ts +15 -0
  133. package/dist/cjs/str/dateformat.d.ts.map +1 -0
  134. package/dist/cjs/str/dateformat.js +149 -0
  135. package/dist/cjs/str/dateformat.js.map +7 -0
  136. package/dist/cjs/str/index.d.ts +459 -0
  137. package/dist/cjs/str/index.d.ts.map +1 -0
  138. package/dist/cjs/str/index.js +143 -0
  139. package/dist/cjs/str/index.js.map +7 -0
  140. package/dist/cjs/str/messageformat.d.ts +14 -0
  141. package/dist/cjs/str/messageformat.d.ts.map +1 -0
  142. package/dist/cjs/str/messageformat.js +114 -0
  143. package/dist/cjs/str/messageformat.js.map +7 -0
  144. package/dist/cjs/str/numberformat.d.ts +19 -0
  145. package/dist/cjs/str/numberformat.d.ts.map +1 -0
  146. package/dist/cjs/str/numberformat.js +170 -0
  147. package/dist/cjs/str/numberformat.js.map +7 -0
  148. package/dist/{strategy → cjs/strategy}/index.d.ts +50 -0
  149. package/dist/cjs/strategy/index.d.ts.map +1 -0
  150. package/dist/cjs/strategy/index.js +92 -0
  151. package/dist/cjs/strategy/index.js.map +7 -0
  152. package/dist/cjs/ta/index.d.ts +1397 -0
  153. package/dist/cjs/ta/index.d.ts.map +1 -0
  154. package/dist/cjs/ta/index.js +1715 -0
  155. package/dist/cjs/ta/index.js.map +7 -0
  156. package/dist/cjs/ta/running-sum.d.ts +30 -0
  157. package/dist/cjs/ta/running-sum.d.ts.map +1 -0
  158. package/dist/cjs/ta/running-sum.js +99 -0
  159. package/dist/cjs/ta/running-sum.js.map +7 -0
  160. package/dist/cjs/ta-series.d.ts +558 -0
  161. package/dist/cjs/ta-series.d.ts.map +1 -0
  162. package/dist/cjs/ta-series.js +606 -0
  163. package/dist/cjs/ta-series.js.map +7 -0
  164. package/dist/cjs/text/index.d.ts +14 -0
  165. package/dist/cjs/text/index.d.ts.map +1 -0
  166. package/dist/cjs/text/index.js +29 -0
  167. package/dist/cjs/text/index.js.map +7 -0
  168. package/dist/cjs/time/datestring.d.ts +23 -0
  169. package/dist/cjs/time/datestring.d.ts.map +1 -0
  170. package/dist/cjs/time/datestring.js +106 -0
  171. package/dist/cjs/time/datestring.js.map +7 -0
  172. package/dist/cjs/time/index.d.ts +89 -0
  173. package/dist/cjs/time/index.d.ts.map +1 -0
  174. package/dist/cjs/time/index.js +85 -0
  175. package/dist/cjs/time/index.js.map +7 -0
  176. package/dist/cjs/time/session.d.ts +17 -0
  177. package/dist/cjs/time/session.d.ts.map +1 -0
  178. package/dist/cjs/time/session.js +65 -0
  179. package/dist/cjs/time/session.js.map +7 -0
  180. package/dist/cjs/time/timezone.d.ts +40 -0
  181. package/dist/cjs/time/timezone.d.ts.map +1 -0
  182. package/dist/cjs/time/timezone.js +125 -0
  183. package/dist/cjs/time/timezone.js.map +7 -0
  184. package/dist/cjs/timeframe/index.d.ts +73 -0
  185. package/dist/cjs/timeframe/index.d.ts.map +1 -0
  186. package/dist/cjs/timeframe/index.js +85 -0
  187. package/dist/cjs/timeframe/index.js.map +7 -0
  188. package/dist/cjs/types/index.d.ts +343 -0
  189. package/dist/cjs/types/index.d.ts.map +1 -0
  190. package/dist/cjs/types/index.js +32 -0
  191. package/dist/cjs/types/index.js.map +7 -0
  192. package/dist/cjs/types/metadata.d.ts +300 -0
  193. package/dist/cjs/types/metadata.d.ts.map +1 -0
  194. package/dist/cjs/types/metadata.js +17 -0
  195. package/dist/cjs/types/metadata.js.map +7 -0
  196. package/dist/cjs/utils/index.d.ts +167 -0
  197. package/dist/cjs/utils/index.d.ts.map +1 -0
  198. package/dist/cjs/utils/index.js +209 -0
  199. package/dist/cjs/utils/index.js.map +7 -0
  200. package/dist/esm/array/index.d.ts +701 -0
  201. package/dist/esm/array/index.d.ts.map +1 -0
  202. package/dist/esm/array/index.js +983 -0
  203. package/dist/esm/array/index.js.map +1 -0
  204. package/dist/esm/box/index.d.ts +444 -0
  205. package/dist/esm/box/index.d.ts.map +1 -0
  206. package/dist/esm/box/index.js +602 -0
  207. package/dist/esm/box/index.js.map +1 -0
  208. package/dist/esm/callsite/index.d.ts +61 -0
  209. package/dist/esm/callsite/index.d.ts.map +1 -0
  210. package/dist/esm/callsite/index.js +97 -0
  211. package/dist/esm/callsite/index.js.map +1 -0
  212. package/dist/esm/chartpoint/index.d.ts +90 -0
  213. package/dist/esm/chartpoint/index.d.ts.map +1 -0
  214. package/dist/esm/chartpoint/index.js +113 -0
  215. package/dist/esm/chartpoint/index.js.map +1 -0
  216. package/dist/esm/color/index.d.ts +285 -0
  217. package/dist/esm/color/index.d.ts.map +1 -0
  218. package/dist/esm/color/index.js +373 -0
  219. package/dist/esm/color/index.js.map +1 -0
  220. package/dist/esm/compare/index.d.ts +26 -0
  221. package/dist/esm/compare/index.d.ts.map +1 -0
  222. package/dist/esm/compare/index.js +39 -0
  223. package/dist/esm/compare/index.js.map +1 -0
  224. package/dist/esm/drawing/registry.d.ts +42 -0
  225. package/dist/esm/drawing/registry.d.ts.map +1 -0
  226. package/dist/esm/drawing/registry.js +89 -0
  227. package/dist/esm/drawing/registry.js.map +1 -0
  228. package/dist/esm/index.d.ts +85 -0
  229. package/dist/esm/index.d.ts.map +1 -0
  230. package/dist/esm/index.js +96 -0
  231. package/dist/esm/index.js.map +1 -0
  232. package/dist/esm/indicator.d.ts +117 -0
  233. package/dist/esm/indicator.d.ts.map +1 -0
  234. package/dist/esm/indicator.js +84 -0
  235. package/dist/esm/indicator.js.map +1 -0
  236. package/dist/esm/input.d.ts +196 -0
  237. package/dist/esm/input.d.ts.map +1 -0
  238. package/dist/esm/input.js +183 -0
  239. package/dist/esm/input.js.map +1 -0
  240. package/dist/esm/label/index.d.ts +303 -0
  241. package/dist/esm/label/index.d.ts.map +1 -0
  242. package/dist/esm/label/index.js +417 -0
  243. package/dist/esm/label/index.js.map +1 -0
  244. package/dist/esm/lib/index.d.ts +8 -0
  245. package/dist/esm/lib/index.d.ts.map +1 -0
  246. package/dist/esm/lib/index.js +8 -0
  247. package/dist/esm/lib/index.js.map +1 -0
  248. package/dist/esm/lib/zigzag/index.d.ts +5 -0
  249. package/dist/esm/lib/zigzag/index.d.ts.map +1 -0
  250. package/dist/esm/lib/zigzag/index.js +5 -0
  251. package/dist/esm/lib/zigzag/index.js.map +1 -0
  252. package/dist/esm/lib/zigzag/zigzag.d.ts +100 -0
  253. package/dist/esm/lib/zigzag/zigzag.d.ts.map +1 -0
  254. package/dist/esm/lib/zigzag/zigzag.js +229 -0
  255. package/dist/esm/lib/zigzag/zigzag.js.map +1 -0
  256. package/dist/esm/line/index.d.ts +342 -0
  257. package/dist/esm/line/index.d.ts.map +1 -0
  258. package/dist/esm/line/index.js +470 -0
  259. package/dist/esm/line/index.js.map +1 -0
  260. package/dist/esm/linefill/index.d.ts +124 -0
  261. package/dist/esm/linefill/index.d.ts.map +1 -0
  262. package/dist/esm/linefill/index.js +144 -0
  263. package/dist/esm/linefill/index.js.map +1 -0
  264. package/dist/esm/map/index.d.ts +69 -0
  265. package/dist/esm/map/index.d.ts.map +1 -0
  266. package/dist/esm/map/index.js +106 -0
  267. package/dist/esm/map/index.js.map +1 -0
  268. package/dist/esm/math/index.d.ts +560 -0
  269. package/dist/esm/math/index.d.ts.map +1 -0
  270. package/dist/esm/math/index.js +495 -0
  271. package/dist/esm/math/index.js.map +1 -0
  272. package/dist/esm/matrix/index.d.ts +1231 -0
  273. package/dist/esm/matrix/index.d.ts.map +1 -0
  274. package/dist/esm/matrix/index.js +2450 -0
  275. package/dist/esm/matrix/index.js.map +1 -0
  276. package/dist/esm/plot.d.ts +76 -0
  277. package/dist/esm/plot.d.ts.map +1 -0
  278. package/dist/esm/plot.js +63 -0
  279. package/dist/esm/plot.js.map +1 -0
  280. package/dist/esm/polyline/index.d.ts +115 -0
  281. package/dist/esm/polyline/index.d.ts.map +1 -0
  282. package/dist/esm/polyline/index.js +157 -0
  283. package/dist/esm/polyline/index.js.map +1 -0
  284. package/dist/esm/runtime/adapters/LightweightChartsAdapter.d.ts +86 -0
  285. package/dist/esm/runtime/adapters/LightweightChartsAdapter.d.ts.map +1 -0
  286. package/dist/esm/runtime/adapters/LightweightChartsAdapter.js +140 -0
  287. package/dist/esm/runtime/adapters/LightweightChartsAdapter.js.map +1 -0
  288. package/dist/esm/runtime/adapters/SimpleInputAdapter.d.ts +59 -0
  289. package/dist/esm/runtime/adapters/SimpleInputAdapter.d.ts.map +1 -0
  290. package/dist/esm/runtime/adapters/SimpleInputAdapter.js +115 -0
  291. package/dist/esm/runtime/adapters/SimpleInputAdapter.js.map +1 -0
  292. package/dist/esm/runtime/index.d.ts +13 -0
  293. package/dist/esm/runtime/index.d.ts.map +1 -0
  294. package/dist/esm/runtime/index.js +14 -0
  295. package/dist/esm/runtime/index.js.map +1 -0
  296. package/dist/esm/runtime/inputs.d.ts +91 -0
  297. package/dist/esm/runtime/inputs.d.ts.map +1 -0
  298. package/dist/esm/runtime/inputs.js +334 -0
  299. package/dist/esm/runtime/inputs.js.map +1 -0
  300. package/dist/esm/runtime/runtime.d.ts +70 -0
  301. package/dist/esm/runtime/runtime.d.ts.map +1 -0
  302. package/dist/esm/runtime/runtime.js +193 -0
  303. package/dist/esm/runtime/runtime.js.map +1 -0
  304. package/dist/esm/runtime/series.d.ts +362 -0
  305. package/dist/esm/runtime/series.d.ts.map +1 -0
  306. package/dist/esm/runtime/series.js +583 -0
  307. package/dist/esm/runtime/series.js.map +1 -0
  308. package/dist/esm/runtime/types.d.ts +282 -0
  309. package/dist/esm/runtime/types.d.ts.map +1 -0
  310. package/dist/esm/runtime/types.js +7 -0
  311. package/dist/esm/runtime/types.js.map +1 -0
  312. package/dist/esm/script/index.d.ts +987 -0
  313. package/dist/esm/script/index.d.ts.map +1 -0
  314. package/dist/esm/script/index.js +1289 -0
  315. package/dist/esm/script/index.js.map +1 -0
  316. package/dist/esm/security/resample.d.ts +63 -0
  317. package/dist/esm/security/resample.d.ts.map +1 -0
  318. package/dist/esm/security/resample.js +110 -0
  319. package/dist/esm/security/resample.js.map +1 -0
  320. package/dist/esm/session/bars.d.ts +80 -0
  321. package/dist/esm/session/bars.d.ts.map +1 -0
  322. package/dist/esm/session/bars.js +232 -0
  323. package/dist/esm/session/bars.js.map +1 -0
  324. package/dist/esm/session/calendar.d.ts +70 -0
  325. package/dist/esm/session/calendar.d.ts.map +1 -0
  326. package/dist/esm/session/calendar.js +172 -0
  327. package/dist/esm/session/calendar.js.map +1 -0
  328. package/dist/esm/str/dateformat.d.ts +15 -0
  329. package/dist/esm/str/dateformat.d.ts.map +1 -0
  330. package/dist/esm/str/dateformat.js +136 -0
  331. package/dist/esm/str/dateformat.js.map +1 -0
  332. package/dist/esm/str/index.d.ts +459 -0
  333. package/dist/esm/str/index.d.ts.map +1 -0
  334. package/dist/esm/str/index.js +540 -0
  335. package/dist/esm/str/index.js.map +1 -0
  336. package/dist/esm/str/messageformat.d.ts +14 -0
  337. package/dist/esm/str/messageformat.d.ts.map +1 -0
  338. package/dist/esm/str/messageformat.js +111 -0
  339. package/dist/esm/str/messageformat.js.map +1 -0
  340. package/dist/esm/str/numberformat.d.ts +19 -0
  341. package/dist/esm/str/numberformat.d.ts.map +1 -0
  342. package/dist/esm/str/numberformat.js +189 -0
  343. package/dist/esm/str/numberformat.js.map +1 -0
  344. package/dist/esm/strategy/index.d.ts +245 -0
  345. package/dist/esm/strategy/index.d.ts.map +1 -0
  346. package/dist/esm/strategy/index.js +84 -0
  347. package/dist/esm/strategy/index.js.map +1 -0
  348. package/dist/esm/ta/index.d.ts +1397 -0
  349. package/dist/esm/ta/index.d.ts.map +1 -0
  350. package/dist/esm/ta/index.js +3227 -0
  351. package/dist/esm/ta/index.js.map +1 -0
  352. package/dist/esm/ta/running-sum.d.ts +30 -0
  353. package/dist/esm/ta/running-sum.d.ts.map +1 -0
  354. package/dist/esm/ta/running-sum.js +113 -0
  355. package/dist/esm/ta/running-sum.js.map +1 -0
  356. package/dist/esm/ta-series.d.ts +558 -0
  357. package/dist/esm/ta-series.d.ts.map +1 -0
  358. package/dist/esm/ta-series.js +910 -0
  359. package/dist/esm/ta-series.js.map +1 -0
  360. package/dist/esm/text/index.d.ts +14 -0
  361. package/dist/esm/text/index.d.ts.map +1 -0
  362. package/dist/esm/text/index.js +14 -0
  363. package/dist/esm/text/index.js.map +1 -0
  364. package/dist/esm/time/datestring.d.ts +23 -0
  365. package/dist/esm/time/datestring.d.ts.map +1 -0
  366. package/dist/esm/time/datestring.js +94 -0
  367. package/dist/esm/time/datestring.js.map +1 -0
  368. package/dist/esm/time/index.d.ts +89 -0
  369. package/dist/esm/time/index.d.ts.map +1 -0
  370. package/dist/esm/time/index.js +108 -0
  371. package/dist/esm/time/index.js.map +1 -0
  372. package/dist/esm/time/session.d.ts +17 -0
  373. package/dist/esm/time/session.d.ts.map +1 -0
  374. package/dist/esm/time/session.js +69 -0
  375. package/dist/esm/time/session.js.map +1 -0
  376. package/dist/esm/time/timezone.d.ts +40 -0
  377. package/dist/esm/time/timezone.d.ts.map +1 -0
  378. package/dist/esm/time/timezone.js +144 -0
  379. package/dist/esm/time/timezone.js.map +1 -0
  380. package/dist/esm/timeframe/index.d.ts +73 -0
  381. package/dist/esm/timeframe/index.d.ts.map +1 -0
  382. package/dist/esm/timeframe/index.js +131 -0
  383. package/dist/esm/timeframe/index.js.map +1 -0
  384. package/dist/esm/types/index.d.ts +343 -0
  385. package/dist/esm/types/index.d.ts.map +1 -0
  386. package/dist/esm/types/index.js +17 -0
  387. package/dist/esm/types/index.js.map +1 -0
  388. package/dist/esm/types/metadata.d.ts +300 -0
  389. package/dist/esm/types/metadata.d.ts.map +1 -0
  390. package/dist/esm/types/metadata.js +7 -0
  391. package/dist/esm/types/metadata.js.map +1 -0
  392. package/dist/esm/utils/index.d.ts +167 -0
  393. package/dist/esm/utils/index.d.ts.map +1 -0
  394. package/dist/esm/utils/index.js +295 -0
  395. package/dist/esm/utils/index.js.map +1 -0
  396. package/package.json +53 -23
  397. package/src/array/index.ts +1056 -0
  398. package/src/box/index.ts +680 -0
  399. package/src/callsite/index.ts +104 -0
  400. package/src/chartpoint/index.ts +126 -0
  401. package/src/color/index.ts +411 -0
  402. package/src/compare/index.ts +46 -0
  403. package/src/drawing/registry.ts +106 -0
  404. package/src/index.ts +201 -0
  405. package/src/indicator.ts +185 -0
  406. package/src/input.ts +280 -0
  407. package/src/label/index.ts +490 -0
  408. package/src/lib/index.ts +8 -0
  409. package/src/lib/zigzag/index.ts +13 -0
  410. package/src/lib/zigzag/zigzag.ts +318 -0
  411. package/src/line/index.ts +530 -0
  412. package/src/linefill/index.ts +152 -0
  413. package/src/map/index.ts +115 -0
  414. package/src/math/index.ts +1071 -0
  415. package/src/matrix/index.ts +2697 -0
  416. package/src/plot.ts +121 -0
  417. package/src/polyline/index.ts +184 -0
  418. package/src/runtime/adapters/LightweightChartsAdapter.ts +201 -0
  419. package/src/runtime/adapters/SimpleInputAdapter.ts +132 -0
  420. package/src/runtime/index.ts +52 -0
  421. package/src/runtime/inputs.ts +377 -0
  422. package/src/runtime/runtime.ts +241 -0
  423. package/src/runtime/series.ts +644 -0
  424. package/src/runtime/types.ts +292 -0
  425. package/src/script/index.ts +1865 -0
  426. package/src/security/resample.ts +119 -0
  427. package/src/session/bars.ts +262 -0
  428. package/src/session/calendar.ts +199 -0
  429. package/src/str/dateformat.ts +104 -0
  430. package/src/str/index.ts +557 -0
  431. package/src/str/messageformat.ts +109 -0
  432. package/src/str/numberformat.ts +197 -0
  433. package/src/strategy/index.ts +281 -0
  434. package/src/ta/index.ts +3580 -0
  435. package/src/ta/running-sum.ts +117 -0
  436. package/src/ta-series.ts +1036 -0
  437. package/src/text/index.ts +14 -0
  438. package/src/time/datestring.ts +96 -0
  439. package/src/time/index.ts +161 -0
  440. package/src/time/session.ts +79 -0
  441. package/src/time/timezone.ts +180 -0
  442. package/src/timeframe/index.ts +144 -0
  443. package/src/types/index.ts +398 -0
  444. package/src/types/metadata.ts +334 -0
  445. package/src/utils/index.ts +334 -0
  446. package/dist/array/index.d.ts +0 -57
  447. package/dist/array/index.d.ts.map +0 -1
  448. package/dist/box/index.d.ts +0 -37
  449. package/dist/box/index.d.ts.map +0 -1
  450. package/dist/callsite/index.d.ts +0 -7
  451. package/dist/callsite/index.d.ts.map +0 -1
  452. package/dist/chartpoint/index.d.ts +0 -8
  453. package/dist/chartpoint/index.d.ts.map +0 -1
  454. package/dist/color/index.d.ts +0 -28
  455. package/dist/color/index.d.ts.map +0 -1
  456. package/dist/compare/index.d.ts +0 -8
  457. package/dist/compare/index.d.ts.map +0 -1
  458. package/dist/drawing/registry.d.ts +0 -19
  459. package/dist/drawing/registry.d.ts.map +0 -1
  460. package/dist/index.cjs +0 -7979
  461. package/dist/index.d.ts +0 -64
  462. package/dist/index.d.ts.map +0 -1
  463. package/dist/index.mjs +0 -7962
  464. package/dist/indicator.d.ts +0 -42
  465. package/dist/indicator.d.ts.map +0 -1
  466. package/dist/input.d.ts +0 -47
  467. package/dist/input.d.ts.map +0 -1
  468. package/dist/label/index.d.ts +0 -30
  469. package/dist/label/index.d.ts.map +0 -1
  470. package/dist/lib/index.d.ts +0 -2
  471. package/dist/lib/index.d.ts.map +0 -1
  472. package/dist/lib/zigzag/index.d.ts.map +0 -1
  473. package/dist/lib/zigzag/zigzag.d.ts +0 -47
  474. package/dist/lib/zigzag/zigzag.d.ts.map +0 -1
  475. package/dist/line/index.d.ts +0 -30
  476. package/dist/line/index.d.ts.map +0 -1
  477. package/dist/linefill/index.d.ts +0 -10
  478. package/dist/linefill/index.d.ts.map +0 -1
  479. package/dist/map/index.d.ts +0 -14
  480. package/dist/map/index.d.ts.map +0 -1
  481. package/dist/math/index.d.ts +0 -53
  482. package/dist/math/index.d.ts.map +0 -1
  483. package/dist/matrix/index.d.ts +0 -52
  484. package/dist/matrix/index.d.ts.map +0 -1
  485. package/dist/plot.d.ts +0 -20
  486. package/dist/plot.d.ts.map +0 -1
  487. package/dist/polyline/index.d.ts +0 -11
  488. package/dist/polyline/index.d.ts.map +0 -1
  489. package/dist/runtime/adapters/LightweightChartsAdapter.d.ts +0 -15
  490. package/dist/runtime/adapters/LightweightChartsAdapter.d.ts.map +0 -1
  491. package/dist/runtime/adapters/SimpleInputAdapter.d.ts +0 -16
  492. package/dist/runtime/adapters/SimpleInputAdapter.d.ts.map +0 -1
  493. package/dist/runtime/index.cjs +0 -600
  494. package/dist/runtime/index.d.ts.map +0 -1
  495. package/dist/runtime/index.mjs +0 -577
  496. package/dist/runtime/inputs.d.ts +0 -13
  497. package/dist/runtime/inputs.d.ts.map +0 -1
  498. package/dist/runtime/runtime.d.ts +0 -16
  499. package/dist/runtime/runtime.d.ts.map +0 -1
  500. package/dist/runtime/series.d.ts +0 -60
  501. package/dist/runtime/series.d.ts.map +0 -1
  502. package/dist/runtime/types.d.ts +0 -122
  503. package/dist/runtime/types.d.ts.map +0 -1
  504. package/dist/script/index.cjs +0 -6372
  505. package/dist/script/index.d.ts +0 -709
  506. package/dist/script/index.d.ts.map +0 -1
  507. package/dist/script/index.mjs +0 -6355
  508. package/dist/security/resample.d.ts +0 -13
  509. package/dist/security/resample.d.ts.map +0 -1
  510. package/dist/session/bars.d.ts +0 -34
  511. package/dist/session/bars.d.ts.map +0 -1
  512. package/dist/session/calendar.d.ts +0 -31
  513. package/dist/session/calendar.d.ts.map +0 -1
  514. package/dist/str/dateformat.d.ts +0 -2
  515. package/dist/str/dateformat.d.ts.map +0 -1
  516. package/dist/str/index.d.ts +0 -24
  517. package/dist/str/index.d.ts.map +0 -1
  518. package/dist/str/messageformat.d.ts +0 -2
  519. package/dist/str/messageformat.d.ts.map +0 -1
  520. package/dist/str/numberformat.d.ts +0 -3
  521. package/dist/str/numberformat.d.ts.map +0 -1
  522. package/dist/strategy/index.d.ts.map +0 -1
  523. package/dist/ta/index.d.ts +0 -72
  524. package/dist/ta/index.d.ts.map +0 -1
  525. package/dist/ta-series.d.ts +0 -143
  526. package/dist/ta-series.d.ts.map +0 -1
  527. package/dist/text/index.d.ts +0 -4
  528. package/dist/text/index.d.ts.map +0 -1
  529. package/dist/time/datestring.d.ts +0 -2
  530. package/dist/time/datestring.d.ts.map +0 -1
  531. package/dist/time/index.d.ts +0 -15
  532. package/dist/time/index.d.ts.map +0 -1
  533. package/dist/time/session.d.ts +0 -2
  534. package/dist/time/session.d.ts.map +0 -1
  535. package/dist/time/timezone.d.ts +0 -13
  536. package/dist/time/timezone.d.ts.map +0 -1
  537. package/dist/timeframe/index.d.ts +0 -17
  538. package/dist/timeframe/index.d.ts.map +0 -1
  539. package/dist/types/index.d.ts +0 -181
  540. package/dist/types/index.d.ts.map +0 -1
  541. package/dist/types/metadata.d.ts +0 -131
  542. package/dist/types/metadata.d.ts.map +0 -1
  543. package/dist/utils/index.d.ts +0 -26
  544. package/dist/utils/index.d.ts.map +0 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/script/index.ts"],
4
+ "sourcesContent": ["/**\n * @fileoverview PineScript-style script API \u2014 write an indicator as a flat\n * script instead of the explicit calculate() convention.\n *\n * ```typescript\n * import { indicator, input, plot, ta } from 'oakscriptjs/script';\n *\n * indicator('My SMA', { overlay: true });\n * const length = input.int(20, 'Length', { minval: 1 });\n * const src = input.source('close', 'Source');\n * plot(ta.sma(src, length), 'SMA', { color: '#2962FF' });\n * ```\n *\n * Execution model: the host calls {@link executeScript} with the script body,\n * the bars and the current input values. Declaration calls (indicator, input.*,\n * plot, hline, fill, alertcondition) run as the body executes and are collected\n * into a {@link ScriptRunResult}: the declarative configs (inputConfig,\n * plotConfig, hlineConfig, fillConfig) plus an IndicatorResult with the plot\n * data. Re-running the body with new bars or inputs is PineScript's\n * recalculation model.\n *\n * `input.*` is idempotent like PineScript: it declares the input AND returns\n * its current value (the host-supplied override, else the default).\n *\n * The OHLCV builtins (open/high/low/close/volume/hl2/hlc3/ohlc4/hlcc4) are\n * Series bound to a module-level BarData that the host swaps per run, so\n * derived Series memoize between identical runs and recompute when the bars\n * version bumps.\n *\n * One script executes at a time (module-level context) \u2014 hosts that run many\n * scripts must serialize executions, which a Web Worker does naturally.\n *\n * @module script\n */\n\nimport type { Bar } from '../types/index.js';\nimport type {\n ArrowData,\n BarColorData,\n FillData,\n FillGradient,\n IndicatorResult,\n MarkerData,\n MarkerLocation,\n MarkerSize,\n ShapeStyle,\n TimeValue,\n} from '../types/metadata.js';\nimport type {\n ArrowConfig,\n BarColorConfig,\n FillConfig,\n HLineConfig,\n InputConfig,\n PlotConfig,\n ShapeConfig,\n} from '../runtime/types.js';\nimport { BarData, Series } from '../runtime/series.js';\nimport * as taSeries from '../ta-series.js';\nimport * as colorCore from '../color/index.js';\nimport { fixnan as fixnanValues, isNA, nz } from '../utils/index.js';\nimport * as lineCore from '../line/index.js';\nimport * as labelCore from '../label/index.js';\nimport * as boxCore from '../box/index.js';\nimport * as linefillCore from '../linefill/index.js';\nimport * as polylineCore from '../polyline/index.js';\nimport * as chartPointCore from '../chartpoint/index.js';\nimport * as textCore from '../text/index.js';\nimport * as mathCore from '../math/index.js';\nimport { resetDrawings, setDrawingLimits } from '../drawing/registry.js';\nimport * as timeframeCore from '../timeframe/index.js';\nimport * as timeCore from '../time/index.js';\nimport * as strCore from '../str/index.js';\nimport { formatMessage } from '../str/messageformat.js';\nimport { TradingCalendar, type SessionSpec } from '../session/calendar.js';\nimport { SessionBars, sessionFlags, type SessionFlags } from '../session/bars.js';\nimport { afterCompletion, heikinAshi, mapToChart, periodsOf, resample } from '../security/resample.js';\nimport type { ChartPoint } from '../types/index.js';\nimport {\n STRATEGY_CONSTANTS,\n STRATEGY_DEFAULTS,\n STRATEGY_NUMBER_VARIABLES,\n STRATEGY_TEXT_VARIABLES,\n type StrategyCloseAllOptions,\n type StrategyCloseOptions,\n type StrategyDirection,\n type StrategyEngine,\n type StrategyEntryOptions,\n type StrategyExitOptions,\n type StrategyNumberVariable,\n type StrategyOptions,\n type StrategyProperties,\n type StrategyRiskDirection,\n type StrategyRiskRule,\n type StrategyRiskValueType,\n type StrategyTextVariable,\n type StrategyTrade,\n type StrategyVariable,\n} from '../strategy/index.js';\n\n/** Everything one run of a script produced. */\nexport interface ScriptRunResult {\n metadata: { title: string; shortTitle?: string; overlay: boolean; precision?: number; format?: string };\n inputConfig: InputConfig[];\n plotConfig: PlotConfig[];\n hlineConfig: HLineConfig[];\n fillConfig: FillConfig[];\n shapeConfig: ShapeConfig[];\n arrowConfig: ArrowConfig[];\n barColorConfig: BarColorConfig[];\n defaultInputs: Record<string, unknown>;\n alertConfig: AlertConditionConfig[];\n /** Strategy properties (declared values, else the PineScript defaults) when the script declares strategy(). */\n strategyConfig?: StrategyProperties;\n /** The renderable output (plots keyed by plotConfig ids, plot-pair fills). */\n result: IndicatorResult & { alerts?: AlertState[] };\n}\n\nexport interface AlertConditionConfig {\n id: string;\n title: string;\n message?: string;\n}\n\n/** Per-run alert evaluation: whether the condition is true on the last bar. */\nexport interface AlertState {\n id: string;\n title: string;\n message?: string;\n triggered: boolean;\n}\n\n/** Handle returned by plot()/hline() so fill() can reference them. */\nexport interface PlotHandle {\n id: string;\n kind: 'plot' | 'hline';\n}\n\ninterface Collector {\n declaration?: 'indicator' | 'strategy';\n title: string;\n shortTitle?: string;\n overlay: boolean;\n precision?: number;\n format?: string;\n inputValues: Record<string, unknown>;\n inputConfig: InputConfig[];\n inputIds: Set<string>;\n defaultInputs: Record<string, unknown>;\n plotConfig: PlotConfig[];\n plots: Record<string, TimeValue[]>;\n hlineConfig: HLineConfig[];\n fills: FillData[];\n fillConfig: FillConfig[];\n shapeConfig: ShapeConfig[];\n markers: MarkerData[];\n arrowConfig: ArrowConfig[];\n arrows: ArrowData[];\n barColorConfig: BarColorConfig[];\n bgcolors: BarColorData[];\n barcolors: BarColorData[];\n alertConfig: AlertConditionConfig[];\n alerts: AlertState[];\n strategy?: StrategyRun;\n}\n\n/** State of the strategy of the current run. */\ninterface StrategyRun {\n properties: StrategyProperties;\n engine?: StrategyEngine;\n /** strategy.eachBar() has run (it runs once per script run). */\n looped: boolean;\n /** Inside the strategy.eachBar() callback. */\n inLoop: boolean;\n}\n\n/** Bars for the current run. Module-level and REUSED across runs so builtins\n * and every Series derived from them keep their version-keyed memoization. */\nconst ctxBars = new BarData([]);\n\nlet ctx: Collector | null = null;\n\nfunction collector(): Collector {\n if (!ctx) {\n throw new Error(\n 'oakscriptjs/script functions can only run inside executeScript() \u2014 ' +\n 'the host (chart/worker) drives script execution.'\n );\n }\n return ctx;\n}\n\nfunction freshCollector(inputValues: Record<string, unknown>): Collector {\n return {\n title: 'Untitled',\n overlay: true,\n inputValues,\n inputConfig: [],\n inputIds: new Set(),\n defaultInputs: {},\n plotConfig: [],\n plots: {},\n hlineConfig: [],\n fills: [],\n fillConfig: [],\n shapeConfig: [],\n markers: [],\n arrowConfig: [],\n arrows: [],\n barColorConfig: [],\n bgcolors: [],\n barcolors: [],\n alertConfig: [],\n alerts: [],\n };\n}\n\n/** Stable input id from the title (\"ATR / Range Period\" \u2192 \"atr_range_period\"). */\nfunction slugId(title: string | undefined, fallback: string, taken: Set<string>): string {\n const base =\n (title ?? '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '_')\n .replace(/^_+|_+$/g, '') || fallback;\n let id = base;\n for (let n = 2; taken.has(id); n++) id = `${base}_${n}`;\n taken.add(id);\n return id;\n}\n\n// \u2500\u2500 Host entry \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** What the host passes to its strategy engine factory when the script declares strategy(). */\nexport interface StrategySetup {\n properties: StrategyProperties;\n bars: readonly Bar[];\n chart: Readonly<ChartContext>;\n}\n\nexport interface ScriptOptions {\n /** Creates the order engine of a strategy script; called by strategy(). */\n strategyEngine?: (setup: StrategySetup) => StrategyEngine;\n}\n\nlet scriptOptions: ScriptOptions = {};\n\n/**\n * Runs a script body against `bars` with the given input overrides and\n * collects everything it declared. `chart` describes the bars (chart timeframe,\n * exchange time zone, session type) for the PineScript values that depend on them. `options.strategyEngine`\n * supplies the order engine of strategy scripts. This is the host-side entry \u2014 editor\n * panels, workers and tests call it; scripts never do.\n */\nexport function executeScript(\n body: () => void,\n barsInput: Bar[],\n inputs: Record<string, unknown> = {},\n chart: ChartContext = {},\n options: ScriptOptions = {}\n): ScriptRunResult {\n ctxBars.setAll(barsInput);\n chartCtx = { ...chart };\n scriptOptions = options;\n ctx = freshCollector(inputs);\n resetDrawings();\n try {\n body();\n const c = ctx;\n return {\n metadata: {\n title: c.title,\n shortTitle: c.shortTitle,\n overlay: c.overlay,\n precision: c.precision,\n format: c.format,\n },\n inputConfig: c.inputConfig,\n plotConfig: c.plotConfig,\n hlineConfig: c.hlineConfig,\n fillConfig: c.fillConfig,\n shapeConfig: c.shapeConfig,\n arrowConfig: c.arrowConfig,\n barColorConfig: c.barColorConfig,\n defaultInputs: c.defaultInputs,\n alertConfig: c.alertConfig,\n strategyConfig: c.strategy?.properties,\n result: {\n metadata: { title: c.title, shorttitle: c.shortTitle, overlay: c.overlay, precision: c.precision },\n plots: c.plots,\n fills: c.fills.length ? c.fills : undefined,\n markers: c.markers.length ? c.markers : undefined,\n arrows: c.arrows.length ? c.arrows : undefined,\n bgcolors: c.bgcolors.length ? c.bgcolors : undefined,\n barcolors: c.barcolors.length ? c.barcolors : undefined,\n alerts: c.alerts.length ? c.alerts : undefined,\n },\n };\n } finally {\n ctx = null;\n }\n}\n\n// \u2500\u2500 Declarations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface IndicatorOptions {\n shorttitle?: string;\n overlay?: boolean;\n precision?: number;\n format?: string;\n /** Lines kept before the oldest are deleted (default 50; PineScript keeps up to 5 more). */\n max_lines_count?: number;\n /** Labels kept before the oldest are deleted (default 50). */\n max_labels_count?: number;\n /** Boxes kept before the oldest are deleted (default 50). */\n max_boxes_count?: number;\n /** Polylines kept before the oldest are deleted (default 50). */\n max_polylines_count?: number;\n}\n\n/** PineScript `indicator()` \u2014 declares the script's metadata. */\nexport function indicator(title: string, options: IndicatorOptions = {}): void {\n const c = collector();\n declare(c, 'indicator');\n c.title = title;\n c.shortTitle = options.shorttitle;\n c.overlay = options.overlay ?? true;\n c.precision = options.precision;\n c.format = options.format;\n setDrawingLimits({\n line: options.max_lines_count,\n label: options.max_labels_count,\n box: options.max_boxes_count,\n polyline: options.max_polylines_count,\n });\n}\n\nfunction declare(c: Collector, kind: 'indicator' | 'strategy'): void {\n if (c.declaration) {\n throw new Error(`${kind}(): the script already declared ${c.declaration}(); a script has one declaration.`);\n }\n c.declaration = kind;\n}\n\n/** Options of every `input.*` kind (PineScript `group`, `inline`, `tooltip`, `confirm`, `display`). */\nexport interface InputOptions {\n group?: string;\n inline?: string;\n tooltip?: string;\n confirm?: boolean;\n display?: InputConfig['display'];\n}\n\nexport interface NumericInputOptions extends InputOptions {\n minval?: number;\n maxval?: number;\n step?: number;\n}\n\nexport interface StringInputOptions extends InputOptions {\n options?: string[];\n}\n\n/** The InputConfig fields of the common input options (unset options are left out). */\nfunction common(opts: InputOptions): Partial<InputConfig> {\n const out: Partial<InputConfig> = {};\n if (opts.group !== undefined) out.group = opts.group;\n if (opts.inline !== undefined) out.inline = opts.inline;\n if (opts.tooltip !== undefined) out.tooltip = opts.tooltip;\n if (opts.confirm !== undefined) out.confirm = opts.confirm;\n if (opts.display !== undefined) out.display = opts.display;\n return out;\n}\n\n/** Declares the input in the collector and returns its current value (the\n * host-supplied override when present, else the default). */\nfunction registerInput<T>(config: Omit<InputConfig, 'id'>, fallbackId: string): T {\n const c = collector();\n const id = slugId(config.title, fallbackId, c.inputIds);\n c.inputConfig.push({ id, ...config });\n c.defaultInputs[id] = config.defval;\n const value = c.inputValues[id];\n return (value === undefined ? config.defval : value) as T;\n}\n\nfunction registerNumeric(type: 'int' | 'float', defval: number, title?: string, opts: NumericInputOptions = {}): number {\n const v = registerInput<unknown>(\n { type, defval, title, min: opts.minval, max: opts.maxval, step: opts.step, ...common(opts) },\n `input_${type}`\n );\n return typeof v === 'number' ? v : defval;\n}\n\n/** PineScript `input.*` \u2014 declares an input AND returns its current value. */\nexport const input = {\n int(defval: number, title?: string, opts: NumericInputOptions = {}): number {\n return Math.round(registerNumeric('int', defval, title, opts));\n },\n float(defval: number, title?: string, opts: NumericInputOptions = {}): number {\n return registerNumeric('float', defval, title, opts);\n },\n bool(defval: boolean, title?: string, opts: InputOptions = {}): boolean {\n return registerInput<boolean>({ type: 'bool', defval, title, ...common(opts) }, 'input_bool');\n },\n string(defval: string, title?: string, opts: StringInputOptions = {}): string {\n return registerInput<string>({ type: 'string', defval, title, options: opts.options, ...common(opts) }, 'input_string');\n },\n color(defval: string, title?: string, opts: InputOptions = {}): string {\n return registerInput<string>({ type: 'color', defval, title, ...common(opts) }, 'input_color');\n },\n /** Declares a source input and returns it as a Series. */\n source(defval: string = 'close', title?: string, opts: InputOptions = {}): Series {\n const name = registerInput<string>({ type: 'source', defval, title, ...common(opts) }, 'input_source');\n return sourceSeries(name);\n },\n /** Timeframe string (\"60\", \"1D\", \"W\"). As in PineScript, \"\" means the chart timeframe. */\n timeframe(defval: string, title?: string, opts: StringInputOptions = {}): string {\n return registerInput<string>(\n { type: 'timeframe', defval, title, options: opts.options, ...common(opts) },\n 'input_timeframe'\n );\n },\n /** Session string (\"0930-1600\", \"0930-1600:23456\"). */\n session(defval: string, title?: string, opts: StringInputOptions = {}): string {\n return registerInput<string>(\n { type: 'session', defval, title, options: opts.options, ...common(opts) },\n 'input_session'\n );\n },\n /** Date and time as a UNIX time in milliseconds, e.g. `input.time(timestamp('2024-01-01'), 'Start')`. */\n time(defval: number, title?: string, opts: InputOptions = {}): number {\n const v = registerInput<unknown>({ type: 'time', defval, title, ...common(opts) }, 'input_time');\n return typeof v === 'number' ? v : defval;\n },\n};\n\n// \u2500\u2500 OHLCV builtins \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport const open = Series.fromBars(ctxBars, 'open');\nexport const high = Series.fromBars(ctxBars, 'high');\nexport const low = Series.fromBars(ctxBars, 'low');\nexport const close = Series.fromBars(ctxBars, 'close');\nexport const volume = Series.fromBars(ctxBars, 'volume');\nexport const hl2 = new Series(ctxBars, (b) => (b.high + b.low) / 2);\nexport const hlc3 = new Series(ctxBars, (b) => (b.high + b.low + b.close) / 3);\nexport const ohlc4 = new Series(ctxBars, (b) => (b.open + b.high + b.low + b.close) / 4);\nexport const hlcc4 = new Series(ctxBars, (b) => (b.high + b.low + b.close + b.close) / 4);\n\nconst SOURCES: Record<string, Series> = { open, high, low, close, volume, hl2, hlc3, ohlc4, hlcc4 };\n\nfunction sourceSeries(name: string): Series {\n return SOURCES[name] ?? close;\n}\n\n// \u2500\u2500 Bound ta namespace \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nconst bars = (): Bar[] => ctxBars.bars;\n\n/** A Series bound to the context bars whose values come from one pass over all bars\n * (cumulative indicators), recomputed when the bars version changes. */\nfunction barsSeries(compute: (b: Bar[]) => Series): Series {\n let version = -1;\n let values: number[] = [];\n return new Series(ctxBars, (_bar, i, data) => {\n if (version !== ctxBars.version) {\n values = compute(data).toArray();\n version = ctxBars.version;\n }\n return values[i] ?? NaN;\n });\n}\n\n/** ta.* with the chart-implicit (bars-first) functions bound to the context,\n * so scripts call them like PineScript: `ta.tr(true)`, `ta.atr(14)`. */\nexport const ta = {\n ...taSeries,\n tr: (handleNa: boolean = false): Series => taSeries.tr(bars(), handleNa),\n atr: (length: number): Series => taSeries.atr(bars(), length),\n sar: (start?: number, inc?: number, max?: number): Series => taSeries.sar(bars(), start, inc, max),\n wpr: (length?: number): Series => taSeries.wpr(bars(), length),\n supertrend: (factor: number, atrLength: number): [Series, Series] =>\n taSeries.supertrend(bars(), factor, atrLength),\n dmi: (diLength: number, adxSmoothing: number): [Series, Series, Series] =>\n taSeries.dmi(bars(), diLength, adxSmoothing),\n kc: (source: Series, length: number, mult: number, useTrueRange?: boolean): [Series, Series, Series] =>\n taSeries.kc(bars(), source, length, mult, useTrueRange),\n kcw: (source: Series, length?: number, mult?: number, useTrueRange?: boolean): Series =>\n taSeries.kcw(bars(), source, length, mult, useTrueRange),\n ichimoku: (\n conversionPeriods: number,\n basePeriods: number,\n laggingSpan2Periods: number,\n displacement: number\n ): [Series, Series, Series, Series, Series] =>\n taSeries.ichimoku(bars(), conversionPeriods, basePeriods, laggingSpan2Periods, displacement),\n /** `ta.highest(source, length)` or `ta.highest(length)` (source = high). */\n highest: (sourceOrLength: Series | number, length?: number): Series =>\n typeof sourceOrLength === 'number' ? taSeries.highest(high, sourceOrLength) : taSeries.highest(sourceOrLength, length!),\n /** `ta.lowest(source, length)` or `ta.lowest(length)` (source = low). */\n lowest: (sourceOrLength: Series | number, length?: number): Series =>\n typeof sourceOrLength === 'number' ? taSeries.lowest(low, sourceOrLength) : taSeries.lowest(sourceOrLength, length!),\n /** `ta.highestbars(source, length)` or `ta.highestbars(length)` (source = high); offsets are 0 or negative. */\n highestbars: (sourceOrLength: Series | number, length?: number): Series =>\n typeof sourceOrLength === 'number'\n ? taSeries.highestbars(high, sourceOrLength)\n : taSeries.highestbars(sourceOrLength, length!),\n /** `ta.lowestbars(source, length)` or `ta.lowestbars(length)` (source = low); offsets are 0 or negative. */\n lowestbars: (sourceOrLength: Series | number, length?: number): Series =>\n typeof sourceOrLength === 'number'\n ? taSeries.lowestbars(low, sourceOrLength)\n : taSeries.lowestbars(sourceOrLength, length!),\n /** `ta.vwap(source, anchor?, stdev_mult?)` with the chart volume; the default anchor is a new trading\n * day (`timeframe.change(\"1D\")`), which needs the chart context (timeframe, time zone, session). */\n vwap: ((source: Series, anchor?: Series, stdev_mult?: number): Series | [Series, Series, Series] => {\n const a = anchor ?? changeOf('1D'); // PineScript default: timeframe.change(\"1D\")\n return stdev_mult === undefined ? taSeries.vwap(source, volume, a) : taSeries.vwapBands(source, volume, a, stdev_mult);\n }) as {\n (source: Series, anchor?: Series): Series;\n (source: Series, anchor: Series | undefined, stdev_mult: number): [Series, Series, Series];\n },\n /** `ta.mfi(source, length)` with the chart volume (PineScript takes 2 arguments). */\n mfi: (source: Series, length: number): Series => taSeries.mfi(source, length, volume),\n /** `ta.pivothigh(source, leftbars, rightbars)` or `ta.pivothigh(leftbars, rightbars)` (source = high).\n * The value appears `rightbars` bars after the pivot bar, as in PineScript. */\n pivothigh: (sourceOrLeft: Series | number, leftOrRight: number, rightbars?: number): Series =>\n typeof sourceOrLeft === 'number'\n ? taSeries.pivothigh(high, sourceOrLeft, leftOrRight)\n : taSeries.pivothigh(sourceOrLeft, leftOrRight, rightbars!),\n /** `ta.pivotlow(source, leftbars, rightbars)` or `ta.pivotlow(leftbars, rightbars)` (source = low). */\n pivotlow: (sourceOrLeft: Series | number, leftOrRight: number, rightbars?: number): Series =>\n typeof sourceOrLeft === 'number'\n ? taSeries.pivotlow(low, sourceOrLeft, leftOrRight)\n : taSeries.pivotlow(sourceOrLeft, leftOrRight, rightbars!),\n // PineScript variables of the chart bars: `ta.obv`, not `ta.obv()`.\n obv: barsSeries(taSeries.obv),\n pvt: barsSeries(taSeries.pvt),\n accdist: barsSeries(taSeries.accdist),\n nvi: barsSeries(taSeries.nvi),\n pvi: barsSeries(taSeries.pvi),\n iii: barsSeries(taSeries.iii),\n wad: barsSeries(taSeries.wad),\n wvad: barsSeries(taSeries.wvad),\n};\n\n/** PineScript `fixnan(source)`: each `na` value becomes the previous non-`na` value.\n * Accepts a Series or a per-bar color array (`undefined` = `na`, as returned by `color.when`). */\nexport function fixnan(source: Series): Series;\nexport function fixnan(source: Array<string | undefined>): Array<string | undefined>;\nexport function fixnan(source: Series | Array<string | undefined>): Series | Array<string | undefined> {\n return source instanceof Series ? Series.fromArray(ctxBars, fixnanValues(source.toArray())) : fixnanValues(source);\n}\n\n// \u2500\u2500 Color helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** Per-bar color selection: truthy \u2192 colorTrue, else colorFalse.\n * colorFalse may be omitted (PineScript `na`): those bars get no color,\n * which bgcolor()/barcolor() skip. */\nfunction colorWhen(cond: Series, colorTrue: string, colorFalse: string): string[];\nfunction colorWhen(cond: Series, colorTrue: string, colorFalse?: string): Array<string | undefined>;\nfunction colorWhen(cond: Series, colorTrue: string, colorFalse?: string): Array<string | undefined> {\n return cond.toArray().map((v) => (!isNA(v) && v !== 0 ? colorTrue : colorFalse));\n}\n\n/** color.* plus `when` \u2014 per-bar conditional colors for plot()/fill()/bgcolor()/barcolor(). */\nexport const color = {\n ...colorCore,\n new: colorCore.new_color,\n when: colorWhen,\n};\n\n// \u2500\u2500 Drawing declarations \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface ScriptPlotOptions {\n /** Static color, or a per-bar color array from color.when(). */\n color?: string | string[];\n linewidth?: number;\n style?: PlotConfig['style'];\n /** Line style (PineScript `linestyle`); default solid. A constant or an input value, not per bar. */\n linestyle?: PlotConfig['linestyle'];\n display?: PlotConfig['display'];\n histbase?: number;\n /** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */\n force_overlay?: boolean;\n}\n\n/** PineScript `plot()` \u2014 declares the plot and supplies its data in one call. */\nfunction plotImpl(series: Series, title?: string, options: ScriptPlotOptions = {}): PlotHandle {\n const c = collector();\n const id = `plot${c.plotConfig.length}`;\n const perBar = Array.isArray(options.color) ? options.color : undefined;\n const staticColor = typeof options.color === 'string' ? options.color : (perBar?.[perBar.length - 1] ?? '#2962FF');\n c.plotConfig.push({\n id,\n title: title ?? id,\n color: staticColor,\n lineWidth: options.linewidth,\n style: options.style,\n linestyle: options.linestyle,\n display: options.display,\n histbase: options.histbase,\n forceOverlay: options.force_overlay,\n });\n const values = series.toArray();\n const b = bars();\n const data: TimeValue[] = [];\n for (let i = 0; i < b.length; i++) {\n const value = values[i];\n if (value === undefined || !Number.isFinite(value)) continue; // PineScript plots +/-Infinity as na\n data.push(perBar ? { time: b[i]!.time, value, color: perBar[i] } : { time: b[i]!.time, value });\n }\n c.plots[id] = data;\n return { id, kind: 'plot' };\n}\n\n/**\n * PineScript `plot()`, with the `plot.style_*` and `plot.linestyle_*` constants:\n * `plot(src, 'Level', { style: plot.style_stepline, linestyle: plot.linestyle_dashed })`.\n */\nexport const plot = Object.assign(plotImpl, {\n style_line: 'line',\n style_linebr: 'linebr',\n style_stepline: 'stepline',\n style_steplinebr: 'steplinebr',\n style_stepline_diamond: 'stepline_diamond',\n style_histogram: 'histogram',\n style_columns: 'columns',\n style_area: 'area',\n style_areabr: 'areabr',\n style_circles: 'circles',\n style_cross: 'cross',\n linestyle_solid: 'solid',\n linestyle_dotted: 'dotted',\n linestyle_dashed: 'dashed',\n} as const);\n\nexport interface ScriptHLineOptions {\n color?: string;\n /** Line style; default dashed (PineScript). */\n linestyle?: HLineConfig['linestyle'];\n linewidth?: number;\n}\n\n/** PineScript `hline()` \u2014 a static horizontal level. Default line style: dashed (PineScript). */\nfunction hlineImpl(price: number, title?: string, options: ScriptHLineOptions = {}): PlotHandle {\n const c = collector();\n const id = `hline${c.hlineConfig.length}`;\n c.hlineConfig.push({\n id,\n price,\n title,\n color: options.color,\n linestyle: options.linestyle ?? 'dashed',\n linewidth: options.linewidth,\n });\n return { id, kind: 'hline' };\n}\n\n/** PineScript `hline()`, with the `hline.style_*` constants: `hline(0, 'Zero', { linestyle: hline.style_dotted })`. */\nexport const hline = Object.assign(hlineImpl, {\n style_solid: 'solid',\n style_dotted: 'dotted',\n style_dashed: 'dashed',\n} as const);\n\nexport interface ScriptFillOptions {\n /** Static color, or a per-bar color array from color.when(). */\n color?: string | string[];\n title?: string;\n}\n\n/** A fill colour argument: a colour, na (null / undefined), or a per-bar array from color.when(). */\nexport type ScriptFillColor = string | null | undefined | Array<string | null | undefined>;\n\n/** A gradient value argument: a number or a Series. */\nexport type ScriptFillValue = number | Series;\n\nfunction perBarValues(v: ScriptFillValue, n: number): number[] {\n return v instanceof Series ? v.toArray().slice(0, n) : new Array<number>(n).fill(v);\n}\n\nfunction perBarColors(c: ScriptFillColor, n: number): Array<string | null> {\n if (Array.isArray(c)) return Array.from({ length: n }, (_, i) => c[i] ?? null);\n return new Array<string | null>(n).fill(c ?? null);\n}\n\n/**\n * PineScript `fill()`, with the three PineScript overloads (positional arguments), for two plots or two hlines:\n * - `fill(p1, p2, color?, title?, ...)`\n * - `fill(p1, p2, top_value, bottom_value, top_color, bottom_color, title?, ...)`: gradient fill; values and colours\n * can change per bar (a Series / a color.when() array)\n * - `fill(p1, p2, { color, title })`: options object (oakscriptjs form, kept for existing scripts)\n * Arguments that change only how the chart shows the fill (`editable`, `show_last`, `fillgaps`, `display`) are\n * accepted and not used.\n */\nexport function fill(a: PlotHandle, b: PlotHandle, options?: ScriptFillOptions): void;\nexport function fill(a: PlotHandle, b: PlotHandle, color: ScriptFillColor, title?: string, ...rest: unknown[]): void;\nexport function fill(\n a: PlotHandle,\n b: PlotHandle,\n top_value: ScriptFillValue,\n bottom_value: ScriptFillValue,\n top_color: ScriptFillColor,\n bottom_color: ScriptFillColor,\n title?: string,\n ...rest: unknown[]\n): void;\nexport function fill(a: PlotHandle, b: PlotHandle, ...args: unknown[]): void {\n const c = collector();\n const third = args[0];\n let perBar: string[] | undefined;\n let staticColor: string | undefined;\n let title: string | undefined;\n let gradient: FillGradient | undefined;\n if (typeof third === 'number' || third instanceof Series) {\n const n = ctxBars.bars.length;\n gradient = {\n topValue: perBarValues(third, n),\n bottomValue: perBarValues(args[1] as ScriptFillValue, n),\n topColor: perBarColors(args[2] as ScriptFillColor, n),\n bottomColor: perBarColors(args[3] as ScriptFillColor, n),\n };\n title = args[4] as string | undefined;\n } else if (third !== null && typeof third === 'object' && !Array.isArray(third)) {\n const options = third as ScriptFillOptions;\n perBar = Array.isArray(options.color) ? options.color : undefined;\n staticColor = typeof options.color === 'string' ? options.color : undefined;\n title = options.title;\n } else {\n const color = third as ScriptFillColor;\n perBar = Array.isArray(color) ? color.map((x) => x ?? '') : undefined;\n staticColor = typeof color === 'string' ? color : undefined;\n title = args[1] as string | undefined;\n }\n if (a.kind === 'hline' && b.kind === 'hline') {\n c.fillConfig.push({\n id: `fill${c.fillConfig.length}`,\n plot1: a.id,\n plot2: b.id,\n color: staticColor,\n colors: perBar,\n gradient,\n title,\n });\n return;\n }\n c.fills.push({\n plot1: a.id,\n plot2: b.id,\n options: { color: staticColor, title },\n colors: perBar,\n gradient,\n });\n}\n\nexport interface PlotShapeOptions {\n style?: ShapeStyle;\n location?: MarkerLocation;\n color?: string;\n text?: string;\n textcolor?: string;\n size?: MarkerSize;\n /** Display offset in bars (marker shown at bar i + offset). */\n offset?: number;\n /** Hover tooltip (extension over PineScript, for label.new-style ports). */\n tooltip?: string;\n /** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */\n force_overlay?: boolean;\n}\n\nexport interface PlotCharOptions extends Omit<PlotShapeOptions, 'style'> {\n char?: string;\n}\n\n/** Shared emitter for plotshape()/plotchar(). Emits one marker per bar where\n * the condition is truthy (not na, not 0). */\nfunction emitMarkers(\n kind: 'shape' | 'char',\n condition: Series,\n title: string | undefined,\n options: PlotShapeOptions & PlotCharOptions\n): void {\n const c = collector();\n const id = `${kind}${c.shapeConfig.filter((s) => s.kind === kind).length}`;\n const style: ShapeStyle | 'char' = kind === 'shape' ? (options.style ?? 'xcross') : 'char';\n const char = kind === 'char' ? (options.char ?? '*') : undefined;\n const location = options.location ?? 'abovebar';\n c.shapeConfig.push({\n id,\n kind,\n title,\n style: kind === 'shape' ? (style as ShapeStyle) : undefined,\n char,\n location,\n color: options.color,\n text: options.text,\n textcolor: options.textcolor,\n size: options.size,\n offset: options.offset,\n forceOverlay: options.force_overlay,\n });\n const values = condition.toArray();\n const b = bars();\n const off = options.offset ?? 0;\n for (let i = 0; i < b.length; i++) {\n const v = values[i];\n if (v === undefined || Number.isNaN(v) || v === 0) continue;\n const j = i + off;\n if (j < 0 || j >= b.length) continue;\n c.markers.push({\n time: b[j]!.time,\n id,\n location,\n style,\n char,\n color: options.color,\n text: options.text,\n textcolor: options.textcolor,\n size: options.size,\n tooltip: options.tooltip,\n price: location === 'absolute' ? v : undefined,\n });\n }\n}\n\n/** PineScript `plotshape()` \u2014 a marker on each bar where the condition holds. */\nexport function plotshape(condition: Series, title?: string, options: PlotShapeOptions = {}): void {\n emitMarkers('shape', condition, title, options);\n}\n\n/** PineScript `plotchar()` \u2014 a character marker on each bar where the condition holds. */\nexport function plotchar(condition: Series, title?: string, options: PlotCharOptions = {}): void {\n emitMarkers('char', condition, title, options);\n}\n\nexport interface PlotArrowOptions {\n /** Color of the up arrows: a color or a per-bar array (default #00FF00, PineScript). */\n colorup?: string | Array<string | undefined>;\n /** Color of the down arrows: a color or a per-bar array (default #FF0000, PineScript). */\n colordown?: string | Array<string | undefined>;\n /** Display offset in bars (arrow shown at bar i + offset). */\n offset?: number;\n /** Minimal arrow height in pixels (default 5). */\n minheight?: number;\n /** Maximal arrow height in pixels (default 100). */\n maxheight?: number;\n display?: ArrowConfig['display'];\n /** Draw on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false. */\n force_overlay?: boolean;\n}\n\n/**\n * PineScript `plotarrow()` \u2014 an up arrow below the bar for a positive value, a down arrow above the bar for a\n * negative value, nothing for 0 / na. The arrows go to `result.arrows` (value and color per bar), the declaration to\n * `arrowConfig`; the renderer scales the height with the absolute value between minheight and maxheight.\n */\nexport function plotarrow(series: Series, title?: string, options: PlotArrowOptions = {}): void {\n const c = collector();\n const id = `arrow${c.arrowConfig.length}`;\n const pick = (col: string | Array<string | undefined> | undefined, fallback: string, i: number): string | undefined =>\n col === undefined ? fallback : typeof col === 'string' ? col : col[i];\n const colorup = typeof options.colorup === 'string' ? options.colorup : '#00FF00';\n const colordown = typeof options.colordown === 'string' ? options.colordown : '#FF0000';\n c.arrowConfig.push({\n id,\n title,\n colorup,\n colordown,\n minheight: options.minheight ?? 5,\n maxheight: options.maxheight ?? 100,\n offset: options.offset,\n display: options.display,\n forceOverlay: options.force_overlay,\n });\n const values = series.toArray();\n const b = bars();\n const off = options.offset ?? 0;\n for (let i = 0; i < b.length; i++) {\n const v = values[i];\n if (v === undefined || Number.isNaN(v) || v === 0) continue;\n const j = i + off;\n if (j < 0 || j >= b.length) continue;\n const color = v > 0 ? pick(options.colorup, '#00FF00', i) : pick(options.colordown, '#FF0000', i);\n if (color === undefined) continue; // na color: no arrow\n c.arrows.push({ time: b[j]!.time, id, value: v, color });\n }\n}\n\n/** Shared emitter for bgcolor()/barcolor(). A static color applies to every\n * bar; a per-bar array (from color.when) skips undefined entries. The offset\n * is baked in: the color computed at bar i lands on bar i + offset. */\nfunction emitBarColors(\n kind: 'bgcolor' | 'barcolor',\n colors: string | Array<string | undefined>,\n options: { offset?: number; title?: string; force_overlay?: boolean }\n): void {\n const c = collector();\n const id = `${kind}${c.barColorConfig.filter((x) => x.kind === kind).length}`;\n c.barColorConfig.push({ id, kind, title: options.title, offset: options.offset, forceOverlay: options.force_overlay });\n const b = bars();\n const off = options.offset ?? 0;\n const target = kind === 'bgcolor' ? c.bgcolors : c.barcolors;\n for (let i = 0; i < b.length; i++) {\n const col = typeof colors === 'string' ? colors : colors[i];\n if (!col) continue;\n const j = i + off;\n if (j < 0 || j >= b.length) continue;\n target.push({ time: b[j]!.time, color: col });\n }\n}\n\n/**\n * PineScript `bgcolor()` \u2014 per-bar background color. `force_overlay: true` colors the main chart pane even when the\n * script is not an overlay.\n */\nexport function bgcolor(\n colors: string | Array<string | undefined>,\n options: { offset?: number; title?: string; force_overlay?: boolean } = {}\n): void {\n emitBarColors('bgcolor', colors, options);\n}\n\n/** PineScript `barcolor()` \u2014 per-bar candle color override. */\nexport function barcolor(\n colors: string | Array<string | undefined>,\n options: { title?: string } = {}\n): void {\n emitBarColors('barcolor', colors, options);\n}\n\n// \u2500\u2500 Per-bar execution (eachBar) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * The scalar view of one bar handed to an {@link eachBar} callback.\n * All fields are plain numbers, so native JS operators work.\n */\nexport interface BarContext {\n /** Bar index (PineScript bar_index). */\n readonly i: number;\n /** Total number of bars. */\n readonly n: number;\n /** Time of the current bar. */\n readonly time: number;\n readonly open: number;\n readonly high: number;\n readonly low: number;\n readonly close: number;\n readonly volume: number;\n /** Value of any Series at the current bar minus `offset` (PineScript src[offset]). */\n get(src: Series, offset?: number): number;\n /** This block's own previous output (PineScript self-reference, offset >= 1). */\n prev(offset?: number): number;\n}\n\n/**\n * Runs the callback once per bar, in order, and collects the returned values\n * into a Series. This is the escape hatch for PineScript logic the vectorized\n * model cannot express:\n *\n * - `var x = 0` / `x := ...` \u2192 a plain `let` variable captured by the closure\n * - per-bar `if` / `for` / `while` \u2192 native JS statements\n * - `src[k]` \u2192 `c.get(src, k)`; self-reference \u2192 `c.prev()`\n *\n * Returning a boolean collects 1/0; returning nothing collects na (NaN).\n *\n * ```typescript\n * let dir = 0; // var dir = 0\n * const trend = eachBar((c) => {\n * if (c.close > c.get(close, 1)) dir = 1; // dir := 1\n * else if (c.close < c.get(close, 1)) dir = -1;\n * return dir;\n * });\n * ```\n */\nexport function eachBar(fn: (c: BarContext) => number | boolean | void): Series {\n collector(); // same lifecycle guard (and error message) as the declaration calls\n const b = bars();\n const out: number[] = new Array(b.length).fill(NaN);\n const cache = new Map<Series, number[]>();\n let idx = 0;\n const ctx: BarContext = {\n get i() {\n return idx;\n },\n n: b.length,\n get time() {\n return b[idx]!.time as number;\n },\n get open() {\n return b[idx]!.open;\n },\n get high() {\n return b[idx]!.high;\n },\n get low() {\n return b[idx]!.low;\n },\n get close() {\n return b[idx]!.close;\n },\n get volume() {\n return b[idx]!.volume ?? NaN;\n },\n get(src: Series, offset: number = 0): number {\n if (offset < 0) throw new RangeError(`c.get(): the offset cannot be negative (${offset} would read a future bar).`);\n let vals = cache.get(src);\n if (!vals) {\n vals = src.toArray();\n cache.set(src, vals);\n }\n const j = idx - offset;\n return j >= 0 && j < vals.length ? (vals[j] ?? NaN) : NaN;\n },\n prev(offset: number = 1): number {\n const j = idx - Math.max(1, offset);\n return j >= 0 ? out[j]! : NaN;\n },\n };\n try {\n for (idx = 0; idx < b.length; idx++) {\n currentBar = idx;\n const r = fn(ctx);\n out[idx] = typeof r === 'number' ? r : typeof r === 'boolean' ? (r ? 1 : 0) : NaN;\n }\n } finally {\n currentBar = -1;\n }\n return Series.fromArray(ctxBars, out);\n}\n\n/** Bar index of the running eachBar() callback, -1 outside eachBar(). */\nlet currentBar = -1;\n\n// \u2500\u2500 Strategy (declaration and strategy.* API; the host supplies the order engine) \u2500\u2500\n\n/** The strategy of the current run; throws when the script did not declare strategy(). */\nfunction strategyRun(caller: string): StrategyRun {\n const run = collector().strategy;\n if (!run) throw new Error(`${caller}: declare the script with strategy() first.`);\n return run;\n}\n\nfunction strategyEngine(caller: string): StrategyEngine {\n const run = strategyRun(caller);\n if (!run.engine) {\n throw new Error(\n `${caller}: no strategy engine; pass it as executeScript(body, bars, inputs, chart, { strategyEngine }).`\n );\n }\n return run.engine;\n}\n\n/** The engine for an order call: order calls run inside strategy.eachBar(), at a bar close. */\nfunction orderEngine(caller: string): StrategyEngine {\n const engine = strategyEngine(caller);\n if (!strategyRun(caller).inLoop) throw new Error(`${caller} must be called inside strategy.eachBar().`);\n return engine;\n}\n\n/** Options without na (NaN) numbers and undefined values: in PineScript an na argument means \"not given\". */\nfunction given<T extends object>(options: T): T {\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(options)) {\n if (value === undefined || (typeof value === 'number' && Number.isNaN(value))) continue;\n out[key] = value;\n }\n return out as T;\n}\n\n/** The engine for a `strategy.*` read: the values are per bar, so they are read inside strategy.eachBar(). */\nfunction readEngine(caller: string): StrategyEngine {\n const engine = strategyEngine(caller);\n if (!strategyRun(caller).inLoop) throw new Error(`${caller} must be read inside strategy.eachBar().`);\n return engine;\n}\n\n/** `strategy.*` variables that do not change from bar to bar, readable anywhere in the script. */\nconst STRATEGY_CONSTANT_VARIABLES: ReadonlySet<StrategyVariable> = new Set(['initial_capital', 'account_currency']);\n\nfunction strategyVariable(name: StrategyVariable): number | string {\n const caller = `strategy.${name}`;\n const engine = STRATEGY_CONSTANT_VARIABLES.has(name) ? strategyEngine(caller) : readEngine(caller);\n const value = engine.get(name);\n if (value === undefined) throw new Error(`strategy.${name} is not provided by the strategy engine.`);\n return value;\n}\n\nfunction riskRule(rule: StrategyRiskRule): void {\n const engine = strategyEngine(`strategy.risk.${rule.rule}()`);\n if (!engine.risk) throw new Error(`strategy.risk.${rule.rule}() is not provided by the strategy engine.`);\n engine.risk(rule);\n}\n\n/** PineScript `strategy()` declaration: script metadata and strategy properties. */\nfunction declareStrategy(title: string, options: StrategyOptions = {}): void {\n const c = collector();\n declare(c, 'strategy');\n c.title = title;\n c.shortTitle = options.shorttitle;\n c.overlay = options.overlay ?? false;\n c.precision = options.precision;\n c.format = options.format;\n setDrawingLimits({\n line: options.max_lines_count,\n label: options.max_labels_count,\n box: options.max_boxes_count,\n polyline: options.max_polylines_count,\n });\n const properties: StrategyProperties = { ...STRATEGY_DEFAULTS };\n const target = properties as unknown as Record<string, unknown>;\n for (const key of [...Object.keys(STRATEGY_DEFAULTS), 'currency']) {\n const value = (options as Record<string, unknown>)[key];\n if (value !== undefined) target[key] = value;\n }\n const factory = scriptOptions.strategyEngine;\n c.strategy = {\n properties,\n engine: factory?.({ properties, bars: ctxBars.bars, chart: chartCtx }),\n looped: false,\n inLoop: false,\n };\n}\n\n/**\n * Runs the strategy logic once per bar, in order, like {@link eachBar}. On each bar the engine first\n * fills the pending orders (`processBar`), then the callback runs at the bar close (order calls,\n * `strategy.*` variables), then `processClose` runs. A script has one strategy.eachBar() per run.\n * The callback's return values are collected into a Series, as with eachBar().\n */\nfunction strategyEachBar(fn: (c: BarContext) => number | boolean | void): Series {\n const run = strategyRun('strategy.eachBar()');\n const engine = strategyEngine('strategy.eachBar()');\n if (run.looped) throw new Error('strategy.eachBar() runs once per script run.');\n run.looped = true;\n return eachBar((c) => {\n engine.processBar(c.i);\n run.inLoop = true;\n try {\n return fn(c);\n } finally {\n run.inLoop = false;\n engine.processClose(c.i);\n }\n });\n}\n\n/** Numeric `strategy.*` variables, read from the engine (current bar inside strategy.eachBar()). */\nexport type StrategyNumberVariables = { readonly [K in StrategyNumberVariable]: number };\n/** Text `strategy.*` variables, read from the engine. */\nexport type StrategyTextVariables = { readonly [K in StrategyTextVariable]: string };\n\n/** PineScript `strategy`: the `strategy()` declaration and the `strategy.*` namespace. */\nexport type StrategyApi = ((title: string, options?: StrategyOptions) => void) &\n typeof STRATEGY_CONSTANTS &\n StrategyNumberVariables &\n StrategyTextVariables & {\n eachBar: typeof strategyEachBar;\n entry(id: string, direction: StrategyDirection, options?: StrategyEntryOptions): void;\n order(id: string, direction: StrategyDirection, options?: StrategyEntryOptions): void;\n exit(id: string, options?: StrategyExitOptions): void;\n close(id: string, options?: StrategyCloseOptions): void;\n close_all(options?: StrategyCloseAllOptions): void;\n cancel(id: string): void;\n cancel_all(): void;\n /** PineScript `strategy.opentrades.*(index)`: open trade `index` (0 = oldest), undefined when it does not exist. */\n opentrade(index: number): StrategyTrade | undefined;\n /** PineScript `strategy.closedtrades.*(index)`: closed trade `index` (0 = oldest), undefined when it does not exist. */\n closedtrade(index: number): StrategyTrade | undefined;\n default_entry_qty(fill_price: number): number;\n risk: {\n allow_entry_in(direction: StrategyRiskDirection): void;\n max_cons_loss_days(count: number, alert_message?: string): void;\n max_drawdown(value: number, type: StrategyRiskValueType, alert_message?: string): void;\n max_intraday_filled_orders(count: number, alert_message?: string): void;\n max_intraday_loss(value: number, type: StrategyRiskValueType, alert_message?: string): void;\n max_position_size(contracts: number): void;\n };\n };\n\nconst strategyMembers = {\n ...STRATEGY_CONSTANTS,\n eachBar: strategyEachBar,\n entry(id: string, direction: StrategyDirection, options: StrategyEntryOptions = {}): void {\n orderEngine('strategy.entry()').entry(id, direction, given(options));\n },\n order(id: string, direction: StrategyDirection, options: StrategyEntryOptions = {}): void {\n orderEngine('strategy.order()').order(id, direction, given(options));\n },\n exit(id: string, options: StrategyExitOptions = {}): void {\n orderEngine('strategy.exit()').exit(id, given(options));\n },\n close(id: string, options: StrategyCloseOptions = {}): void {\n orderEngine('strategy.close()').close(id, given(options));\n },\n close_all(options: StrategyCloseAllOptions = {}): void {\n orderEngine('strategy.close_all()').close_all(given(options));\n },\n cancel(id: string): void {\n orderEngine('strategy.cancel()').cancel(id);\n },\n cancel_all(): void {\n orderEngine('strategy.cancel_all()').cancel_all();\n },\n opentrade(index: number): StrategyTrade | undefined {\n return readEngine('strategy.opentrade()').openTrade(index);\n },\n closedtrade(index: number): StrategyTrade | undefined {\n return readEngine('strategy.closedtrade()').closedTrade(index);\n },\n default_entry_qty(fill_price: number): number {\n const engine = readEngine('strategy.default_entry_qty()');\n if (!engine.defaultEntryQty) throw new Error('strategy.default_entry_qty() is not provided by the strategy engine.');\n return engine.defaultEntryQty(fill_price);\n },\n risk: {\n allow_entry_in: (direction: StrategyRiskDirection) => riskRule({ rule: 'allow_entry_in', direction }),\n max_cons_loss_days: (count: number, alert_message?: string) =>\n riskRule(given({ rule: 'max_cons_loss_days' as const, count, alert_message })),\n max_drawdown: (value: number, type: StrategyRiskValueType, alert_message?: string) =>\n riskRule(given({ rule: 'max_drawdown' as const, value, type, alert_message })),\n max_intraday_filled_orders: (count: number, alert_message?: string) =>\n riskRule(given({ rule: 'max_intraday_filled_orders' as const, count, alert_message })),\n max_intraday_loss: (value: number, type: StrategyRiskValueType, alert_message?: string) =>\n riskRule(given({ rule: 'max_intraday_loss' as const, value, type, alert_message })),\n max_position_size: (contracts: number) => riskRule({ rule: 'max_position_size', contracts }),\n },\n};\n\nconst variableGetters: PropertyDescriptorMap = {};\nfor (const name of [...STRATEGY_NUMBER_VARIABLES, ...STRATEGY_TEXT_VARIABLES]) {\n variableGetters[name] = { get: () => strategyVariable(name), enumerable: true };\n}\n\n/**\n * PineScript `strategy`: call it to declare a strategy, and use its members as the `strategy.*` namespace.\n * OakScriptJS does not fill orders: the host passes an engine in `executeScript(..., { strategyEngine })`,\n * and the order calls and `strategy.*` variables are forwarded to it.\n *\n * ```typescript\n * strategy('MA Cross', { initial_capital: 10000, default_qty_type: strategy.percent_of_equity, default_qty_value: 100 });\n * const up = ta.crossover(ta.sma(close, 9), ta.sma(close, 21));\n * strategy.eachBar((c) => {\n * if (c.get(up) && strategy.position_size === 0) {\n * strategy.entry('L', strategy.long);\n * strategy.exit('X', { from_entry: 'L', stop: c.close * 0.95, limit: c.close * 1.15 });\n * }\n * });\n * ```\n */\nexport const strategy = Object.defineProperties(\n Object.assign((title: string, options?: StrategyOptions) => declareStrategy(title, options), strategyMembers),\n variableGetters\n) as StrategyApi;\n\n// \u2500\u2500 Chart context (issue #100) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * What the caller knows about the loaded bars. PineScript reads these values from the chart and\n * the symbol; nothing is fetched here. A script that needs a value the caller did not give throws.\n */\nexport interface ChartContext {\n /** Chart timeframe: \"5\", \"60\", \"1D\", \"1W\"... (PineScript `timeframe.period`) */\n timeframe?: string;\n /** Exchange time zone: \"America/New_York\", \"Etc/UTC\"... (PineScript `syminfo.timezone`) */\n timezone?: string;\n /** Session type of the bars (PineScript `syminfo.session`); default \"regular\" */\n sessionType?: 'regular' | 'extended';\n /**\n * Session of the loaded bars in the symbol session format: hours (\"0930-1600\", \"1700-1600\", \"24x7\"),\n * corrections (early closes, days off) and holidays. Needed by `time(tf)`, `time_close`,\n * `timeframe.change`, `time_tradingday`, `session.*` and the default anchor of `ta.vwap`.\n */\n session?: SessionSpec | string;\n /** Regular trading hours when the bars include extended hours (default: `session`); holidays default to `session`'s */\n regularSession?: SessionSpec | string;\n /** Chart symbol as PineScript `syminfo.tickerid` (e.g. \"NASDAQ:AAPL\"); needed by `request.security(syminfo.tickerid, ...)` */\n tickerid?: string;\n /** Unit of `Bar.time`: 's' (default, as lightweight-charts) or 'ms'. PineScript times are in ms. */\n timeUnit?: 's' | 'ms';\n /** Minimum price move of the symbol (PineScript `syminfo.mintick`), e.g. 0.01; used by `math.round_to_mintick` */\n mintick?: number;\n /** Currency value of one point of price move for one contract (PineScript `syminfo.pointvalue`); 1 for stocks */\n pointvalue?: number;\n /** Smallest tradable quantity (PineScript `syminfo.mincontract`); 1 for whole shares */\n mincontract?: number;\n /**\n * The last bar is closed (`barstate.isconfirmed` on the last bar). Default false: PineScript treats the last bar\n * of the data as not confirmed until the data feed closes it.\n */\n lastBarConfirmed?: boolean;\n /** The last bar receives live updates (`barstate.isrealtime`); default false (a calculation on history). */\n realtime?: boolean;\n /** On a realtime last bar: this run is the first update of the bar (`barstate.isnew`); default true. */\n lastBarNew?: boolean;\n}\n\nlet chartCtx: ChartContext = {};\n\nfunction chartTimeframe(): timeframeCore.TimeframeInfo {\n collector();\n if (!chartCtx.timeframe) {\n throw new Error('The chart timeframe is not known: pass it as executeScript(body, bars, inputs, { timeframe }).');\n }\n return timeframeCore.info(chartCtx.timeframe);\n}\n\nfunction exchangeTimezone(): string {\n collector();\n if (!chartCtx.timezone) {\n throw new Error('The exchange time zone is not known: pass it as executeScript(body, bars, inputs, { timezone }).');\n }\n return chartCtx.timezone;\n}\n\n/**\n * PineScript `timeframe.*`: the chart timeframe variables (from the chart context), and\n * `in_seconds(timeframe?)`, `from_seconds(seconds)`.\n */\nexport const timeframe = {\n ...timeframeCore,\n get period(): string {\n return chartTimeframe().period;\n },\n get main_period(): string {\n return chartTimeframe().period;\n },\n get multiplier(): number {\n return chartTimeframe().multiplier;\n },\n get isintraday(): boolean {\n return chartTimeframe().isintraday;\n },\n get isdaily(): boolean {\n return chartTimeframe().isdaily;\n },\n get isweekly(): boolean {\n return chartTimeframe().isweekly;\n },\n get ismonthly(): boolean {\n return chartTimeframe().ismonthly;\n },\n get isminutes(): boolean {\n return chartTimeframe().isminutes;\n },\n get isseconds(): boolean {\n return chartTimeframe().isseconds;\n },\n get isticks(): boolean {\n return chartTimeframe().isticks;\n },\n get isdwm(): boolean {\n return chartTimeframe().isdwm;\n },\n /** PineScript `timeframe.change(tf)`: 1 on bars that open a new `tf` period (0 on the first bar). */\n change(tf: string): Series {\n return changeOf(tf || chartTimeframe().period);\n },\n /** Seconds in `timeframe`; without it (or with \"\") the chart timeframe, as in PineScript. */\n in_seconds(tf?: string): number {\n return timeframeCore.in_seconds(tf === undefined || tf === '' ? chartTimeframe().period : tf);\n },\n};\n\n/** A symbol property that the host passes in the chart context. */\nfunction symbolProperty(key: 'mintick' | 'pointvalue' | 'mincontract'): number {\n collector();\n const value = chartCtx[key];\n if (value === undefined) {\n throw new Error(`syminfo.${key} is not known: pass it as executeScript(body, bars, inputs, { ${key} }).`);\n }\n return value;\n}\n\n/**\n * PineScript `syminfo.timezone`, `syminfo.tickerid`, `syminfo.session` (session type), `syminfo.mintick`,\n * `syminfo.pointvalue` and `syminfo.mincontract`, from the chart context.\n */\nexport const syminfo = {\n get mintick(): number {\n return symbolProperty('mintick');\n },\n get pointvalue(): number {\n return symbolProperty('pointvalue');\n },\n get mincontract(): number {\n return symbolProperty('mincontract');\n },\n get timezone(): string {\n return exchangeTimezone();\n },\n get tickerid(): string {\n collector();\n if (!chartCtx.tickerid) {\n throw new Error('The chart symbol is not known: pass it as executeScript(body, bars, inputs, { tickerid }).');\n }\n return chartCtx.tickerid;\n },\n get session(): string {\n collector();\n return chartCtx.sessionType ?? 'regular';\n },\n};\n\n/** A calendar function: `(time, timezone?)` on a UNIX time or on a Series of times. */\ninterface CalendarFunction {\n (time: number, timezone?: string): number;\n (time: Series, timezone?: string): Series;\n}\n\nfunction calendar(fn: (time: number, timezone: string) => number): CalendarFunction {\n return ((time: number | Series, timezone?: string) => {\n const tz = timezone ?? exchangeTimezone();\n return time instanceof Series ? Series.fromArray(ctxBars, time.toArray().map((t) => fn(t, tz))) : fn(time, tz);\n }) as CalendarFunction;\n}\n\n/** PineScript `year(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const year = calendar(timeCore.year);\n/** PineScript `month(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const month = calendar(timeCore.month);\n/** PineScript `weekofyear(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const weekofyear = calendar(timeCore.weekofyear);\n/** PineScript `dayofmonth(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const dayofmonth = calendar(timeCore.dayofmonth);\n/** PineScript `dayofweek(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const dayofweek = calendar(timeCore.dayofweek);\n/** PineScript `hour(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const hour = calendar(timeCore.hour);\n/** PineScript `minute(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const minute = calendar(timeCore.minute);\n/** PineScript `second(time, timezone?)`; the default time zone is the exchange time zone. */\nexport const second = calendar(timeCore.second);\n\n/**\n * PineScript `timestamp`: date string (GMT+0 by default), `(timezone, year, month, day, ...)`, or\n * `(year, month, day, ...)` in the exchange time zone.\n */\nexport function timestamp(dateString: string): number;\nexport function timestamp(\n timezone: string,\n year: number,\n month: number,\n day: number,\n hour?: number,\n minute?: number,\n second?: number\n): number;\nexport function timestamp(year: number, month: number, day: number, hour?: number, minute?: number, second?: number): number;\nexport function timestamp(first: string | number, ...rest: Array<number | undefined>): number {\n if (typeof first === 'number') {\n const [m, d, h, mi, s] = rest as [number, number, number?, number?, number?];\n return timeCore.timestamp(exchangeTimezone(), first, m, d, h, mi, s);\n }\n if (rest.length === 0) return timeCore.timestamp(first);\n const [y, m, d, h, mi, s] = rest as [number, number, number, number?, number?, number?];\n return timeCore.timestamp(first, y, m, d, h, mi, s);\n}\n\n/** Session test of PineScript `time(timeframe, session, timezone)`; the default time zone is the exchange time zone. */\nexport function inSession(time: number, session: string, timezone?: string): boolean {\n return timeCore.inSession(time, session, timezone ?? exchangeTimezone());\n}\n\n/** PineScript `str.*`; `format_time` and the dates of `format` use the exchange time zone by default. */\nexport const str = {\n ...strCore,\n format_time(time: number, format: string = \"yyyy-MM-dd'T'HH:mm:ssZ\", timezone?: string): string {\n return strCore.format_time(time, format, timezone ?? exchangeTimezone());\n },\n format(pattern: string, ...args: unknown[]): string {\n return formatMessage(pattern, args, exchangeTimezone);\n },\n};\n\n// \u2500\u2500 Session values (issue #100) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** Bar time in ms (PineScript `time`). */\nfunction barTime(bar: Bar): number {\n return (bar.time as number) * (chartCtx.timeUnit === 'ms' ? 1 : 1000);\n}\n\nconst toSpec = (s: SessionSpec | string): SessionSpec => (typeof s === 'string' ? { session: s } : s);\n\nlet sessionCache: { ctx: ChartContext; bars: SessionBars; regular: SessionBars } | null = null;\n\n/** Session calendars of the run (loaded bars and regular hours), built from the chart context. */\nfunction sessionBars(): { bars: SessionBars; regular: SessionBars } {\n const tz = exchangeTimezone();\n const tf = chartTimeframe().period;\n if (!chartCtx.session) {\n throw new Error('The session is not known: pass it as executeScript(body, bars, inputs, { session }).');\n }\n if (sessionCache?.ctx !== chartCtx) {\n const loaded = toSpec(chartCtx.session);\n const regular = chartCtx.regularSession ? toSpec(chartCtx.regularSession) : loaded;\n sessionCache = {\n ctx: chartCtx,\n bars: new SessionBars(new TradingCalendar(tz, loaded), tf),\n regular: new SessionBars(new TradingCalendar(tz, { holidays: loaded.holidays, ...regular }), tf),\n };\n }\n return sessionCache;\n}\n\n/**\n * Calendar for `time(tf, session, timezone)` arguments. Without session and time zone: the loaded\n * session. As in PineScript, an explicit time zone reads the symbol session hours in that zone without\n * corrections and holidays, and an explicit session follows PineScript's session string rules.\n */\nfunction calendarFor(session?: string, timezone?: string): { bars: SessionBars; test: boolean } {\n const { bars } = sessionBars();\n if (!session && !timezone) return { bars, test: false };\n const tz = timezone ?? exchangeTimezone();\n const spec = session ? { session } : { session: toSpec(chartCtx.session!).session };\n return { bars: new SessionBars(new TradingCalendar(tz, spec, session ? 'pine' : 'symbol'), bars.chart.period), test: true };\n}\n\nfunction perBar(fn: (t: number, i: number, times: number[]) => number): Series {\n const times = ctxBars.bars.map(barTime);\n return Series.fromArray(ctxBars, times.map((t, i) => fn(t, i, times)));\n}\n\n/** A Series that can also be called, like PineScript's `time` (variable) and `time(...)` (function). */\nfunction callableSeries<F extends (...args: never[]) => Series>(series: Series, fn: F): Series & F {\n Object.setPrototypeOf(fn, Series.prototype);\n Object.assign(fn, series);\n return fn as Series & F;\n}\n\nfunction timeFunction(tf?: string, session?: string, timezone?: string): Series {\n collector();\n const { bars, test } = calendarFor(session, timezone);\n const timeframeString = tf || chartTimeframe().period;\n return perBar((t) => (test && !bars.inside(t) ? NaN : bars.timeOf(t, timeframeString)));\n}\n\nfunction timeCloseFunction(tf?: string, session?: string, timezone?: string): Series {\n collector();\n const { bars, test } = calendarFor(session, timezone);\n const timeframeString = tf || chartTimeframe().period;\n return perBar((t) => (test && !bars.inside(t) ? NaN : bars.closeOf(t, timeframeString)));\n}\n\n/**\n * PineScript `time`: the bar open time in ms (a Series), and `time(timeframe?, session?, timezone?)`:\n * the open time of the `timeframe` period that contains the bar, `na` outside `session`.\n */\nexport const time = callableSeries(new Series(ctxBars, (b) => barTime(b)), timeFunction);\n\n/**\n * PineScript `time_close`: the bar close time in ms (a Series), and `time_close(timeframe?, session?, timezone?)`.\n * Needs the chart timeframe and session.\n */\nexport const time_close = callableSeries(\n new Series(ctxBars, (_b, i) => sessionBars().bars.closeOf(barTime(ctxBars.bars[i]!), chartTimeframe().period)),\n timeCloseFunction\n);\n\n/** PineScript `time_tradingday`: 00:00 UTC of the trading day of each bar, in ms. */\nexport const time_tradingday = new Series(ctxBars, (b) => sessionBars().bars.tradingDayTime(barTime(b)));\n\nfunction changeOf(tf: string): Series {\n const { bars } = sessionBars();\n return perBar((t, i, times) => (i > 0 && bars.timeOf(t, tf) !== bars.timeOf(times[i - 1]!, tf) ? 1 : 0));\n}\n\nfunction flag(key: keyof SessionFlags): Series {\n const { bars, regular } = sessionBars();\n const values = sessionFlags(ctxBars.bars.map(barTime), bars, regular)[key];\n return Series.fromArray(ctxBars, values.map((v) => (v ? 1 : 0)));\n}\n\n/** A 1 / 0 Series from a per-bar test on the bar index and the number of bars. */\nfunction barFlag(test: (i: number, n: number) => boolean): Series {\n const n = ctxBars.bars.length;\n return Series.fromArray(ctxBars, Array.from({ length: n }, (_, i) => (test(i, n) ? 1 : 0)));\n}\n\nconst lastRealtime = (i: number, n: number): boolean => i === n - 1 && chartCtx.realtime === true;\n\n/**\n * PineScript `barstate.*` (1 / 0 per bar). All bars but the last are confirmed history bars. The last bar is\n * confirmed only when the host says so (`ChartContext.lastBarConfirmed`, e.g. the closing update of a realtime\n * bar), and is a realtime bar only when it receives live updates (`ChartContext.realtime`); without live updates\n * it is a history bar, as in PineScript.\n * `islastconfirmedhistory` is the last bar when it is confirmed and not realtime, else the bar before it.\n */\nexport const barstate = {\n get isfirst(): Series { return barFlag((i) => i === 0); },\n get islast(): Series { return barFlag((i, n) => i === n - 1); },\n get isconfirmed(): Series { return barFlag((i, n) => i < n - 1 || chartCtx.lastBarConfirmed === true); },\n get isrealtime(): Series { return barFlag(lastRealtime); },\n get ishistory(): Series { return barFlag((i, n) => !lastRealtime(i, n)); },\n get isnew(): Series { return barFlag((i, n) => !lastRealtime(i, n) || chartCtx.lastBarNew !== false); },\n get islastconfirmedhistory(): Series {\n return barFlag((i, n) => {\n const lastConfirmed = chartCtx.lastBarConfirmed === true && chartCtx.realtime !== true;\n return i === (lastConfirmed ? n - 1 : n - 2);\n });\n },\n};\n\n/**\n * PineScript `session.*` (1 / 0 per bar) and the constants `session.regular` / `session.extended`.\n * First and last bars are per session period; market / pre / post market use the regular hours.\n */\nexport const session = {\n regular: 'regular',\n extended: 'extended',\n get isfirstbar(): Series { return flag('isfirstbar'); },\n get islastbar(): Series { return flag('islastbar'); },\n get ismarket(): Series { return flag('ismarket'); },\n get ispremarket(): Series { return flag('ispremarket'); },\n get ispostmarket(): Series { return flag('ispostmarket'); },\n get isfirstbar_regular(): Series { return flag('isfirstbar_regular'); },\n get islastbar_regular(): Series { return flag('islastbar_regular'); },\n};\n\n// \u2500\u2500 request.security (issue #101) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** PineScript `barmerge.*` constants of `request.security`. */\nexport const barmerge = {\n gaps_on: 'gaps_on',\n gaps_off: 'gaps_off',\n lookahead_on: 'lookahead_on',\n lookahead_off: 'lookahead_off',\n} as const;\n\nconst HEIKIN_ASHI = 'heikinashi:';\n\n/** PineScript `ticker.heikinashi(symbol)` / `ticker.standard(symbol)` for the chart symbol. */\nexport const ticker = {\n heikinashi(symbol: string): string {\n return HEIKIN_ASHI + symbol;\n },\n standard(symbol: string): string {\n return symbol.startsWith(HEIKIN_ASHI) ? symbol.slice(HEIKIN_ASHI.length) : symbol;\n },\n};\n\n/** What an expression of `request.security` may return. */\nexport type SecurityValue = Series | number | boolean | Array<Series | number | boolean>;\n\nfunction valuesOf(value: Series | number | boolean, length: number): number[] {\n if (!(value instanceof Series)) return new Array<number>(length).fill(Number(value));\n if (value.bars !== ctxBars.bars) {\n throw new Error(\n 'request.security(): the expression returned a series computed on the chart bars. ' +\n 'Compute the series inside the expression, e.g. () => ta.ema(close, 10).'\n );\n }\n return value.toArray().slice();\n}\n\n/**\n * PineScript `request.security` for the chart symbol (`syminfo.tickerid`, `\"\"`, `ticker.heikinashi(...)`,\n * `ticker.standard(...)`) and a timeframe equal to or higher than the chart's. The higher-timeframe bars are\n * built by grouping the chart bars, and `expression` runs on them (its `ta.*` calls, tuples and `timeframe.*`\n * see the higher timeframe). Other symbols need external data and throw; a lower timeframe throws.\n *\n * PineScript rules: lookahead off shows a period's value from the\n * bar that completes it; lookahead on from its first bar; gaps on keeps only the bar where the value appears.\n * Built bars can differ from the exchange's bars (official open / close, volume).\n */\nfunction security<T extends SecurityValue>(\n symbol: string,\n timeframe: string,\n expression: () => T,\n gaps: string = barmerge.gaps_off,\n lookahead: string = barmerge.lookahead_off\n): T extends unknown[] ? Series[] : Series {\n collector();\n const heikin = symbol.startsWith(HEIKIN_ASHI);\n const base = heikin ? symbol.slice(HEIKIN_ASHI.length) : symbol;\n if (base !== '' && base !== chartCtx.tickerid) {\n throw new Error(`request.security: \"${symbol}\" is not the chart symbol; other symbols need external data.`);\n }\n const chart = chartTimeframe();\n const tf = timeframeCore.info(timeframe || chart.period).period;\n if (timeframeCore.in_seconds(tf) < timeframeCore.in_seconds(chart.period)) {\n throw new Error(`request.security: timeframe \"${tf}\" is lower than the chart timeframe \"${chart.period}\".`);\n }\n\n const chartBars = ctxBars.bars;\n const times = chartBars.map(barTime);\n let htf: Bar[];\n let group: number[];\n let latest: number[];\n if (tf === chart.period) {\n htf = chartBars;\n group = chartBars.map((_, i) => i);\n latest = group;\n } else {\n const { bars: loaded, regular } = sessionBars();\n // D / W / M periods follow the regular hours; intraday periods the loaded session\n const calendar = timeframeCore.info(tf).isdwm ? regular : loaded;\n const starts = times.map((t) => calendar.timeOf(t, tf));\n const dayPeriods = times.map((t, i) => {\n const at = loaded.calendar.locate(t);\n const periods = at ? calendar.calendar.periods(at.date) : [];\n return periods.length ? calendar.timeOf(periods[0]![0], tf) : starts[i]!;\n });\n const reaches = times.map((t) => loaded.closeOf(t, chart.period) >= calendar.periodEnd(t, tf));\n ({ group, latest } = periodsOf(starts, dayPeriods, reaches));\n const unit = chartCtx.timeUnit === 'ms' ? 1 : 1000;\n // a higher-timeframe bar ends at the bar that completes it (no value from after the completion)\n const after = afterCompletion(group, latest);\n const kept = (_: unknown, i: number): boolean => !after[i];\n htf = resample(chartBars.filter(kept), starts.map((s) => s / unit).filter(kept)).bars;\n }\n if (heikin) htf = heikinAshi(htf);\n\n const savedCtx = chartCtx;\n let result: T;\n let values: number[][];\n ctxBars.setAll(htf);\n chartCtx = { ...chartCtx, timeframe: tf };\n try {\n result = expression();\n const parts = Array.isArray(result) ? result : [result];\n values = parts.map((p) => valuesOf(p, htf.length));\n } finally {\n ctxBars.setAll(chartBars);\n chartCtx = savedCtx;\n }\n const mapped = values.map((v) =>\n Series.fromArray(ctxBars, mapToChart(v, group, latest, lookahead === barmerge.lookahead_on, gaps === barmerge.gaps_on))\n );\n return (Array.isArray(result) ? mapped : mapped[0]) as T extends unknown[] ? Series[] : Series;\n}\n\n/** PineScript `request.*`: `security` for the chart symbol (issue #101). */\nexport const request = { security };\n\n// \u2500\u2500 Drawing objects \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n// The drawing namespaces come from this bundle so that they share the registry that\n// executeScript() resets. `line.all` etc. are read like PineScript variables.\n\n/** PineScript `line.*`; `line.all` lists the live lines in creation order. */\nexport const line = {\n ...lineCore,\n get all() {\n return lineCore.all();\n },\n};\n\n/** PineScript `label.*`; `label.all` lists the live labels in creation order. */\nexport const label = {\n ...labelCore,\n get all() {\n return labelCore.all();\n },\n};\n\n/** PineScript `box.*`; `box.all` lists the live boxes in creation order. */\nexport const box = {\n ...boxCore,\n get all() {\n return boxCore.all();\n },\n};\n\n/** PineScript `linefill.*`; `linefill.all` lists the live linefills in creation order. */\nexport const linefill = {\n ...linefillCore,\n get all() {\n return linefillCore.all();\n },\n};\n\n/** PineScript `polyline.*`; `polyline.all` lists the live polylines in creation order. */\nexport const polyline = {\n ...polylineCore,\n get all() {\n return polylineCore.all();\n },\n};\n\n/** PineScript `text.format_*` constants. */\nexport const text = { ...textCore };\n\n/**\n * PineScript `chart.point.*`. `chart.point.now(price?)` is the point of the current bar\n * (index, time, and `price`, default the close), so it runs inside eachBar().\n */\nexport const chart = {\n point: {\n ...chartPointCore,\n now(price?: number): ChartPoint {\n collector();\n if (currentBar < 0) {\n throw new Error('chart.point.now() needs a current bar: call it inside eachBar().');\n }\n const bar = ctxBars.bars[currentBar]!;\n return chartPointCore.new_point(barTime(bar), currentBar, price ?? bar.close);\n },\n },\n};\n\n/** Wraps a plain value array (e.g. a side output accumulated inside eachBar)\n * into a Series aligned with the current bars. */\nexport function seriesOf(values: number[]): Series {\n collector();\n return Series.fromArray(ctxBars, values);\n}\n\n/** PineScript `alertcondition()` \u2014 collected for the host's alert engine. */\nexport function alertcondition(condition: Series, title: string, message?: string): void {\n const c = collector();\n const id = `alert${c.alertConfig.length}`;\n c.alertConfig.push({ id, title, message });\n const last = condition.length() ? condition.last() : NaN;\n c.alerts.push({ id, title, message, triggered: !isNA(last) && last !== 0 });\n}\n\n// \u2500\u2500 Convenience re-exports \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport { Series, BarData, isNA as na, nz };\nexport { STRATEGY_DEFAULTS } from '../strategy/index.js';\nexport type {\n StrategyCloseAllOptions,\n StrategyCloseOptions,\n StrategyCommissionType,\n StrategyDirection,\n StrategyEngine,\n StrategyEntryOptions,\n StrategyExitOptions,\n StrategyNumberVariable,\n StrategyOcaType,\n StrategyOptions,\n StrategyProperties,\n StrategyQtyType,\n StrategyRiskDirection,\n StrategyRiskRule,\n StrategyRiskValueType,\n StrategyTextVariable,\n StrategyTrade,\n StrategyVariable,\n} from '../strategy/index.js';\n\n/** PineScript `math.*`; `math.round_to_mintick(x)` uses `syminfo.mintick` of the chart context. */\nexport const math = {\n ...mathCore,\n round_to_mintick: ((number: number | Series, mintick?: number) => {\n const tick = mintick ?? syminfo.mintick;\n return number instanceof Series ? mathCore.round_to_mintick(number, tick) : mathCore.round_to_mintick(number, tick);\n }) as typeof mathCore.round_to_mintick,\n};\nexport * as compare from '../compare/index.js';\nexport type {\n Bar,\n IndicatorResult,\n TimeValue,\n InputConfig,\n PlotConfig,\n HLineConfig,\n FillConfig,\n ShapeConfig,\n ArrowConfig,\n BarColorConfig,\n MarkerData,\n ArrowData,\n BarColorData,\n MarkerLocation,\n MarkerSize,\n ShapeStyle,\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyDA,oBAAgC;AAChC,eAA0B;AAC1B,gBAA2B;AAC3B,mBAAiD;AACjD,eAA0B;AAC1B,gBAA2B;AAC3B,cAAyB;AACzB,mBAA8B;AAC9B,mBAA8B;AAC9B,qBAAgC;AAChC,eAA0B;AAC1B,eAA0B;AAC1B,sBAAgD;AAChD,oBAA+B;AAC/B,eAA0B;AAC1B,cAAyB;AACzB,2BAA8B;AAC9B,sBAAkD;AAClD,kBAA6D;AAC7D,sBAA6E;AAE7E,sBAoBO;AAsrDP,I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a,GAAG;AAClB,cAAM,IAAI,MAAM,kEAAkE;AAAA,MACpF;AACA,YAAM,MAAM,QAAQ,KAAK,UAAU;AACnC,aAAO,eAAe,UAAU,QAAQ,GAAG,GAAG,YAAY,SAAS,IAAI,KAAK;AAAA,IAC9E;AAAA,EACF;AACF;AAIO,SAAS,SAAS,QAA0B;AACjD,YAAU;AACV,SAAO,qBAAO,UAAU,SAAS,MAAM;AACzC;AAGO,SAAS,eAAe,WAAmB,OAAe,SAAwB;AACvF,QAAM,IAAI,UAAU;AACpB,QAAM,KAAK,QAAQ,EAAE,YAAY,MAAM;AACvC,IAAE,YAAY,KAAK,EAAE,IAAI,OAAO,QAAQ,CAAC;AACzC,QAAM,OAAO,UAAU,OAAO,IAAI,UAAU,KAAK,IAAI;AACrD,IAAE,OAAO,KAAK,EAAE,IAAI,OAAO,SAAS,WAAW,KAAC,mBAAK,IAAI,KAAK,SAAS,EAAE,CAAC;AAC5E;AA4BO,MAAM,OAAO;AAAA,EAClB,GAAG;AAAA,EACH,mBAAmB,CAAC,QAAyB,YAAqB;AAChE,UAAM,OAAO,WAAW,QAAQ;AAChC,WAAO,kBAAkB,uBAAS,SAAS,iBAAiB,QAAQ,IAAI,IAAI,SAAS,iBAAiB,QAAQ,IAAI;AAAA,EACpH;AACF;",
6
+ "names": ["import_strategy", "chart", "fixnanValues", "perBar", "color", "ctx", "time", "m", "d", "h", "mi", "s", "session", "bars", "timeframe", "calendar"]
7
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Same-symbol `request.security` by resampling the chart bars (issue #101).
3
+ * PineScript rules:
4
+ *
5
+ * - `lookahead_off` (default): the value of a higher-timeframe period appears on the chart bar that
6
+ * completes the period; before that, the chart bars show the previous period's value
7
+ * - `lookahead_on`: every chart bar of a period shows the value of that period
8
+ * - `gaps_on`: only the bar where the value appears has it (the completing bar with lookahead off, the
9
+ * first bar of the period with lookahead on); the other bars are `na`
10
+ * - a bar completes its period only if it closes at or after the end of the period (a period still
11
+ * trading keeps showing the previous completed value); when the bars at the end of a period are missing
12
+ * (data gap, a day off not in the calendar), the period completes on the first bar of the next period
13
+ * - D / W / M periods follow the regular hours: on extended-hours charts the premarket bars still show
14
+ * the previous period, which completes on the last bar of its trading day
15
+ * - a higher-timeframe bar only holds the chart bars up to the bar that completes it: the premarket bars
16
+ * that still show the previous period are not part of its bar (no value from after the completion)
17
+ */
18
+ import type { Bar } from '../types/index.js';
19
+ /** Higher-timeframe bars and the period index of each chart bar. */
20
+ export interface Resampled {
21
+ bars: Bar[];
22
+ /** Index in `bars` of the period of each chart bar */
23
+ group: number[];
24
+ }
25
+ /**
26
+ * Groups consecutive chart bars with the same period start into higher-timeframe bars.
27
+ * @param bars - Chart bars (in order)
28
+ * @param periodStart - Period start of each chart bar, in the unit of `Bar.time`
29
+ */
30
+ export declare function resample(bars: Bar[], periodStart: number[]): Resampled;
31
+ /**
32
+ * Period index of each chart bar, and the latest completed period at each chart bar.
33
+ * @param starts - Period start of each chart bar (the higher-timeframe bar it belongs to)
34
+ * @param dayPeriods - Period of the trading day of each chart bar in the loaded session: on extended-hours
35
+ * charts the premarket bars still belong to the previous daily period, but a new trading day completes it
36
+ * @param reaches - True when the chart bar closes at or after the end of its period
37
+ */
38
+ export declare function periodsOf(starts: number[], dayPeriods: number[], reaches: boolean[]): {
39
+ group: number[];
40
+ latest: number[];
41
+ };
42
+ /**
43
+ * True for the chart bars that come after the bar that completed their period: on extended-hours charts
44
+ * the premarket bars of the next trading day still show the previous D / W / M period, but they are not
45
+ * part of its higher-timeframe bar. A period's first bar is never after its completion.
46
+ * @param group - Period index of each chart bar
47
+ * @param latest - Latest completed period at each chart bar
48
+ */
49
+ export declare function afterCompletion(group: number[], latest: number[]): boolean[];
50
+ /**
51
+ * Maps values computed on the higher-timeframe bars to the chart bars.
52
+ * @param values - One value per higher-timeframe bar
53
+ * @param group - Period index of each chart bar
54
+ * @param latest - Latest completed period at each chart bar (-1: none yet)
55
+ */
56
+ export declare function mapToChart(values: number[], group: number[], latest: number[], lookahead: boolean, gaps: boolean): number[];
57
+ /**
58
+ * Heikin Ashi bars (PineScript `ticker.heikinashi`): close = (open + high + low + close) / 4, open = the
59
+ * average of the previous Heikin Ashi open and close ((open + close) / 2 on the first bar),
60
+ * high / low = the extremes of high / low and the Heikin Ashi open and close.
61
+ */
62
+ export declare function heikinAshi(bars: Bar[]): Bar[];
63
+ //# sourceMappingURL=resample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resample.d.ts","sourceRoot":"","sources":["../../../src/security/resample.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,oEAAoE;AACpE,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,sDAAsD;IACtD,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,SAAS,CAiBtE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAe3H;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAE5E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAU3H;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAS7C"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var resample_exports = {};
20
+ __export(resample_exports, {
21
+ afterCompletion: () => afterCompletion,
22
+ heikinAshi: () => heikinAshi,
23
+ mapToChart: () => mapToChart,
24
+ periodsOf: () => periodsOf,
25
+ resample: () => resample
26
+ });
27
+ module.exports = __toCommonJS(resample_exports);
28
+ function resample(bars, periodStart) {
29
+ const out = [];
30
+ const group = [];
31
+ bars.forEach((b, i) => {
32
+ const start = periodStart[i];
33
+ const last = out[out.length - 1];
34
+ if (!last || last.time !== start) {
35
+ out.push({ time: start, open: b.open, high: b.high, low: b.low, close: b.close, volume: b.volume ?? NaN });
36
+ } else {
37
+ last.high = Math.max(last.high, b.high);
38
+ last.low = Math.min(last.low, b.low);
39
+ last.close = b.close;
40
+ last.volume = (last.volume ?? 0) + (b.volume ?? NaN);
41
+ }
42
+ group.push(out.length - 1);
43
+ });
44
+ return { bars: out, group };
45
+ }
46
+ function periodsOf(starts, dayPeriods, reaches) {
47
+ const n = starts.length;
48
+ const group = [];
49
+ starts.forEach((s, i) => group.push(i === 0 ? 0 : group[i - 1] + (s !== starts[i - 1] ? 1 : 0)));
50
+ const latest = [];
51
+ starts.forEach((s, i) => {
52
+ let done = i === 0 ? -1 : latest[i - 1];
53
+ if (i > 0 && group[i] !== group[i - 1]) done = Math.max(done, group[i] - 1);
54
+ const ends = i < n - 1 ? starts[i + 1] !== s || dayPeriods[i + 1] !== dayPeriods[i] : true;
55
+ if (ends && reaches[i]) done = Math.max(done, group[i]);
56
+ latest.push(done);
57
+ });
58
+ return { group, latest };
59
+ }
60
+ function afterCompletion(group, latest) {
61
+ return group.map((g, i) => i > 0 && group[i - 1] === g && latest[i - 1] >= g);
62
+ }
63
+ function mapToChart(values, group, latest, lookahead, gaps) {
64
+ return group.map((g, i) => {
65
+ if (lookahead) {
66
+ const first = i === 0 || group[i - 1] !== g;
67
+ return gaps && !first ? NaN : values[g] ?? NaN;
68
+ }
69
+ const done = latest[i];
70
+ if (done < 0 || gaps && i > 0 && latest[i - 1] === done) return NaN;
71
+ return values[done] ?? NaN;
72
+ });
73
+ }
74
+ function heikinAshi(bars) {
75
+ const out = [];
76
+ bars.forEach((b, i) => {
77
+ const close = (b.open + b.high + b.low + b.close) / 4;
78
+ const prev = out[i - 1];
79
+ const open = prev ? (prev.open + prev.close) / 2 : (b.open + b.close) / 2;
80
+ out.push({ time: b.time, open, high: Math.max(b.high, open, close), low: Math.min(b.low, open, close), close, volume: b.volume });
81
+ });
82
+ return out;
83
+ }
84
+ //# sourceMappingURL=resample.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/security/resample.ts"],
4
+ "sourcesContent": ["/**\n * Same-symbol `request.security` by resampling the chart bars (issue #101).\n * PineScript rules:\n *\n * - `lookahead_off` (default): the value of a higher-timeframe period appears on the chart bar that\n * completes the period; before that, the chart bars show the previous period's value\n * - `lookahead_on`: every chart bar of a period shows the value of that period\n * - `gaps_on`: only the bar where the value appears has it (the completing bar with lookahead off, the\n * first bar of the period with lookahead on); the other bars are `na`\n * - a bar completes its period only if it closes at or after the end of the period (a period still\n * trading keeps showing the previous completed value); when the bars at the end of a period are missing\n * (data gap, a day off not in the calendar), the period completes on the first bar of the next period\n * - D / W / M periods follow the regular hours: on extended-hours charts the premarket bars still show\n * the previous period, which completes on the last bar of its trading day\n * - a higher-timeframe bar only holds the chart bars up to the bar that completes it: the premarket bars\n * that still show the previous period are not part of its bar (no value from after the completion)\n */\n\nimport type { Bar } from '../types/index.js';\n\n/** Higher-timeframe bars and the period index of each chart bar. */\nexport interface Resampled {\n bars: Bar[];\n /** Index in `bars` of the period of each chart bar */\n group: number[];\n}\n\n/**\n * Groups consecutive chart bars with the same period start into higher-timeframe bars.\n * @param bars - Chart bars (in order)\n * @param periodStart - Period start of each chart bar, in the unit of `Bar.time`\n */\nexport function resample(bars: Bar[], periodStart: number[]): Resampled {\n const out: Bar[] = [];\n const group: number[] = [];\n bars.forEach((b, i) => {\n const start = periodStart[i]!;\n const last = out[out.length - 1];\n if (!last || last.time !== start) {\n out.push({ time: start, open: b.open, high: b.high, low: b.low, close: b.close, volume: b.volume ?? NaN });\n } else {\n last.high = Math.max(last.high, b.high);\n last.low = Math.min(last.low, b.low);\n last.close = b.close;\n last.volume = (last.volume ?? 0) + (b.volume ?? NaN);\n }\n group.push(out.length - 1);\n });\n return { bars: out, group };\n}\n\n/**\n * Period index of each chart bar, and the latest completed period at each chart bar.\n * @param starts - Period start of each chart bar (the higher-timeframe bar it belongs to)\n * @param dayPeriods - Period of the trading day of each chart bar in the loaded session: on extended-hours\n * charts the premarket bars still belong to the previous daily period, but a new trading day completes it\n * @param reaches - True when the chart bar closes at or after the end of its period\n */\nexport function periodsOf(starts: number[], dayPeriods: number[], reaches: boolean[]): { group: number[]; latest: number[] } {\n const n = starts.length;\n const group: number[] = [];\n starts.forEach((s, i) => group.push(i === 0 ? 0 : group[i - 1]! + (s !== starts[i - 1] ? 1 : 0)));\n const latest: number[] = [];\n starts.forEach((s, i) => {\n let done = i === 0 ? -1 : latest[i - 1]!;\n // a new period completes all the earlier ones (their last bars may be missing)\n if (i > 0 && group[i] !== group[i - 1]) done = Math.max(done, group[i]! - 1);\n // the last bar of its period in the loaded session (the premarket bars after it do not complete it again)\n const ends = i < n - 1 ? starts[i + 1] !== s || dayPeriods[i + 1] !== dayPeriods[i] : true;\n if (ends && reaches[i]) done = Math.max(done, group[i]!);\n latest.push(done);\n });\n return { group, latest };\n}\n\n/**\n * True for the chart bars that come after the bar that completed their period: on extended-hours charts\n * the premarket bars of the next trading day still show the previous D / W / M period, but they are not\n * part of its higher-timeframe bar. A period's first bar is never after its completion.\n * @param group - Period index of each chart bar\n * @param latest - Latest completed period at each chart bar\n */\nexport function afterCompletion(group: number[], latest: number[]): boolean[] {\n return group.map((g, i) => i > 0 && group[i - 1] === g && latest[i - 1]! >= g);\n}\n\n/**\n * Maps values computed on the higher-timeframe bars to the chart bars.\n * @param values - One value per higher-timeframe bar\n * @param group - Period index of each chart bar\n * @param latest - Latest completed period at each chart bar (-1: none yet)\n */\nexport function mapToChart(values: number[], group: number[], latest: number[], lookahead: boolean, gaps: boolean): number[] {\n return group.map((g, i) => {\n if (lookahead) {\n const first = i === 0 || group[i - 1] !== g;\n return gaps && !first ? NaN : (values[g] ?? NaN);\n }\n const done = latest[i]!;\n if (done < 0 || (gaps && i > 0 && latest[i - 1] === done)) return NaN;\n return values[done] ?? NaN;\n });\n}\n\n/**\n * Heikin Ashi bars (PineScript `ticker.heikinashi`): close = (open + high + low + close) / 4, open = the\n * average of the previous Heikin Ashi open and close ((open + close) / 2 on the first bar),\n * high / low = the extremes of high / low and the Heikin Ashi open and close.\n */\nexport function heikinAshi(bars: Bar[]): Bar[] {\n const out: Bar[] = [];\n bars.forEach((b, i) => {\n const close = (b.open + b.high + b.low + b.close) / 4;\n const prev = out[i - 1];\n const open = prev ? (prev.open + prev.close) / 2 : (b.open + b.close) / 2;\n out.push({ time: b.time, open, high: Math.max(b.high, open, close), low: Math.min(b.low, open, close), close, volume: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AAI,EAAE,KAAK,MAAM,KAAK,GAAG,OAAO,QAAQ,EAAE,OAAO,CAAC;AAAA,EAClI,CAAC;AACD,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * PineScript values that depend on the chart timeframe and the symbol session (issue #100):
3
+ * `time(tf)`, `time_close(tf)`, `timeframe.change(tf)`, `time_tradingday`, `session.*`.
4
+ * PineScript rules:
5
+ *
6
+ * - intraday periods are aligned on the start of the session period of the trading day: 240 minutes from
7
+ * 09:30 gives 09:30, 13:30; `time(tf)` is the start of the period that contains the bar open
8
+ * - "D" is the session start of the trading day; "W" / "M" the session start of the first trading day
9
+ * of the week (Monday to Sunday) / month
10
+ * - intraday closes are cut at the end of the session period; the "D" close is the session end
11
+ * - on intraday charts the "W" / "M" (and "nD") close is the session start of the next period's first
12
+ * trading day; on D / W / M charts it is the session end of the last trading day of the week / month
13
+ * - on D / W / M charts, intraday timeframes give the chart bar's time, and the end of the session
14
+ * period that contains the bar open as close
15
+ * - `time_tradingday` is 00:00 UTC of the trading day (on W / M charts, of the last trading day)
16
+ *
17
+ * Multipliers above one day (issue #100 follow-up): periods restart each
18
+ * calendar year. "nD" groups n trading days from the first trading day of the year; "nW" groups n weeks from
19
+ * the first week whose Monday is in the year; "nM" groups n months from January. The last group of a year
20
+ * can be shorter.
21
+ */
22
+ import { type TimeframeInfo } from '../timeframe/index.js';
23
+ import { TradingCalendar, type DateNum } from './calendar.js';
24
+ /** Values of the bars of one chart, for a trading calendar. */
25
+ export declare class SessionBars {
26
+ readonly calendar: TradingCalendar;
27
+ readonly chart: TimeframeInfo;
28
+ private readonly yearDays;
29
+ constructor(calendar: TradingCalendar, chartTimeframe: string);
30
+ /** Trading days of a calendar year, in order. */
31
+ private tradingDaysOf;
32
+ /**
33
+ * Dates [from, to] of the `n`-`unit` period that contains `date` (for "D": its first and last trading days).
34
+ * Periods restart each calendar year.
35
+ */
36
+ private periodRange;
37
+ private dayStart;
38
+ private dayEnd;
39
+ /** PineScript `time(tf)` for a bar that opens at `time`; NaN when no trading day is found. */
40
+ timeOf(time: number, timeframe: string): number;
41
+ /** PineScript `time_close(tf)` for a bar that opens at `time`. */
42
+ closeOf(time: number, timeframe: string): number;
43
+ /** Trading day of a bar: on D / W / M charts the last trading day of the chart period. */
44
+ tradingDay(time: number): DateNum | null;
45
+ /**
46
+ * End of the `timeframe` period that contains `time`: the intraday close, the session end of the day,
47
+ * or the session end of the last trading day of the period. Used to know whether the last loaded
48
+ * bar completes a higher-timeframe period (request.security).
49
+ */
50
+ periodEnd(time: number, timeframe: string): number;
51
+ /** PineScript `time_tradingday`: 00:00 UTC of the trading day. */
52
+ tradingDayTime(time: number): number;
53
+ /** True when the bar at `time` is inside the session. */
54
+ inside(time: number): boolean;
55
+ /** Session start and end of the trading day of `time`, or null. */
56
+ dayBounds(time: number): {
57
+ date: DateNum;
58
+ start: number;
59
+ end: number;
60
+ } | null;
61
+ }
62
+ /** PineScript `session.*` flags of each bar. */
63
+ export interface SessionFlags {
64
+ isfirstbar: boolean[];
65
+ islastbar: boolean[];
66
+ ismarket: boolean[];
67
+ ispremarket: boolean[];
68
+ ispostmarket: boolean[];
69
+ isfirstbar_regular: boolean[];
70
+ islastbar_regular: boolean[];
71
+ }
72
+ /**
73
+ * `session.*` flags for bars that open at `times` (in order). `regular` gives the regular trading
74
+ * hours when the bars include extended hours. PineScript rules: flags use the bar open
75
+ * time; first and last bars are per session period (a trading day can have two periods, e.g. after a
76
+ * futures holiday); pre / post market compare with the regular hours of the same trading day; on
77
+ * D / W / M charts every bar is its own session (first, last, market, first and last regular).
78
+ */
79
+ export declare function sessionFlags(times: number[], bars: SessionBars, regular: SessionBars): SessionFlags;
80
+ //# sourceMappingURL=bars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bars.d.ts","sourceRoot":"","sources":["../../../src/session/bars.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAA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