oakscriptjs 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/README.md +25 -1
  2. package/bin/oakscript.mjs +10 -3
  3. package/dist/cjs/box/index.d.ts +348 -289
  4. package/dist/cjs/box/index.d.ts.map +1 -1
  5. package/dist/cjs/box/index.js.map +2 -2
  6. package/dist/cjs/check/node.d.ts.map +1 -1
  7. package/dist/cjs/check/node.js +1 -0
  8. package/dist/cjs/check/node.js.map +2 -2
  9. package/dist/cjs/check/preview.d.ts +31 -0
  10. package/dist/cjs/check/preview.d.ts.map +1 -0
  11. package/dist/cjs/check/preview.js +303 -0
  12. package/dist/cjs/check/preview.js.map +7 -0
  13. package/dist/cjs/color/index.d.ts +11 -11
  14. package/dist/cjs/color/index.js.map +1 -1
  15. package/dist/cjs/color/parse.d.ts +2 -0
  16. package/dist/cjs/color/parse.d.ts.map +1 -1
  17. package/dist/cjs/color/parse.js +6 -0
  18. package/dist/cjs/color/parse.js.map +2 -2
  19. package/dist/cjs/compare/index.d.ts +76 -12
  20. package/dist/cjs/compare/index.d.ts.map +1 -1
  21. package/dist/cjs/compare/index.js.map +2 -2
  22. package/dist/cjs/drawing/registry.d.ts +28 -5
  23. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  24. package/dist/cjs/drawing/registry.js +14 -0
  25. package/dist/cjs/drawing/registry.js.map +2 -2
  26. package/dist/cjs/index.d.ts +1 -1
  27. package/dist/cjs/index.js +1 -1
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/label/index.d.ts +265 -187
  30. package/dist/cjs/label/index.d.ts.map +1 -1
  31. package/dist/cjs/label/index.js +1 -1
  32. package/dist/cjs/label/index.js.map +2 -2
  33. package/dist/cjs/line/index.d.ts +247 -207
  34. package/dist/cjs/line/index.d.ts.map +1 -1
  35. package/dist/cjs/line/index.js.map +2 -2
  36. package/dist/cjs/linefill/index.d.ts +61 -89
  37. package/dist/cjs/linefill/index.d.ts.map +1 -1
  38. package/dist/cjs/linefill/index.js.map +2 -2
  39. package/dist/cjs/math/index.d.ts +49 -40
  40. package/dist/cjs/math/index.d.ts.map +1 -1
  41. package/dist/cjs/math/index.js.map +2 -2
  42. package/dist/cjs/polyline/index.d.ts +57 -78
  43. package/dist/cjs/polyline/index.d.ts.map +1 -1
  44. package/dist/cjs/polyline/index.js.map +2 -2
  45. package/dist/cjs/runtime/input-active.d.ts +2 -2
  46. package/dist/cjs/runtime/input-active.js.map +1 -1
  47. package/dist/cjs/runtime/series.d.ts +241 -161
  48. package/dist/cjs/runtime/series.d.ts.map +1 -1
  49. package/dist/cjs/runtime/series.js +223 -127
  50. package/dist/cjs/runtime/series.js.map +2 -2
  51. package/dist/cjs/script/api/alert.d.ts +37 -0
  52. package/dist/cjs/script/api/alert.d.ts.map +1 -0
  53. package/dist/cjs/script/api/alert.js +17 -0
  54. package/dist/cjs/script/api/alert.js.map +7 -0
  55. package/dist/cjs/script/api/calc.d.ts +232 -0
  56. package/dist/cjs/script/api/calc.d.ts.map +1 -0
  57. package/dist/cjs/script/api/calc.js +17 -0
  58. package/dist/cjs/script/api/calc.js.map +7 -0
  59. package/dist/cjs/script/api/color.d.ts +213 -0
  60. package/dist/cjs/script/api/color.d.ts.map +1 -0
  61. package/dist/cjs/script/api/color.js +17 -0
  62. package/dist/cjs/script/api/color.js.map +7 -0
  63. package/dist/cjs/script/api/context.d.ts +764 -0
  64. package/dist/cjs/script/api/context.d.ts.map +1 -0
  65. package/dist/cjs/script/api/context.js +17 -0
  66. package/dist/cjs/script/api/context.js.map +7 -0
  67. package/dist/cjs/script/api/log.d.ts +58 -0
  68. package/dist/cjs/script/api/log.d.ts.map +1 -0
  69. package/dist/cjs/script/api/log.js +17 -0
  70. package/dist/cjs/script/api/log.js.map +7 -0
  71. package/dist/cjs/script/api/strategy.d.ts +391 -0
  72. package/dist/cjs/script/api/strategy.d.ts.map +1 -0
  73. package/dist/cjs/script/api/strategy.js +17 -0
  74. package/dist/cjs/script/api/strategy.js.map +7 -0
  75. package/dist/cjs/script/api/ta.d.ts +1012 -0
  76. package/dist/cjs/script/api/ta.d.ts.map +1 -0
  77. package/dist/cjs/script/api/ta.js +17 -0
  78. package/dist/cjs/script/api/ta.js.map +7 -0
  79. package/dist/cjs/script/api/table.d.ts +479 -0
  80. package/dist/cjs/script/api/table.d.ts.map +1 -0
  81. package/dist/cjs/script/api/table.js +17 -0
  82. package/dist/cjs/script/api/table.js.map +7 -0
  83. package/dist/cjs/script/constants.d.ts +228 -83
  84. package/dist/cjs/script/constants.d.ts.map +1 -1
  85. package/dist/cjs/script/constants.js +87 -0
  86. package/dist/cjs/script/constants.js.map +2 -2
  87. package/dist/cjs/script/define.d.ts +94 -0
  88. package/dist/cjs/script/define.d.ts.map +1 -0
  89. package/dist/cjs/script/define.js +127 -0
  90. package/dist/cjs/script/define.js.map +7 -0
  91. package/dist/cjs/script/drawing-args.d.ts.map +1 -1
  92. package/dist/cjs/script/drawing-args.js +1 -1
  93. package/dist/cjs/script/drawing-args.js.map +2 -2
  94. package/dist/cjs/script/formula.d.ts +53 -0
  95. package/dist/cjs/script/formula.d.ts.map +1 -0
  96. package/dist/cjs/script/formula.js +402 -0
  97. package/dist/cjs/script/formula.js.map +7 -0
  98. package/dist/cjs/script/globals.d.ts +10 -0
  99. package/dist/cjs/script/globals.d.ts.map +1 -1
  100. package/dist/cjs/script/globals.js.map +1 -1
  101. package/dist/cjs/script/index.d.ts +1065 -1006
  102. package/dist/cjs/script/index.d.ts.map +1 -1
  103. package/dist/cjs/script/index.js +532 -61
  104. package/dist/cjs/script/index.js.map +3 -3
  105. package/dist/cjs/script/json.d.ts +117 -0
  106. package/dist/cjs/script/json.d.ts.map +1 -0
  107. package/dist/cjs/script/json.js +321 -0
  108. package/dist/cjs/script/json.js.map +7 -0
  109. package/dist/cjs/security/other.d.ts +8 -3
  110. package/dist/cjs/security/other.d.ts.map +1 -1
  111. package/dist/cjs/security/other.js +23 -6
  112. package/dist/cjs/security/other.js.map +2 -2
  113. package/dist/cjs/str/index.d.ts +50 -75
  114. package/dist/cjs/str/index.d.ts.map +1 -1
  115. package/dist/cjs/str/index.js +2 -2
  116. package/dist/cjs/str/index.js.map +2 -2
  117. package/dist/cjs/strategy/index.d.ts +102 -1
  118. package/dist/cjs/strategy/index.d.ts.map +1 -1
  119. package/dist/cjs/strategy/index.js.map +2 -2
  120. package/dist/cjs/table/index.d.ts +330 -49
  121. package/dist/cjs/table/index.d.ts.map +1 -1
  122. package/dist/cjs/table/index.js +55 -27
  123. package/dist/cjs/table/index.js.map +2 -2
  124. package/dist/cjs/text/index.d.ts +12 -14
  125. package/dist/cjs/text/index.d.ts.map +1 -1
  126. package/dist/cjs/text/index.js.map +2 -2
  127. package/dist/cjs/types/index.d.ts +15 -8
  128. package/dist/cjs/types/index.d.ts.map +1 -1
  129. package/dist/cjs/types/index.js +12 -3
  130. package/dist/cjs/types/index.js.map +2 -2
  131. package/dist/esm/box/index.d.ts +348 -289
  132. package/dist/esm/box/index.d.ts.map +1 -1
  133. package/dist/esm/box/index.js +276 -276
  134. package/dist/esm/box/index.js.map +1 -1
  135. package/dist/esm/check/node.d.ts.map +1 -1
  136. package/dist/esm/check/node.js +1 -0
  137. package/dist/esm/check/node.js.map +1 -1
  138. package/dist/esm/check/preview.d.ts +31 -0
  139. package/dist/esm/check/preview.d.ts.map +1 -0
  140. package/dist/esm/check/preview.js +296 -0
  141. package/dist/esm/check/preview.js.map +1 -0
  142. package/dist/esm/color/index.d.ts +11 -11
  143. package/dist/esm/color/index.js +11 -11
  144. package/dist/esm/color/parse.d.ts +2 -0
  145. package/dist/esm/color/parse.d.ts.map +1 -1
  146. package/dist/esm/color/parse.js +7 -0
  147. package/dist/esm/color/parse.js.map +1 -1
  148. package/dist/esm/compare/index.d.ts +76 -12
  149. package/dist/esm/compare/index.d.ts.map +1 -1
  150. package/dist/esm/compare/index.js +76 -12
  151. package/dist/esm/compare/index.js.map +1 -1
  152. package/dist/esm/drawing/registry.d.ts +28 -5
  153. package/dist/esm/drawing/registry.d.ts.map +1 -1
  154. package/dist/esm/drawing/registry.js +39 -3
  155. package/dist/esm/drawing/registry.js.map +1 -1
  156. package/dist/esm/index.d.ts +1 -1
  157. package/dist/esm/index.js +1 -1
  158. package/dist/esm/label/index.d.ts +265 -187
  159. package/dist/esm/label/index.d.ts.map +1 -1
  160. package/dist/esm/label/index.js +207 -177
  161. package/dist/esm/label/index.js.map +1 -1
  162. package/dist/esm/line/index.d.ts +247 -207
  163. package/dist/esm/line/index.d.ts.map +1 -1
  164. package/dist/esm/line/index.js +202 -194
  165. package/dist/esm/line/index.js.map +1 -1
  166. package/dist/esm/linefill/index.d.ts +61 -89
  167. package/dist/esm/linefill/index.d.ts.map +1 -1
  168. package/dist/esm/linefill/index.js +61 -89
  169. package/dist/esm/linefill/index.js.map +1 -1
  170. package/dist/esm/math/index.d.ts +49 -40
  171. package/dist/esm/math/index.d.ts.map +1 -1
  172. package/dist/esm/math/index.js +22 -9
  173. package/dist/esm/math/index.js.map +1 -1
  174. package/dist/esm/polyline/index.d.ts +57 -78
  175. package/dist/esm/polyline/index.d.ts.map +1 -1
  176. package/dist/esm/polyline/index.js +57 -78
  177. package/dist/esm/polyline/index.js.map +1 -1
  178. package/dist/esm/runtime/input-active.d.ts +2 -2
  179. package/dist/esm/runtime/input-active.js +2 -2
  180. package/dist/esm/runtime/series.d.ts +241 -161
  181. package/dist/esm/runtime/series.d.ts.map +1 -1
  182. package/dist/esm/runtime/series.js +241 -161
  183. package/dist/esm/runtime/series.js.map +1 -1
  184. package/dist/esm/script/api/alert.d.ts +37 -0
  185. package/dist/esm/script/api/alert.d.ts.map +1 -0
  186. package/dist/esm/script/api/alert.js +7 -0
  187. package/dist/esm/script/api/alert.js.map +1 -0
  188. package/dist/esm/script/api/calc.d.ts +232 -0
  189. package/dist/esm/script/api/calc.d.ts.map +1 -0
  190. package/dist/esm/script/api/calc.js +6 -0
  191. package/dist/esm/script/api/calc.js.map +1 -0
  192. package/dist/esm/script/api/color.d.ts +213 -0
  193. package/dist/esm/script/api/color.d.ts.map +1 -0
  194. package/dist/esm/script/api/color.js +6 -0
  195. package/dist/esm/script/api/color.js.map +1 -0
  196. package/dist/esm/script/api/context.d.ts +764 -0
  197. package/dist/esm/script/api/context.d.ts.map +1 -0
  198. package/dist/esm/script/api/context.js +7 -0
  199. package/dist/esm/script/api/context.js.map +1 -0
  200. package/dist/esm/script/api/log.d.ts +58 -0
  201. package/dist/esm/script/api/log.d.ts.map +1 -0
  202. package/dist/esm/script/api/log.js +6 -0
  203. package/dist/esm/script/api/log.js.map +1 -0
  204. package/dist/esm/script/api/strategy.d.ts +391 -0
  205. package/dist/esm/script/api/strategy.d.ts.map +1 -0
  206. package/dist/esm/script/api/strategy.js +7 -0
  207. package/dist/esm/script/api/strategy.js.map +1 -0
  208. package/dist/esm/script/api/ta.d.ts +1012 -0
  209. package/dist/esm/script/api/ta.d.ts.map +1 -0
  210. package/dist/esm/script/api/ta.js +6 -0
  211. package/dist/esm/script/api/ta.js.map +1 -0
  212. package/dist/esm/script/api/table.d.ts +479 -0
  213. package/dist/esm/script/api/table.d.ts.map +1 -0
  214. package/dist/esm/script/api/table.js +7 -0
  215. package/dist/esm/script/api/table.js.map +1 -0
  216. package/dist/esm/script/constants.d.ts +228 -83
  217. package/dist/esm/script/constants.d.ts.map +1 -1
  218. package/dist/esm/script/constants.js +110 -24
  219. package/dist/esm/script/constants.js.map +1 -1
  220. package/dist/esm/script/define.d.ts +94 -0
  221. package/dist/esm/script/define.d.ts.map +1 -0
  222. package/dist/esm/script/define.js +136 -0
  223. package/dist/esm/script/define.js.map +1 -0
  224. package/dist/esm/script/drawing-args.d.ts.map +1 -1
  225. package/dist/esm/script/drawing-args.js +2 -1
  226. package/dist/esm/script/drawing-args.js.map +1 -1
  227. package/dist/esm/script/formula.d.ts +53 -0
  228. package/dist/esm/script/formula.d.ts.map +1 -0
  229. package/dist/esm/script/formula.js +408 -0
  230. package/dist/esm/script/formula.js.map +1 -0
  231. package/dist/esm/script/globals.d.ts +10 -0
  232. package/dist/esm/script/globals.d.ts.map +1 -1
  233. package/dist/esm/script/globals.js.map +1 -1
  234. package/dist/esm/script/index.d.ts +1065 -1006
  235. package/dist/esm/script/index.d.ts.map +1 -1
  236. package/dist/esm/script/index.js +1099 -153
  237. package/dist/esm/script/index.js.map +1 -1
  238. package/dist/esm/script/json.d.ts +117 -0
  239. package/dist/esm/script/json.d.ts.map +1 -0
  240. package/dist/esm/script/json.js +375 -0
  241. package/dist/esm/script/json.js.map +1 -0
  242. package/dist/esm/security/other.d.ts +8 -3
  243. package/dist/esm/security/other.d.ts.map +1 -1
  244. package/dist/esm/security/other.js +45 -10
  245. package/dist/esm/security/other.js.map +1 -1
  246. package/dist/esm/str/index.d.ts +50 -75
  247. package/dist/esm/str/index.d.ts.map +1 -1
  248. package/dist/esm/str/index.js +51 -76
  249. package/dist/esm/str/index.js.map +1 -1
  250. package/dist/esm/strategy/index.d.ts +102 -1
  251. package/dist/esm/strategy/index.d.ts.map +1 -1
  252. package/dist/esm/strategy/index.js +1 -1
  253. package/dist/esm/strategy/index.js.map +1 -1
  254. package/dist/esm/table/index.d.ts +330 -49
  255. package/dist/esm/table/index.d.ts.map +1 -1
  256. package/dist/esm/table/index.js +372 -61
  257. package/dist/esm/table/index.js.map +1 -1
  258. package/dist/esm/text/index.d.ts +12 -14
  259. package/dist/esm/text/index.d.ts.map +1 -1
  260. package/dist/esm/text/index.js +12 -14
  261. package/dist/esm/text/index.js.map +1 -1
  262. package/dist/esm/types/index.d.ts +15 -8
  263. package/dist/esm/types/index.d.ts.map +1 -1
  264. package/dist/esm/types/index.js +15 -8
  265. package/dist/esm/types/index.js.map +1 -1
  266. package/docs/first-indicator.md +152 -0
  267. package/docs/guide.md +1185 -0
  268. package/docs/inventory.md +772 -0
  269. package/docs/no-code.md +207 -0
  270. package/docs/recipes.md +202 -0
  271. package/package.json +2 -1
  272. package/skills/oakscript/SKILL.md +8 -0
  273. package/skills/oakscript/reference/errors.md +3 -2
  274. package/skills/oakscript/reference/timeframes-symbols.md +4 -0
  275. package/src/box/index.ts +348 -289
  276. package/src/check/node.ts +1 -0
  277. package/src/check/preview.ts +307 -0
  278. package/src/color/index.ts +11 -11
  279. package/src/color/parse.ts +7 -0
  280. package/src/compare/index.ts +76 -12
  281. package/src/drawing/registry.ts +44 -5
  282. package/src/index.ts +1 -1
  283. package/src/label/index.ts +267 -189
  284. package/src/line/index.ts +248 -208
  285. package/src/linefill/index.ts +61 -89
  286. package/src/math/index.ts +51 -42
  287. package/src/polyline/index.ts +57 -78
  288. package/src/runtime/input-active.ts +2 -2
  289. package/src/runtime/series.ts +243 -163
  290. package/src/script/api/alert.ts +43 -0
  291. package/src/script/api/calc.ts +250 -0
  292. package/src/script/api/color.ts +245 -0
  293. package/src/script/api/context.ts +944 -0
  294. package/src/script/api/log.ts +60 -0
  295. package/src/script/api/strategy.ts +410 -0
  296. package/src/script/api/ta.ts +1115 -0
  297. package/src/script/api/table.ts +538 -0
  298. package/src/script/constants.ts +229 -25
  299. package/src/script/define.ts +221 -0
  300. package/src/script/drawing-args.ts +2 -1
  301. package/src/script/formula.ts +438 -0
  302. package/src/script/globals.ts +10 -0
  303. package/src/script/index.ts +1520 -241
  304. package/src/script/json.ts +457 -0
  305. package/src/security/other.ts +43 -9
  306. package/src/str/index.ts +51 -76
  307. package/src/strategy/index.ts +102 -1
  308. package/src/table/index.ts +388 -62
  309. package/src/text/index.ts +12 -14
  310. package/src/types/index.ts +15 -8
@@ -44,115 +44,200 @@ export declare const STRATEGY_CONSTANTS: {
44
44
  };
45
45
  /** Arguments of the PineScript `strategy()` declaration, after `title`. */
46
46
  export interface StrategyOptions {
47
+ /** Short name shown in the legend. Default: the title. */
47
48
  shorttitle?: string;
49
+ /** true: drawn over the price chart; false: in its own pane. Default: false. */
48
50
  overlay?: boolean;
51
+ /** Number format of the values: `format.price`, `format.volume`, `format.percent`... Default: the symbol's price format. */
49
52
  format?: string;
53
+ /** Decimals shown for the values. Default: the symbol's. */
50
54
  precision?: number;
55
+ /** Price scale the strategy uses: `scale.right`, `scale.left` or `scale.none`. */
51
56
  scale?: string;
57
+ /** Most entries allowed in the same direction; 0 and 1 both allow one. Default: 0. */
52
58
  pyramiding?: number;
59
+ /** true: runs the bar again after an order fills inside it, so new orders can be sent at once. Default: false. */
53
60
  calc_on_order_fills?: boolean;
61
+ /** true: runs on every price update of the live bar, not only when it closes. Default: false. */
54
62
  calc_on_every_tick?: boolean;
55
63
  /** Runs the strategy on each tick of the history bars too (the reference app's "On history bar tick"). */
56
64
  calc_on_every_history_tick?: boolean;
65
+ /** History length kept for the script's Series. Default: worked out from the script. */
57
66
  max_bars_back?: number;
67
+ /** Ticks the price must go past a limit price before the limit order fills. Default: 0. */
58
68
  backtest_fill_limits_assumption?: number;
69
+ /** Unit of `default_qty_value`: `strategy.fixed` (contracts / shares), `strategy.cash` or `strategy.percent_of_equity`. Default: `strategy.percent_of_equity`. */
59
70
  default_qty_type?: StrategyQtyType;
71
+ /** Size of an order that gives no `qty`, in the unit of `default_qty_type`. Default: 100. */
60
72
  default_qty_value?: number;
73
+ /** Money the account starts with, in the account currency. Default: 100000. */
61
74
  initial_capital?: number;
62
75
  /** Account currency; default: the symbol currency. */
63
76
  currency?: string;
64
77
  /** Ticks added to market and stop fills. */
65
78
  slippage?: number;
79
+ /** How `commission_value` is read: `strategy.commission.percent` (of the order value), `.cash_per_contract` or `.cash_per_order`. Default: percent. */
66
80
  commission_type?: StrategyCommissionType;
81
+ /** Commission per order, in the unit of `commission_type`. Default: 0. */
67
82
  commission_value?: number;
83
+ /** true: orders fill at the close of the bar that sent them instead of the next bar's open. Default: false. */
68
84
  process_orders_on_close?: boolean;
85
+ /** Which entry an exit closes first: "FIFO" (the oldest) or "ANY" (the one named by `from_entry`). Default: "FIFO". */
69
86
  close_entries_rule?: 'FIFO' | 'ANY';
87
+ /** Share of a long position's value the account must hold, in percent (100: no leverage). Default: 100. */
70
88
  margin_long?: number;
89
+ /** Share of a short position's value the account must hold, in percent. Default: 100. */
71
90
  margin_short?: number;
91
+ /** true: outputs are drawn in the order the script writes them. Default: false. */
72
92
  explicit_plot_zorder?: boolean;
93
+ /** Most `line` drawings kept on the chart (the oldest go). Default: 50. */
73
94
  max_lines_count?: number;
95
+ /** Most labels kept on the chart (the oldest go). Default: 50. */
74
96
  max_labels_count?: number;
97
+ /** Most boxes kept on the chart (the oldest go). Default: 50. */
75
98
  max_boxes_count?: number;
99
+ /** Runs only on the last this many bars; 0 runs on all. Default: 0. */
76
100
  calc_bars_count?: number;
101
+ /** Yearly risk-free rate, in percent, for the Sharpe and Sortino ratios. Default: 2. */
77
102
  risk_free_rate?: number;
103
+ /** true: fills orders with the bars of a lower timeframe inside each bar, for more exact fills. Default: false. */
78
104
  use_bar_magnifier?: boolean;
105
+ /** true: on synthetic charts (Heikin Ashi...) orders fill at the real prices. Default: false. */
79
106
  fill_orders_on_standard_ohlc?: boolean;
107
+ /** Most polylines kept on the chart (the oldest go). Default: 50. */
80
108
  max_polylines_count?: number;
81
109
  }
82
110
  /** Strategy properties passed to the engine: the declared values, else the PineScript defaults. */
83
111
  export interface StrategyProperties {
112
+ /** Most entries in the same direction (0 and 1 allow one). */
84
113
  pyramiding: number;
114
+ /** Runs the bar again after a fill inside it. */
85
115
  calc_on_order_fills: boolean;
116
+ /** Runs on every price update of the live bar. */
86
117
  calc_on_every_tick: boolean;
118
+ /** Runs on each price step of the history bars. */
87
119
  calc_on_every_history_tick: boolean;
120
+ /** Ticks the price must pass a limit price by before it fills. */
88
121
  backtest_fill_limits_assumption: number;
122
+ /** Unit of `default_qty_value`. */
89
123
  default_qty_type: StrategyQtyType;
124
+ /** Size of an order that gives no `qty`. */
90
125
  default_qty_value: number;
126
+ /** Money the account starts with. */
91
127
  initial_capital: number;
92
128
  /** undefined: the symbol currency. */
93
129
  currency?: string;
130
+ /** Ticks added against you to market and stop fills. */
94
131
  slippage: number;
132
+ /** How `commission_value` is read. */
95
133
  commission_type: StrategyCommissionType;
134
+ /** Commission per order. */
96
135
  commission_value: number;
136
+ /** Orders fill at the close of the bar that sent them. */
97
137
  process_orders_on_close: boolean;
138
+ /** "FIFO": exits close the oldest entry first; "ANY": the entry they name. */
98
139
  close_entries_rule: 'FIFO' | 'ANY';
140
+ /** Margin of long positions, in percent of their value. */
99
141
  margin_long: number;
142
+ /** Margin of short positions, in percent of their value. */
100
143
  margin_short: number;
144
+ /** Runs on the last this many bars; 0: all. */
101
145
  calc_bars_count: number;
146
+ /** Yearly risk-free rate in percent (Sharpe, Sortino). */
102
147
  risk_free_rate: number;
148
+ /** Fills orders with lower-timeframe bars. */
103
149
  use_bar_magnifier: boolean;
150
+ /** Fills at real prices on synthetic charts. */
104
151
  fill_orders_on_standard_ohlc: boolean;
105
152
  }
106
- /** PineScript defaults of the `strategy()` arguments (v6 reference). */
153
+ /** Default values of the `strategy()` options, used for every option a strategy leaves out. */
107
154
  export declare const STRATEGY_DEFAULTS: StrategyProperties;
108
155
  /** `strategy.entry()` / `strategy.order()` arguments after `id` and `direction`. */
109
156
  export interface StrategyEntryOptions {
157
+ /** Contracts / shares to trade. Default: from `default_qty_type` and `default_qty_value`. */
110
158
  qty?: number;
159
+ /** Limit price: the order fills at this price or better. Left out with `stop` too: a market order. */
111
160
  limit?: number;
161
+ /** Stop price: the order fills once the price reaches it. With `limit`: a stop-limit order. */
112
162
  stop?: number;
163
+ /** Name of a one-cancels-all group the order belongs to. */
113
164
  oca_name?: string;
165
+ /** What a fill in the group does to the others: `strategy.oca.cancel`, `.reduce` or `.none`. Default: none. */
114
166
  oca_type?: StrategyOcaType;
167
+ /** Text shown with the order's fill on the chart and in the trade list. */
115
168
  comment?: string;
169
+ /** Text of the alert sent when the order fills. */
116
170
  alert_message?: string;
171
+ /** true: the order's fill sends no alert. Default: false. */
117
172
  disable_alert?: boolean;
118
173
  }
119
174
  /** `strategy.exit()` arguments after `id`. `profit`, `loss`, `trail_points` and `trail_offset` are in ticks. */
120
175
  export interface StrategyExitOptions {
176
+ /** Id of the entry to exit. Default: every open entry. */
121
177
  from_entry?: string;
178
+ /** Contracts / shares to exit. Default: the whole position (see `qty_percent`). */
122
179
  qty?: number;
180
+ /** Share of the position to exit, in percent. Default: 100. */
123
181
  qty_percent?: number;
182
+ /** Take-profit distance from the entry price, in ticks. */
124
183
  profit?: number;
184
+ /** Take-profit price. */
125
185
  limit?: number;
186
+ /** Stop-loss distance from the entry price, in ticks. */
126
187
  loss?: number;
188
+ /** Stop-loss price. */
127
189
  stop?: number;
190
+ /** Price at which the trailing stop starts. */
128
191
  trail_price?: number;
192
+ /** Distance from the entry, in ticks, at which the trailing stop starts. */
129
193
  trail_points?: number;
194
+ /** Distance the trailing stop keeps from the best price, in ticks. */
130
195
  trail_offset?: number;
196
+ /** Name of the one-cancels-all group of the exit's orders. Default: one group per exit. */
131
197
  oca_name?: string;
198
+ /** Text shown with the exit fill. */
132
199
  comment?: string;
200
+ /** Text shown when the take-profit fills. Default: `comment`. */
133
201
  comment_profit?: string;
202
+ /** Text shown when the stop-loss fills. Default: `comment`. */
134
203
  comment_loss?: string;
204
+ /** Text shown when the trailing stop fills. Default: `comment`. */
135
205
  comment_trailing?: string;
206
+ /** Text of the alert sent when the exit fills. */
136
207
  alert_message?: string;
208
+ /** Alert text when the take-profit fills. Default: `alert_message`. */
137
209
  alert_profit?: string;
210
+ /** Alert text when the stop-loss fills. Default: `alert_message`. */
138
211
  alert_loss?: string;
212
+ /** Alert text when the trailing stop fills. Default: `alert_message`. */
139
213
  alert_trailing?: string;
214
+ /** true: the exit sends no alert. Default: false. */
140
215
  disable_alert?: boolean;
141
216
  }
142
217
  /** `strategy.close()` arguments after `id`. */
143
218
  export interface StrategyCloseOptions {
219
+ /** Text shown with the closing fill. */
144
220
  comment?: string;
221
+ /** Contracts / shares to close. Default: all of the entry. */
145
222
  qty?: number;
223
+ /** Share to close, in percent. Default: 100. */
146
224
  qty_percent?: number;
225
+ /** Text of the alert sent when it fills. */
147
226
  alert_message?: string;
227
+ /** true: closes at the current bar's close instead of the next bar's open. Default: false. */
148
228
  immediately?: boolean;
229
+ /** true: sends no alert. Default: false. */
149
230
  disable_alert?: boolean;
150
231
  }
151
232
  /** `strategy.close_all()` arguments. */
152
233
  export interface StrategyCloseAllOptions {
234
+ /** Text shown with the closing fill. */
153
235
  comment?: string;
236
+ /** Text of the alert sent when it fills. */
154
237
  alert_message?: string;
238
+ /** true: closes at the current bar's close instead of the next bar's open. Default: false. */
155
239
  immediately?: boolean;
240
+ /** true: sends no alert. Default: false. */
156
241
  disable_alert?: boolean;
157
242
  }
158
243
  /** A `strategy.risk.*` rule. */
@@ -187,25 +272,41 @@ export type StrategyRiskRule = {
187
272
  * comments are undefined when the engine does not provide them.
188
273
  */
189
274
  export interface StrategyTrade {
275
+ /** Id of the entry order. */
190
276
  entry_id: string;
277
+ /** Price the entry filled at. */
191
278
  entry_price: number;
279
+ /** Bar number of the entry (0 = first bar). */
192
280
  entry_bar_index: number;
281
+ /** Time of the entry, in UNIX milliseconds. */
193
282
  entry_time: number;
194
283
  /** undefined when the order had no comment, or when the engine does not keep it apart from the id. */
195
284
  entry_comment?: string;
196
285
  /** Signed quantity: positive for a long trade, negative for a short trade. */
197
286
  size: number;
287
+ /** Profit of the trade in the account currency (negative for a loss), after commission. */
198
288
  profit: number;
289
+ /** Profit of the trade in percent of its entry value. */
199
290
  profit_percent: number;
291
+ /** Commission paid for the trade. */
200
292
  commission: number;
293
+ /** Largest open profit the trade reached, in the account currency. */
201
294
  max_runup: number;
295
+ /** Largest open profit in percent. */
202
296
  max_runup_percent: number;
297
+ /** Largest open loss the trade reached, in the account currency. */
203
298
  max_drawdown: number;
299
+ /** Largest open loss in percent. */
204
300
  max_drawdown_percent: number;
301
+ /** Id of the order that closed the trade. */
205
302
  exit_id?: string;
303
+ /** Price the exit filled at. */
206
304
  exit_price?: number;
305
+ /** Bar number of the exit. */
207
306
  exit_bar_index?: number;
307
+ /** Time of the exit, in UNIX milliseconds. */
208
308
  exit_time?: number;
309
+ /** Comment of the exit order. */
209
310
  exit_comment?: string;
210
311
  }
211
312
  /** Numeric `strategy.*` variables. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/strategy/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,mBAAmB,CAAC;AACrE,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,mBAAmB,GAAG,gBAAgB,CAAC;AACxF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC3D,kEAAkE;AAClE,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAC7D,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,GAAG,MAAM,CAAC;AAEjE,yCAAyC;AACzC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;CASrB,CAAC;AAEX,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0GAA0G;IAC1G,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+BAA+B,CAAC,EAAE,MAAM,CAAC;IACzC,gBAAgB,CAAC,EAAE,eAAe,CAA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`strategy.*` API.\n *\n * OakScriptJS does not simulate orders. The script API (`oakscriptjs/script`) declares the strategy,\n * forwards every `strategy.*` call to a {@link StrategyEngine} that the host supplies, and reads the\n * `strategy.*` variables from it. The engine fills the orders, keeps the trades and computes the\n * results.\n *\n * Names follow PineScript v6: option objects use the PineScript argument names, and the engine\n * receives them unchanged. An `na` (NaN) numeric argument is removed before the call, since in\n * PineScript it means \"not given\". The deprecated `when` argument does not exist: use `if`.\n *\n * @module strategy\n */\n\nexport type StrategyDirection = 'long' | 'short';\nexport type StrategyQtyType = 'fixed' | 'cash' | 'percent_of_equity';\nexport type StrategyCommissionType = 'percent' | 'cash_per_contract' | 'cash_per_order';\nexport type StrategyOcaType = 'none' | 'cancel' | 'reduce';\n/** `strategy.direction.*`, for `strategy.risk.allow_entry_in`. */\nexport type StrategyRiskDirection = 'all' | 'long' | 'short';\nexport type StrategyRiskValueType = 'percent_of_equity' | 'cash';\n\n/** PineScript `strategy.*` constants. */\nexport const STRATEGY_CONSTANTS = {\n long: 'long',\n short: 'short',\n fixed: 'fixed',\n cash: 'cash',\n percent_of_equity: 'percent_of_equity',\n commission: { percent: 'percent', cash_per_contract: 'cash_per_contract', cash_per_order: 'cash_per_order' },\n direction: { all: 'all', long: 'long', short: 'short' },\n oca: { none: 'none', cancel: 'cancel', reduce: 'reduce' },\n} as const;\n\n/** Arguments of the PineScript `strategy()` declaration, after `title`. */\nexport interface StrategyOptions {\n shorttitle?: string;\n overlay?: boolean;\n format?: string;\n precision?: number;\n scale?: string;\n pyramiding?: number;\n calc_on_order_fills?: boolean;\n calc_on_every_tick?: boolean;\n /** Runs the strategy on each tick of the history bars too (the reference app's \"On history bar tick\"). */\n calc_on_every_history_tick?: boolean;\n max_bars_back?: number;\n backtest_fill_limits_assumption?: number;\n default_qty_type?: StrategyQtyType;\n default_qty_value?: number;\n initial_capital?: number;\n /** Account currency; default: the symbol currency. */\n currency?: string;\n /** Ticks added to market and stop fills. */\n slippage?: number;\n commission_type?: StrategyCommissionType;\n commission_value?: number;\n process_orders_on_close?: boolean;\n close_entries_rule?: 'FIFO' | 'ANY';\n margin_long?: number;\n margin_short?: number;\n explicit_plot_zorder?: boolean;\n max_lines_count?: number;\n max_labels_count?: number;\n max_boxes_count?: number;\n calc_bars_count?: number;\n risk_free_rate?: number;\n use_bar_magnifier?: boolean;\n fill_orders_on_standard_ohlc?: boolean;\n max_polylines_count?: number;\n}\n\n/** Strategy properties passed to the engine: the declared values, else the PineScript defaults. */\nexport interface StrategyProperties {\n pyramiding: number;\n calc_on_order_fills: boolean;\n calc_on_every_tick: boolean;\n calc_on_every_history_tick: boolean;\n backtest_fill_limits_assumption: number;\n default_qty_type: StrategyQtyType;\n default_qty_value: number;\n initial_capital: number;\n /** undefined: the symbol currency. */\n currency?: string;\n slippage: number;\n commission_type: StrategyCommissionType;\n commission_value: number;\n process_orders_on_close: boolean;\n close_entries_rule: 'FIFO' | 'ANY';\n margin_long: number;\n margin_short: number;\n calc_bars_count: number;\n risk_free_rate: number;\n use_bar_magnifier: boolean;\n fill_orders_on_standard_ohlc: boolean;\n}\n\n/** PineScript defaults of the `strategy()` arguments (v6 reference). */\nexport const STRATEGY_DEFAULTS: StrategyProperties = {\n pyramiding: 0,\n calc_on_order_fills: false,\n calc_on_every_tick: false,\n calc_on_every_history_tick: false,\n backtest_fill_limits_assumption: 0,\n // v6 values; PineScript v5: fixed / 1 / 1000000 and margins 0\n default_qty_type: 'percent_of_equity',\n default_qty_value: 100,\n initial_capital: 100000,\n slippage: 0,\n commission_type: 'percent',\n commission_value: 0,\n process_orders_on_close: false,\n close_entries_rule: 'FIFO',\n margin_long: 100,\n margin_short: 100,\n calc_bars_count: 0,\n risk_free_rate: 2,\n use_bar_magnifier: false,\n fill_orders_on_standard_ohlc: false,\n};\n\n/** `strategy.entry()` / `strategy.order()` arguments after `id` and `direction`. */\nexport interface StrategyEntryOptions {\n qty?: number;\n limit?: number;\n stop?: number;\n oca_name?: string;\n oca_type?: StrategyOcaType;\n comment?: string;\n alert_message?: string;\n disable_alert?: boolean;\n}\n\n/** `strategy.exit()` arguments after `id`. `profit`, `loss`, `trail_points` and `trail_offset` are in ticks. */\nexport interface StrategyExitOptions {\n from_entry?: string;\n qty?: number;\n qty_percent?: number;\n profit?: number;\n limit?: number;\n loss?: number;\n stop?: number;\n trail_price?: number;\n trail_points?: number;\n trail_offset?: number;\n oca_name?: string;\n comment?: string;\n comment_profit?: string;\n comment_loss?: string;\n comment_trailing?: string;\n alert_message?: string;\n alert_profit?: string;\n alert_loss?: string;\n alert_trailing?: string;\n disable_alert?: boolean;\n}\n\n/** `strategy.close()` arguments after `id`. */\nexport interface StrategyCloseOptions {\n comment?: string;\n qty?: number;\n qty_percent?: number;\n alert_message?: string;\n immediately?: boolean;\n disable_alert?: boolean;\n}\n\n/** `strategy.close_all()` arguments. */\nexport interface StrategyCloseAllOptions {\n comment?: string;\n alert_message?: string;\n immediately?: boolean;\n disable_alert?: boolean;\n}\n\n/** A `strategy.risk.*` rule. */\nexport type StrategyRiskRule =\n | { rule: 'allow_entry_in'; direction: StrategyRiskDirection }\n | { rule: 'max_cons_loss_days'; count: number; alert_message?: string }\n | { rule: 'max_drawdown'; value: number; type: StrategyRiskValueType; alert_message?: string }\n | { rule: 'max_intraday_filled_orders'; count: number; alert_message?: string }\n | { rule: 'max_intraday_loss'; value: number; type: StrategyRiskValueType; alert_message?: string }\n | { rule: 'max_position_size'; contracts: number };\n\n/**\n * One trade, as the PineScript `strategy.opentrades.*(i)` / `strategy.closedtrades.*(i)` functions\n * return it. Times are UNIX milliseconds. The `exit_*` fields are for closed trades only; `exit_id` and the\n * comments are undefined when the engine does not provide them.\n */\nexport interface StrategyTrade {\n entry_id: string;\n entry_price: number;\n entry_bar_index: number;\n entry_time: number;\n /** undefined when the order had no comment, or when the engine does not keep it apart from the id. */\n entry_comment?: string;\n /** Signed quantity: positive for a long trade, negative for a short trade. */\n size: number;\n profit: number;\n profit_percent: number;\n commission: number;\n max_runup: number;\n max_runup_percent: number;\n max_drawdown: number;\n max_drawdown_percent: number;\n exit_id?: string;\n exit_price?: number;\n exit_bar_index?: number;\n exit_time?: number;\n exit_comment?: string;\n}\n\n/** Numeric `strategy.*` variables. */\nexport const STRATEGY_NUMBER_VARIABLES = [\n 'position_size',\n 'position_avg_price',\n 'equity',\n 'initial_capital',\n 'netprofit',\n 'netprofit_percent',\n 'openprofit',\n 'openprofit_percent',\n 'grossprofit',\n 'grossprofit_percent',\n 'grossloss',\n 'grossloss_percent',\n 'opentrades',\n 'closedtrades',\n 'wintrades',\n 'losstrades',\n 'eventrades',\n 'avg_trade',\n 'avg_trade_percent',\n 'avg_winning_trade',\n 'avg_winning_trade_percent',\n 'avg_losing_trade',\n 'avg_losing_trade_percent',\n 'max_drawdown',\n 'max_drawdown_percent',\n 'max_runup',\n 'max_runup_percent',\n 'max_contracts_held_all',\n 'max_contracts_held_long',\n 'max_contracts_held_short',\n 'margin_liquidation_price',\n] as const;\n\n/** Text `strategy.*` variables. */\nexport const STRATEGY_TEXT_VARIABLES = ['position_entry_name', 'account_currency'] as const;\n\nexport type StrategyNumberVariable = (typeof STRATEGY_NUMBER_VARIABLES)[number];\nexport type StrategyTextVariable = (typeof STRATEGY_TEXT_VARIABLES)[number];\nexport type StrategyVariable = StrategyNumberVariable | StrategyTextVariable;\n\n/**\n * The order engine the host supplies. OakScriptJS calls it in this order on each bar `i` of\n * `strategy.eachBar()`:\n *\n * 1. `processBar(i)`: fill the orders placed before bar `i` (at the open and inside the bar);\n * 2. the script runs at the close of bar `i`: order calls and variable reads;\n * 3. `processClose(i)`: after the script; with `process_orders_on_close`, fill the new market orders\n * at the close.\n */\nexport interface StrategyEngine {\n processBar(bar: number): void;\n processClose(bar: number): void;\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 /** Current value of a `strategy.*` variable; undefined when the engine does not provide it. */\n get(variable: StrategyVariable): number | string | undefined;\n /** Open trade number `index` (0 = oldest); undefined when it does not exist. */\n openTrade(index: number): StrategyTrade | undefined;\n /** Closed trade number `index` (0 = oldest); undefined when it does not exist. */\n closedTrade(index: number): StrategyTrade | undefined;\n /** `strategy.risk.*` rules; optional. */\n risk?(rule: StrategyRiskRule): void;\n /** `strategy.default_entry_qty(fill_price)`; optional. */\n defaultEntryQty?(fillPrice: number): number;\n /**\n * The engine state at the end of a bar (orders, positions, trades, equity), for an incremental script run\n * (createScriptRun, #196); optional. With {@link restore}, a live update of a strategy calculates the newest bars\n * only: the engine of the next run gets the state of the last confirmed bar. Without them, every update is a full run.\n */\n save?(): unknown;\n /** Puts back a state given by {@link save} (on a new engine of the same script and bars). */\n restore?(state: unknown): void;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,qBAAqB;AAAA,EAChC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB,YAAY,EAAE,SAAS,WAAW,mBAAmB,qBAAqB,gBAAgB,iBAAiB;AAAA,EAC3G,WAAW,EAAE,KAAK,OAAO,MAAM,QAAQ,OAAO,QAAQ;AAAA,EACtD,KAAK,EAAE,MAAM,QAAQ,QAAQ,UAAU,QAAQ,SAAS;AAC1D;AAkEO,MAAM,oBAAwC;AAAA,EACnD,YAAY;AAAA,EACZ,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,4BAA4B;AAAA,EAC5B,iCAAiC;AAAA;AAAA,EAEjC,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,yBAAyB;AAAA,EACzB,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,8BAA8B;AAChC;AA8FO,MAAM,4BAA4B;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,MAAM,0BAA0B,CAAC,uBAAuB,kBAAkB;",
4
+ "sourcesContent": ["/**\n * @fileoverview Types and constants of the PineScript `strategy.*` API.\n *\n * OakScriptJS does not simulate orders. The script API (`oakscriptjs/script`) declares the strategy,\n * forwards every `strategy.*` call to a {@link StrategyEngine} that the host supplies, and reads the\n * `strategy.*` variables from it. The engine fills the orders, keeps the trades and computes the\n * results.\n *\n * Names follow PineScript v6: option objects use the PineScript argument names, and the engine\n * receives them unchanged. An `na` (NaN) numeric argument is removed before the call, since in\n * PineScript it means \"not given\". The deprecated `when` argument does not exist: use `if`.\n *\n * @module strategy\n */\n\nexport type StrategyDirection = 'long' | 'short';\nexport type StrategyQtyType = 'fixed' | 'cash' | 'percent_of_equity';\nexport type StrategyCommissionType = 'percent' | 'cash_per_contract' | 'cash_per_order';\nexport type StrategyOcaType = 'none' | 'cancel' | 'reduce';\n/** `strategy.direction.*`, for `strategy.risk.allow_entry_in`. */\nexport type StrategyRiskDirection = 'all' | 'long' | 'short';\nexport type StrategyRiskValueType = 'percent_of_equity' | 'cash';\n\n/** PineScript `strategy.*` constants. */\nexport const STRATEGY_CONSTANTS = {\n long: 'long',\n short: 'short',\n fixed: 'fixed',\n cash: 'cash',\n percent_of_equity: 'percent_of_equity',\n commission: { percent: 'percent', cash_per_contract: 'cash_per_contract', cash_per_order: 'cash_per_order' },\n direction: { all: 'all', long: 'long', short: 'short' },\n oca: { none: 'none', cancel: 'cancel', reduce: 'reduce' },\n} as const;\n\n/** Arguments of the PineScript `strategy()` declaration, after `title`. */\nexport interface StrategyOptions {\n /** Short name shown in the legend. Default: the title. */\n shorttitle?: string;\n /** true: drawn over the price chart; false: in its own pane. Default: false. */\n overlay?: boolean;\n /** Number format of the values: `format.price`, `format.volume`, `format.percent`... Default: the symbol's price format. */\n format?: string;\n /** Decimals shown for the values. Default: the symbol's. */\n precision?: number;\n /** Price scale the strategy uses: `scale.right`, `scale.left` or `scale.none`. */\n scale?: string;\n /** Most entries allowed in the same direction; 0 and 1 both allow one. Default: 0. */\n pyramiding?: number;\n /** true: runs the bar again after an order fills inside it, so new orders can be sent at once. Default: false. */\n calc_on_order_fills?: boolean;\n /** true: runs on every price update of the live bar, not only when it closes. Default: false. */\n calc_on_every_tick?: boolean;\n /** Runs the strategy on each tick of the history bars too (the reference app's \"On history bar tick\"). */\n calc_on_every_history_tick?: boolean;\n /** History length kept for the script's Series. Default: worked out from the script. */\n max_bars_back?: number;\n /** Ticks the price must go past a limit price before the limit order fills. Default: 0. */\n backtest_fill_limits_assumption?: number;\n /** Unit of `default_qty_value`: `strategy.fixed` (contracts / shares), `strategy.cash` or `strategy.percent_of_equity`. Default: `strategy.percent_of_equity`. */\n default_qty_type?: StrategyQtyType;\n /** Size of an order that gives no `qty`, in the unit of `default_qty_type`. Default: 100. */\n default_qty_value?: number;\n /** Money the account starts with, in the account currency. Default: 100000. */\n initial_capital?: number;\n /** Account currency; default: the symbol currency. */\n currency?: string;\n /** Ticks added to market and stop fills. */\n slippage?: number;\n /** How `commission_value` is read: `strategy.commission.percent` (of the order value), `.cash_per_contract` or `.cash_per_order`. Default: percent. */\n commission_type?: StrategyCommissionType;\n /** Commission per order, in the unit of `commission_type`. Default: 0. */\n commission_value?: number;\n /** true: orders fill at the close of the bar that sent them instead of the next bar's open. Default: false. */\n process_orders_on_close?: boolean;\n /** Which entry an exit closes first: \"FIFO\" (the oldest) or \"ANY\" (the one named by `from_entry`). Default: \"FIFO\". */\n close_entries_rule?: 'FIFO' | 'ANY';\n /** Share of a long position's value the account must hold, in percent (100: no leverage). Default: 100. */\n margin_long?: number;\n /** Share of a short position's value the account must hold, in percent. Default: 100. */\n margin_short?: number;\n /** true: outputs are drawn in the order the script writes them. Default: false. */\n explicit_plot_zorder?: boolean;\n /** Most `line` drawings kept on the chart (the oldest go). Default: 50. */\n max_lines_count?: number;\n /** Most labels kept on the chart (the oldest go). Default: 50. */\n max_labels_count?: number;\n /** Most boxes kept on the chart (the oldest go). Default: 50. */\n max_boxes_count?: number;\n /** Runs only on the last this many bars; 0 runs on all. Default: 0. */\n calc_bars_count?: number;\n /** Yearly risk-free rate, in percent, for the Sharpe and Sortino ratios. Default: 2. */\n risk_free_rate?: number;\n /** true: fills orders with the bars of a lower timeframe inside each bar, for more exact fills. Default: false. */\n use_bar_magnifier?: boolean;\n /** true: on synthetic charts (Heikin Ashi...) orders fill at the real prices. Default: false. */\n fill_orders_on_standard_ohlc?: boolean;\n /** Most polylines kept on the chart (the oldest go). Default: 50. */\n max_polylines_count?: number;\n}\n\n/** Strategy properties passed to the engine: the declared values, else the PineScript defaults. */\nexport interface StrategyProperties {\n /** Most entries in the same direction (0 and 1 allow one). */\n pyramiding: number;\n /** Runs the bar again after a fill inside it. */\n calc_on_order_fills: boolean;\n /** Runs on every price update of the live bar. */\n calc_on_every_tick: boolean;\n /** Runs on each price step of the history bars. */\n calc_on_every_history_tick: boolean;\n /** Ticks the price must pass a limit price by before it fills. */\n backtest_fill_limits_assumption: number;\n /** Unit of `default_qty_value`. */\n default_qty_type: StrategyQtyType;\n /** Size of an order that gives no `qty`. */\n default_qty_value: number;\n /** Money the account starts with. */\n initial_capital: number;\n /** undefined: the symbol currency. */\n currency?: string;\n /** Ticks added against you to market and stop fills. */\n slippage: number;\n /** How `commission_value` is read. */\n commission_type: StrategyCommissionType;\n /** Commission per order. */\n commission_value: number;\n /** Orders fill at the close of the bar that sent them. */\n process_orders_on_close: boolean;\n /** \"FIFO\": exits close the oldest entry first; \"ANY\": the entry they name. */\n close_entries_rule: 'FIFO' | 'ANY';\n /** Margin of long positions, in percent of their value. */\n margin_long: number;\n /** Margin of short positions, in percent of their value. */\n margin_short: number;\n /** Runs on the last this many bars; 0: all. */\n calc_bars_count: number;\n /** Yearly risk-free rate in percent (Sharpe, Sortino). */\n risk_free_rate: number;\n /** Fills orders with lower-timeframe bars. */\n use_bar_magnifier: boolean;\n /** Fills at real prices on synthetic charts. */\n fill_orders_on_standard_ohlc: boolean;\n}\n\n/** Default values of the `strategy()` options, used for every option a strategy leaves out. */\nexport const STRATEGY_DEFAULTS: StrategyProperties = {\n pyramiding: 0,\n calc_on_order_fills: false,\n calc_on_every_tick: false,\n calc_on_every_history_tick: false,\n backtest_fill_limits_assumption: 0,\n // v6 values; PineScript v5: fixed / 1 / 1000000 and margins 0\n default_qty_type: 'percent_of_equity',\n default_qty_value: 100,\n initial_capital: 100000,\n slippage: 0,\n commission_type: 'percent',\n commission_value: 0,\n process_orders_on_close: false,\n close_entries_rule: 'FIFO',\n margin_long: 100,\n margin_short: 100,\n calc_bars_count: 0,\n risk_free_rate: 2,\n use_bar_magnifier: false,\n fill_orders_on_standard_ohlc: false,\n};\n\n/** `strategy.entry()` / `strategy.order()` arguments after `id` and `direction`. */\nexport interface StrategyEntryOptions {\n /** Contracts / shares to trade. Default: from `default_qty_type` and `default_qty_value`. */\n qty?: number;\n /** Limit price: the order fills at this price or better. Left out with `stop` too: a market order. */\n limit?: number;\n /** Stop price: the order fills once the price reaches it. With `limit`: a stop-limit order. */\n stop?: number;\n /** Name of a one-cancels-all group the order belongs to. */\n oca_name?: string;\n /** What a fill in the group does to the others: `strategy.oca.cancel`, `.reduce` or `.none`. Default: none. */\n oca_type?: StrategyOcaType;\n /** Text shown with the order's fill on the chart and in the trade list. */\n comment?: string;\n /** Text of the alert sent when the order fills. */\n alert_message?: string;\n /** true: the order's fill sends no alert. Default: false. */\n disable_alert?: boolean;\n}\n\n/** `strategy.exit()` arguments after `id`. `profit`, `loss`, `trail_points` and `trail_offset` are in ticks. */\nexport interface StrategyExitOptions {\n /** Id of the entry to exit. Default: every open entry. */\n from_entry?: string;\n /** Contracts / shares to exit. Default: the whole position (see `qty_percent`). */\n qty?: number;\n /** Share of the position to exit, in percent. Default: 100. */\n qty_percent?: number;\n /** Take-profit distance from the entry price, in ticks. */\n profit?: number;\n /** Take-profit price. */\n limit?: number;\n /** Stop-loss distance from the entry price, in ticks. */\n loss?: number;\n /** Stop-loss price. */\n stop?: number;\n /** Price at which the trailing stop starts. */\n trail_price?: number;\n /** Distance from the entry, in ticks, at which the trailing stop starts. */\n trail_points?: number;\n /** Distance the trailing stop keeps from the best price, in ticks. */\n trail_offset?: number;\n /** Name of the one-cancels-all group of the exit's orders. Default: one group per exit. */\n oca_name?: string;\n /** Text shown with the exit fill. */\n comment?: string;\n /** Text shown when the take-profit fills. Default: `comment`. */\n comment_profit?: string;\n /** Text shown when the stop-loss fills. Default: `comment`. */\n comment_loss?: string;\n /** Text shown when the trailing stop fills. Default: `comment`. */\n comment_trailing?: string;\n /** Text of the alert sent when the exit fills. */\n alert_message?: string;\n /** Alert text when the take-profit fills. Default: `alert_message`. */\n alert_profit?: string;\n /** Alert text when the stop-loss fills. Default: `alert_message`. */\n alert_loss?: string;\n /** Alert text when the trailing stop fills. Default: `alert_message`. */\n alert_trailing?: string;\n /** true: the exit sends no alert. Default: false. */\n disable_alert?: boolean;\n}\n\n/** `strategy.close()` arguments after `id`. */\nexport interface StrategyCloseOptions {\n /** Text shown with the closing fill. */\n comment?: string;\n /** Contracts / shares to close. Default: all of the entry. */\n qty?: number;\n /** Share to close, in percent. Default: 100. */\n qty_percent?: number;\n /** Text of the alert sent when it fills. */\n alert_message?: string;\n /** true: closes at the current bar's close instead of the next bar's open. Default: false. */\n immediately?: boolean;\n /** true: sends no alert. Default: false. */\n disable_alert?: boolean;\n}\n\n/** `strategy.close_all()` arguments. */\nexport interface StrategyCloseAllOptions {\n /** Text shown with the closing fill. */\n comment?: string;\n /** Text of the alert sent when it fills. */\n alert_message?: string;\n /** true: closes at the current bar's close instead of the next bar's open. Default: false. */\n immediately?: boolean;\n /** true: sends no alert. Default: false. */\n disable_alert?: boolean;\n}\n\n/** A `strategy.risk.*` rule. */\nexport type StrategyRiskRule =\n | { rule: 'allow_entry_in'; direction: StrategyRiskDirection }\n | { rule: 'max_cons_loss_days'; count: number; alert_message?: string }\n | { rule: 'max_drawdown'; value: number; type: StrategyRiskValueType; alert_message?: string }\n | { rule: 'max_intraday_filled_orders'; count: number; alert_message?: string }\n | { rule: 'max_intraday_loss'; value: number; type: StrategyRiskValueType; alert_message?: string }\n | { rule: 'max_position_size'; contracts: number };\n\n/**\n * One trade, as the PineScript `strategy.opentrades.*(i)` / `strategy.closedtrades.*(i)` functions\n * return it. Times are UNIX milliseconds. The `exit_*` fields are for closed trades only; `exit_id` and the\n * comments are undefined when the engine does not provide them.\n */\nexport interface StrategyTrade {\n /** Id of the entry order. */\n entry_id: string;\n /** Price the entry filled at. */\n entry_price: number;\n /** Bar number of the entry (0 = first bar). */\n entry_bar_index: number;\n /** Time of the entry, in UNIX milliseconds. */\n entry_time: number;\n /** undefined when the order had no comment, or when the engine does not keep it apart from the id. */\n entry_comment?: string;\n /** Signed quantity: positive for a long trade, negative for a short trade. */\n size: number;\n /** Profit of the trade in the account currency (negative for a loss), after commission. */\n profit: number;\n /** Profit of the trade in percent of its entry value. */\n profit_percent: number;\n /** Commission paid for the trade. */\n commission: number;\n /** Largest open profit the trade reached, in the account currency. */\n max_runup: number;\n /** Largest open profit in percent. */\n max_runup_percent: number;\n /** Largest open loss the trade reached, in the account currency. */\n max_drawdown: number;\n /** Largest open loss in percent. */\n max_drawdown_percent: number;\n /** Id of the order that closed the trade. */\n exit_id?: string;\n /** Price the exit filled at. */\n exit_price?: number;\n /** Bar number of the exit. */\n exit_bar_index?: number;\n /** Time of the exit, in UNIX milliseconds. */\n exit_time?: number;\n /** Comment of the exit order. */\n exit_comment?: string;\n}\n\n/** Numeric `strategy.*` variables. */\nexport const STRATEGY_NUMBER_VARIABLES = [\n 'position_size',\n 'position_avg_price',\n 'equity',\n 'initial_capital',\n 'netprofit',\n 'netprofit_percent',\n 'openprofit',\n 'openprofit_percent',\n 'grossprofit',\n 'grossprofit_percent',\n 'grossloss',\n 'grossloss_percent',\n 'opentrades',\n 'closedtrades',\n 'wintrades',\n 'losstrades',\n 'eventrades',\n 'avg_trade',\n 'avg_trade_percent',\n 'avg_winning_trade',\n 'avg_winning_trade_percent',\n 'avg_losing_trade',\n 'avg_losing_trade_percent',\n 'max_drawdown',\n 'max_drawdown_percent',\n 'max_runup',\n 'max_runup_percent',\n 'max_contracts_held_all',\n 'max_contracts_held_long',\n 'max_contracts_held_short',\n 'margin_liquidation_price',\n] as const;\n\n/** Text `strategy.*` variables. */\nexport const STRATEGY_TEXT_VARIABLES = ['position_entry_name', 'account_currency'] as const;\n\nexport type StrategyNumberVariable = (typeof STRATEGY_NUMBER_VARIABLES)[number];\nexport type StrategyTextVariable = (typeof STRATEGY_TEXT_VARIABLES)[number];\nexport type StrategyVariable = StrategyNumberVariable | StrategyTextVariable;\n\n/**\n * The order engine the host supplies. OakScriptJS calls it in this order on each bar `i` of\n * `strategy.eachBar()`:\n *\n * 1. `processBar(i)`: fill the orders placed before bar `i` (at the open and inside the bar);\n * 2. the script runs at the close of bar `i`: order calls and variable reads;\n * 3. `processClose(i)`: after the script; with `process_orders_on_close`, fill the new market orders\n * at the close.\n */\nexport interface StrategyEngine {\n processBar(bar: number): void;\n processClose(bar: number): void;\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 /** Current value of a `strategy.*` variable; undefined when the engine does not provide it. */\n get(variable: StrategyVariable): number | string | undefined;\n /** Open trade number `index` (0 = oldest); undefined when it does not exist. */\n openTrade(index: number): StrategyTrade | undefined;\n /** Closed trade number `index` (0 = oldest); undefined when it does not exist. */\n closedTrade(index: number): StrategyTrade | undefined;\n /** `strategy.risk.*` rules; optional. */\n risk?(rule: StrategyRiskRule): void;\n /** `strategy.default_entry_qty(fill_price)`; optional. */\n defaultEntryQty?(fillPrice: number): number;\n /**\n * The engine state at the end of a bar (orders, positions, trades, equity), for an incremental script run\n * (createScriptRun, #196); optional. With {@link restore}, a live update of a strategy calculates the newest bars\n * only: the engine of the next run gets the state of the last confirmed bar. Without them, every update is a full run.\n */\n save?(): unknown;\n /** Puts back a state given by {@link save} (on a new engine of the same script and bars). */\n restore?(state: unknown): void;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,qBAAqB;AAAA,EAChC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB,YAAY,EAAE,SAAS,WAAW,mBAAmB,qBAAqB,gBAAgB,iBAAiB;AAAA,EAC3G,WAAW,EAAE,KAAK,OAAO,MAAM,QAAQ,OAAO,QAAQ;AAAA,EACtD,KAAK,EAAE,MAAM,QAAQ,QAAQ,UAAU,QAAQ,SAAS;AAC1D;AAiHO,MAAM,oBAAwC;AAAA,EACnD,YAAY;AAAA,EACZ,qBAAqB;AAAA,EACrB,oBAAoB;AAAA,EACpB,4BAA4B;AAAA,EAC5B,iCAAiC;AAAA;AAAA,EAEjC,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB,UAAU;AA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