ta-pattern-lib
Version:
Technical Analysis and Backtesting Framework for Node.js
47 lines • 2.25 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculate_median_ohlc = exports.calculate_heikin_ashi = void 0;
const lodash_round_1 = __importDefault(require("lodash.round"));
const feature_statistics_1 = require("./feature_statistics");
const calculate_heikin_ashi = (ohlc) => {
const heikin_ashi_data = [];
// console.log("ohlc", ohlc);
for (let i = 0; i < ohlc.length; i++) {
const current_ohlc = ohlc[i];
const prev_heikin_ashi = i > 0 ? heikin_ashi_data[i - 1] : { open: 0, high: 0, low: 0, close: 0 };
const haClose = (current_ohlc.open + current_ohlc.high + current_ohlc.low + current_ohlc.close) / 4;
const haOpen = (prev_heikin_ashi.open + prev_heikin_ashi.close) / 2;
const haHigh = Math.max(current_ohlc.high, haOpen, haClose);
const haLow = Math.min(current_ohlc.low, haOpen, haClose);
const heikin_ashi = {
...current_ohlc,
open: (0, lodash_round_1.default)(haOpen, 2),
high: (0, lodash_round_1.default)(haHigh, 2),
low: (0, lodash_round_1.default)(haLow, 2),
close: (0, lodash_round_1.default)(haClose, 2),
};
heikin_ashi_data.push(heikin_ashi);
}
return heikin_ashi_data;
};
exports.calculate_heikin_ashi = calculate_heikin_ashi;
const calculate_median_ohlc = (ohlc) => {
const med_open = (0, feature_statistics_1.stats_median)(ohlc.map((tick) => tick.open));
const med_high = (0, feature_statistics_1.stats_median)(ohlc.map((tick) => tick.high));
const med_low = (0, feature_statistics_1.stats_median)(ohlc.map((tick) => tick.low));
const med_close = (0, feature_statistics_1.stats_median)(ohlc.map((tick) => tick.close));
const med_volume = (0, feature_statistics_1.stats_median)(ohlc.map((tick) => tick.volume));
return {
time: ohlc[0].time,
close: med_close,
high: med_high,
low: med_low,
open: med_open,
volume: med_volume,
};
};
exports.calculate_median_ohlc = calculate_median_ohlc;
//# sourceMappingURL=feature_ohlc.js.map
;