Skip to content

Commit

Permalink
feat: Add Momentum to Accelerator Oscillator (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benny Neugebauer authored Aug 5, 2021
1 parent eea7899 commit ae9bc24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/AC/AC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ describe('AC', () => {
// https://github.com/jesse-ai/jesse/blob/53297462d48ebf43f9df46ab5005076d25073e5e/tests/test_indicators.py#L14
expect(ac.isStable).toBeTrue();
expect(ac.getResult().toFixed(2)).toBe('-21.97');
expect(ac.momentum.getResult().toFixed(2)).toBe('-9.22');
});

it('throws an error when there is not enough input data', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/AC/AC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Big, {BigSource} from 'big.js';
import {NotEnoughDataError} from '../error';
import {AO} from '../AO/AO';
import {SMA} from '../SMA/SMA';
import {MOM} from '../MOM/MOM';

/**
* The Accelerator Oscillator (AC) is an indicator used to detect when a momentum changes. It has been developed by
Expand All @@ -12,13 +13,15 @@ import {SMA} from '../SMA/SMA';
* change of momentum.
*/
export class AC implements SimpleIndicator {
public readonly momentum: MOM;
private readonly ao: AO;
private result: Big | undefined;
private readonly signalSMA: SMA;

constructor(public readonly shortAO: number, public readonly longAO: number, public readonly signalInterval: number) {
this.ao = new AO(shortAO, longAO);
this.signalSMA = new SMA(signalInterval);
this.momentum = new MOM(1);
}

get isStable(): boolean {
Expand All @@ -40,6 +43,7 @@ export class AC implements SimpleIndicator {
this.signalSMA.update(ao);
if (this.signalSMA.isStable) {
this.result = ao.sub(this.signalSMA.getResult());
this.momentum.update(this.result);
}
}
}
Expand Down

0 comments on commit ae9bc24

Please sign in to comment.