@showr/indicators
Version:
Technical indicators for Trading made with Showr
32 lines (31 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MACD = void 0;
const core_1 = require("@showr/core");
const __1 = require("../");
class MACD extends core_1.Indicator {
constructor(name = 'MACD', params) {
super(name, function (dataset) {
const datasetLength = dataset.value.length;
if (datasetLength === 1) {
return 0;
}
return (dataset.quotes[datasetLength - 1].getIndicator('ema12') -
dataset.quotes[datasetLength - 1].getIndicator('ema26'));
}, {
params,
beforeCalculate: (dataset) => {
const ema12 = new __1.EMA('ema12', {
period: 12,
attribute: params.attribute,
});
const ema26 = new __1.EMA('ema26', {
period: 26,
attribute: params.attribute,
});
dataset.apply(ema12, ema26);
},
});
}
}
exports.MACD = MACD;