UNPKG

series-processing

Version:

Time-series processing for forex, market analysis, including MA, EMA,...

24 lines (21 loc) 879 B
/** * True range * tr = max(high - low, high - lowPrev, low - closePrev) * * <output series> = max(<high series>, <low series>, <close series>) */ export const truerange = (outputKey, inputKey1, inputKey2, inputKey3) => (lastPoint, dataStream) => { const 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; } const t = Math.max( lastPoint[inputKey1] - lastPoint[inputKey2], lastPoint[inputKey1] - previousPoint[inputKey2], lastPoint[inputKey2] - previousPoint[inputKey3] ); return { [outputKey] : t }; };