trading-signals 6.0.1 → 6.1.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 +3 -1
- package/dist/index.cjs +105 -21
- package/dist/index.d.cts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +101 -19
- package/package.json +2 -2
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. Moving Average Convergence Divergence (MACD)
|
|
138
138
|
1. On-Balance Volume (OBV)
|
|
139
139
|
1. Rate-of-Change (ROC)
|
|
140
|
+
1. Relative Moving Average (RMA)
|
|
140
141
|
1. Relative Strength Index (RSI)
|
|
141
142
|
1. Simple Moving Average (SMA)
|
|
142
143
|
1. Stochastic Oscillator (STOCH)
|
|
@@ -201,12 +202,13 @@ It is very important to do your own analysis before making any investment based
|
|
|
201
202
|
- [Cloud9Trader Indicators (JavaScript)](https://github.com/Cloud9Trader/TechnicalIndicators)
|
|
202
203
|
- [Crypto Trading Hub Indicators (TypeScript)](https://github.com/anandanand84/technicalindicators)
|
|
203
204
|
- [Jesse Trading Bot Indicators (Python)](https://docs.jesse.trade/docs/indicators/reference.html)
|
|
205
|
+
- [LEAN Indicators](https://github.com/QuantConnect/Lean/tree/master/Indicators)
|
|
204
206
|
- [libindicators (C#)](https://github.com/mgfx/libindicators)
|
|
205
207
|
- [Pandas TA (Python)](https://github.com/twopirllc/pandas-ta)
|
|
208
|
+
- [ta4j (Java)](https://github.com/ta4j/ta4j)
|
|
206
209
|
- [Technical Analysis for Rust (Rust)](https://github.com/greyblake/ta-rs)
|
|
207
210
|
- [Technical Analysis Library using Pandas and Numpy (Python)](https://github.com/bukosabino/ta)
|
|
208
211
|
- [Tulip Indicators (ANSI C)](https://github.com/TulipCharts/tulipindicators)
|
|
209
|
-
- [ta4j (Java)](https://github.com/ta4j/ta4j)
|
|
210
212
|
|
|
211
213
|
## Maintainers
|
|
212
214
|
|
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: () =>
|
|
39
|
+
Big: () => import_big25.default,
|
|
40
40
|
BigIndicatorSeries: () => BigIndicatorSeries,
|
|
41
41
|
BollingerBands: () => BollingerBands,
|
|
42
42
|
BollingerBandsWidth: () => BollingerBandsWidth,
|
|
@@ -65,6 +65,7 @@ __export(index_exports, {
|
|
|
65
65
|
FasterMovingAverage: () => FasterMovingAverage,
|
|
66
66
|
FasterOBV: () => FasterOBV,
|
|
67
67
|
FasterPeriod: () => FasterPeriod,
|
|
68
|
+
FasterRMA: () => FasterRMA,
|
|
68
69
|
FasterROC: () => FasterROC,
|
|
69
70
|
FasterRSI: () => FasterRSI,
|
|
70
71
|
FasterSMA: () => FasterSMA,
|
|
@@ -81,6 +82,7 @@ __export(index_exports, {
|
|
|
81
82
|
NumberIndicatorSeries: () => NumberIndicatorSeries,
|
|
82
83
|
OBV: () => OBV,
|
|
83
84
|
Period: () => Period,
|
|
85
|
+
RMA: () => RMA,
|
|
84
86
|
ROC: () => ROC,
|
|
85
87
|
RSI: () => RSI,
|
|
86
88
|
SMA: () => SMA,
|
|
@@ -100,7 +102,7 @@ __export(index_exports, {
|
|
|
100
102
|
pushUpdate: () => pushUpdate
|
|
101
103
|
});
|
|
102
104
|
module.exports = __toCommonJS(index_exports);
|
|
103
|
-
var
|
|
105
|
+
var import_big25 = __toESM(require("big.js"), 1);
|
|
104
106
|
|
|
105
107
|
// src/error/NotEnoughDataError.ts
|
|
106
108
|
var NotEnoughDataError = class extends Error {
|
|
@@ -260,8 +262,7 @@ var FasterSMA = class extends FasterMovingAverage {
|
|
|
260
262
|
update(price, replace) {
|
|
261
263
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
262
264
|
if (this.prices.length === this.interval) {
|
|
263
|
-
|
|
264
|
-
return this.setResult(sum / this.prices.length, replace);
|
|
265
|
+
return this.setResult(getFasterAverage(this.prices), replace);
|
|
265
266
|
}
|
|
266
267
|
return null;
|
|
267
268
|
}
|
|
@@ -1435,8 +1436,89 @@ var FasterOBV = class extends NumberIndicatorSeries {
|
|
|
1435
1436
|
}
|
|
1436
1437
|
};
|
|
1437
1438
|
|
|
1438
|
-
// src/
|
|
1439
|
+
// src/RMA/RMA.ts
|
|
1439
1440
|
var import_big19 = __toESM(require("big.js"), 1);
|
|
1441
|
+
var RMA = class extends MovingAverage {
|
|
1442
|
+
constructor(interval) {
|
|
1443
|
+
super(interval);
|
|
1444
|
+
this.interval = interval;
|
|
1445
|
+
this.weightFactor = 1 / this.interval;
|
|
1446
|
+
}
|
|
1447
|
+
pricesCounter = 0;
|
|
1448
|
+
weightFactor;
|
|
1449
|
+
update(_price, replace) {
|
|
1450
|
+
if (!replace) {
|
|
1451
|
+
this.pricesCounter++;
|
|
1452
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1453
|
+
this.pricesCounter++;
|
|
1454
|
+
}
|
|
1455
|
+
const price = new import_big19.default(_price);
|
|
1456
|
+
if (replace && this.previousResult) {
|
|
1457
|
+
return this.setResult(
|
|
1458
|
+
price.times(this.weightFactor).add(this.previousResult.times(1 - this.weightFactor)),
|
|
1459
|
+
replace
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
return this.setResult(
|
|
1463
|
+
price.times(this.weightFactor).add((this.result ?? price).times(1 - this.weightFactor)),
|
|
1464
|
+
replace
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
getResultOrThrow() {
|
|
1468
|
+
if (this.pricesCounter < this.interval) {
|
|
1469
|
+
throw new NotEnoughDataError();
|
|
1470
|
+
}
|
|
1471
|
+
return this.result;
|
|
1472
|
+
}
|
|
1473
|
+
get isStable() {
|
|
1474
|
+
try {
|
|
1475
|
+
this.getResultOrThrow();
|
|
1476
|
+
return true;
|
|
1477
|
+
} catch {
|
|
1478
|
+
return false;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
var FasterRMA = class extends FasterMovingAverage {
|
|
1483
|
+
constructor(interval) {
|
|
1484
|
+
super(interval);
|
|
1485
|
+
this.interval = interval;
|
|
1486
|
+
this.weightFactor = 1 / this.interval;
|
|
1487
|
+
}
|
|
1488
|
+
pricesCounter = 0;
|
|
1489
|
+
weightFactor;
|
|
1490
|
+
update(price, replace) {
|
|
1491
|
+
if (!replace) {
|
|
1492
|
+
this.pricesCounter++;
|
|
1493
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1494
|
+
this.pricesCounter++;
|
|
1495
|
+
}
|
|
1496
|
+
if (replace && this.previousResult !== void 0) {
|
|
1497
|
+
return this.setResult(price * this.weightFactor + this.previousResult * (1 - this.weightFactor), replace);
|
|
1498
|
+
}
|
|
1499
|
+
return this.setResult(
|
|
1500
|
+
price * this.weightFactor + (this.result !== void 0 ? this.result : price) * (1 - this.weightFactor),
|
|
1501
|
+
replace
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
getResultOrThrow() {
|
|
1505
|
+
if (this.pricesCounter < this.interval) {
|
|
1506
|
+
throw new NotEnoughDataError();
|
|
1507
|
+
}
|
|
1508
|
+
return this.result;
|
|
1509
|
+
}
|
|
1510
|
+
get isStable() {
|
|
1511
|
+
try {
|
|
1512
|
+
this.getResultOrThrow();
|
|
1513
|
+
return true;
|
|
1514
|
+
} catch {
|
|
1515
|
+
return false;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
// src/ROC/ROC.ts
|
|
1521
|
+
var import_big20 = __toESM(require("big.js"), 1);
|
|
1440
1522
|
var ROC = class extends BigIndicatorSeries {
|
|
1441
1523
|
constructor(interval) {
|
|
1442
1524
|
super();
|
|
@@ -1446,7 +1528,7 @@ var ROC = class extends BigIndicatorSeries {
|
|
|
1446
1528
|
update(price, replace) {
|
|
1447
1529
|
const comparePrice = pushUpdate(this.prices, replace, price, this.interval);
|
|
1448
1530
|
if (comparePrice) {
|
|
1449
|
-
return this.setResult(new
|
|
1531
|
+
return this.setResult(new import_big20.default(price).sub(comparePrice).div(comparePrice), replace);
|
|
1450
1532
|
}
|
|
1451
1533
|
return null;
|
|
1452
1534
|
}
|
|
@@ -1467,7 +1549,7 @@ var FasterROC = class extends NumberIndicatorSeries {
|
|
|
1467
1549
|
};
|
|
1468
1550
|
|
|
1469
1551
|
// src/RSI/RSI.ts
|
|
1470
|
-
var
|
|
1552
|
+
var import_big21 = __toESM(require("big.js"), 1);
|
|
1471
1553
|
var RSI = class extends BigIndicatorSeries {
|
|
1472
1554
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1473
1555
|
super();
|
|
@@ -1478,25 +1560,25 @@ var RSI = class extends BigIndicatorSeries {
|
|
|
1478
1560
|
previousPrices = [];
|
|
1479
1561
|
avgGain;
|
|
1480
1562
|
avgLoss;
|
|
1481
|
-
maxValue = new
|
|
1563
|
+
maxValue = new import_big21.default(100);
|
|
1482
1564
|
update(price, replace) {
|
|
1483
1565
|
pushUpdate(this.previousPrices, replace, price, this.interval);
|
|
1484
1566
|
if (this.previousPrices.length < 2) {
|
|
1485
1567
|
return null;
|
|
1486
1568
|
}
|
|
1487
|
-
const currentPrice = new
|
|
1488
|
-
const previousPrice = new
|
|
1569
|
+
const currentPrice = new import_big21.default(price);
|
|
1570
|
+
const previousPrice = new import_big21.default(this.previousPrices[this.previousPrices.length - 2]);
|
|
1489
1571
|
if (currentPrice.gt(previousPrice)) {
|
|
1490
|
-
this.avgLoss.update(new
|
|
1572
|
+
this.avgLoss.update(new import_big21.default(0), replace);
|
|
1491
1573
|
this.avgGain.update(currentPrice.sub(previousPrice), replace);
|
|
1492
1574
|
} else {
|
|
1493
1575
|
this.avgLoss.update(previousPrice.sub(currentPrice), replace);
|
|
1494
|
-
this.avgGain.update(new
|
|
1576
|
+
this.avgGain.update(new import_big21.default(0), replace);
|
|
1495
1577
|
}
|
|
1496
1578
|
if (this.avgGain.isStable) {
|
|
1497
1579
|
const avgLoss = this.avgLoss.getResultOrThrow();
|
|
1498
1580
|
if (avgLoss.eq(0)) {
|
|
1499
|
-
return this.setResult(new
|
|
1581
|
+
return this.setResult(new import_big21.default(100), replace);
|
|
1500
1582
|
}
|
|
1501
1583
|
const relativeStrength = this.avgGain.getResultOrThrow().div(avgLoss);
|
|
1502
1584
|
return this.setResult(this.maxValue.minus(this.maxValue.div(relativeStrength.add(1))), replace);
|
|
@@ -1542,7 +1624,7 @@ var FasterRSI = class extends NumberIndicatorSeries {
|
|
|
1542
1624
|
};
|
|
1543
1625
|
|
|
1544
1626
|
// src/STOCH/StochasticOscillator.ts
|
|
1545
|
-
var
|
|
1627
|
+
var import_big22 = __toESM(require("big.js"), 1);
|
|
1546
1628
|
var StochasticOscillator = class extends TechnicalIndicator {
|
|
1547
1629
|
/**
|
|
1548
1630
|
* Constructs a Stochastic Oscillator.
|
|
@@ -1567,8 +1649,8 @@ var StochasticOscillator = class extends TechnicalIndicator {
|
|
|
1567
1649
|
if (this.candles.length === this.n) {
|
|
1568
1650
|
const highest = getMaximum(this.candles.map((candle2) => candle2.high));
|
|
1569
1651
|
const lowest = getMinimum(this.candles.map((candle2) => candle2.low));
|
|
1570
|
-
const divisor = new
|
|
1571
|
-
let fastK = new
|
|
1652
|
+
const divisor = new import_big22.default(highest).minus(lowest);
|
|
1653
|
+
let fastK = new import_big22.default(100).mul(new import_big22.default(candle.close).minus(lowest));
|
|
1572
1654
|
fastK = fastK.div(divisor.eq(0) ? 1 : divisor);
|
|
1573
1655
|
const stochK = this.periodM.update(fastK, replace);
|
|
1574
1656
|
const stochD = stochK && this.periodP.update(stochK, replace);
|
|
@@ -1621,7 +1703,7 @@ var FasterStochasticOscillator = class extends TechnicalIndicator {
|
|
|
1621
1703
|
};
|
|
1622
1704
|
|
|
1623
1705
|
// src/STOCH/StochasticRSI.ts
|
|
1624
|
-
var
|
|
1706
|
+
var import_big23 = __toESM(require("big.js"), 1);
|
|
1625
1707
|
var StochasticRSI = class extends BigIndicatorSeries {
|
|
1626
1708
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1627
1709
|
super();
|
|
@@ -1640,7 +1722,7 @@ var StochasticRSI = class extends BigIndicatorSeries {
|
|
|
1640
1722
|
const max = periodResult.highest;
|
|
1641
1723
|
const denominator = max.minus(min);
|
|
1642
1724
|
if (denominator.eq(0)) {
|
|
1643
|
-
return this.setResult(new
|
|
1725
|
+
return this.setResult(new import_big23.default(100), false);
|
|
1644
1726
|
}
|
|
1645
1727
|
const numerator = rsiResult.minus(min);
|
|
1646
1728
|
return this.setResult(numerator.div(denominator), false);
|
|
@@ -1678,7 +1760,7 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1678
1760
|
};
|
|
1679
1761
|
|
|
1680
1762
|
// src/WMA/WMA.ts
|
|
1681
|
-
var
|
|
1763
|
+
var import_big24 = __toESM(require("big.js"), 1);
|
|
1682
1764
|
var WMA = class extends MovingAverage {
|
|
1683
1765
|
constructor(interval) {
|
|
1684
1766
|
super(interval);
|
|
@@ -1689,9 +1771,9 @@ var WMA = class extends MovingAverage {
|
|
|
1689
1771
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1690
1772
|
if (this.prices.length === this.interval) {
|
|
1691
1773
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1692
|
-
const weightedPrice = new
|
|
1774
|
+
const weightedPrice = new import_big24.default(price2).mul(index + 1);
|
|
1693
1775
|
return acc.add(weightedPrice);
|
|
1694
|
-
}, new
|
|
1776
|
+
}, new import_big24.default(0));
|
|
1695
1777
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1696
1778
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1697
1779
|
return this.setResult(weightedMa, replace);
|
|
@@ -1756,6 +1838,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1756
1838
|
FasterMovingAverage,
|
|
1757
1839
|
FasterOBV,
|
|
1758
1840
|
FasterPeriod,
|
|
1841
|
+
FasterRMA,
|
|
1759
1842
|
FasterROC,
|
|
1760
1843
|
FasterRSI,
|
|
1761
1844
|
FasterSMA,
|
|
@@ -1772,6 +1855,7 @@ var FasterWMA = class extends FasterMovingAverage {
|
|
|
1772
1855
|
NumberIndicatorSeries,
|
|
1773
1856
|
OBV,
|
|
1774
1857
|
Period,
|
|
1858
|
+
RMA,
|
|
1775
1859
|
ROC,
|
|
1776
1860
|
RSI,
|
|
1777
1861
|
SMA,
|
package/dist/index.d.cts
CHANGED
|
@@ -102,8 +102,27 @@ declare class FasterWMA extends FasterMovingAverage {
|
|
|
102
102
|
update(price: number, replace: boolean): number | null;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
declare class RMA extends MovingAverage {
|
|
106
|
+
readonly interval: number;
|
|
107
|
+
private pricesCounter;
|
|
108
|
+
private readonly weightFactor;
|
|
109
|
+
constructor(interval: number);
|
|
110
|
+
update(_price: BigSource, replace: boolean): Big__default;
|
|
111
|
+
getResultOrThrow(): Big__default;
|
|
112
|
+
get isStable(): boolean;
|
|
113
|
+
}
|
|
114
|
+
declare class FasterRMA extends FasterMovingAverage {
|
|
115
|
+
readonly interval: number;
|
|
116
|
+
private pricesCounter;
|
|
117
|
+
private readonly weightFactor;
|
|
118
|
+
constructor(interval: number);
|
|
119
|
+
update(price: number, replace: boolean): number;
|
|
120
|
+
getResultOrThrow(): number;
|
|
121
|
+
get isStable(): boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type MovingAverageTypes = typeof EMA | typeof RMA | typeof SMA | typeof WMA | typeof WSMA;
|
|
125
|
+
type FasterMovingAverageTypes = typeof FasterEMA | typeof FasterRMA | typeof FasterSMA | typeof FasterWMA | typeof FasterWSMA;
|
|
107
126
|
|
|
108
127
|
interface BandsResult {
|
|
109
128
|
lower: Big$2;
|
|
@@ -617,4 +636,4 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
617
636
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
618
637
|
}
|
|
619
638
|
|
|
620
|
-
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPeriod, type FasterPeriodResult, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseNumber, type HighLowNumber, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseNumber, type OpenHighLowCloseVolume, type OpenHighLowCloseVolumeNumber, Period, type PeriodResult, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TR, TechnicalIndicator, WMA, WSMA, getAverage, getFasterAverage, getFasterStandardDeviation, getMaximum, getMinimum, getStandardDeviation, getStreaks, pushUpdate };
|
|
639
|
+
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseNumber, type HighLowNumber, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseNumber, type OpenHighLowCloseVolume, type OpenHighLowCloseVolumeNumber, Period, type PeriodResult, RMA, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TR, TechnicalIndicator, WMA, WSMA, getAverage, getFasterAverage, getFasterStandardDeviation, getMaximum, getMinimum, getStandardDeviation, getStreaks, pushUpdate };
|
package/dist/index.d.ts
CHANGED
|
@@ -102,8 +102,27 @@ declare class FasterWMA extends FasterMovingAverage {
|
|
|
102
102
|
update(price: number, replace: boolean): number | null;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
declare class RMA extends MovingAverage {
|
|
106
|
+
readonly interval: number;
|
|
107
|
+
private pricesCounter;
|
|
108
|
+
private readonly weightFactor;
|
|
109
|
+
constructor(interval: number);
|
|
110
|
+
update(_price: BigSource, replace: boolean): Big__default;
|
|
111
|
+
getResultOrThrow(): Big__default;
|
|
112
|
+
get isStable(): boolean;
|
|
113
|
+
}
|
|
114
|
+
declare class FasterRMA extends FasterMovingAverage {
|
|
115
|
+
readonly interval: number;
|
|
116
|
+
private pricesCounter;
|
|
117
|
+
private readonly weightFactor;
|
|
118
|
+
constructor(interval: number);
|
|
119
|
+
update(price: number, replace: boolean): number;
|
|
120
|
+
getResultOrThrow(): number;
|
|
121
|
+
get isStable(): boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type MovingAverageTypes = typeof EMA | typeof RMA | typeof SMA | typeof WMA | typeof WSMA;
|
|
125
|
+
type FasterMovingAverageTypes = typeof FasterEMA | typeof FasterRMA | typeof FasterSMA | typeof FasterWMA | typeof FasterWSMA;
|
|
107
126
|
|
|
108
127
|
interface BandsResult {
|
|
109
128
|
lower: Big$2;
|
|
@@ -617,4 +636,4 @@ declare class FasterTR extends NumberIndicatorSeries<HighLowCloseNumber> {
|
|
|
617
636
|
update(candle: HighLowCloseNumber, replace: boolean): number;
|
|
618
637
|
}
|
|
619
638
|
|
|
620
|
-
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPeriod, type FasterPeriodResult, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseNumber, type HighLowNumber, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseNumber, type OpenHighLowCloseVolume, type OpenHighLowCloseVolumeNumber, Period, type PeriodResult, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TR, TechnicalIndicator, WMA, WSMA, getAverage, getFasterAverage, getFasterStandardDeviation, getMaximum, getMinimum, getStandardDeviation, getStreaks, pushUpdate };
|
|
639
|
+
export { AC, ADX, AO, ATR, AccelerationBands, type BandsResult, BaseIndicatorSeries, BigIndicatorSeries, BollingerBands, BollingerBandsWidth, CCI, CG, DEMA, DMA, type DMAResult, DX, EMA, FasterAC, FasterADX, FasterAO, FasterATR, FasterAccelerationBands, type FasterBandsResult, FasterBollingerBands, FasterBollingerBandsWidth, FasterCCI, FasterCG, FasterDEMA, FasterDMA, type FasterDMAResult, FasterDX, FasterEMA, FasterMACD, type FasterMACDResult, FasterMAD, FasterMOM, FasterMovingAverage, type FasterMovingAverageTypes, FasterOBV, FasterPeriod, type FasterPeriodResult, FasterRMA, FasterROC, FasterRSI, FasterSMA, FasterStochasticOscillator, FasterStochasticRSI, type FasterStochasticResult, FasterTR, FasterWMA, FasterWSMA, type HighLow, type HighLowClose, type HighLowCloseNumber, type HighLowNumber, MACD, type MACDConfig, type MACDResult, MAD, MOM, MovingAverage, type MovingAverageTypes, NotEnoughDataError, NumberIndicatorSeries, OBV, type OpenHighLowClose, type OpenHighLowCloseNumber, type OpenHighLowCloseVolume, type OpenHighLowCloseVolumeNumber, Period, type PeriodResult, RMA, ROC, RSI, SMA, StochasticOscillator, StochasticRSI, type StochasticResult, type Streak, TR, TechnicalIndicator, WMA, WSMA, getAverage, getFasterAverage, getFasterStandardDeviation, getMaximum, getMinimum, getStandardDeviation, getStreaks, pushUpdate };
|
package/dist/index.js
CHANGED
|
@@ -159,8 +159,7 @@ var FasterSMA = class extends FasterMovingAverage {
|
|
|
159
159
|
update(price, replace) {
|
|
160
160
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
161
161
|
if (this.prices.length === this.interval) {
|
|
162
|
-
|
|
163
|
-
return this.setResult(sum / this.prices.length, replace);
|
|
162
|
+
return this.setResult(getFasterAverage(this.prices), replace);
|
|
164
163
|
}
|
|
165
164
|
return null;
|
|
166
165
|
}
|
|
@@ -1334,8 +1333,89 @@ var FasterOBV = class extends NumberIndicatorSeries {
|
|
|
1334
1333
|
}
|
|
1335
1334
|
};
|
|
1336
1335
|
|
|
1337
|
-
// src/
|
|
1336
|
+
// src/RMA/RMA.ts
|
|
1338
1337
|
import Big19 from "big.js";
|
|
1338
|
+
var RMA = class extends MovingAverage {
|
|
1339
|
+
constructor(interval) {
|
|
1340
|
+
super(interval);
|
|
1341
|
+
this.interval = interval;
|
|
1342
|
+
this.weightFactor = 1 / this.interval;
|
|
1343
|
+
}
|
|
1344
|
+
pricesCounter = 0;
|
|
1345
|
+
weightFactor;
|
|
1346
|
+
update(_price, replace) {
|
|
1347
|
+
if (!replace) {
|
|
1348
|
+
this.pricesCounter++;
|
|
1349
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1350
|
+
this.pricesCounter++;
|
|
1351
|
+
}
|
|
1352
|
+
const price = new Big19(_price);
|
|
1353
|
+
if (replace && this.previousResult) {
|
|
1354
|
+
return this.setResult(
|
|
1355
|
+
price.times(this.weightFactor).add(this.previousResult.times(1 - this.weightFactor)),
|
|
1356
|
+
replace
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
return this.setResult(
|
|
1360
|
+
price.times(this.weightFactor).add((this.result ?? price).times(1 - this.weightFactor)),
|
|
1361
|
+
replace
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
getResultOrThrow() {
|
|
1365
|
+
if (this.pricesCounter < this.interval) {
|
|
1366
|
+
throw new NotEnoughDataError();
|
|
1367
|
+
}
|
|
1368
|
+
return this.result;
|
|
1369
|
+
}
|
|
1370
|
+
get isStable() {
|
|
1371
|
+
try {
|
|
1372
|
+
this.getResultOrThrow();
|
|
1373
|
+
return true;
|
|
1374
|
+
} catch {
|
|
1375
|
+
return false;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
var FasterRMA = class extends FasterMovingAverage {
|
|
1380
|
+
constructor(interval) {
|
|
1381
|
+
super(interval);
|
|
1382
|
+
this.interval = interval;
|
|
1383
|
+
this.weightFactor = 1 / this.interval;
|
|
1384
|
+
}
|
|
1385
|
+
pricesCounter = 0;
|
|
1386
|
+
weightFactor;
|
|
1387
|
+
update(price, replace) {
|
|
1388
|
+
if (!replace) {
|
|
1389
|
+
this.pricesCounter++;
|
|
1390
|
+
} else if (replace && this.pricesCounter === 0) {
|
|
1391
|
+
this.pricesCounter++;
|
|
1392
|
+
}
|
|
1393
|
+
if (replace && this.previousResult !== void 0) {
|
|
1394
|
+
return this.setResult(price * this.weightFactor + this.previousResult * (1 - this.weightFactor), replace);
|
|
1395
|
+
}
|
|
1396
|
+
return this.setResult(
|
|
1397
|
+
price * this.weightFactor + (this.result !== void 0 ? this.result : price) * (1 - this.weightFactor),
|
|
1398
|
+
replace
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
getResultOrThrow() {
|
|
1402
|
+
if (this.pricesCounter < this.interval) {
|
|
1403
|
+
throw new NotEnoughDataError();
|
|
1404
|
+
}
|
|
1405
|
+
return this.result;
|
|
1406
|
+
}
|
|
1407
|
+
get isStable() {
|
|
1408
|
+
try {
|
|
1409
|
+
this.getResultOrThrow();
|
|
1410
|
+
return true;
|
|
1411
|
+
} catch {
|
|
1412
|
+
return false;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
// src/ROC/ROC.ts
|
|
1418
|
+
import Big20 from "big.js";
|
|
1339
1419
|
var ROC = class extends BigIndicatorSeries {
|
|
1340
1420
|
constructor(interval) {
|
|
1341
1421
|
super();
|
|
@@ -1345,7 +1425,7 @@ var ROC = class extends BigIndicatorSeries {
|
|
|
1345
1425
|
update(price, replace) {
|
|
1346
1426
|
const comparePrice = pushUpdate(this.prices, replace, price, this.interval);
|
|
1347
1427
|
if (comparePrice) {
|
|
1348
|
-
return this.setResult(new
|
|
1428
|
+
return this.setResult(new Big20(price).sub(comparePrice).div(comparePrice), replace);
|
|
1349
1429
|
}
|
|
1350
1430
|
return null;
|
|
1351
1431
|
}
|
|
@@ -1366,7 +1446,7 @@ var FasterROC = class extends NumberIndicatorSeries {
|
|
|
1366
1446
|
};
|
|
1367
1447
|
|
|
1368
1448
|
// src/RSI/RSI.ts
|
|
1369
|
-
import
|
|
1449
|
+
import Big21 from "big.js";
|
|
1370
1450
|
var RSI = class extends BigIndicatorSeries {
|
|
1371
1451
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1372
1452
|
super();
|
|
@@ -1377,25 +1457,25 @@ var RSI = class extends BigIndicatorSeries {
|
|
|
1377
1457
|
previousPrices = [];
|
|
1378
1458
|
avgGain;
|
|
1379
1459
|
avgLoss;
|
|
1380
|
-
maxValue = new
|
|
1460
|
+
maxValue = new Big21(100);
|
|
1381
1461
|
update(price, replace) {
|
|
1382
1462
|
pushUpdate(this.previousPrices, replace, price, this.interval);
|
|
1383
1463
|
if (this.previousPrices.length < 2) {
|
|
1384
1464
|
return null;
|
|
1385
1465
|
}
|
|
1386
|
-
const currentPrice = new
|
|
1387
|
-
const previousPrice = new
|
|
1466
|
+
const currentPrice = new Big21(price);
|
|
1467
|
+
const previousPrice = new Big21(this.previousPrices[this.previousPrices.length - 2]);
|
|
1388
1468
|
if (currentPrice.gt(previousPrice)) {
|
|
1389
|
-
this.avgLoss.update(new
|
|
1469
|
+
this.avgLoss.update(new Big21(0), replace);
|
|
1390
1470
|
this.avgGain.update(currentPrice.sub(previousPrice), replace);
|
|
1391
1471
|
} else {
|
|
1392
1472
|
this.avgLoss.update(previousPrice.sub(currentPrice), replace);
|
|
1393
|
-
this.avgGain.update(new
|
|
1473
|
+
this.avgGain.update(new Big21(0), replace);
|
|
1394
1474
|
}
|
|
1395
1475
|
if (this.avgGain.isStable) {
|
|
1396
1476
|
const avgLoss = this.avgLoss.getResultOrThrow();
|
|
1397
1477
|
if (avgLoss.eq(0)) {
|
|
1398
|
-
return this.setResult(new
|
|
1478
|
+
return this.setResult(new Big21(100), replace);
|
|
1399
1479
|
}
|
|
1400
1480
|
const relativeStrength = this.avgGain.getResultOrThrow().div(avgLoss);
|
|
1401
1481
|
return this.setResult(this.maxValue.minus(this.maxValue.div(relativeStrength.add(1))), replace);
|
|
@@ -1441,7 +1521,7 @@ var FasterRSI = class extends NumberIndicatorSeries {
|
|
|
1441
1521
|
};
|
|
1442
1522
|
|
|
1443
1523
|
// src/STOCH/StochasticOscillator.ts
|
|
1444
|
-
import
|
|
1524
|
+
import Big22 from "big.js";
|
|
1445
1525
|
var StochasticOscillator = class extends TechnicalIndicator {
|
|
1446
1526
|
/**
|
|
1447
1527
|
* Constructs a Stochastic Oscillator.
|
|
@@ -1466,8 +1546,8 @@ var StochasticOscillator = class extends TechnicalIndicator {
|
|
|
1466
1546
|
if (this.candles.length === this.n) {
|
|
1467
1547
|
const highest = getMaximum(this.candles.map((candle2) => candle2.high));
|
|
1468
1548
|
const lowest = getMinimum(this.candles.map((candle2) => candle2.low));
|
|
1469
|
-
const divisor = new
|
|
1470
|
-
let fastK = new
|
|
1549
|
+
const divisor = new Big22(highest).minus(lowest);
|
|
1550
|
+
let fastK = new Big22(100).mul(new Big22(candle.close).minus(lowest));
|
|
1471
1551
|
fastK = fastK.div(divisor.eq(0) ? 1 : divisor);
|
|
1472
1552
|
const stochK = this.periodM.update(fastK, replace);
|
|
1473
1553
|
const stochD = stochK && this.periodP.update(stochK, replace);
|
|
@@ -1520,7 +1600,7 @@ var FasterStochasticOscillator = class extends TechnicalIndicator {
|
|
|
1520
1600
|
};
|
|
1521
1601
|
|
|
1522
1602
|
// src/STOCH/StochasticRSI.ts
|
|
1523
|
-
import
|
|
1603
|
+
import Big23 from "big.js";
|
|
1524
1604
|
var StochasticRSI = class extends BigIndicatorSeries {
|
|
1525
1605
|
constructor(interval, SmoothingIndicator = WSMA) {
|
|
1526
1606
|
super();
|
|
@@ -1539,7 +1619,7 @@ var StochasticRSI = class extends BigIndicatorSeries {
|
|
|
1539
1619
|
const max = periodResult.highest;
|
|
1540
1620
|
const denominator = max.minus(min);
|
|
1541
1621
|
if (denominator.eq(0)) {
|
|
1542
|
-
return this.setResult(new
|
|
1622
|
+
return this.setResult(new Big23(100), false);
|
|
1543
1623
|
}
|
|
1544
1624
|
const numerator = rsiResult.minus(min);
|
|
1545
1625
|
return this.setResult(numerator.div(denominator), false);
|
|
@@ -1577,7 +1657,7 @@ var FasterStochasticRSI = class extends NumberIndicatorSeries {
|
|
|
1577
1657
|
};
|
|
1578
1658
|
|
|
1579
1659
|
// src/WMA/WMA.ts
|
|
1580
|
-
import
|
|
1660
|
+
import Big24 from "big.js";
|
|
1581
1661
|
var WMA = class extends MovingAverage {
|
|
1582
1662
|
constructor(interval) {
|
|
1583
1663
|
super(interval);
|
|
@@ -1588,9 +1668,9 @@ var WMA = class extends MovingAverage {
|
|
|
1588
1668
|
pushUpdate(this.prices, replace, price, this.interval);
|
|
1589
1669
|
if (this.prices.length === this.interval) {
|
|
1590
1670
|
const weightedPricesSum = this.prices.reduce((acc, price2, index) => {
|
|
1591
|
-
const weightedPrice = new
|
|
1671
|
+
const weightedPrice = new Big24(price2).mul(index + 1);
|
|
1592
1672
|
return acc.add(weightedPrice);
|
|
1593
|
-
}, new
|
|
1673
|
+
}, new Big24(0));
|
|
1594
1674
|
const weightBase = this.interval * (this.interval + 1) / 2;
|
|
1595
1675
|
const weightedMa = weightedPricesSum.div(weightBase);
|
|
1596
1676
|
return this.setResult(weightedMa, replace);
|
|
@@ -1654,6 +1734,7 @@ export {
|
|
|
1654
1734
|
FasterMovingAverage,
|
|
1655
1735
|
FasterOBV,
|
|
1656
1736
|
FasterPeriod,
|
|
1737
|
+
FasterRMA,
|
|
1657
1738
|
FasterROC,
|
|
1658
1739
|
FasterRSI,
|
|
1659
1740
|
FasterSMA,
|
|
@@ -1670,6 +1751,7 @@ export {
|
|
|
1670
1751
|
NumberIndicatorSeries,
|
|
1671
1752
|
OBV,
|
|
1672
1753
|
Period,
|
|
1754
|
+
RMA,
|
|
1673
1755
|
ROC,
|
|
1674
1756
|
RSI,
|
|
1675
1757
|
SMA,
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@vitest/coverage-v8": "^1.1.1",
|
|
16
16
|
"benchmark": "^2.1.4",
|
|
17
17
|
"dependency-cruiser": "^16.9.0",
|
|
18
|
-
"eslint": "^8.
|
|
18
|
+
"eslint": "^8.57.0",
|
|
19
19
|
"generate-changelog": "^1.8.0",
|
|
20
20
|
"husky": "^4.3.8",
|
|
21
21
|
"lint-staged": "^15.0.2",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"test:types": "npm run lint:types"
|
|
105
105
|
},
|
|
106
106
|
"type": "module",
|
|
107
|
-
"version": "6.0
|
|
107
|
+
"version": "6.1.0"
|
|
108
108
|
}
|