trading-signals 3.3.0 → 3.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/dist/MACD/MACD.d.ts +20 -5
- package/dist/MACD/MACD.js +53 -14
- package/dist/MACD/MACD.js.map +1 -1
- package/package.json +1 -1
package/dist/MACD/MACD.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EMA } from '../EMA/EMA';
|
|
1
|
+
import { EMA, FasterEMA } from '../EMA/EMA';
|
|
2
2
|
import Big, { BigSource } from 'big.js';
|
|
3
|
-
import { DEMA } from '..';
|
|
3
|
+
import { DEMA, FasterDEMA } from '..';
|
|
4
4
|
import { Indicator } from '../Indicator';
|
|
5
5
|
export declare type MACDConfig = {
|
|
6
6
|
indicator: typeof EMA | typeof DEMA;
|
|
@@ -13,15 +13,30 @@ export declare type MACDResult = {
|
|
|
13
13
|
macd: Big;
|
|
14
14
|
signal: Big;
|
|
15
15
|
};
|
|
16
|
+
export declare type FasterMACDResult = {
|
|
17
|
+
histogram: number;
|
|
18
|
+
macd: number;
|
|
19
|
+
signal: number;
|
|
20
|
+
};
|
|
16
21
|
export declare class MACD implements Indicator<MACDResult> {
|
|
17
|
-
|
|
22
|
+
readonly prices: BigSource[];
|
|
18
23
|
readonly long: EMA | DEMA;
|
|
19
24
|
readonly short: EMA | DEMA;
|
|
20
25
|
private readonly signal;
|
|
21
|
-
private age;
|
|
22
26
|
private result;
|
|
23
27
|
constructor(config: MACDConfig);
|
|
24
28
|
get isStable(): boolean;
|
|
25
|
-
update(_price: BigSource): void;
|
|
29
|
+
update(_price: BigSource): void | MACDResult;
|
|
26
30
|
getResult(): MACDResult;
|
|
27
31
|
}
|
|
32
|
+
export declare class FasterMACD implements Indicator<FasterMACDResult> {
|
|
33
|
+
readonly short: FasterEMA | FasterDEMA;
|
|
34
|
+
readonly long: FasterEMA | FasterDEMA;
|
|
35
|
+
readonly signal: FasterEMA | FasterDEMA;
|
|
36
|
+
readonly prices: number[];
|
|
37
|
+
private result;
|
|
38
|
+
constructor(short: FasterEMA | FasterDEMA, long: FasterEMA | FasterDEMA, signal: FasterEMA | FasterDEMA);
|
|
39
|
+
getResult(): FasterMACDResult;
|
|
40
|
+
get isStable(): boolean;
|
|
41
|
+
update(price: number): void | FasterMACDResult;
|
|
42
|
+
}
|
package/dist/MACD/MACD.js
CHANGED
|
@@ -3,32 +3,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MACD = void 0;
|
|
6
|
+
exports.FasterMACD = exports.MACD = void 0;
|
|
7
7
|
const big_js_1 = __importDefault(require("big.js"));
|
|
8
8
|
const __1 = require("..");
|
|
9
9
|
class MACD {
|
|
10
10
|
constructor(config) {
|
|
11
|
-
this.
|
|
12
|
-
this.age = 0;
|
|
11
|
+
this.prices = [];
|
|
13
12
|
this.long = new config.indicator(config.longInterval);
|
|
14
13
|
this.short = new config.indicator(config.shortInterval);
|
|
15
14
|
this.signal = new config.indicator(config.signalInterval);
|
|
16
15
|
}
|
|
17
16
|
get isStable() {
|
|
18
|
-
return this.
|
|
17
|
+
return this.result !== undefined;
|
|
19
18
|
}
|
|
20
19
|
update(_price) {
|
|
21
20
|
const price = new big_js_1.default(_price);
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
macd
|
|
30
|
-
signal
|
|
31
|
-
|
|
21
|
+
this.prices.push(price);
|
|
22
|
+
const short = this.short.update(price);
|
|
23
|
+
const long = this.long.update(price);
|
|
24
|
+
if (this.prices.length > this.long.interval) {
|
|
25
|
+
this.prices.shift();
|
|
26
|
+
}
|
|
27
|
+
if (this.prices.length === this.long.interval) {
|
|
28
|
+
const macd = short.sub(long);
|
|
29
|
+
const signal = this.signal.update(macd);
|
|
30
|
+
return (this.result = {
|
|
31
|
+
histogram: macd.sub(signal),
|
|
32
|
+
macd: macd,
|
|
33
|
+
signal,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
getResult() {
|
|
34
38
|
if (!this.isStable || this.result === undefined) {
|
|
@@ -38,4 +42,39 @@ class MACD {
|
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
exports.MACD = MACD;
|
|
45
|
+
class FasterMACD {
|
|
46
|
+
constructor(short, long, signal) {
|
|
47
|
+
this.short = short;
|
|
48
|
+
this.long = long;
|
|
49
|
+
this.signal = signal;
|
|
50
|
+
this.prices = [];
|
|
51
|
+
}
|
|
52
|
+
getResult() {
|
|
53
|
+
if (this.result === undefined) {
|
|
54
|
+
throw new __1.NotEnoughDataError();
|
|
55
|
+
}
|
|
56
|
+
return this.result;
|
|
57
|
+
}
|
|
58
|
+
get isStable() {
|
|
59
|
+
return this.result !== undefined;
|
|
60
|
+
}
|
|
61
|
+
update(price) {
|
|
62
|
+
this.prices.push(price);
|
|
63
|
+
const short = this.short.update(price);
|
|
64
|
+
const long = this.long.update(price);
|
|
65
|
+
if (this.prices.length > this.long.interval) {
|
|
66
|
+
this.prices.shift();
|
|
67
|
+
}
|
|
68
|
+
if (this.prices.length === this.long.interval) {
|
|
69
|
+
const macd = short - long;
|
|
70
|
+
const signal = this.signal.update(macd);
|
|
71
|
+
return (this.result = {
|
|
72
|
+
histogram: macd - signal,
|
|
73
|
+
macd,
|
|
74
|
+
signal,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.FasterMACD = FasterMACD;
|
|
41
80
|
//# sourceMappingURL=MACD.js.map
|
package/dist/MACD/MACD.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MACD.js","sourceRoot":"","sources":["../../src/MACD/MACD.ts"],"names":[],"mappings":";;;;;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