Skip to content

Commit

Permalink
feat: Add isStable to DMA indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Jun 1, 2020
1 parent e1d7771 commit 5f1f9dc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/DMA/DMA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import twoDays from '../test/fixtures/DMA/LTC-USDT-1h-2d.json';
import {DMA} from './DMA';

describe('DMA', () => {
describe('isStable', () => {
it('is dependant on the long interval', () => {
const dma = new DMA(3, 5);
dma.update(40);
dma.update(30);
dma.update(20);
expect(dma.isStable).toBeFalse();
dma.update(10);
dma.update(30);
expect(dma.isStable).toBeTrue();
});
});

describe('getResult', () => {
it('detects uptrends', () => {
const dma = new DMA(3, 8);
Expand Down
4 changes: 4 additions & 0 deletions src/DMA/DMA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export class DMA {
this.long = new SMA(long);
}

get isStable(): boolean {
return this.long.isStable;
}

update(_price: BigSource): void {
const price = new Big(_price);

Expand Down
4 changes: 2 additions & 2 deletions src/MACD/MACD.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe('MACD', () => {
];

expect(mockedPrices.length).toBe(longInterval);
expect(macd.isStable).toBe(false);
expect(macd.isStable).toBeFalse();

mockedPrices.forEach(price => macd.update(price));

expect(macd.isStable).toBe(true);
expect(macd.isStable).toBeTrue();
});
});
});
4 changes: 2 additions & 2 deletions src/ROC/ROC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ describe('ROC', () => {
];

expect(mockedPrices.length).toBe(interval + 1);
expect(indicator.isStable).toBe(false);
expect(indicator.isStable).toBeFalse();

mockedPrices.forEach(price => indicator.update(price));

expect(indicator.isStable).toBe(true);
expect(indicator.isStable).toBeTrue();
});
});
});
4 changes: 2 additions & 2 deletions src/SMA/SMA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ describe('SMA', () => {
const sma = new SMA(3);
sma.update(40);
sma.update(30);
expect(sma.isStable).toBe(false);
expect(sma.isStable).toBeFalse();
sma.update(20);
expect(sma.isStable).toBe(true);
expect(sma.isStable).toBeTrue();
sma.update('10');
sma.update(new Big(30));
expect(sma.getResult().valueOf()).toBe('20');
Expand Down

0 comments on commit 5f1f9dc

Please sign in to comment.