Skip to content

Commit

Permalink
refactor(SMA): Use average-calculating code
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Jan 14, 2025
1 parent b9dfc73 commit fa3a57d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/SMA/SMA.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {BigSource} from 'big.js';
import {FasterMovingAverage, MovingAverage} from '../MA/MovingAverage.js';
import {getAverage} from '../util/getAverage.js';
import {getAverage, getFasterAverage} from '../util/getAverage.js';
import {pushUpdate} from '../util/pushUpdate.js';

/**
Expand Down Expand Up @@ -33,8 +33,7 @@ export class FasterSMA extends FasterMovingAverage {
pushUpdate(this.prices, replace, price, this.interval);

if (this.prices.length === this.interval) {
const sum = this.prices.reduce((a, b) => a + b, 0);
return this.setResult(sum / this.prices.length, replace);
return this.setResult(getFasterAverage(this.prices), replace);
}

return null;
Expand Down

0 comments on commit fa3a57d

Please sign in to comment.