pricehistory
Version:
Series data with technical indicators.
113 lines (112 loc) • 6.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const simpul_1 = require("simpul");
function setCandleCandlestick(option, candle, series) {
if (option.candlestick !== true ||
typeof candle.priceOpen !== "number" ||
typeof candle.priceHigh !== "number" ||
typeof candle.priceLow !== "number" ||
typeof candle.priceClose !== "number")
return;
const size = typeof candle.priceRange === "number"
? candle.priceRange
: simpul_1.math.discrepancy(candle.priceLow, candle.priceHigh);
const body = simpul_1.math.discrepancy(candle.priceOpen, candle.priceClose);
const upper = simpul_1.math.discrepancy(Math.max(candle.priceOpen, candle.priceClose), candle.priceHigh);
const lower = simpul_1.math.discrepancy(Math.min(candle.priceOpen, candle.priceClose), candle.priceLow);
const upperGap = simpul_1.math.discrepancy(candle.priceClose, candle.priceHigh);
const lowerGap = simpul_1.math.discrepancy(candle.priceClose, candle.priceLow);
candle.candlestickBody = simpul_1.math.percent(body, size);
candle.candlestickUpper = simpul_1.math.percent(upper, size);
candle.candlestickLower = simpul_1.math.percent(lower, size);
candle.candlestickUpperGap = simpul_1.math.percent(upperGap, size);
candle.candlestickLowerGap = simpul_1.math.percent(lowerGap, size);
candle.candlestickIsBullish = candle.priceClose > candle.priceOpen;
candle.candlestickIsBearish = candle.priceClose < candle.priceOpen;
candle.candlestickIsNeutral = candle.priceClose === candle.priceOpen;
const prev1 = series[series.length - 2];
const prev2 = series[series.length - 3];
candle.candlestickIsBullishPrev1 = false;
candle.candlestickIsBullishPrev2 = false;
candle.candlestickIsEngulfed = false;
candle.candlestickIsGapUp = false;
candle.candlestickIsGapDown = false;
if (typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceOpen) === "number" &&
typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceHigh) === "number" &&
typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceLow) === "number" &&
typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceClose) === "number") {
candle.candlestickIsBullishPrev1 = prev1.priceClose > prev1.priceOpen;
const currEnd = getEnds([candle.priceOpen, candle.priceClose]);
const prev1End = getEnds([prev1.priceOpen, prev1.priceClose]);
candle.candlestickIsEngulfed =
prev1End.top <= currEnd.top && prev1End.bottom >= currEnd.bottom;
candle.candlestickIsGapUp = prev1End.top < currEnd.bottom;
candle.candlestickIsGapDown = prev1End.bottom > currEnd.top;
}
if (typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceOpen) === "number" &&
typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceHigh) === "number" &&
typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceLow) === "number" &&
typeof (prev1 === null || prev1 === void 0 ? void 0 : prev1.priceClose) === "number" &&
typeof (prev2 === null || prev2 === void 0 ? void 0 : prev2.priceOpen) === "number" &&
typeof (prev2 === null || prev2 === void 0 ? void 0 : prev2.priceHigh) === "number" &&
typeof (prev2 === null || prev2 === void 0 ? void 0 : prev2.priceLow) === "number" &&
typeof (prev2 === null || prev2 === void 0 ? void 0 : prev2.priceClose) === "number") {
candle.candlestickIsBullishPrev2 = prev2.priceClose > prev2.priceOpen;
}
if (typeof candle.candlestickUpper !== "number" ||
typeof candle.candlestickBody !== "number" ||
typeof candle.candlestickLower !== "number")
return;
candle.candlestickIsUpper0 = candle.candlestickUpper < 10;
candle.candlestickIsBody0 = candle.candlestickBody < 10;
candle.candlestickIsLower0 = candle.candlestickLower < 10;
candle.candlestickIsUpperGap0 = candle.candlestickUpperGap < 10;
candle.candlestickIsLowerGap0 = candle.candlestickLowerGap < 10;
candle.candlestickIsUpper1 = candle.candlestickUpper > 90;
candle.candlestickIsBody1 = candle.candlestickBody > 90;
candle.candlestickIsLower1 = candle.candlestickLower > 90;
candle.candlestickIsUpperGap1 = candle.candlestickUpperGap > 90;
candle.candlestickIsLowerGap1 = candle.candlestickLowerGap > 90;
candle.candlestickIsUpperGreaterThanBody1 =
candle.candlestickUpper > candle.candlestickBody;
candle.candlestickIsUpperGreaterThanBody2 =
candle.candlestickUpper > candle.candlestickBody * 2;
candle.candlestickIsUpperGreaterThanBody3 =
candle.candlestickUpper > candle.candlestickBody * 3;
candle.candlestickIsUpperSmallerThanBody1 =
candle.candlestickUpper < candle.candlestickBody;
candle.candlestickIsUpperSmallerThanBody2 =
candle.candlestickUpper < candle.candlestickBody / 2;
candle.candlestickIsUpperSmallerThanBody3 =
candle.candlestickUpper < candle.candlestickBody / 3;
candle.candlestickIsLowerGreaterThanBody1 =
candle.candlestickLower > candle.candlestickBody;
candle.candlestickIsLowerGreaterThanBody2 =
candle.candlestickLower > candle.candlestickBody * 2;
candle.candlestickIsLowerGreaterThanBody3 =
candle.candlestickLower > candle.candlestickBody * 3;
candle.candlestickIsLowerSmallerThanBody1 =
candle.candlestickLower < candle.candlestickBody;
candle.candlestickIsLowerSmallerThanBody2 =
candle.candlestickLower < candle.candlestickBody / 2;
candle.candlestickIsLowerSmallerThanBody3 =
candle.candlestickLower < candle.candlestickBody / 3;
candle.candlestickIsUpperGapGreaterThanLowerGap1 =
candle.candlestickUpperGap > candle.candlestickLowerGap;
candle.candlestickIsUpperGapGreaterThanLowerGap2 =
candle.candlestickUpperGap > candle.candlestickLowerGap * 2;
candle.candlestickIsUpperGapGreaterThanLowerGap3 =
candle.candlestickUpperGap > candle.candlestickLowerGap * 3;
candle.candlestickIsLowerGapGreaterThanUpperGap1 =
candle.candlestickLowerGap > candle.candlestickUpperGap;
candle.candlestickIsLowerGapGreaterThanUpperGap2 =
candle.candlestickLowerGap > candle.candlestickUpperGap * 2;
candle.candlestickIsLowerGapGreaterThanUpperGap3 =
candle.candlestickLowerGap > candle.candlestickUpperGap * 3;
}
function getEnds(candle) {
return candle[0] <= candle[1]
? { bottom: candle[0], top: candle[1] }
: { bottom: candle[1], top: candle[0] };
}
exports.default = setCandleCandlestick;