pricehistory
Version:
Series data with technical indicators.
61 lines (60 loc) • 2.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const simpul_1 = require("simpul");
const option_propsPrice_1 = __importDefault(require("./option.propsPrice"));
function setCandleSMA(option, candle, series, period) {
var _a;
if (option.sma !== true)
return;
if (typeof candle.priceClose === "number") {
const prices = [];
for (const i of series) {
if (typeof i.priceClose === "number")
prices.push(i.priceClose);
}
const sma = simpul_1.math.mean(prices);
if (typeof sma === "number") {
const key = `sma${period}`;
candle[key] = sma;
for (const priceProp of option_propsPrice_1.default) {
if (priceProp === key)
continue;
if (typeof candle[priceProp] === "number") {
candle[`${key}Signal${(0, simpul_1.capitalize)(priceProp)}`] = simpul_1.math.change.percent(sma, candle[priceProp]);
}
}
if (typeof option.smaStats === "object" && ((_a = option.smaStats) === null || _a === void 0 ? void 0 : _a.length)) {
for (const smaStat of option.smaStats) {
if (smaStat === "variance") {
candle[`${key}Variance`] = simpul_1.math.variance(prices);
}
else if (smaStat === "standarddeviation") {
candle[`${key}StandardDeviation`] = simpul_1.math.standarddeviation(prices);
}
else if (smaStat === "zscore") {
candle[`${key}Zscore`] = simpul_1.math.zscore(candle.priceClose, prices);
}
else if (smaStat === "trendSlope") {
candle[`${key}TrendSlope`] = simpul_1.math.trendSlope(prices);
}
}
}
}
}
if (typeof candle.volume === "number") {
const volumes = [];
for (const i of series) {
if (typeof i.volume === "number")
volumes.push(i.volume);
}
const sma = simpul_1.math.mean(volumes);
if (typeof sma === "number") {
candle[`sma${period}Volume`] = sma;
candle[`sma${period}VolumeSignal`] = simpul_1.math.change.percent(sma, candle.volume);
}
}
}
exports.default = setCandleSMA;