series-processing
Version:
Time-series processing for forex, market analysis, including MA, EMA,...
24 lines (20 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MACD = undefined;
var _EMA = require('./EMA');
var _subtract = require('./subtract');
/**
* Moving Average Convergence/Divergence (MACD)
* @see https://en.wikipedia.org/wiki/Moving_average
*
* <output series> = macd(<input series>, fastLength, slowLength, signalLength)
*/
var MACD = exports.MACD = function MACD(outputKey, inputKey, fastLength, slowLength, signalLength) {
return [(0, _EMA.EMA)(outputKey + '_fast', inputKey, fastLength), // fast = ema(close, fastLength)
(0, _EMA.EMA)(outputKey + '_slow', inputKey, slowLength), // slow = ema(close, slowLength)
(0, _subtract.subtract)(outputKey + '_macd', outputKey + '_fast', outputKey + '_slow'), // macd = fast - slow
(0, _EMA.EMA)(outputKey + '_emacd', outputKey + '_macd', signalLength), // emacd = ema(macd, signalLength)
(0, _subtract.subtract)(outputKey, outputKey + '_macd', outputKey + '_emacd')];
};