trading-signals 6.3.0 → 6.4.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.
package/README.md CHANGED
@@ -137,6 +137,7 @@ Most of the time, the minimum amount of data depends on the interval / time peri
137
137
  1. Momentum (MOM / MTM)
138
138
  1. Moving Average Convergence Divergence (MACD)
139
139
  1. On-Balance Volume (OBV)
140
+ 1. Parabolic SAR (PSAR)
140
141
  1. Rate-of-Change (ROC)
141
142
  1. Relative Moving Average (RMA)
142
143
  1. Relative Strength Index (RSI)
package/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ __export(index_exports, {
36
36
  ATR: () => ATR,
37
37
  AccelerationBands: () => AccelerationBands,
38
38
  BaseIndicatorSeries: () => BaseIndicatorSeries,
39
- Big: () => import_big26.default,
39
+ Big: () => import_big27.default,
40
40
  BigIndicatorSeries: () => BigIndicatorSeries,
41
41
  BollingerBands: () => BollingerBands,
42
42
  BollingerBandsWidth: () => BollingerBandsWidth,
@@ -65,6 +65,7 @@ __export(index_exports, {
65
65
  FasterMOM: () => FasterMOM,
66
66
  FasterMovingAverage: () => FasterMovingAverage,
67
67
  FasterOBV: () => FasterOBV,
68
+ FasterPSAR: () => FasterPSAR,
68
69
  FasterPeriod: () => FasterPeriod,
69
70
  FasterRMA: () => FasterRMA,
70
71
  FasterROC: () => FasterROC,
@@ -83,6 +84,7 @@ __export(index_exports, {
83
84
  NotEnoughDataError: () => NotEnoughDataError,
84
85
  NumberIndicatorSeries: () => NumberIndicatorSeries,
85
86
  OBV: () => OBV,
87
+ PSAR: () => PSAR,
86
88
  Period: () => Period,
87
89
  RMA: () => RMA,
88
90
  ROC: () => ROC,
@@ -104,7 +106,7 @@ __export(index_exports, {
104
106
  pushUpdate: () => pushUpdate
105
107
  });
106
108
  module.exports = __toCommonJS(index_exports);
107
- var import_big26 = __toESM(require("big.js"), 1);
109
+ var import_big27 = __toESM(require("big.js"), 1);
108
110
 
109
111
  // src/error/NotEnoughDataError.ts
110
112
  var NotEnoughDataError = class extends Error {
@@ -1350,8 +1352,118 @@ var FasterDMA = class extends TechnicalIndicator {
1350
1352
  }
1351
1353
  };
1352
1354
 
1353
- // src/MACD/MACD.ts
1355
+ // src/LINREG/LinearRegression.ts
1354
1356
  var import_big17 = __toESM(require("big.js"), 1);
1357
+ var LinearRegression = class extends TechnicalIndicator {
1358
+ prices = [];
1359
+ period;
1360
+ constructor(config) {
1361
+ super();
1362
+ this.period = config.period;
1363
+ }
1364
+ calculateRegression(prices) {
1365
+ const n = new import_big17.default(prices.length);
1366
+ const xValues = Array.from({ length: prices.length }, (_, i) => new import_big17.default(i));
1367
+ const yValues = prices.map((p) => new import_big17.default(p));
1368
+ const sumX = xValues.reduce((sum, x) => sum.add(x), new import_big17.default(0));
1369
+ const sumY = yValues.reduce((sum, y) => sum.add(y), new import_big17.default(0));
1370
+ const sumXY = xValues.reduce((sum, x, i) => sum.add(x.mul(yValues[i])), new import_big17.default(0));
1371
+ const sumXX = xValues.reduce((sum, x) => sum.add(x.mul(x)), new import_big17.default(0));
1372
+ const slope = sumXY.mul(n).sub(sumX.mul(sumY)).div(sumXX.mul(n).sub(sumX.mul(sumX)));
1373
+ const intercept = sumY.sub(slope.mul(sumX)).div(n);
1374
+ const prediction = slope.mul(xValues[xValues.length - 1]).add(intercept);
1375
+ return {
1376
+ intercept,
1377
+ prediction,
1378
+ slope
1379
+ };
1380
+ }
1381
+ update(price, replace) {
1382
+ pushUpdate(this.prices, replace, price, this.period);
1383
+ if (this.prices.length < this.period) {
1384
+ return null;
1385
+ }
1386
+ return this.result = this.calculateRegression(this.prices);
1387
+ }
1388
+ getResultOrThrow() {
1389
+ if (this.prices.length < this.period) {
1390
+ throw new NotEnoughDataError();
1391
+ }
1392
+ return this.result;
1393
+ }
1394
+ get isStable() {
1395
+ try {
1396
+ this.getResultOrThrow();
1397
+ return true;
1398
+ } catch {
1399
+ return false;
1400
+ }
1401
+ }
1402
+ };
1403
+ var FasterLinearRegression = class extends TechnicalIndicator {
1404
+ prices = [];
1405
+ period;
1406
+ constructor(config) {
1407
+ super();
1408
+ this.period = config.period;
1409
+ }
1410
+ calculateRegression(prices) {
1411
+ const n = prices.length;
1412
+ const isPerfectLinearTrend = prices.every((price, i) => {
1413
+ if (i === 0) {
1414
+ return true;
1415
+ }
1416
+ return Math.abs(price - prices[i - 1] - 1) < 1e-10;
1417
+ });
1418
+ if (isPerfectLinearTrend) {
1419
+ const slope2 = 1;
1420
+ const intercept2 = prices[0] - slope2;
1421
+ const nextX = n;
1422
+ const prediction2 = slope2 * nextX + intercept2;
1423
+ return { intercept: intercept2, prediction: prediction2, slope: slope2 };
1424
+ }
1425
+ const sumX = (n - 1) * n / 2;
1426
+ const sumY = prices.reduce((a, b) => a + b, 0);
1427
+ let sumXY = 0;
1428
+ let sumXX = 0;
1429
+ for (let i = 0; i < n; i++) {
1430
+ sumXY += i * prices[i];
1431
+ sumXX += i * i;
1432
+ }
1433
+ const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
1434
+ const intercept = (sumY - slope * sumX) / n;
1435
+ const prediction = slope * n + intercept;
1436
+ return {
1437
+ intercept,
1438
+ prediction,
1439
+ slope
1440
+ };
1441
+ }
1442
+ update(price, replace) {
1443
+ pushUpdate(this.prices, replace, price, this.period);
1444
+ if (this.prices.length < this.period) {
1445
+ return null;
1446
+ }
1447
+ return this.result = this.calculateRegression(this.prices);
1448
+ }
1449
+ getResultOrThrow() {
1450
+ if (!this.result) {
1451
+ throw new NotEnoughDataError();
1452
+ }
1453
+ return this.result;
1454
+ }
1455
+ get isStable() {
1456
+ try {
1457
+ this.getResultOrThrow();
1458
+ return true;
1459
+ } catch {
1460
+ return false;
1461
+ }
1462
+ }
1463
+ };
1464
+
1465
+ // src/MACD/MACD.ts
1466
+ var import_big18 = __toESM(require("big.js"), 1);
1355
1467
  var MACD = class extends TechnicalIndicator {
1356
1468
  prices = [];
1357
1469
  long;
@@ -1364,7 +1476,7 @@ var MACD = class extends TechnicalIndicator {
1364
1476
  this.signal = new config.indicator(config.signalInterval);
1365
1477
  }
1366
1478
  update(_price, replace) {
1367
- const price = new import_big17.default(_price);
1479
+ const price = new import_big18.default(_price);
1368
1480
  pushUpdate(this.prices, replace, price, this.long.interval);
1369
1481
  const short = this.short.update(price, replace);
1370
1482
  const long = this.long.update(price, replace);
@@ -1406,7 +1518,7 @@ var FasterMACD = class extends TechnicalIndicator {
1406
1518
  };
1407
1519
 
1408
1520
  // src/OBV/OBV.ts
1409
- var import_big18 = __toESM(require("big.js"), 1);
1521
+ var import_big19 = __toESM(require("big.js"), 1);
1410
1522
  var OBV = class extends BigIndicatorSeries {
1411
1523
  candles = [];
1412
1524
  update(candle, replace) {
@@ -1416,8 +1528,8 @@ var OBV = class extends BigIndicatorSeries {
1416
1528
  }
1417
1529
  const prevCandle = this.candles[this.candles.length - 2];
1418
1530
  const prevPrice = prevCandle.close;
1419
- const prevResult = this.result ?? new import_big18.default(0);
1420
- const currentPrice = new import_big18.default(candle.close);
1531
+ const prevResult = this.result ?? new import_big19.default(0);
1532
+ const currentPrice = new import_big19.default(candle.close);
1421
1533
  const nextResult = currentPrice.gt(prevPrice) ? candle.volume : currentPrice.lt(prevPrice) ? -candle.volume : 0;
1422
1534
  return this.setResult(prevResult.add(nextResult), replace);
1423
1535
  }
@@ -1439,7 +1551,7 @@ var FasterOBV = class extends NumberIndicatorSeries {
1439
1551
  };
1440
1552
 
1441
1553
  // src/RMA/RMA.ts
1442
- var import_big19 = __toESM(require("big.js"), 1);
1554
+ var import_big20 = __toESM(require("big.js"), 1);
1443
1555
  var RMA = class extends MovingAverage {
1444
1556
  constructor(interval) {
1445
1557
  super(interval);
@@ -1454,7 +1566,7 @@ var RMA = class extends MovingAverage {
1454
1566
  } else if (replace && this.pricesCounter === 0) {
1455
1567
  this.pricesCounter++;
1456
1568
  }
1457
- const price = new import_big19.default(_price);
1569
+ const price = new import_big20.default(_price);
1458
1570
  if (replace && this.previousResult) {
1459
1571
  return this.setResult(
1460
1572
  price.times(this.weightFactor).add(this.previousResult.times(1 - this.weightFactor)),
@@ -1520,7 +1632,7 @@ var FasterRMA = class extends FasterMovingAverage {
1520
1632
  };
1521
1633
 
1522
1634
  // src/ROC/ROC.ts
1523
- var import_big20 = __toESM(require("big.js"), 1);
1635
+ var import_big21 = __toESM(require("big.js"), 1);
1524
1636
  var ROC = class extends BigIndicatorSeries {
1525
1637
  constructor(interval) {
1526
1638
  super();
@@ -1530,7 +1642,7 @@ var ROC = class extends BigIndicatorSeries {
1530
1642
  update(price, replace) {
1531
1643
  const comparePrice = pushUpdate(this.prices, replace, price, this.interval);
1532
1644
  if (comparePrice) {
1533
- return this.setResult(new import_big20.default(price).sub(comparePrice).div(comparePrice), replace);
1645
+ return this.setResult(new import_big21.default(price).sub(comparePrice).div(comparePrice), replace);
1534
1646
  }
1535
1647
  return null;
1536
1648
  }
@@ -1551,7 +1663,7 @@ var FasterROC = class extends NumberIndicatorSeries {
1551
1663
  };
1552
1664
 
1553
1665
  // src/RSI/RSI.ts
1554
- var import_big21 = __toESM(require("big.js"), 1);
1666
+ var import_big22 = __toESM(require("big.js"), 1);
1555
1667
  var RSI = class extends BigIndicatorSeries {
1556
1668
  constructor(interval, SmoothingIndicator = WSMA) {
1557
1669
  super();
@@ -1562,25 +1674,25 @@ var RSI = class extends BigIndicatorSeries {
1562
1674
  previousPrices = [];
1563
1675
  avgGain;
1564
1676
  avgLoss;
1565
- maxValue = new import_big21.default(100);
1677
+ maxValue = new import_big22.default(100);
1566
1678
  update(price, replace) {
1567
1679
  pushUpdate(this.previousPrices, replace, price, this.interval);
1568
1680
  if (this.previousPrices.length < 2) {
1569
1681
  return null;
1570
1682
  }
1571
- const currentPrice = new import_big21.default(price);
1572
- const previousPrice = new import_big21.default(this.previousPrices[this.previousPrices.length - 2]);
1683
+ const currentPrice = new import_big22.default(price);
1684
+ const previousPrice = new import_big22.default(this.previousPrices[this.previousPrices.length - 2]);
1573
1685
  if (currentPrice.gt(previousPrice)) {
1574
- this.avgLoss.update(new import_big21.default(0), replace);
1686
+ this.avgLoss.update(new import_big22.default(0), replace);
1575
1687
  this.avgGain.update(currentPrice.sub(previousPrice), replace);
1576
1688
  } else {
1577
1689
  this.avgLoss.update(previousPrice.sub(currentPrice), replace);
1578
- this.avgGain.update(new import_big21.default(0), replace);
1690
+ this.avgGain.update(new import_big22.default(0), replace);
1579
1691
  }
1580
1692
  if (this.avgGain.isStable) {
1581
1693
  const avgLoss = this.avgLoss.getResultOrThrow();
1582
1694
  if (avgLoss.eq(0)) {
1583
- return this.setResult(new import_big21.default(100), replace);
1695
+ return this.setResult(new import_big22.default(100), replace);
1584
1696
  }
1585
1697
  const relativeStrength = this.avgGain.getResultOrThrow().div(avgLoss);
1586
1698
  return this.setResult(this.maxValue.minus(this.maxValue.div(relativeStrength.add(1))), replace);
@@ -1625,8 +1737,261 @@ var FasterRSI = class extends NumberIndicatorSeries {
1625
1737
  }
1626
1738
  };
1627
1739
 
1740
+ // src/PSAR/PSAR.ts
1741
+ var import_big23 = __toESM(require("big.js"), 1);
1742
+ var PSAR = class extends BigIndicatorSeries {
1743
+ accelerationStep;
1744
+ accelerationMax;
1745
+ acceleration = new import_big23.default(0);
1746
+ extreme = null;
1747
+ lastSar = null;
1748
+ isLong = null;
1749
+ previousCandle = null;
1750
+ prePreviousCandle = null;
1751
+ constructor(config) {
1752
+ super();
1753
+ this.accelerationStep = new import_big23.default(config.accelerationStep);
1754
+ this.accelerationMax = new import_big23.default(config.accelerationMax);
1755
+ if (this.accelerationStep.lte(0)) {
1756
+ throw new Error("Acceleration step must be greater than 0");
1757
+ }
1758
+ if (this.accelerationMax.lte(this.accelerationStep)) {
1759
+ throw new Error("Acceleration max must be greater than acceleration step");
1760
+ }
1761
+ }
1762
+ get isStable() {
1763
+ return this.lastSar !== null;
1764
+ }
1765
+ update(candle, replace) {
1766
+ const high = new import_big23.default(candle.high);
1767
+ const low = new import_big23.default(candle.low);
1768
+ const notEnoughData = !this.previousCandle || this.lastSar === null;
1769
+ if (replace && notEnoughData) {
1770
+ this.previousCandle = candle;
1771
+ return null;
1772
+ }
1773
+ if (!this.previousCandle) {
1774
+ this.previousCandle = candle;
1775
+ return null;
1776
+ }
1777
+ if (this.lastSar === null) {
1778
+ const currentMidpoint = high.add(low).div(2);
1779
+ const previousMidpoint = new import_big23.default(this.previousCandle.high).add(this.previousCandle.low).div(2);
1780
+ this.isLong = currentMidpoint.gte(previousMidpoint);
1781
+ if (this.isLong) {
1782
+ this.extreme = high;
1783
+ this.lastSar = new import_big23.default(this.previousCandle.low);
1784
+ } else {
1785
+ this.extreme = low;
1786
+ this.lastSar = new import_big23.default(this.previousCandle.high);
1787
+ }
1788
+ this.acceleration = this.accelerationStep;
1789
+ this.prePreviousCandle = this.previousCandle;
1790
+ this.previousCandle = candle;
1791
+ return this.setResult(this.lastSar, replace);
1792
+ }
1793
+ let sar = this.extreme.minus(this.lastSar).mul(this.acceleration).add(this.lastSar);
1794
+ if (this.isLong) {
1795
+ if (this.previousCandle) {
1796
+ const previousLow = new import_big23.default(this.previousCandle.low);
1797
+ if (this.prePreviousCandle && low.lt(sar)) {
1798
+ const prePreviousLow = new import_big23.default(this.prePreviousCandle.low);
1799
+ if (prePreviousLow.lt(sar)) {
1800
+ sar = prePreviousLow;
1801
+ }
1802
+ if (previousLow.lt(sar)) {
1803
+ sar = previousLow;
1804
+ }
1805
+ } else if (previousLow.lt(sar)) {
1806
+ sar = previousLow;
1807
+ }
1808
+ }
1809
+ if (this.extreme && high.gt(this.extreme)) {
1810
+ this.extreme = high;
1811
+ if (this.acceleration.lt(this.accelerationMax)) {
1812
+ this.acceleration = this.acceleration.add(this.accelerationStep);
1813
+ if (this.acceleration.gt(this.accelerationMax)) {
1814
+ this.acceleration = this.accelerationMax;
1815
+ }
1816
+ }
1817
+ }
1818
+ if (low.lt(sar)) {
1819
+ this.isLong = false;
1820
+ sar = this.extreme;
1821
+ this.extreme = low;
1822
+ this.acceleration = this.accelerationStep;
1823
+ }
1824
+ } else {
1825
+ if (this.previousCandle) {
1826
+ const previousHigh = new import_big23.default(this.previousCandle.high);
1827
+ const hasPrevPrev = this.prePreviousCandle != null;
1828
+ if (hasPrevPrev && high.gt(sar)) {
1829
+ const prePreviousHigh = new import_big23.default(this.prePreviousCandle.high);
1830
+ if (prePreviousHigh.gt(sar)) {
1831
+ sar = prePreviousHigh;
1832
+ }
1833
+ if (previousHigh.gt(sar)) {
1834
+ sar = previousHigh;
1835
+ }
1836
+ } else if (previousHigh.gt(sar)) {
1837
+ sar = previousHigh;
1838
+ }
1839
+ }
1840
+ if (this.extreme && low.lt(this.extreme)) {
1841
+ this.extreme = low;
1842
+ if (this.acceleration.lt(this.accelerationMax)) {
1843
+ this.acceleration = this.acceleration.add(this.accelerationStep);
1844
+ if (this.acceleration.gt(this.accelerationMax)) {
1845
+ this.acceleration = this.accelerationMax;
1846
+ }
1847
+ }
1848
+ }
1849
+ if (this.extreme && high.gt(sar)) {
1850
+ this.isLong = true;
1851
+ sar = this.extreme;
1852
+ this.extreme = high;
1853
+ this.acceleration = this.accelerationStep;
1854
+ if (sar.gte(low)) {
1855
+ sar = low.minus(0.01);
1856
+ }
1857
+ }
1858
+ }
1859
+ this.lastSar = sar;
1860
+ this.prePreviousCandle = this.previousCandle;
1861
+ this.previousCandle = candle;
1862
+ return this.setResult(sar, replace);
1863
+ }
1864
+ getResultOrThrow() {
1865
+ if (this.lastSar === null) {
1866
+ throw new NotEnoughDataError("PSAR requires at least 2 candles");
1867
+ }
1868
+ return super.getResultOrThrow();
1869
+ }
1870
+ };
1871
+ var FasterPSAR = class extends NumberIndicatorSeries {
1872
+ accelerationStep;
1873
+ accelerationMax;
1874
+ acceleration = 0;
1875
+ extreme = null;
1876
+ lastSar = null;
1877
+ isLong = null;
1878
+ previousCandle = null;
1879
+ prePreviousCandle = null;
1880
+ constructor(config) {
1881
+ super();
1882
+ this.accelerationStep = config.accelerationStep;
1883
+ this.accelerationMax = config.accelerationMax;
1884
+ if (this.accelerationStep <= 0) {
1885
+ throw new Error("Acceleration step must be greater than 0");
1886
+ }
1887
+ if (this.accelerationMax <= this.accelerationStep) {
1888
+ throw new Error("Acceleration max must be greater than acceleration step");
1889
+ }
1890
+ }
1891
+ get isStable() {
1892
+ return this.lastSar !== null;
1893
+ }
1894
+ update(candle, replace) {
1895
+ const { high, low } = candle;
1896
+ const notEnoughData = !this.previousCandle || this.lastSar === null;
1897
+ if (replace && notEnoughData) {
1898
+ this.previousCandle = candle;
1899
+ return null;
1900
+ }
1901
+ if (!this.previousCandle) {
1902
+ this.previousCandle = candle;
1903
+ return null;
1904
+ }
1905
+ if (this.lastSar === null) {
1906
+ const currentMidpoint = (high + low) / 2;
1907
+ const previousMidpoint = (this.previousCandle.high + this.previousCandle.low) / 2;
1908
+ this.isLong = currentMidpoint >= previousMidpoint;
1909
+ if (this.isLong) {
1910
+ this.extreme = high;
1911
+ this.lastSar = this.previousCandle.low;
1912
+ } else {
1913
+ this.extreme = low;
1914
+ this.lastSar = this.previousCandle.high;
1915
+ }
1916
+ this.acceleration = this.accelerationStep;
1917
+ this.prePreviousCandle = this.previousCandle;
1918
+ this.previousCandle = candle;
1919
+ return this.setResult(this.lastSar, replace);
1920
+ }
1921
+ let sar = (this.extreme - this.lastSar) * this.acceleration + this.lastSar;
1922
+ if (this.isLong) {
1923
+ if (this.previousCandle) {
1924
+ const hasPrevPrev = this.prePreviousCandle != null;
1925
+ if (hasPrevPrev && low < sar) {
1926
+ if (this.prePreviousCandle.low < sar) {
1927
+ sar = this.prePreviousCandle.low;
1928
+ }
1929
+ sar = this.previousCandle.low < sar ? this.previousCandle.low : sar;
1930
+ } else if (this.previousCandle.low < sar) {
1931
+ sar = this.previousCandle.low;
1932
+ }
1933
+ }
1934
+ if (high > this.extreme) {
1935
+ this.extreme = high;
1936
+ if (this.acceleration < this.accelerationMax) {
1937
+ this.acceleration += this.accelerationStep;
1938
+ if (this.acceleration > this.accelerationMax) {
1939
+ this.acceleration = this.accelerationMax;
1940
+ }
1941
+ }
1942
+ }
1943
+ if (low < sar) {
1944
+ this.isLong = false;
1945
+ sar = this.extreme;
1946
+ this.extreme = low;
1947
+ this.acceleration = this.accelerationStep;
1948
+ }
1949
+ } else {
1950
+ if (this.previousCandle) {
1951
+ const hasPrevPrev = this.prePreviousCandle != null;
1952
+ if (hasPrevPrev && high > sar) {
1953
+ if (this.prePreviousCandle.high > sar) {
1954
+ sar = this.prePreviousCandle.high;
1955
+ }
1956
+ sar = this.previousCandle.high > sar ? this.previousCandle.high : sar;
1957
+ } else if (this.previousCandle.high > sar) {
1958
+ sar = this.previousCandle.high;
1959
+ }
1960
+ }
1961
+ if (low < this.extreme) {
1962
+ this.extreme = low;
1963
+ if (this.acceleration < this.accelerationMax) {
1964
+ this.acceleration += this.accelerationStep;
1965
+ if (this.acceleration > this.accelerationMax) {
1966
+ this.acceleration = this.accelerationMax;
1967
+ }
1968
+ }
1969
+ }
1970
+ if (high > sar) {
1971
+ this.isLong = true;
1972
+ sar = this.extreme;
1973
+ this.extreme = high;
1974
+ this.acceleration = this.accelerationStep;
1975
+ if (sar >= low) {
1976
+ sar = low - 0.01;
1977
+ }
1978
+ }
1979
+ }
1980
+ this.lastSar = sar;
1981
+ this.prePreviousCandle = this.previousCandle;
1982
+ this.previousCandle = candle;
1983
+ return this.setResult(sar, replace);
1984
+ }
1985
+ getResultOrThrow() {
1986
+ if (this.lastSar === null) {
1987
+ throw new NotEnoughDataError("PSAR requires at least 2 candles");
1988
+ }
1989
+ return super.getResultOrThrow();
1990
+ }
1991
+ };
1992
+
1628
1993
  // src/STOCH/StochasticOscillator.ts
1629
- var import_big22 = __toESM(require("big.js"), 1);
1994
+ var import_big24 = __toESM(require("big.js"), 1);
1630
1995
  var StochasticOscillator = class extends TechnicalIndicator {
1631
1996
  /**
1632
1997
  * Constructs a Stochastic Oscillator.
@@ -1651,8 +2016,8 @@ var StochasticOscillator = class extends TechnicalIndicator {
1651
2016
  if (this.candles.length === this.n) {
1652
2017
  const highest = getMaximum(this.candles.map((candle2) => candle2.high));
1653
2018
  const lowest = getMinimum(this.candles.map((candle2) => candle2.low));
1654
- const divisor = new import_big22.default(highest).minus(lowest);
1655
- let fastK = new import_big22.default(100).mul(new import_big22.default(candle.close).minus(lowest));
2019
+ const divisor = new import_big24.default(highest).minus(lowest);
2020
+ let fastK = new import_big24.default(100).mul(new import_big24.default(candle.close).minus(lowest));
1656
2021
  fastK = fastK.div(divisor.eq(0) ? 1 : divisor);
1657
2022
  const stochK = this.periodM.update(fastK, replace);
1658
2023
  const stochD = stochK && this.periodP.update(stochK, replace);
@@ -1705,7 +2070,7 @@ var FasterStochasticOscillator = class extends TechnicalIndicator {
1705
2070
  };
1706
2071
 
1707
2072
  // src/STOCH/StochasticRSI.ts
1708
- var import_big23 = __toESM(require("big.js"), 1);
2073
+ var import_big25 = __toESM(require("big.js"), 1);
1709
2074
  var StochasticRSI = class extends BigIndicatorSeries {
1710
2075
  constructor(interval, SmoothingRSI = WSMA, smoothing = {
1711
2076
  d: new SMA(3),
@@ -1728,7 +2093,7 @@ var StochasticRSI = class extends BigIndicatorSeries {
1728
2093
  const max = periodResult.highest;
1729
2094
  const denominator = max.minus(min);
1730
2095
  if (denominator.eq(0)) {
1731
- return this.setResult(new import_big23.default(100), replace);
2096
+ return this.setResult(new import_big25.default(100), replace);
1732
2097
  }
1733
2098
  const numerator = rsiResult.minus(min);
1734
2099
  const stochRSI = numerator.div(denominator);
@@ -1779,118 +2144,8 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
1779
2144
  }
1780
2145
  };
1781
2146
 
1782
- // src/LINREG/LinearRegression.ts
1783
- var import_big24 = __toESM(require("big.js"), 1);
1784
- var LinearRegression = class extends TechnicalIndicator {
1785
- prices = [];
1786
- period;
1787
- constructor(config) {
1788
- super();
1789
- this.period = config.period;
1790
- }
1791
- calculateRegression(prices) {
1792
- const n = new import_big24.default(prices.length);
1793
- const xValues = Array.from({ length: prices.length }, (_, i) => new import_big24.default(i));
1794
- const yValues = prices.map((p) => new import_big24.default(p));
1795
- const sumX = xValues.reduce((sum, x) => sum.add(x), new import_big24.default(0));
1796
- const sumY = yValues.reduce((sum, y) => sum.add(y), new import_big24.default(0));
1797
- const sumXY = xValues.reduce((sum, x, i) => sum.add(x.mul(yValues[i])), new import_big24.default(0));
1798
- const sumXX = xValues.reduce((sum, x) => sum.add(x.mul(x)), new import_big24.default(0));
1799
- const slope = sumXY.mul(n).sub(sumX.mul(sumY)).div(sumXX.mul(n).sub(sumX.mul(sumX)));
1800
- const intercept = sumY.sub(slope.mul(sumX)).div(n);
1801
- const prediction = slope.mul(xValues[xValues.length - 1]).add(intercept);
1802
- return {
1803
- intercept,
1804
- prediction,
1805
- slope
1806
- };
1807
- }
1808
- update(price, replace) {
1809
- pushUpdate(this.prices, replace, price, this.period);
1810
- if (this.prices.length < this.period) {
1811
- return null;
1812
- }
1813
- return this.result = this.calculateRegression(this.prices);
1814
- }
1815
- getResultOrThrow() {
1816
- if (this.prices.length < this.period) {
1817
- throw new NotEnoughDataError();
1818
- }
1819
- return this.result;
1820
- }
1821
- get isStable() {
1822
- try {
1823
- this.getResultOrThrow();
1824
- return true;
1825
- } catch {
1826
- return false;
1827
- }
1828
- }
1829
- };
1830
- var FasterLinearRegression = class extends TechnicalIndicator {
1831
- prices = [];
1832
- period;
1833
- constructor(config) {
1834
- super();
1835
- this.period = config.period;
1836
- }
1837
- calculateRegression(prices) {
1838
- const n = prices.length;
1839
- const isPerfectLinearTrend = prices.every((price, i) => {
1840
- if (i === 0) {
1841
- return true;
1842
- }
1843
- return Math.abs(price - prices[i - 1] - 1) < 1e-10;
1844
- });
1845
- if (isPerfectLinearTrend) {
1846
- const slope2 = 1;
1847
- const intercept2 = prices[0] - slope2;
1848
- const nextX = n;
1849
- const prediction2 = slope2 * nextX + intercept2;
1850
- return { intercept: intercept2, prediction: prediction2, slope: slope2 };
1851
- }
1852
- const sumX = (n - 1) * n / 2;
1853
- const sumY = prices.reduce((a, b) => a + b, 0);
1854
- let sumXY = 0;
1855
- let sumXX = 0;
1856
- for (let i = 0; i < n; i++) {
1857
- sumXY += i * prices[i];
1858
- sumXX += i * i;
1859
- }
1860
- const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
1861
- const intercept = (sumY - slope * sumX) / n;
1862
- const prediction = slope * n + intercept;
1863
- return {
1864
- intercept,
1865
- prediction,
1866
- slope
1867
- };
1868
- }
1869
- update(price, replace) {
1870
- pushUpdate(this.prices, replace, price, this.period);
1871
- if (this.prices.length < this.period) {
1872
- return null;
1873
- }
1874
- return this.result = this.calculateRegression(this.prices);
1875
- }
1876
- getResultOrThrow() {
1877
- if (!this.result) {
1878
- throw new NotEnoughDataError();
1879
- }
1880
- return this.result;
1881
- }
1882
- get isStable() {
1883
- try {
1884
- this.getResultOrThrow();
1885
- return true;
1886
- } catch {
1887
- return false;
1888
- }
1889
- }
1890
- };
1891
-
1892
2147
  // src/WMA/WMA.ts
1893
- var import_big25 = __toESM(require("big.js"), 1);
2148
+ var import_big26 = __toESM(require("big.js"), 1);
1894
2149
  var WMA = class extends MovingAverage {
1895
2150
  constructor(interval) {
1896
2151
  super(interval);
@@ -1901,9 +2156,9 @@ var WMA = class extends MovingAverage {
1901
2156
  pushUpdate(this.prices, replace, price, this.interval);
1902
2157
  if (this.prices.length === this.interval) {
1903
2158
  const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
1904
- const weightedPrice = new import_big25.default(price2).mul(index + 1);
2159
+ const weightedPrice = new import_big26.default(price2).mul(index + 1);
1905
2160
  return acc.add(weightedPrice);
1906
- }, new import_big25.default(0));
2161
+ }, new import_big26.default(0));
1907
2162
  const weightBase = this.interval * (this.interval + 1) / 2;
1908
2163
  const weightedMa = weightedPricesSum.div(weightBase);
1909
2164
  return this.setResult(weightedMa, replace);
@@ -1968,6 +2223,7 @@ var FasterWMA = class extends FasterMovingAverage {
1968
2223
  FasterMOM,
1969
2224
  FasterMovingAverage,
1970
2225
  FasterOBV,
2226
+ FasterPSAR,
1971
2227
  FasterPeriod,
1972
2228
  FasterRMA,
1973
2229
  FasterROC,
@@ -1986,6 +2242,7 @@ var FasterWMA = class extends FasterMovingAverage {
1986
2242
  NotEnoughDataError,
1987
2243
  NumberIndicatorSeries,
1988
2244
  OBV,
2245
+ PSAR,
1989
2246
  Period,
1990
2247
  RMA,
1991
2248
  ROC,