series-processing
Version:
Time-series processing for forex, market analysis, including MA, EMA,...
27 lines (21 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* True range
* tr = max(high - low, high - lowPrev, low - closePrev)
*
* <output series> = max(<high series>, <low series>, <close series>)
*/
var truerange = exports.truerange = function truerange(outputKey, inputKey1, inputKey2, inputKey3) {
return function (lastPoint, dataStream) {
var previousPoint = dataStream.getPrevious();
if (typeof lastPoint === 'undefined' || lastPoint === null || typeof lastPoint[inputKey1] === 'undefined' || typeof lastPoint[inputKey2] === 'undefined' || typeof previousPoint === 'undefined' || previousPoint === null || typeof previousPoint[inputKey2] === 'undefined' || typeof previousPoint[inputKey3] === 'undefined') {
return null;
}
var t = Math.max(lastPoint[inputKey1] - lastPoint[inputKey2], lastPoint[inputKey1] - previousPoint[inputKey2], lastPoint[inputKey2] - previousPoint[inputKey3]);
return _defineProperty({}, outputKey, t);
};
};