oakscriptjs 0.15.3 → 0.16.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 (144) hide show
  1. package/dist/cjs/check/format.d.ts.map +1 -1
  2. package/dist/cjs/check/format.js +5 -0
  3. package/dist/cjs/check/format.js.map +2 -2
  4. package/dist/cjs/check/harness.d.ts +24 -0
  5. package/dist/cjs/check/harness.d.ts.map +1 -1
  6. package/dist/cjs/check/harness.js +33 -0
  7. package/dist/cjs/check/harness.js.map +2 -2
  8. package/dist/cjs/check/index.d.ts +9 -0
  9. package/dist/cjs/check/index.d.ts.map +1 -1
  10. package/dist/cjs/check/index.js +7 -0
  11. package/dist/cjs/check/index.js.map +2 -2
  12. package/dist/cjs/color/index.d.ts.map +1 -1
  13. package/dist/cjs/color/index.js +19 -2
  14. package/dist/cjs/color/index.js.map +2 -2
  15. package/dist/cjs/color/parse.d.ts +8 -6
  16. package/dist/cjs/color/parse.d.ts.map +1 -1
  17. package/dist/cjs/color/parse.js +15 -2
  18. package/dist/cjs/color/parse.js.map +2 -2
  19. package/dist/cjs/drawing/registry.d.ts +68 -0
  20. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  21. package/dist/cjs/drawing/registry.js +99 -9
  22. package/dist/cjs/drawing/registry.js.map +2 -2
  23. package/dist/cjs/index.d.ts +3 -2
  24. package/dist/cjs/index.d.ts.map +1 -1
  25. package/dist/cjs/index.js +5 -1
  26. package/dist/cjs/index.js.map +2 -2
  27. package/dist/cjs/runtime/series.d.ts +16 -0
  28. package/dist/cjs/runtime/series.d.ts.map +1 -1
  29. package/dist/cjs/runtime/series.js +19 -2
  30. package/dist/cjs/runtime/series.js.map +2 -2
  31. package/dist/cjs/script/closure-writes.d.ts +16 -0
  32. package/dist/cjs/script/closure-writes.d.ts.map +1 -0
  33. package/dist/cjs/script/closure-writes.js +435 -0
  34. package/dist/cjs/script/closure-writes.js.map +7 -0
  35. package/dist/cjs/script/globals.d.ts +2 -0
  36. package/dist/cjs/script/globals.d.ts.map +1 -1
  37. package/dist/cjs/script/globals.js.map +1 -1
  38. package/dist/cjs/script/incremental.d.ts +140 -0
  39. package/dist/cjs/script/incremental.d.ts.map +1 -0
  40. package/dist/cjs/script/incremental.js +142 -0
  41. package/dist/cjs/script/incremental.js.map +7 -0
  42. package/dist/cjs/script/index.d.ts +116 -31
  43. package/dist/cjs/script/index.d.ts.map +1 -1
  44. package/dist/cjs/script/index.js +471 -25
  45. package/dist/cjs/script/index.js.map +3 -3
  46. package/dist/cjs/str/numberformat.d.ts.map +1 -1
  47. package/dist/cjs/str/numberformat.js +23 -0
  48. package/dist/cjs/str/numberformat.js.map +2 -2
  49. package/dist/cjs/strategy/index.d.ts +8 -0
  50. package/dist/cjs/strategy/index.d.ts.map +1 -1
  51. package/dist/cjs/strategy/index.js.map +1 -1
  52. package/dist/cjs/ta/running-sum.d.ts.map +1 -1
  53. package/dist/cjs/ta/running-sum.js +72 -3
  54. package/dist/cjs/ta/running-sum.js.map +2 -2
  55. package/dist/cjs/ta/step.d.ts +476 -0
  56. package/dist/cjs/ta/step.d.ts.map +1 -0
  57. package/dist/cjs/ta/step.js +1000 -0
  58. package/dist/cjs/ta/step.js.map +7 -0
  59. package/dist/cjs/ta-series.d.ts +1 -1
  60. package/dist/cjs/ta-series.js +3 -3
  61. package/dist/cjs/ta-series.js.map +1 -1
  62. package/dist/esm/check/format.d.ts.map +1 -1
  63. package/dist/esm/check/format.js +5 -0
  64. package/dist/esm/check/format.js.map +1 -1
  65. package/dist/esm/check/harness.d.ts +24 -0
  66. package/dist/esm/check/harness.d.ts.map +1 -1
  67. package/dist/esm/check/harness.js +40 -6
  68. package/dist/esm/check/harness.js.map +1 -1
  69. package/dist/esm/check/index.d.ts +9 -0
  70. package/dist/esm/check/index.d.ts.map +1 -1
  71. package/dist/esm/check/index.js +11 -1
  72. package/dist/esm/check/index.js.map +1 -1
  73. package/dist/esm/color/index.d.ts.map +1 -1
  74. package/dist/esm/color/index.js +23 -3
  75. package/dist/esm/color/index.js.map +1 -1
  76. package/dist/esm/color/parse.d.ts +8 -6
  77. package/dist/esm/color/parse.d.ts.map +1 -1
  78. package/dist/esm/color/parse.js +19 -2
  79. package/dist/esm/color/parse.js.map +1 -1
  80. package/dist/esm/drawing/registry.d.ts +68 -0
  81. package/dist/esm/drawing/registry.d.ts.map +1 -1
  82. package/dist/esm/drawing/registry.js +156 -10
  83. package/dist/esm/drawing/registry.js.map +1 -1
  84. package/dist/esm/index.d.ts +3 -2
  85. package/dist/esm/index.d.ts.map +1 -1
  86. package/dist/esm/index.js +6 -3
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/runtime/series.d.ts +16 -0
  89. package/dist/esm/runtime/series.d.ts.map +1 -1
  90. package/dist/esm/runtime/series.js +21 -1
  91. package/dist/esm/runtime/series.js.map +1 -1
  92. package/dist/esm/script/closure-writes.d.ts +16 -0
  93. package/dist/esm/script/closure-writes.d.ts.map +1 -0
  94. package/dist/esm/script/closure-writes.js +323 -0
  95. package/dist/esm/script/closure-writes.js.map +1 -0
  96. package/dist/esm/script/globals.d.ts +2 -0
  97. package/dist/esm/script/globals.d.ts.map +1 -1
  98. package/dist/esm/script/globals.js.map +1 -1
  99. package/dist/esm/script/incremental.d.ts +140 -0
  100. package/dist/esm/script/incremental.d.ts.map +1 -0
  101. package/dist/esm/script/incremental.js +173 -0
  102. package/dist/esm/script/incremental.js.map +1 -0
  103. package/dist/esm/script/index.d.ts +116 -31
  104. package/dist/esm/script/index.d.ts.map +1 -1
  105. package/dist/esm/script/index.js +561 -24
  106. package/dist/esm/script/index.js.map +1 -1
  107. package/dist/esm/str/numberformat.d.ts.map +1 -1
  108. package/dist/esm/str/numberformat.js +30 -0
  109. package/dist/esm/str/numberformat.js.map +1 -1
  110. package/dist/esm/strategy/index.d.ts +8 -0
  111. package/dist/esm/strategy/index.d.ts.map +1 -1
  112. package/dist/esm/ta/running-sum.d.ts.map +1 -1
  113. package/dist/esm/ta/running-sum.js +79 -4
  114. package/dist/esm/ta/running-sum.js.map +1 -1
  115. package/dist/esm/ta/step.d.ts +476 -0
  116. package/dist/esm/ta/step.d.ts.map +1 -0
  117. package/dist/esm/ta/step.js +1089 -0
  118. package/dist/esm/ta/step.js.map +1 -0
  119. package/dist/esm/ta-series.d.ts +1 -1
  120. package/dist/esm/ta-series.js +4 -4
  121. package/package.json +1 -1
  122. package/skills/oakscript/SKILL.md +2 -2
  123. package/skills/oakscript/reference/check.md +5 -0
  124. package/skills/oakscript/reference/errors.md +0 -1
  125. package/skills/oakscript/reference/pine-differences.md +1 -2
  126. package/skills/oakscript/reference/plotting.md +5 -7
  127. package/skills/oakscript/reference/script-structure.md +6 -0
  128. package/src/check/format.ts +7 -0
  129. package/src/check/harness.ts +57 -0
  130. package/src/check/index.ts +16 -0
  131. package/src/color/index.ts +22 -3
  132. package/src/color/parse.ts +28 -3
  133. package/src/drawing/registry.ts +172 -10
  134. package/src/index.ts +9 -2
  135. package/src/runtime/series.ts +33 -1
  136. package/src/script/closure-writes.ts +279 -0
  137. package/src/script/globals.ts +2 -0
  138. package/src/script/incremental.ts +246 -0
  139. package/src/script/index.ts +695 -26
  140. package/src/str/numberformat.ts +29 -0
  141. package/src/strategy/index.ts +8 -0
  142. package/src/ta/running-sum.ts +78 -3
  143. package/src/ta/step.ts +1145 -0
  144. package/src/ta-series.ts +4 -4
@@ -0,0 +1,1089 @@
1
+ /**
2
+ * ta.* functions one bar at a time (#196).
3
+ *
4
+ * Each machine is the state of one ta.* call. {@link BarStep.step} gives the result of the current bar from the kept
5
+ * state of the earlier bars, without changing it: calling it again on the same bar (a live update of the forming bar,
6
+ * or the same call in a loop) starts again from the same state. {@link BarStep.commit} ends the bar: its last step is
7
+ * kept for the next bars. A bar without a step is not in the history of the call (a call in an `if` block), and a
8
+ * commit without a step does nothing.
9
+ *
10
+ * Driven once per bar over an array (step, commit), a machine gives the doubles of the array function of `ta`, bit for
11
+ * bit (tests/ta/step.test.ts): the same rules for na and ±Infinity, the same operation order.
12
+ */
13
+ import { RunningSum, isNa } from './running-sum.js';
14
+ import { checkPositiveLength, checkSumLength, checkWindowLength } from './limits.js';
15
+ import { eq, ge, gt, le } from '../compare/index.js';
16
+ /** A value ta.* functions skip: na (NaN, null, undefined) or ±Infinity. */
17
+ const skipped = (v) => v === undefined || v === null || !Number.isFinite(v);
18
+ // ── Window sums ──────────────────────────────────────────────────────────────
19
+ /**
20
+ * `math.sum(source, length)`: the correctly rounded sum of the last `length` non-na values; a bar with an na value
21
+ * keeps the previous result. The length can change from one bar to the next (series length).
22
+ */
23
+ export class SumStep {
24
+ sum = new RunningSum();
25
+ stepped = false;
26
+ step(value, length) {
27
+ const len = Math.floor(length);
28
+ this.stepped = len >= 1;
29
+ if (!this.stepped)
30
+ return NaN;
31
+ return isNa(value) ? this.sum.stepNa(len) : this.sum.step(value, len);
32
+ }
33
+ commit() {
34
+ if (this.stepped)
35
+ this.sum.commit();
36
+ this.stepped = false;
37
+ }
38
+ /** Forget the steps of the current bar (the bar is not in the history) */
39
+ discard() {
40
+ this.stepped = false;
41
+ }
42
+ }
43
+ /** `ta.sma(source, length)`: {@link SumStep} divided by the length. */
44
+ export class SmaStep {
45
+ sum = new SumStep();
46
+ step(value, length) {
47
+ checkSumLength('ta.sma', Math.floor(length), 0);
48
+ return this.sum.step(value, length) / Math.floor(length);
49
+ }
50
+ commit() {
51
+ this.sum.commit();
52
+ }
53
+ }
54
+ /**
55
+ * `ta.variance(source, length, biased)` from the window sums of the values and of their squares: biased
56
+ * `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)` (na for a length of 1).
57
+ */
58
+ export class VarianceStep {
59
+ name;
60
+ sums = new SumStep();
61
+ squares = new SumStep();
62
+ constructor(name = 'ta.variance') {
63
+ this.name = name;
64
+ }
65
+ step(value, length, biased = true) {
66
+ const len = Math.floor(length);
67
+ checkSumLength(this.name, len, 0);
68
+ const sum = this.sums.step(value, len);
69
+ const sq = this.squares.step(isNa(value) ? NaN : value * value, len);
70
+ if ((biased ? len : len - 1) <= 0)
71
+ return NaN;
72
+ const mean = sum / len;
73
+ return biased ? sq / len - mean * mean : sq / (len - 1) - (mean * sum) / (len - 1);
74
+ }
75
+ commit() {
76
+ this.sums.commit();
77
+ this.squares.commit();
78
+ }
79
+ }
80
+ /** `ta.stdev(source, length, biased)`: the square root of {@link VarianceStep} (0 when it is not positive). */
81
+ export class StdevStep {
82
+ variance = new VarianceStep('ta.stdev');
83
+ step(value, length, biased = true) {
84
+ const v = this.variance.step(value, length, biased);
85
+ return Number.isNaN(v) ? NaN : v > 0 ? Math.sqrt(v) : 0;
86
+ }
87
+ commit() {
88
+ this.variance.commit();
89
+ }
90
+ }
91
+ // ── Moving averages ──────────────────────────────────────────────────────────
92
+ /**
93
+ * Exponential averages seeded with `ta.sma` on the bar of the `length`-th non-na value (ta.ema, ta.rma); a bar with an
94
+ * na value gives na and keeps the state.
95
+ */
96
+ class SeededAverage {
97
+ seed = new SumStep();
98
+ value = NaN;
99
+ count = 0;
100
+ stepped = false;
101
+ /** The last step of the bar added its value to the seed sum */
102
+ seeded = false;
103
+ nextValue = NaN;
104
+ nextCount = 0;
105
+ len;
106
+ constructor(name, length) {
107
+ checkPositiveLength(name, length, 0);
108
+ this.len = Math.floor(length);
109
+ }
110
+ step(value) {
111
+ this.stepped = true;
112
+ this.seeded = false;
113
+ this.nextValue = this.value;
114
+ this.nextCount = this.count;
115
+ if (skipped(value))
116
+ return NaN;
117
+ this.nextCount = this.count + 1;
118
+ if (this.count < this.len) {
119
+ this.seeded = true;
120
+ const s = this.seed.step(value, this.len);
121
+ if (this.nextCount < this.len)
122
+ return NaN;
123
+ this.nextValue = s / this.len;
124
+ return this.nextValue;
125
+ }
126
+ this.nextValue = this.next(value, this.value);
127
+ return this.nextValue;
128
+ }
129
+ commit() {
130
+ if (!this.stepped)
131
+ return;
132
+ this.stepped = false;
133
+ if (this.seeded)
134
+ this.seed.commit();
135
+ else
136
+ this.seed.discard();
137
+ this.value = this.nextValue;
138
+ this.count = this.nextCount;
139
+ }
140
+ }
141
+ /** `ta.ema(source, length)`: `(source - ema) * 2 / (length + 1) + ema` after the seed. */
142
+ export class EmaStep extends SeededAverage {
143
+ multiplier;
144
+ constructor(length) {
145
+ super('ema', length);
146
+ this.multiplier = 2 / (this.len + 1);
147
+ }
148
+ next(value, previous) {
149
+ return (value - previous) * this.multiplier + previous;
150
+ }
151
+ }
152
+ /** `ta.rma(source, length)`: `(source + (length - 1) * rma) / length` after the seed. */
153
+ export class RmaStep extends SeededAverage {
154
+ constructor(length, name = 'rma') {
155
+ super(name, length);
156
+ }
157
+ next(value, previous) {
158
+ return (value + (this.len - 1) * previous) / this.len;
159
+ }
160
+ }
161
+ /** The PineScript ta.wma partial sum: `a + b`, 0 when `|a + b| <= 1e-10 * max(1, |a| + |b|)`. */
162
+ function wmaAdd(a, b) {
163
+ const sum = a + b;
164
+ return Math.abs(sum) <= 1e-10 * Math.max(1, Math.abs(a) + Math.abs(b)) ? 0 : sum;
165
+ }
166
+ /**
167
+ * `ta.wma(source, length)`: na on a bar with an na value and until `length` non-na values; otherwise the last `length`
168
+ * bars (an na bar holds the previous non-na value), summed from the oldest with the PineScript zero rule.
169
+ */
170
+ export class WmaStep {
171
+ filled = [];
172
+ last = NaN;
173
+ count = 0;
174
+ stepped = false;
175
+ nextFilled = NaN;
176
+ nextValid = false;
177
+ step(value, length) {
178
+ const len = Math.floor(length);
179
+ checkPositiveLength('wma', len, this.filled.length);
180
+ this.stepped = true;
181
+ const na = skipped(value);
182
+ this.nextValid = !na;
183
+ this.nextFilled = na ? this.last : value;
184
+ if (na || !(len >= 1) || this.count + 1 < len)
185
+ return NaN;
186
+ const n = this.filled.length;
187
+ let sum = 0;
188
+ let weightSum = 0;
189
+ for (let j = len - 1; j >= 0; j--) {
190
+ const weight = len - j;
191
+ sum = wmaAdd(sum, (j === 0 ? this.nextFilled : this.filled[n - j]) * weight);
192
+ weightSum += weight;
193
+ }
194
+ return sum / weightSum;
195
+ }
196
+ commit() {
197
+ if (!this.stepped)
198
+ return;
199
+ this.stepped = false;
200
+ if (this.nextValid) {
201
+ this.last = this.nextFilled;
202
+ this.count++;
203
+ }
204
+ this.filled.push(this.nextFilled);
205
+ }
206
+ }
207
+ // ── Changes ──────────────────────────────────────────────────────────────────
208
+ /** The values of the earlier bars of a call (one per bar with a step), for the `source[length]` of ta.change & co. */
209
+ class HistoryStep {
210
+ history = [];
211
+ stepped = false;
212
+ pending = NaN;
213
+ /** The current bar's value, kept by commit() */
214
+ keep(value) {
215
+ this.stepped = true;
216
+ this.pending = value;
217
+ }
218
+ /** The value `k` bars back (k >= 1), NaN before the first bar */
219
+ back(k) {
220
+ const i = this.history.length - k;
221
+ return i >= 0 ? this.history[i] : NaN;
222
+ }
223
+ commit() {
224
+ if (!this.stepped)
225
+ return;
226
+ this.stepped = false;
227
+ this.history.push(this.pending);
228
+ }
229
+ }
230
+ /** `ta.change(source, length)`: `source - source[length]` (na for the first `length` bars). */
231
+ export class ChangeStep extends HistoryStep {
232
+ length;
233
+ constructor(length = 1) {
234
+ super();
235
+ this.length = length;
236
+ checkPositiveLength('change', length, 0);
237
+ }
238
+ step(value) {
239
+ this.keep(value);
240
+ return this.history.length < this.length ? NaN : value - this.back(this.length);
241
+ }
242
+ }
243
+ /** `ta.mom(source, length)`: `source - source[length]`, na when either is na. */
244
+ export class MomStep extends HistoryStep {
245
+ length;
246
+ constructor(length) {
247
+ super();
248
+ this.length = length;
249
+ checkPositiveLength('mom', length, 0);
250
+ }
251
+ step(value) {
252
+ this.keep(value);
253
+ if (this.history.length < this.length)
254
+ return NaN;
255
+ const old = this.back(this.length);
256
+ return Number.isNaN(value) || Number.isNaN(old) ? NaN : value - old;
257
+ }
258
+ }
259
+ /** `ta.roc(source, length)`: `100 * (source - source[length]) / source[length]` (a zero base gives ±Infinity). */
260
+ export class RocStep extends HistoryStep {
261
+ length;
262
+ constructor(length) {
263
+ super();
264
+ this.length = length;
265
+ checkPositiveLength('roc', length, 0);
266
+ }
267
+ step(value) {
268
+ this.keep(value);
269
+ if (this.history.length < this.length)
270
+ return NaN;
271
+ const old = this.back(this.length);
272
+ if (Number.isNaN(old) || Number.isNaN(value))
273
+ return NaN;
274
+ return (100 * (value - old)) / old;
275
+ }
276
+ }
277
+ /** `ta.tr(handle_na)`: max(high - low, |high - close[1]|, |low - close[1]|); on the first bar or after an na close, na
278
+ * (or high - low with handle_na). */
279
+ export class TrStep extends HistoryStep {
280
+ handleNa;
281
+ constructor(handleNa = false) {
282
+ super();
283
+ this.handleNa = handleNa;
284
+ }
285
+ step(high, low, close) {
286
+ this.keep(close);
287
+ const prev = this.back(1);
288
+ if (this.history.length === 0 || Number.isNaN(prev))
289
+ return this.handleNa ? high - low : NaN;
290
+ return Math.max(high - low, Math.abs(high - prev), Math.abs(low - prev));
291
+ }
292
+ }
293
+ /** `ta.atr(length)`: {@link RmaStep} of `ta.tr(true)`. */
294
+ export class AtrStep {
295
+ tr = new TrStep(true);
296
+ rma;
297
+ constructor(length) {
298
+ checkPositiveLength('atr->rma', length, 0);
299
+ this.rma = new RmaStep(length, 'atr->rma');
300
+ }
301
+ step(high, low, close) {
302
+ return this.rma.step(this.tr.step(high, low, close));
303
+ }
304
+ commit() {
305
+ this.tr.commit();
306
+ this.rma.commit();
307
+ }
308
+ }
309
+ /**
310
+ * `ta.rsi(source, length)`: the rma of the gains and of the losses of the changes from the previous bar; 100 when the
311
+ * average loss is 0, else 0 when the average gain is 0 (comparisons with the 1e-10 tolerance).
312
+ */
313
+ export class RsiStep extends HistoryStep {
314
+ gains;
315
+ losses;
316
+ constructor(length) {
317
+ super();
318
+ checkPositiveLength('rsi', length, 0, 'y');
319
+ this.gains = new RmaStep(length);
320
+ this.losses = new RmaStep(length);
321
+ }
322
+ step(value) {
323
+ this.keep(value);
324
+ if (this.history.length === 0)
325
+ return NaN;
326
+ const c = value - this.back(1);
327
+ const up = this.gains.step(Number.isNaN(c) ? NaN : c > 0 ? c : 0);
328
+ const down = this.losses.step(Number.isNaN(c) ? NaN : c < 0 ? -c : 0);
329
+ if (eq(down, 0))
330
+ return 100;
331
+ if (eq(up, 0))
332
+ return 0;
333
+ return 100 - 100 / (1 + up / down);
334
+ }
335
+ commit() {
336
+ super.commit();
337
+ this.gains.commit();
338
+ this.losses.commit();
339
+ }
340
+ }
341
+ // ── Running state ────────────────────────────────────────────────────────────
342
+ /** `ta.cum(source)`: the sum of the non-na values; na on a bar with an na value. */
343
+ export class CumStep {
344
+ sum = 0;
345
+ next = 0;
346
+ stepped = false;
347
+ step(value) {
348
+ this.stepped = true;
349
+ this.next = this.sum;
350
+ if (!Number.isFinite(value))
351
+ return NaN;
352
+ this.next = this.sum + value;
353
+ return this.next;
354
+ }
355
+ commit() {
356
+ if (this.stepped)
357
+ this.sum = this.next;
358
+ this.stepped = false;
359
+ }
360
+ }
361
+ /** Compared with the last earlier bar where both values were not na (ta.crossover, ta.crossunder). */
362
+ class CrossTestStep {
363
+ test;
364
+ prevA = NaN;
365
+ prevB = NaN;
366
+ nextA = NaN;
367
+ nextB = NaN;
368
+ stepped = false;
369
+ constructor(test) {
370
+ this.test = test;
371
+ }
372
+ step(a, b) {
373
+ this.stepped = true;
374
+ const both = !Number.isNaN(a) && !Number.isNaN(b);
375
+ this.nextA = both ? a : this.prevA;
376
+ this.nextB = both ? b : this.prevB;
377
+ return this.test(a, b, this.prevA, this.prevB);
378
+ }
379
+ commit() {
380
+ if (!this.stepped)
381
+ return;
382
+ this.stepped = false;
383
+ this.prevA = this.nextA;
384
+ this.prevB = this.nextB;
385
+ }
386
+ }
387
+ /** `ta.crossover(a, b)` */
388
+ export class CrossoverStep extends CrossTestStep {
389
+ constructor() {
390
+ super((a, b, pa, pb) => a > b && pa <= pb);
391
+ }
392
+ }
393
+ /** `ta.crossunder(a, b)` */
394
+ export class CrossunderStep extends CrossTestStep {
395
+ constructor() {
396
+ super((a, b, pa, pb) => a < b && pa >= pb);
397
+ }
398
+ }
399
+ /** `ta.cross(a, b)`: true when the values are strictly on the other side of the last strict side. */
400
+ export class CrossStep {
401
+ side = 0;
402
+ next = 0;
403
+ stepped = false;
404
+ step(a, b) {
405
+ this.stepped = true;
406
+ this.next = this.side;
407
+ if (Number.isNaN(a) || Number.isNaN(b))
408
+ return false;
409
+ const crossed = (this.side < 0 && a > b) || (this.side > 0 && a < b);
410
+ if (a < b)
411
+ this.next = -1;
412
+ else if (a > b)
413
+ this.next = 1;
414
+ return crossed;
415
+ }
416
+ commit() {
417
+ if (this.stepped)
418
+ this.side = this.next;
419
+ this.stepped = false;
420
+ }
421
+ }
422
+ /** `ta.barssince(condition)`: 0 on a true bar, then +1 per bar; na before the first true bar. */
423
+ export class BarssinceStep {
424
+ value = NaN;
425
+ next = NaN;
426
+ stepped = false;
427
+ step(condition) {
428
+ this.stepped = true;
429
+ this.next = condition ? 0 : Number.isNaN(this.value) ? NaN : this.value + 1;
430
+ return this.next;
431
+ }
432
+ commit() {
433
+ if (this.stepped)
434
+ this.value = this.next;
435
+ this.stepped = false;
436
+ }
437
+ }
438
+ /** `ta.valuewhen(condition, source, occurrence)`: the source value of the `occurrence`-th last true bar (0: the last). */
439
+ export class ValuewhenStep {
440
+ occurrence;
441
+ values = [];
442
+ pending = null;
443
+ stepped = false;
444
+ constructor(occurrence) {
445
+ this.occurrence = occurrence;
446
+ }
447
+ step(condition, value) {
448
+ this.stepped = true;
449
+ this.pending = condition ? value : null;
450
+ const n = this.values.length + (condition ? 1 : 0);
451
+ const k = n - 1 - this.occurrence;
452
+ if (k < 0 || k >= n)
453
+ return NaN;
454
+ return k === this.values.length ? value : (this.values[k] ?? NaN);
455
+ }
456
+ commit() {
457
+ if (this.stepped && this.pending !== null)
458
+ this.values.push(this.pending);
459
+ this.stepped = false;
460
+ this.pending = null;
461
+ }
462
+ }
463
+ /** `ta.obv`: the cumulated `sign(close - close[1]) * volume` (na on the first bar). */
464
+ export class ObvStep extends HistoryStep {
465
+ cum = new CumStep();
466
+ step(close, volume) {
467
+ this.keep(close);
468
+ return this.cum.step(this.history.length === 0 ? NaN : Math.sign(close - this.back(1)) * volume);
469
+ }
470
+ commit() {
471
+ super.commit();
472
+ this.cum.commit();
473
+ }
474
+ }
475
+ // ── Window extremes ──────────────────────────────────────────────────────────
476
+ /**
477
+ * `ta.highest` / `ta.lowest`: the extreme of the last `length` non-na values (all of them when fewer), also on a bar
478
+ * whose own value is na; na before bar `length - 1` and while no value was received. Math.max / Math.min of the
479
+ * window: +0 wins over -0 for the highest, -0 for the lowest.
480
+ */
481
+ class ExtremeStep {
482
+ lowest;
483
+ values = [];
484
+ bars = 0;
485
+ pending = NaN;
486
+ stepped = false;
487
+ constructor(lowest) {
488
+ this.lowest = lowest;
489
+ }
490
+ step(value, length) {
491
+ checkWindowLength(this.lowest ? 'lowest' : 'highest', length, this.bars);
492
+ this.stepped = true;
493
+ this.pending = value;
494
+ const len = Math.trunc(length);
495
+ const own = !skipped(value);
496
+ const n = this.values.length + (own ? 1 : 0);
497
+ if (this.bars < len - 1 || n === 0)
498
+ return NaN;
499
+ let best = own ? value : this.values[n - 1];
500
+ const from = Math.max(0, n - len);
501
+ for (let i = from; i < this.values.length; i++) {
502
+ const v = this.values[i];
503
+ best = this.lowest ? Math.min(best, v) : Math.max(best, v);
504
+ }
505
+ return best;
506
+ }
507
+ commit() {
508
+ if (!this.stepped)
509
+ return;
510
+ this.stepped = false;
511
+ this.bars++;
512
+ if (!skipped(this.pending))
513
+ this.values.push(this.pending);
514
+ }
515
+ }
516
+ /** `ta.highest(source, length)` */
517
+ export class HighestStep extends ExtremeStep {
518
+ constructor() {
519
+ super(false);
520
+ }
521
+ }
522
+ /** `ta.lowest(source, length)` */
523
+ export class LowestStep extends ExtremeStep {
524
+ constructor() {
525
+ super(true);
526
+ }
527
+ }
528
+ // ── Composites ───────────────────────────────────────────────────────────────
529
+ /** `ta.macd(source, fast, slow, signal)`: `[macd, signal, histogram]`. */
530
+ export class MacdStep {
531
+ fast;
532
+ slow;
533
+ signal;
534
+ constructor(fastLength, slowLength, signalLength) {
535
+ this.fast = new EmaStep(fastLength);
536
+ this.slow = new EmaStep(slowLength);
537
+ this.signal = new EmaStep(signalLength);
538
+ }
539
+ step(value) {
540
+ const line = this.fast.step(value) - this.slow.step(value);
541
+ const signal = this.signal.step(line);
542
+ return [line, signal, line - signal];
543
+ }
544
+ commit() {
545
+ this.fast.commit();
546
+ this.slow.commit();
547
+ this.signal.commit();
548
+ }
549
+ }
550
+ /** `ta.bb(source, length, mult)`: `[basis, upper, lower]`. */
551
+ export class BbStep {
552
+ mult;
553
+ basis = new SumStep();
554
+ dev = new StdevStep();
555
+ len;
556
+ constructor(length, mult) {
557
+ this.mult = mult;
558
+ checkSumLength('ta.bb', length, 0);
559
+ this.len = Math.floor(length);
560
+ }
561
+ step(value) {
562
+ const basis = this.basis.step(value, this.len) / this.len;
563
+ const dev = this.dev.step(value, this.len);
564
+ return [basis, basis + this.mult * dev, basis - this.mult * dev];
565
+ }
566
+ commit() {
567
+ this.basis.commit();
568
+ this.dev.commit();
569
+ }
570
+ }
571
+ /** `ta.vwma(source, length)`: `sma(source * volume) / sma(volume)`, na when the volume average is 0 or na. */
572
+ export class VwmaStep {
573
+ numerator = new SumStep();
574
+ denominator = new SumStep();
575
+ len;
576
+ constructor(length) {
577
+ checkPositiveLength('vwma->sma', length, 0);
578
+ this.len = Math.floor(length);
579
+ }
580
+ step(value, volume) {
581
+ checkSumLength('ta.sma', this.len, 0);
582
+ const num = this.numerator.step(value * volume, this.len) / this.len;
583
+ const den = this.denominator.step(volume, this.len) / this.len;
584
+ return den === 0 || Number.isNaN(den) ? NaN : num / den;
585
+ }
586
+ commit() {
587
+ this.numerator.commit();
588
+ this.denominator.commit();
589
+ }
590
+ }
591
+ /**
592
+ * `ta.stoch(source, high, low, length)`: `100 * (source - lowest(low)) / (highest(high) - lowest(low))`; an na result
593
+ * keeps the previous one.
594
+ */
595
+ export class StochStep {
596
+ length;
597
+ highest = new HighestStep();
598
+ lowest = new LowestStep();
599
+ previous = NaN;
600
+ next = NaN;
601
+ stepped = false;
602
+ constructor(length) {
603
+ this.length = length;
604
+ checkPositiveLength('stoch->highest', length, 0);
605
+ }
606
+ step(source, high, low) {
607
+ this.stepped = true;
608
+ const lo = this.lowest.step(low, this.length);
609
+ const k = (100 * (source - lo)) / (this.highest.step(high, this.length) - lo);
610
+ this.next = Number.isNaN(k) ? this.previous : k;
611
+ return this.next;
612
+ }
613
+ commit() {
614
+ if (!this.stepped)
615
+ return;
616
+ this.stepped = false;
617
+ this.previous = this.next;
618
+ this.highest.commit();
619
+ this.lowest.commit();
620
+ }
621
+ }
622
+ // ── More composites ──────────────────────────────────────────────────────────
623
+ /** `ta.hma(source, length)`: wma(2 * wma(source, length / 2) - wma(source, length), floor(sqrt(length))). */
624
+ export class HmaStep {
625
+ length;
626
+ half = new WmaStep();
627
+ full = new WmaStep();
628
+ outer = new WmaStep();
629
+ halfLength;
630
+ sqrtLength;
631
+ constructor(length) {
632
+ this.length = length;
633
+ checkPositiveLength('hma', length, 0);
634
+ this.halfLength = Math.floor(length / 2);
635
+ this.sqrtLength = Math.floor(Math.sqrt(length));
636
+ }
637
+ step(value) {
638
+ const diff = 2 * this.half.step(value, this.halfLength) - this.full.step(value, this.length);
639
+ return this.outer.step(diff, this.sqrtLength);
640
+ }
641
+ commit() {
642
+ this.half.commit();
643
+ this.full.commit();
644
+ this.outer.commit();
645
+ }
646
+ }
647
+ /** `ta.dev(source, length)`: the mean of |source - sma| over the last `length` bars (na until bar length - 1). */
648
+ export class DevStep extends HistoryStep {
649
+ mean = new SmaStep();
650
+ len;
651
+ constructor(length) {
652
+ super();
653
+ checkPositiveLength('dev', length, 0);
654
+ this.len = Math.floor(length);
655
+ }
656
+ step(value) {
657
+ this.keep(value);
658
+ const mean = this.mean.step(value, this.len);
659
+ if (this.history.length < this.len - 1 || Number.isNaN(mean))
660
+ return NaN;
661
+ let sum = 0;
662
+ for (let k = 0; k < this.len; k++)
663
+ sum += Math.abs((k === 0 ? value : this.back(k)) - mean);
664
+ return sum / this.len;
665
+ }
666
+ commit() {
667
+ super.commit();
668
+ this.mean.commit();
669
+ }
670
+ }
671
+ /** `ta.cci(source, length)`: (source - sma) / (0.015 * dev); a zero dev keeps the previous value (0 at the start). */
672
+ export class CciStep {
673
+ length;
674
+ mean = new SmaStep();
675
+ dev;
676
+ last = 0;
677
+ next = 0;
678
+ stepped = false;
679
+ constructor(length) {
680
+ this.length = length;
681
+ checkPositiveLength('cci', length, 0);
682
+ this.dev = new DevStep(length);
683
+ }
684
+ step(value) {
685
+ this.stepped = true;
686
+ this.next = this.last;
687
+ const mean = this.mean.step(value, this.length);
688
+ const d = this.dev.step(value);
689
+ if (Number.isNaN(mean) || Number.isNaN(d))
690
+ return NaN;
691
+ if (!eq(d, 0))
692
+ this.next = (value - mean) / (0.015 * d);
693
+ return this.next;
694
+ }
695
+ commit() {
696
+ if (this.stepped)
697
+ this.last = this.next;
698
+ this.stepped = false;
699
+ this.mean.commit();
700
+ this.dev.commit();
701
+ }
702
+ }
703
+ /** `ta.mfi(source, length)`: the window sums of the money flow of the up and down bars. */
704
+ export class MfiStep extends HistoryStep {
705
+ length;
706
+ upper = new SumStep();
707
+ lower = new SumStep();
708
+ constructor(length) {
709
+ super();
710
+ this.length = length;
711
+ checkPositiveLength('mfi', length, 0);
712
+ }
713
+ step(value, volume) {
714
+ this.keep(value);
715
+ const change = this.history.length === 0 ? NaN : value - this.back(1);
716
+ const flow = volume * value;
717
+ const zero = (x) => (Math.abs(x) <= 1e-10 ? 0 : x);
718
+ const u = zero(this.upper.step(le(change, 0) ? 0 : flow, this.length));
719
+ const l = zero(this.lower.step(ge(change, 0) ? 0 : flow, this.length));
720
+ if (Number.isNaN(u) || Number.isNaN(l))
721
+ return NaN;
722
+ if (l === 0)
723
+ return 100;
724
+ const ratio = 1 + u / l;
725
+ return ratio === 0 ? NaN : 100 - 100 / ratio;
726
+ }
727
+ commit() {
728
+ super.commit();
729
+ this.upper.commit();
730
+ this.lower.commit();
731
+ }
732
+ }
733
+ /** `ta.dmi(diLength, adxSmoothing)`: [+DI, -DI, ADX]; a DI that cannot be computed keeps the previous one. */
734
+ export class DmiStep {
735
+ tr = new TrStep(false);
736
+ trur;
737
+ plus;
738
+ minus;
739
+ adx;
740
+ prevHigh = NaN;
741
+ prevLow = NaN;
742
+ bars = 0;
743
+ lastPlus = NaN;
744
+ lastMinus = NaN;
745
+ next = [NaN, NaN, NaN, NaN];
746
+ stepped = false;
747
+ constructor(diLength, adxSmoothing) {
748
+ this.trur = new RmaStep(diLength);
749
+ this.plus = new RmaStep(diLength);
750
+ this.minus = new RmaStep(diLength);
751
+ this.adx = new RmaStep(adxSmoothing);
752
+ }
753
+ step(high, low, close) {
754
+ this.stepped = true;
755
+ const up = this.bars === 0 ? NaN : high - this.prevHigh;
756
+ const down = this.bars === 0 ? NaN : this.prevLow - low;
757
+ const plusDM = Number.isNaN(up) ? NaN : gt(up, down) && gt(up, 0) ? up : 0;
758
+ const minusDM = Number.isNaN(down) ? NaN : gt(down, up) && gt(down, 0) ? down : 0;
759
+ const t = this.trur.step(this.tr.step(high, low, close));
760
+ const directional = (v, last) => {
761
+ const value = t === 0 ? NaN : (100 * v) / t;
762
+ return Number.isNaN(value) ? last : value;
763
+ };
764
+ const plus = directional(this.plus.step(plusDM), this.lastPlus);
765
+ const minus = directional(this.minus.step(minusDM), this.lastMinus);
766
+ const sum = plus + minus;
767
+ const dx = Math.abs(plus - minus) / (eq(sum, 0) ? 1 : sum);
768
+ const adx = 100 * this.adx.step(dx);
769
+ this.next = [plus, minus, high, low];
770
+ return [plus, minus, adx];
771
+ }
772
+ commit() {
773
+ if (!this.stepped)
774
+ return;
775
+ this.stepped = false;
776
+ [this.lastPlus, this.lastMinus, this.prevHigh, this.prevLow] = this.next;
777
+ this.bars++;
778
+ this.tr.commit();
779
+ this.trur.commit();
780
+ this.plus.commit();
781
+ this.minus.commit();
782
+ this.adx.commit();
783
+ }
784
+ }
785
+ /** `ta.linreg(source, length, offset)`: least squares line of the last `length` bars (na when one of them is NaN). */
786
+ export class LinregStep extends HistoryStep {
787
+ offset;
788
+ len;
789
+ constructor(length, offset = 0) {
790
+ super();
791
+ this.offset = offset;
792
+ checkPositiveLength('linreg', length, 0);
793
+ this.len = Math.floor(length);
794
+ }
795
+ step(value) {
796
+ this.keep(value);
797
+ const len = this.len;
798
+ if (this.history.length < len - 1)
799
+ return NaN;
800
+ const at = (j) => (j === len - 1 ? value : this.back(len - 1 - j));
801
+ for (let j = 0; j < len; j++)
802
+ if (isNaN(at(j)))
803
+ return NaN;
804
+ let sumX = 0;
805
+ let sumY = 0;
806
+ let sumXY = 0;
807
+ let sumX2 = 0;
808
+ for (let j = 0; j < len; j++) {
809
+ const x = j + 1;
810
+ const y = at(j);
811
+ sumX += x;
812
+ sumY += y;
813
+ sumXY += x * y;
814
+ sumX2 += x * x;
815
+ }
816
+ const slope = (len * sumXY - sumX * sumY) / (len * sumX2 - sumX * sumX);
817
+ const intercept = sumY / len - (slope * sumX) / len + slope;
818
+ return intercept + slope * (len - 1 - this.offset);
819
+ }
820
+ }
821
+ /** `ta.percentrank(source, length)`: the percentage of the `length` bars before that are less than or equal to the bar. */
822
+ export class PercentrankStep extends HistoryStep {
823
+ length;
824
+ constructor(length) {
825
+ super();
826
+ this.length = length;
827
+ checkPositiveLength('percentrank', length, 0);
828
+ }
829
+ step(value) {
830
+ this.keep(value);
831
+ if (this.history.length < this.length)
832
+ return NaN;
833
+ let count = 0;
834
+ for (let j = 1; j <= this.length; j++)
835
+ if (le(this.back(j), value))
836
+ count++;
837
+ return (count * 100) / this.length;
838
+ }
839
+ }
840
+ /** `ta.median(source, length)`: the median of the last `length` non-na values (sorted as ta.median keeps them). */
841
+ export class MedianStep {
842
+ sorted = [];
843
+ kept = [];
844
+ nextSorted = null;
845
+ nextValue = null;
846
+ stepped = false;
847
+ len;
848
+ constructor(length) {
849
+ checkPositiveLength('median', length, 0);
850
+ this.len = Math.floor(length);
851
+ }
852
+ static bound(sorted, v, after) {
853
+ let lo = 0;
854
+ let hi = sorted.length;
855
+ while (lo < hi) {
856
+ const m = (lo + hi) >> 1;
857
+ if (after ? sorted[m] <= v : sorted[m] < v)
858
+ lo = m + 1;
859
+ else
860
+ hi = m;
861
+ }
862
+ return lo;
863
+ }
864
+ step(value) {
865
+ this.stepped = true;
866
+ const len = this.len;
867
+ let sorted = this.sorted;
868
+ let count = this.kept.length;
869
+ this.nextValue = null;
870
+ this.nextSorted = null;
871
+ if (Number.isFinite(value)) {
872
+ sorted = sorted.slice();
873
+ count++;
874
+ sorted.splice(MedianStep.bound(sorted, value, false), 0, value);
875
+ // the value that leaves the window: kept[count - 1 - len] in the order of the kept values (this one is last)
876
+ if (count > len) {
877
+ const k = count - 1 - len;
878
+ const leaving = k === this.kept.length ? value : this.kept[k];
879
+ sorted.splice(MedianStep.bound(sorted, leaving, true) - 1, 1);
880
+ }
881
+ this.nextValue = value;
882
+ this.nextSorted = sorted;
883
+ }
884
+ if (!(len >= 1) || count < len)
885
+ return NaN;
886
+ const mid = Math.floor(len / 2);
887
+ return len % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
888
+ }
889
+ commit() {
890
+ if (!this.stepped)
891
+ return;
892
+ this.stepped = false;
893
+ if (this.nextValue !== null) {
894
+ this.kept.push(this.nextValue);
895
+ this.sorted = this.nextSorted;
896
+ }
897
+ }
898
+ }
899
+ /** `ta.correlation(source1, source2, length)`: covariance over the square root of the two variances. */
900
+ export class CorrelationStep {
901
+ length;
902
+ meanXY = new SmaStep();
903
+ meanX = new SmaStep();
904
+ meanY = new SmaStep();
905
+ varX = new VarianceStep();
906
+ varY = new VarianceStep();
907
+ constructor(length) {
908
+ this.length = length;
909
+ checkPositiveLength('correlation', length, 0);
910
+ }
911
+ step(a, b) {
912
+ const product = a === null || a === undefined || b === null || b === undefined ? NaN : a * b;
913
+ const mxy = this.meanXY.step(product, this.length);
914
+ const cov = mxy - this.meanX.step(a, this.length) * this.meanY.step(b, this.length);
915
+ const vx = this.varX.step(a, this.length);
916
+ const vy = this.varY.step(b, this.length);
917
+ if (Number.isNaN(cov))
918
+ return NaN;
919
+ if (Math.abs(cov) <= 1e-10)
920
+ return 0;
921
+ const denominator = Math.sqrt(vx * vy);
922
+ return denominator === 0 ? NaN : cov / denominator;
923
+ }
924
+ commit() {
925
+ this.meanXY.commit();
926
+ this.meanX.commit();
927
+ this.meanY.commit();
928
+ this.varX.commit();
929
+ this.varY.commit();
930
+ }
931
+ }
932
+ /** `ta.wpr(length)`: 100 * (close - highest(high)) / (highest(high) - lowest(low)); na on a zero range. */
933
+ export class WprStep {
934
+ length;
935
+ highest = new HighestStep();
936
+ lowest = new LowestStep();
937
+ constructor(length = 14) {
938
+ this.length = length;
939
+ checkPositiveLength('wpr', length, 0);
940
+ }
941
+ step(high, low, close) {
942
+ const hmax = this.highest.step(high, this.length);
943
+ const range = hmax - this.lowest.step(low, this.length);
944
+ return range === 0 ? NaN : (100 * (close - hmax)) / range;
945
+ }
946
+ commit() {
947
+ this.highest.commit();
948
+ this.lowest.commit();
949
+ }
950
+ }
951
+ /** `ta.supertrend(factor, atrPeriod)`: [supertrend, direction] (bands from hl2 and the atr, as ta.supertrend). */
952
+ export class SupertrendStep {
953
+ factor;
954
+ wicks;
955
+ atr;
956
+ lastLower = NaN;
957
+ lastUpper = NaN;
958
+ prevSuperTrend = NaN;
959
+ prevAtr = NaN;
960
+ prevHigh = NaN;
961
+ prevLow = NaN;
962
+ bars = 0;
963
+ next = [NaN, NaN, NaN, NaN, NaN, NaN];
964
+ stepped = false;
965
+ constructor(factor, atrPeriod, wicks = false) {
966
+ this.factor = factor;
967
+ this.wicks = wicks;
968
+ this.atr = new AtrStep(atrPeriod);
969
+ }
970
+ step(high, low, close) {
971
+ this.stepped = true;
972
+ const nz = (v) => (isNaN(v) ? 0 : v);
973
+ const source = (high + low) / 2;
974
+ const atr = this.atr.step(high, low, close);
975
+ const atrValue = atr * this.factor;
976
+ let upperBand = source + atrValue;
977
+ let lowerBand = source - atrValue;
978
+ const prevLowerBand = nz(this.lastLower);
979
+ const prevUpperBand = nz(this.lastUpper);
980
+ const highPrice = this.wicks ? high : close;
981
+ const lowPrice = this.wicks ? low : close;
982
+ const prevLowPrice = this.bars > 0 ? this.prevLow : NaN;
983
+ const prevHighPrice = this.bars > 0 ? this.prevHigh : NaN;
984
+ lowerBand = lowerBand > prevLowerBand || prevLowPrice < prevLowerBand ? lowerBand : prevLowerBand;
985
+ upperBand = upperBand < prevUpperBand || prevHighPrice > prevUpperBand ? upperBand : prevUpperBand;
986
+ let direction;
987
+ if (this.bars === 0 || isNaN(this.prevAtr))
988
+ direction = 1;
989
+ else if (this.prevSuperTrend === prevUpperBand)
990
+ direction = highPrice > upperBand ? -1 : 1;
991
+ else
992
+ direction = lowPrice < lowerBand ? 1 : -1;
993
+ const superTrend = direction === -1 ? lowerBand : upperBand;
994
+ this.next = [lowerBand, upperBand, superTrend, atr, highPrice, lowPrice];
995
+ return [superTrend, direction];
996
+ }
997
+ commit() {
998
+ if (!this.stepped)
999
+ return;
1000
+ this.stepped = false;
1001
+ [this.lastLower, this.lastUpper, this.prevSuperTrend, this.prevAtr, this.prevHigh, this.prevLow] = this.next;
1002
+ this.bars++;
1003
+ this.atr.commit();
1004
+ }
1005
+ }
1006
+ // ── Factories (PineScript names) ─────────────────────────────────────────────
1007
+ /**
1008
+ * One machine per ta.* call, by PineScript name (#196): `const ema = taStep.ema(14)`, then on each bar
1009
+ * `ema.step(close)` (again on the same bar for a live update of the forming bar) and `ema.commit()` when the bar is
1010
+ * final. Driven once per bar over an array, a machine gives the doubles of the `ta` / `taCore` function.
1011
+ * The window functions take their length on each step (a series length is allowed); the others at creation.
1012
+ */
1013
+ export const taStep = {
1014
+ /** `math.sum(source, length)`: step(value, length) */
1015
+ sum: () => new SumStep(),
1016
+ /** `ta.sma(source, length)`: step(value, length) */
1017
+ sma: () => new SmaStep(),
1018
+ /** `ta.variance(source, length, biased)`: step(value, length, biased?) */
1019
+ variance: () => new VarianceStep(),
1020
+ /** `ta.stdev(source, length, biased)`: step(value, length, biased?) */
1021
+ stdev: () => new StdevStep(),
1022
+ /** `ta.ema(source, length)`: step(value) */
1023
+ ema: (length) => new EmaStep(length),
1024
+ /** `ta.rma(source, length)`: step(value) */
1025
+ rma: (length) => new RmaStep(length),
1026
+ /** `ta.wma(source, length)`: step(value, length) */
1027
+ wma: () => new WmaStep(),
1028
+ /** `ta.change(source, length)`: step(value) */
1029
+ change: (length = 1) => new ChangeStep(length),
1030
+ /** `ta.mom(source, length)`: step(value) */
1031
+ mom: (length) => new MomStep(length),
1032
+ /** `ta.roc(source, length)`: step(value) */
1033
+ roc: (length) => new RocStep(length),
1034
+ /** `ta.tr(handle_na)`: step(high, low, close) */
1035
+ tr: (handle_na = false) => new TrStep(handle_na),
1036
+ /** `ta.atr(length)`: step(high, low, close) */
1037
+ atr: (length) => new AtrStep(length),
1038
+ /** `ta.rsi(source, length)`: step(value) */
1039
+ rsi: (length) => new RsiStep(length),
1040
+ /** `ta.cum(source)`: step(value) */
1041
+ cum: () => new CumStep(),
1042
+ /** `ta.crossover(a, b)`: step(a, b) */
1043
+ crossover: () => new CrossoverStep(),
1044
+ /** `ta.crossunder(a, b)`: step(a, b) */
1045
+ crossunder: () => new CrossunderStep(),
1046
+ /** `ta.cross(a, b)`: step(a, b) */
1047
+ cross: () => new CrossStep(),
1048
+ /** `ta.barssince(condition)`: step(condition) */
1049
+ barssince: () => new BarssinceStep(),
1050
+ /** `ta.valuewhen(condition, source, occurrence)`: step(condition, value) */
1051
+ valuewhen: (occurrence) => new ValuewhenStep(occurrence),
1052
+ /** `ta.obv`: step(close, volume) */
1053
+ obv: () => new ObvStep(),
1054
+ /** `ta.highest(source, length)`: step(value, length) */
1055
+ highest: () => new HighestStep(),
1056
+ /** `ta.lowest(source, length)`: step(value, length) */
1057
+ lowest: () => new LowestStep(),
1058
+ /** `ta.macd(source, fast, slow, signal)`: step(value) gives [macd, signal, histogram] */
1059
+ macd: (fastLength, slowLength, signalLength) => new MacdStep(fastLength, slowLength, signalLength),
1060
+ /** `ta.bb(source, length, mult)`: step(value) gives [basis, upper, lower] */
1061
+ bb: (length, mult) => new BbStep(length, mult),
1062
+ /** `ta.vwma(source, length)`: step(value, volume) */
1063
+ vwma: (length) => new VwmaStep(length),
1064
+ /** `ta.stoch(source, high, low, length)`: step(source, high, low) */
1065
+ stoch: (length) => new StochStep(length),
1066
+ /** `ta.hma(source, length)`: step(value) */
1067
+ hma: (length) => new HmaStep(length),
1068
+ /** `ta.dev(source, length)`: step(value) */
1069
+ dev: (length) => new DevStep(length),
1070
+ /** `ta.cci(source, length)`: step(value) */
1071
+ cci: (length) => new CciStep(length),
1072
+ /** `ta.mfi(source, length)`: step(value, volume) */
1073
+ mfi: (length) => new MfiStep(length),
1074
+ /** `ta.dmi(diLength, adxSmoothing)`: step(high, low, close) gives [plus, minus, adx] */
1075
+ dmi: (diLength, adxSmoothing) => new DmiStep(diLength, adxSmoothing),
1076
+ /** `ta.linreg(source, length, offset)`: step(value), called on every bar (in an if block: callsite.linreg) */
1077
+ linreg: (length, offset = 0) => new LinregStep(length, offset),
1078
+ /** `ta.percentrank(source, length)`: step(value) */
1079
+ percentrank: (length) => new PercentrankStep(length),
1080
+ /** `ta.median(source, length)`: step(value) */
1081
+ median: (length) => new MedianStep(length),
1082
+ /** `ta.correlation(source1, source2, length)`: step(a, b) */
1083
+ correlation: (length) => new CorrelationStep(length),
1084
+ /** `ta.wpr(length)`: step(high, low, close) */
1085
+ wpr: (length = 14) => new WprStep(length),
1086
+ /** `ta.supertrend(factor, atrPeriod)`: step(high, low, close) gives [supertrend, direction] */
1087
+ supertrend: (factor, atrPeriod) => new SupertrendStep(factor, atrPeriod),
1088
+ };
1089
+ //# sourceMappingURL=step.js.map