Skip to content

Commit

Permalink
feat(AC,AO): Directly return result on update
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Aug 12, 2021
1 parent 4e07eb6 commit 1ea3efe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/AC/AC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export class AC implements SimpleIndicator {
return this.result;
}

update(low: BigSource, high: BigSource): void {
this.ao.update(low, high);
if (this.ao.isStable) {
const ao = this.ao.getResult();
update(low: BigSource, high: BigSource): void | Big {
const ao = this.ao.update(low, high);
if (ao) {
this.signal.update(ao);
if (this.signal.isStable) {
this.result = ao.sub(this.signal.getResult());
this.momentum.update(this.result);
return this.result;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/AO/AO.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ describe('AO', () => {
];
const ao = new AO(5, 34);
for (let i = 0; i < lows.length; i++) {
ao.update(lows[i], highs[i]);
const newResult = ao.update(lows[i], highs[i]);
if (ao.isStable) {
expect(newResult!).not.toBeUndefined();
const actual = ao.getResult().toFixed(4);
const expected = aos.shift();
expect(parseFloat(actual)).toBe(expected!);
Expand Down
3 changes: 2 additions & 1 deletion src/AO/AO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AO implements SimpleIndicator {
return this.result;
}

update(low: BigSource, high: BigSource): void {
update(low: BigSource, high: BigSource): void | Big {
const candleSum = new Big(low).add(high);
const medianPrice = candleSum.div(2);

Expand All @@ -39,6 +39,7 @@ export class AO implements SimpleIndicator {

if (this.short.isStable && this.long.isStable) {
this.result = this.short.getResult().sub(this.long.getResult());
return this.result;
}
}
}

0 comments on commit 1ea3efe

Please sign in to comment.