trading-utils
Version:
A collection of helpful trading utility functions.
23 lines • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmaIndicatorImpl = void 0;
const lodash_1 = require("lodash");
const movingAverageService_1 = require("../common/movingAverageService");
class EmaIndicatorImpl {
calculate(prices) {
const hundredDayEMAs = this.calculateEMAIndicators(prices);
return prices[prices.length - 1] > hundredDayEMAs[hundredDayEMAs.length - 1] ? 'LONG' : 'SHORT';
}
calculateEMAIndicators = (prices) => {
const movingAverageLength = 50;
const multiplier = 2 / (movingAverageLength + 1);
const sma = movingAverageService_1.movingAverageService.calculateSMA(prices.slice(0, movingAverageLength));
const emas = [sma];
for (let i = movingAverageLength, a = 0; i < prices.length; i++, a++) {
emas.push(movingAverageService_1.movingAverageService.calculateEMA(prices[i], emas[a], multiplier));
}
return emas.map((value) => lodash_1.round(value, 2));
};
}
exports.EmaIndicatorImpl = EmaIndicatorImpl;
//# sourceMappingURL=emaIndicator.js.map