File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ describe('DMA', () => {
30
30
} ) ;
31
31
32
32
describe ( 'isStable' , ( ) => {
33
- it ( 'is dependant on the long interval' , ( ) => {
33
+ it ( 'is dependant on the long interval (SMA) ' , ( ) => {
34
34
const dma = new DMA ( 3 , 5 ) ;
35
35
dma . update ( 40 ) ;
36
36
dma . update ( 30 ) ;
@@ -40,6 +40,17 @@ describe('DMA', () => {
40
40
dma . update ( 30 ) ;
41
41
expect ( dma . isStable ) . toBeTrue ( ) ;
42
42
} ) ;
43
+
44
+ it ( 'is dependant on the long interval (EMA)' , ( ) => {
45
+ const dma = new DMA ( 3 , 5 , EMA ) ;
46
+ dma . update ( 40 ) ;
47
+ dma . update ( 30 ) ;
48
+ dma . update ( 20 ) ;
49
+ expect ( dma . isStable ) . toBeFalse ( ) ;
50
+ dma . update ( 10 ) ;
51
+ dma . update ( 30 ) ;
52
+ expect ( dma . isStable ) . toBeTrue ( ) ;
53
+ } ) ;
43
54
} ) ;
44
55
45
56
describe ( 'getResult' , ( ) => {
Original file line number Diff line number Diff line change @@ -7,21 +7,22 @@ export type DMAResult = {long: Big; short: Big};
7
7
export class DMA {
8
8
public readonly long : MovingAverage ;
9
9
public readonly short : MovingAverage ;
10
+ private received : number = 0 ;
10
11
11
12
constructor ( short : number , long : number , Indicator : typeof EMA | typeof SMA = SMA ) {
12
13
this . short = new Indicator ( short ) ;
13
14
this . long = new Indicator ( long ) ;
14
15
}
15
16
16
17
get isStable ( ) : boolean {
17
- return this . long . isStable ;
18
+ return this . received >= this . long . interval ;
18
19
}
19
20
20
21
update ( _price : BigSource ) : void {
21
22
const price = new Big ( _price ) ;
22
-
23
23
this . short . update ( price ) ;
24
24
this . long . update ( price ) ;
25
+ this . received += 1 ;
25
26
}
26
27
27
28
getResult ( ) : DMAResult {
You can’t perform that action at this time.
0 commit comments