react-financial-charts
Version:
React charts specific to finance.
31 lines • 1.11 kB
JavaScript
import { identity, mappedSlidingWindow } from "../utils";
export default function () {
let source = identity;
const calculator = (data) => {
const algorithm = mappedSlidingWindow()
.windowSize(2)
// @ts-ignore
.undefinedValue(({ open, high, low, close }) => {
close = (open + high + low + close) / 4;
return { open, high, low, close };
})
.accumulator(([prev, now]) => {
const { date, volume } = now;
const close = (now.open + now.high + now.low + now.close) / 4;
const open = (prev.open + prev.close) / 2;
const high = Math.max(open, now.high, close);
const low = Math.min(open, now.low, close);
return { date, open, high, low, close, volume };
});
return algorithm(data);
};
calculator.source = (newSource) => {
if (newSource === undefined) {
return source;
}
source = newSource;
return calculator;
};
return calculator;
}
//# sourceMappingURL=heikinAshi.js.map