@supersolutions/super-chart-core 0.0.0 → 0.2.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.
@@ -0,0 +1,511 @@
1
+ import {
2
+ anchoredVwap,
3
+ atr,
4
+ atrBands,
5
+ bbPercent,
6
+ cci,
7
+ donchian,
8
+ ema,
9
+ highest,
10
+ ichimoku,
11
+ indicatorField,
12
+ keltner,
13
+ lowest,
14
+ macd,
15
+ mfi,
16
+ mom,
17
+ obv,
18
+ ownedKernel,
19
+ ownedWindow,
20
+ previousRangeHighLow,
21
+ rma,
22
+ roc,
23
+ rsi,
24
+ sma,
25
+ stochK,
26
+ stochRsi,
27
+ sum,
28
+ supertrend,
29
+ trueRange
30
+ } from "./chunk-B2X7UKEZ.js";
31
+
32
+ // packages/core/src/model/indicatorPack.ts
33
+ var TECHNICAL_INDICATOR_NAMES = Object.freeze([
34
+ "SC_RSI",
35
+ "SC_MACD",
36
+ "SC_SMA",
37
+ "SC_ATR",
38
+ "SC_ATR_BANDS",
39
+ "SC_KELTNER",
40
+ "SC_DONCHIAN",
41
+ "SC_VWAP",
42
+ "SC_STOCH",
43
+ "SC_STOCHRSI",
44
+ "SC_MFI",
45
+ "SC_BBP",
46
+ "SC_SUPERTREND",
47
+ "SC_ICHIMOKU",
48
+ "SC_PDHL"
49
+ ]);
50
+ function rows(keys, values) {
51
+ const result = new Array(values[0]?.length ?? 0);
52
+ for (let i = 0; i < result.length; i++) {
53
+ const row = /* @__PURE__ */ Object.create(null);
54
+ for (let j = 0; j < keys.length; j++) {
55
+ const value = values[j][i];
56
+ row[keys[j]] = value !== null && Number.isFinite(value) ? value : null;
57
+ }
58
+ result[i] = row;
59
+ }
60
+ return result;
61
+ }
62
+ function prices(bars) {
63
+ return { high: indicatorField(bars, "high"), low: indicatorField(bars, "low"), close: indicatorField(bars, "close") };
64
+ }
65
+ function lines(...entries) {
66
+ return Object.freeze(entries.map(([key, title]) => Object.freeze({ key, title, type: "line" })));
67
+ }
68
+ function parameters(name, supplied, defaults, kinds) {
69
+ if (supplied.length > defaults.length)
70
+ throw new RangeError(`${name} accepts at most ${defaults.length} parameters`);
71
+ return defaults.map((fallback, index) => {
72
+ const value = supplied[index] ?? fallback;
73
+ if (!Number.isFinite(value))
74
+ throw new RangeError(`${name} parameters must be finite`);
75
+ switch (kinds[index]) {
76
+ case "period":
77
+ if (!Number.isSafeInteger(value) || value < 1)
78
+ throw new RangeError(`${name} periods must be positive safe integers`);
79
+ break;
80
+ case "positive":
81
+ if (value <= 0)
82
+ throw new RangeError(`${name} multiplier must be positive`);
83
+ break;
84
+ case "anchor":
85
+ if (!Number.isInteger(value) || value < 0 || value > 4)
86
+ throw new RangeError("SC_VWAP anchor must be 0, 1, 2, 3 or 4");
87
+ break;
88
+ case "offset":
89
+ break;
90
+ case "range":
91
+ if (value !== 0 && value !== 1)
92
+ throw new RangeError("SC_PDHL period must be 0 (day) or 1 (week)");
93
+ break;
94
+ }
95
+ return value;
96
+ });
97
+ }
98
+ function define(name, defaults, kinds, pane, figures, calculate) {
99
+ const normalized = (supplied) => parameters(name, supplied, defaults, kinds);
100
+ const compute = (bars, supplied) => calculate(bars, normalized(supplied));
101
+ if (name === "SC_SMA" || name === "SC_RSI" || name === "SC_MACD") {
102
+ ownedKernel(compute, {
103
+ name: name === "SC_SMA" ? "MA" : name === "SC_RSI" ? "RSI" : "MACD",
104
+ parameters: normalized,
105
+ ...name === "SC_SMA" ? { maKey: "sma" } : {}
106
+ });
107
+ }
108
+ if (name === "SC_DONCHIAN") {
109
+ ownedWindow(compute, {
110
+ inputStart: (supplied, from) => Math.max(0, from - normalized(supplied)[0] + 1),
111
+ outputStart: (_p, from) => from
112
+ });
113
+ }
114
+ if (name === "SC_ICHIMOKU") {
115
+ ownedWindow(compute, {
116
+ inputStart: (supplied, from, length) => {
117
+ const p = normalized(supplied), shift = Math.min(p[3] - 1, length);
118
+ return Math.max(0, from - 2 * shift - Math.max(p[0], p[1], p[2]) + 1);
119
+ },
120
+ outputStart: (supplied, from, length) => Math.max(0, from - Math.min(normalized(supplied)[3] - 1, length))
121
+ });
122
+ }
123
+ return Object.freeze({
124
+ name,
125
+ params: Object.freeze([...defaults]),
126
+ pane,
127
+ figures,
128
+ calculate: compute
129
+ });
130
+ }
131
+ var bands = lines(["basis", "Basis"], ["upper", "Upper"], ["lower", "Lower"]);
132
+ var oscillator = lines(["k", "%K"], ["d", "%D"]);
133
+ var DAY_MS = 864e5;
134
+ function vwapPeriod(timestamp, anchor, offset) {
135
+ const shifted = timestamp + offset * 6e4;
136
+ if (!Number.isFinite(shifted))
137
+ return null;
138
+ if (anchor === 0)
139
+ return Math.floor(shifted / DAY_MS);
140
+ if (anchor === 1)
141
+ return Math.floor((Math.floor(shifted / DAY_MS) - 3) / 7);
142
+ const date = new Date(shifted);
143
+ const year = date.getUTCFullYear(), month = date.getUTCMonth();
144
+ if (!Number.isFinite(year))
145
+ return null;
146
+ if (anchor === 2)
147
+ return year * 100 + month;
148
+ if (anchor === 3)
149
+ return year * 10 + Math.floor(month / 3);
150
+ return year;
151
+ }
152
+ var TECHNICAL_INDICATOR_DEFINITIONS = Object.freeze([
153
+ define("SC_RSI", [14], ["period"], "separate", lines(["rsi", "RSI"]), (bars, p) => {
154
+ return rows(["rsi"], [rsi(indicatorField(bars, "close"), p[0])]);
155
+ }),
156
+ define("SC_MACD", [12, 26, 9], ["period", "period", "period"], "separate", Object.freeze([
157
+ Object.freeze({ key: "hist", title: "Histogram", type: "bar" }),
158
+ Object.freeze({ key: "dif", title: "MACD", type: "line" }),
159
+ Object.freeze({ key: "dea", title: "Signal", type: "line" })
160
+ ]), (bars, p) => {
161
+ const result = macd(indicatorField(bars, "close"), p[0], p[1], p[2]);
162
+ return rows(["hist", "dif", "dea"], [result.hist, result.dif, result.dea]);
163
+ }),
164
+ define("SC_SMA", [9], ["period"], "price", lines(["sma", "SMA"]), (bars, p) => {
165
+ return rows(["sma"], [sma(indicatorField(bars, "close"), p[0])]);
166
+ }),
167
+ define("SC_ATR", [14], ["period"], "separate", lines(["atr", "ATR"]), (bars, p) => {
168
+ const { high, low, close } = prices(bars);
169
+ return rows(["atr"], [atr(high, low, close, p[0])]);
170
+ }),
171
+ define("SC_ATR_BANDS", [14, 2], ["period", "positive"], "price", bands, (bars, p) => {
172
+ const { high, low, close } = prices(bars);
173
+ const result = atrBands(high, low, close, p[0], p[1]);
174
+ return rows(["basis", "upper", "lower"], [result.basis, result.upper, result.lower]);
175
+ }),
176
+ define("SC_KELTNER", [20, 2, 10], ["period", "positive", "period"], "price", bands, (bars, p) => {
177
+ const { high, low, close } = prices(bars);
178
+ const result = keltner(high, low, close, p[0], p[1], p[2]);
179
+ return rows(["basis", "upper", "lower"], [result.basis, result.upper, result.lower]);
180
+ }),
181
+ define("SC_DONCHIAN", [20], ["period"], "price", bands, (bars, p) => {
182
+ const result = donchian(indicatorField(bars, "high"), indicatorField(bars, "low"), p[0]);
183
+ return rows(["basis", "upper", "lower"], [result.basis, result.upper, result.lower]);
184
+ }),
185
+ define("SC_VWAP", [0, 0, 2], ["anchor", "offset", "positive"], "price", lines(["vwap", "VWAP"], ["upper", "Upper"], ["lower", "Lower"]), (bars, p) => {
186
+ const { high, low, close } = prices(bars);
187
+ const volume = indicatorField(bars, "volume");
188
+ const periods = bars.map((bar) => vwapPeriod(bar.timestamp, p[0], p[1]));
189
+ const result = anchoredVwap(high, low, close, volume, periods, true);
190
+ const upper = new Array(bars.length), lower = new Array(bars.length);
191
+ for (let i = 0; i < bars.length; i++) {
192
+ const value = result.vwap[i], deviation = result.stdev[i];
193
+ upper[i] = value === null || deviation === null ? null : value + p[2] * deviation;
194
+ lower[i] = value === null || deviation === null ? null : value - p[2] * deviation;
195
+ }
196
+ return rows(["vwap", "upper", "lower"], [result.vwap, upper, lower]);
197
+ }),
198
+ define("SC_STOCH", [14, 1, 3], ["period", "period", "period"], "separate", oscillator, (bars, p) => {
199
+ const { high, low, close } = prices(bars);
200
+ const k = sma(stochK(high, low, close, p[0]), p[1]);
201
+ return rows(["k", "d"], [k, sma(k, p[2])]);
202
+ }),
203
+ define("SC_STOCHRSI", [14, 14, 3, 3], ["period", "period", "period", "period"], "separate", oscillator, (bars, p) => {
204
+ const result = stochRsi(indicatorField(bars, "close"), p[0], p[1], p[2], p[3]);
205
+ return rows(["k", "d"], [result.k, result.d]);
206
+ }),
207
+ define("SC_MFI", [14], ["period"], "separate", lines(["mfi", "MFI"]), (bars, p) => {
208
+ const { high, low, close } = prices(bars);
209
+ return rows(["mfi"], [mfi(high, low, close, indicatorField(bars, "volume"), p[0])]);
210
+ }),
211
+ define("SC_BBP", [20, 2], ["period", "positive"], "separate", lines(["b", "%B"]), (bars, p) => {
212
+ return rows(["b"], [bbPercent(indicatorField(bars, "close"), p[0], p[1])]);
213
+ }),
214
+ define("SC_SUPERTREND", [10, 3], ["period", "positive"], "price", Object.freeze([
215
+ Object.freeze({ key: "up", title: "Supertrend Up", type: "line", color: "#26A69A" }),
216
+ Object.freeze({ key: "down", title: "Supertrend Down", type: "line", color: "#EF5350" })
217
+ ]), (bars, p) => {
218
+ const { high, low, close } = prices(bars);
219
+ const result = supertrend(high, low, close, p[0], p[1]);
220
+ const up = new Array(bars.length), down = new Array(bars.length);
221
+ for (let i = 0; i < bars.length; i++) {
222
+ up[i] = result.trend[i] === 1 ? result.line[i] : null;
223
+ down[i] = result.trend[i] === -1 ? result.line[i] : null;
224
+ }
225
+ return rows(["up", "down"], [up, down]);
226
+ }),
227
+ define("SC_ICHIMOKU", [9, 26, 52, 26], ["period", "period", "period", "period"], "price", lines(
228
+ ["conversion", "Conversion"],
229
+ ["base", "Base"],
230
+ ["spanA", "Span A"],
231
+ ["spanB", "Span B"],
232
+ ["lagging", "Lagging"]
233
+ ), (bars, p) => {
234
+ const { high, low, close } = prices(bars);
235
+ const displacement = Math.min(p[3], bars.length + 1);
236
+ const result = ichimoku(high, low, close, p[0], p[1], p[2], displacement);
237
+ return rows(["conversion", "base", "spanA", "spanB", "lagging"], [result.conversion, result.base, result.spanA, result.spanB, result.lagging]);
238
+ }),
239
+ define("SC_PDHL", [0], ["range"], "price", lines(["high", "Previous High"], ["low", "Previous Low"]), (bars, p) => {
240
+ const range = previousRangeHighLow(bars, p[0] === 1 ? "week" : "day", "UTC");
241
+ const high = range !== null && Number.isFinite(range.high) ? range.high : null;
242
+ const low = range !== null && Number.isFinite(range.low) ? range.low : null;
243
+ const row = Object.freeze({ high, low });
244
+ return new Array(bars.length).fill(row);
245
+ })
246
+ ]);
247
+
248
+ // packages/core/src/model/classicIndicators.ts
249
+ var CLASSIC_INDICATOR_NAMES = Object.freeze([
250
+ "CCI",
251
+ "DMI",
252
+ "CR",
253
+ "PSY",
254
+ "DMA",
255
+ "TRIX",
256
+ "OBV",
257
+ "VR",
258
+ "WR",
259
+ "MTM",
260
+ "EMV",
261
+ "ROC",
262
+ "PVT",
263
+ "AO",
264
+ "SAR",
265
+ "BIAS",
266
+ "BRAR",
267
+ "SMA",
268
+ "BBI"
269
+ ]);
270
+ function finite(value) {
271
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
272
+ }
273
+ function field(bars, key) {
274
+ return indicatorField(bars, key, key === "volume" ? "volume" : "finite");
275
+ }
276
+ function combine(a, b, operation) {
277
+ return a.map((x, i) => x === null || b[i] === null ? null : finite(operation(x, b[i])));
278
+ }
279
+ function ratio(a, b, scale = 100) {
280
+ return combine(a, b, (x, y) => y === 0 ? NaN : scale * x / y);
281
+ }
282
+ function lag(values, count = 1) {
283
+ return values.map((_, i) => i < count ? null : values[i - count]);
284
+ }
285
+ function subtract(a, b) {
286
+ return combine(a, b, (x, y) => x - y);
287
+ }
288
+ function positiveDifference(a, b) {
289
+ return combine(a, b, (x, y) => Math.max(0, x - y));
290
+ }
291
+ function midpoint(high, low) {
292
+ return combine(high, low, (h, l) => (h + l) / 2);
293
+ }
294
+ function rows2(keys, values) {
295
+ const result = new Array(values[0]?.length ?? 0);
296
+ for (let i = 0; i < result.length; i++) {
297
+ const row = /* @__PURE__ */ Object.create(null);
298
+ for (let j = 0; j < keys.length; j++)
299
+ row[keys[j]] = finite(values[j][i]);
300
+ result[i] = row;
301
+ }
302
+ return result;
303
+ }
304
+ function lines2(...entries) {
305
+ return Object.freeze(entries.map(([key, title]) => Object.freeze({ key, title, type: "line" })));
306
+ }
307
+ function define2(name, defaults, figures, calculate, pane = "separate") {
308
+ return Object.freeze({
309
+ name,
310
+ params: Object.freeze([...defaults]),
311
+ pane,
312
+ figures,
313
+ calculate: (bars, supplied) => {
314
+ if (supplied.length > defaults.length)
315
+ throw new RangeError(`${name} accepts at most ${defaults.length} parameters`);
316
+ const params = defaults.map((fallback, index) => {
317
+ const value = supplied[index] ?? fallback;
318
+ if (!Number.isFinite(value) || value <= 0 || name !== "SAR" && !Number.isSafeInteger(value)) {
319
+ throw new RangeError(`${name} requires ${name === "SAR" ? "positive finite factors" : "positive integer periods"}`);
320
+ }
321
+ return value;
322
+ });
323
+ if (name === "SAR" && (params[0] > params[2] || params[1] > params[2] || params[2] > 100)) {
324
+ throw new RangeError("SAR factors use hundredths: initial and increment must not exceed the maximum, which must not exceed 100");
325
+ }
326
+ return calculate(bars, params);
327
+ }
328
+ });
329
+ }
330
+ function directionalMovement(bars, p) {
331
+ const high = field(bars, "high"), low = field(bars, "low"), close = field(bars, "close");
332
+ const rise = subtract(high, lag(high)), fall = subtract(lag(low), low);
333
+ const positive = combine(rise, fall, (up, down) => up > down && up > 0 ? up : 0);
334
+ const negative = combine(rise, fall, (up, down) => down > up && down > 0 ? down : 0);
335
+ const ranges = trueRange(high, low, close);
336
+ if (ranges.length > 0)
337
+ ranges[0] = null;
338
+ const averageRange = rma(ranges, p[0]);
339
+ const pdi = combine(rma(positive, p[0]), averageRange, (dm, range) => range === 0 ? 0 : 100 * dm / range);
340
+ const mdi = combine(rma(negative, p[0]), averageRange, (dm, range) => range === 0 ? 0 : 100 * dm / range);
341
+ const dx = combine(pdi, mdi, (up, down) => up + down === 0 ? 0 : 100 * Math.abs(up - down) / (up + down));
342
+ const adx = rma(dx, p[1]);
343
+ const adxr = combine(adx, lag(adx, p[1]), (now, previous) => (now + previous) / 2);
344
+ return rows2(["pdi", "mdi", "adx", "adxr"], [pdi, mdi, adx, adxr]);
345
+ }
346
+ function pressureRatio(bars, p) {
347
+ const high = field(bars, "high"), low = field(bars, "low");
348
+ const previousMidpoint = lag(midpoint(high, low));
349
+ const cr = ratio(sum(positiveDifference(high, previousMidpoint), p[0]), sum(positiveDifference(previousMidpoint, low), p[0]));
350
+ return rows2(["cr", "ma1", "ma2", "ma3", "ma4"], [cr, ...p.slice(1).map((period) => sma(cr, period))]);
351
+ }
352
+ function volumeRatio(bars, p) {
353
+ const close = field(bars, "close"), volume = field(bars, "volume");
354
+ const movement = subtract(close, lag(close));
355
+ const up = combine(movement, volume, (change, value) => change > 0 ? value : 0);
356
+ const down = combine(movement, volume, (change, value) => change < 0 ? value : 0);
357
+ const equal = sum(combine(movement, volume, (change, value) => change === 0 ? value : 0), p[0]);
358
+ const numerator = combine(sum(up, p[0]), equal, (u, e) => 2 * u + e);
359
+ const denominator = combine(sum(down, p[0]), equal, (d, e) => 2 * d + e);
360
+ const vr = ratio(numerator, denominator);
361
+ return rows2(["vr", "signal"], [vr, sma(vr, p[1])]);
362
+ }
363
+ function priceVolumeTrend(bars) {
364
+ const close = field(bars, "close"), volume = field(bars, "volume");
365
+ const result = new Array(bars.length).fill(null);
366
+ let total = 0;
367
+ for (let i = 0; i < close.length; i++) {
368
+ const value = close[i];
369
+ if (value === null)
370
+ continue;
371
+ if (i === 0) {
372
+ result[i] = 0;
373
+ continue;
374
+ }
375
+ const previous = close[i - 1], amount = volume[i];
376
+ if (previous === null || previous === 0 || amount === null)
377
+ continue;
378
+ const increment = (value - previous) / previous * amount;
379
+ if (!Number.isFinite(increment) || !Number.isFinite(total + increment))
380
+ continue;
381
+ total += increment;
382
+ result[i] = total;
383
+ }
384
+ return rows2(["pvt"], [result]);
385
+ }
386
+ function easeOfMovement(bars, p) {
387
+ const high = field(bars, "high"), low = field(bars, "low"), volume = field(bars, "volume");
388
+ const middle = midpoint(high, low);
389
+ const distance = subtract(middle, lag(middle));
390
+ const distanceTimesRange = combine(distance, subtract(high, low), (d, range) => d * range);
391
+ const raw = ratio(distanceTimesRange, volume, 1);
392
+ const emv = sma(raw, p[0]);
393
+ return rows2(["emv", "signal"], [emv, sma(emv, p[1])]);
394
+ }
395
+ function willingness(bars, p) {
396
+ const high = field(bars, "high"), low = field(bars, "low"), open = field(bars, "open");
397
+ const previousClose = lag(field(bars, "close"));
398
+ const ar = ratio(sum(subtract(high, open), p[0]), sum(subtract(open, low), p[0]));
399
+ const br = ratio(sum(positiveDifference(high, previousClose), p[0]), sum(positiveDifference(previousClose, low), p[0]));
400
+ return rows2(["ar", "br"], [ar, br]);
401
+ }
402
+ function parabolicSar(bars, p) {
403
+ const high = field(bars, "high"), low = field(bars, "low"), close = field(bars, "close");
404
+ const result = new Array(bars.length).fill(null);
405
+ const start = p[0] / 100, increment = p[1] / 100, maximum = p[2] / 100;
406
+ let segment = -1, rising = false, value = 0, extreme = 0, acceleration = start;
407
+ for (let i = 0; i < bars.length; i++) {
408
+ const h = high[i], l = low[i], c = close[i];
409
+ if (h === null || l === null || c === null || h < l || c < l || c > h) {
410
+ segment = -1;
411
+ continue;
412
+ }
413
+ if (segment < 0) {
414
+ segment = i;
415
+ continue;
416
+ }
417
+ if (i === segment + 1) {
418
+ rising = c > close[i - 1];
419
+ value = rising ? low[i - 1] : high[i - 1];
420
+ extreme = rising ? h : l;
421
+ acceleration = start;
422
+ } else {
423
+ const candidate = value + acceleration * (extreme - value);
424
+ if (!Number.isFinite(candidate)) {
425
+ segment = i;
426
+ continue;
427
+ }
428
+ if (rising ? l < candidate : h > candidate) {
429
+ value = extreme;
430
+ rising = !rising;
431
+ extreme = rising ? h : l;
432
+ acceleration = start;
433
+ } else {
434
+ value = rising ? Math.min(candidate, low[i - 1], low[i - 2]) : Math.max(candidate, high[i - 1], high[i - 2]);
435
+ if (rising ? h > extreme : l < extreme) {
436
+ extreme = rising ? h : l;
437
+ acceleration = Math.min(acceleration + increment, maximum);
438
+ }
439
+ }
440
+ }
441
+ result[i] = value;
442
+ }
443
+ return rows2(["sar"], [result]);
444
+ }
445
+ var CLASSIC_INDICATOR_DEFINITIONS = Object.freeze([
446
+ define2("CCI", [20], lines2(["cci", "CCI"]), (bars, p) => rows2(["cci"], [cci(field(bars, "high"), field(bars, "low"), field(bars, "close"), p[0])])),
447
+ define2("DMI", [14, 6], lines2(["pdi", "+DI"], ["mdi", "-DI"], ["adx", "ADX"], ["adxr", "ADXR"]), directionalMovement),
448
+ define2("CR", [26, 10, 20, 40, 60], lines2(["cr", "CR"], ["ma1", "MA1"], ["ma2", "MA2"], ["ma3", "MA3"], ["ma4", "MA4"]), pressureRatio),
449
+ define2("PSY", [12, 6], lines2(["psy", "PSY"], ["signal", "Signal"]), (bars, p) => {
450
+ const close = field(bars, "close");
451
+ const rises = combine(close, lag(close), (value, previous) => value > previous ? 1 : 0);
452
+ const psy = sma(rises, p[0]).map((value) => value === null ? null : value * 100);
453
+ return rows2(["psy", "signal"], [psy, sma(psy, p[1])]);
454
+ }),
455
+ define2("DMA", [10, 50, 10], lines2(["dma", "DMA"], ["signal", "Signal"]), (bars, p) => {
456
+ const close = field(bars, "close");
457
+ const dma = subtract(sma(close, p[0]), sma(close, p[1]));
458
+ return rows2(["dma", "signal"], [dma, sma(dma, p[2])]);
459
+ }),
460
+ define2("TRIX", [12, 9], lines2(["trix", "TRIX"], ["signal", "Signal EMA"]), (bars, p) => {
461
+ const triple = ema(ema(ema(field(bars, "close"), p[0]), p[0]), p[0]);
462
+ const trix = roc(triple, 1);
463
+ return rows2(["trix", "signal"], [trix, ema(trix, p[1])]);
464
+ }),
465
+ define2("OBV", [30], lines2(["obv", "OBV"], ["signal", "Signal"]), (bars, p) => {
466
+ const value = obv(field(bars, "close"), field(bars, "volume"));
467
+ return rows2(["obv", "signal"], [value, sma(value, p[0])]);
468
+ }),
469
+ define2("VR", [26, 6], lines2(["vr", "VR"], ["signal", "Signal"]), volumeRatio),
470
+ define2("WR", [14], lines2(["wr", "Williams %R"]), (bars, p) => {
471
+ const upper = highest(field(bars, "high"), p[0]), lower = lowest(field(bars, "low"), p[0]);
472
+ return rows2(["wr"], [ratio(subtract(upper, field(bars, "close")), subtract(upper, lower), -100)]);
473
+ }),
474
+ define2("MTM", [12, 6], lines2(["mtm", "MTM"], ["signal", "Signal"]), (bars, p) => {
475
+ const value = mom(field(bars, "close"), p[0]);
476
+ return rows2(["mtm", "signal"], [value, sma(value, p[1])]);
477
+ }),
478
+ define2("EMV", [14, 9], lines2(["emv", "EMV"], ["signal", "Signal"]), easeOfMovement),
479
+ define2("ROC", [12, 6], lines2(["roc", "ROC"], ["signal", "Signal"]), (bars, p) => {
480
+ const value = roc(field(bars, "close"), p[0]);
481
+ return rows2(["roc", "signal"], [value, sma(value, p[1])]);
482
+ }),
483
+ define2("PVT", [], lines2(["pvt", "PVT"]), (bars) => priceVolumeTrend(bars)),
484
+ define2("AO", [5, 34], Object.freeze([Object.freeze({ key: "ao", title: "AO", type: "bar" })]), (bars, p) => {
485
+ const middle = midpoint(field(bars, "high"), field(bars, "low"));
486
+ return rows2(["ao"], [subtract(sma(middle, p[0]), sma(middle, p[1]))]);
487
+ }),
488
+ define2("SAR", [2, 2, 20], lines2(["sar", "SAR"]), parabolicSar, "price"),
489
+ define2("BIAS", [6, 12, 24], lines2(["bias1", "BIAS1"], ["bias2", "BIAS2"], ["bias3", "BIAS3"]), (bars, p) => {
490
+ const close = field(bars, "close");
491
+ return rows2(["bias1", "bias2", "bias3"], p.map((period) => {
492
+ const average = sma(close, period);
493
+ return ratio(subtract(close, average), average);
494
+ }));
495
+ }),
496
+ define2("BRAR", [26], lines2(["ar", "AR"], ["br", "BR"]), willingness),
497
+ define2("SMA", [9], lines2(["sma", "SMA"]), (bars, p) => rows2(["sma"], [sma(field(bars, "close"), p[0])]), "price"),
498
+ define2("BBI", [3, 6, 12, 24], lines2(["bbi", "BBI"]), (bars, p) => {
499
+ const close = field(bars, "close");
500
+ const averages = p.map((period) => sma(close, period));
501
+ const value = averages[0].map((a, i) => {
502
+ const b = averages[1][i], c = averages[2][i], d = averages[3][i];
503
+ return a === null || b === null || c === null || d === null ? null : (a + b + c + d) / 4;
504
+ });
505
+ return rows2(["bbi"], [value]);
506
+ }, "price")
507
+ ]);
508
+ export {
509
+ CLASSIC_INDICATOR_DEFINITIONS,
510
+ TECHNICAL_INDICATOR_DEFINITIONS
511
+ };