UNPKG

stock-indicator

Version:

Stock Indicator Library

58 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CR = CR; const common_1 = require("../common"); function CR(HIGH, LOW, N = 26, M1 = 10, M2 = 20, M3 = 40, M4 = 62) { // check input (0, common_1.checkArrayOfNumbers)(HIGH, "HIGH"); (0, common_1.checkArrayOfNumbers)(LOW, "LOW"); (0, common_1.checkNumber)(N, 1, HIGH, "N", "HIGH"); (0, common_1.checkNumber)(M1, 1, HIGH, "M1", "HIGH"); (0, common_1.checkNumber)(M2, 1, HIGH, "M2", "HIGH"); (0, common_1.checkNumber)(M3, 1, HIGH, "M3", "HIGH"); (0, common_1.checkNumber)(M4, 1, HIGH, "M4", "HIGH"); // MID:=REF(HIGH+LOW,1)/2; const MID = [ null, ...HIGH.map((h, i) => (h + LOW[i]) / 2).slice(0, -1), ]; console.log("MID:", MID.slice(0, 10)); // CR:SUM(MAX(0,HIGH-MID),N)/SUM(MAX(0,MID-LOW),N)*100; const CR = (0, common_1.funArrDiv)((0, common_1.funMS)(HIGH.map((h, i) => (MID[i] !== null ? Math.max(0, h - MID[i]) : null)), N), (0, common_1.funMS)(LOW.map((l, i) => (MID[i] !== null ? Math.max(0, MID[i] - l) : null)), N)).map((v) => (v !== null ? v * 100 : null)); /** * ****************当REF的参数N为小数时,处理方式不同********************** * 前面补null个数为Math.ceil(N) * 后门的计算为 [].slice(Math.ceil(N % 1),-Math.floor(N)) * 这个特此说明一下,REF可以写成函数进行处理 */ // MA1:REF(MA(CR,M1),M1/2.5+1); const MA1 = [ ...Array.from({ length: Math.ceil(M1 / 2.5 + 1) }).fill(null), ...(0, common_1.funMA)(CR, M1) .slice(Math.ceil((M1 / 2.5) % 1), -Math.floor(M1 / 2.5 + 1)) .map((v) => (0, common_1.funRound)(v, 3)), ]; // MA2:REF(MA(CR,M2),M2/2.5+1); const MA2 = [ ...Array.from({ length: Math.ceil(M2 / 2.5 + 1) }).fill(null), ...(0, common_1.funMA)(CR, M2) .slice(Math.ceil((M2 / 2.5) % 1), -Math.floor(M2 / 2.5 + 1)) .map((v) => (0, common_1.funRound)(v, 3)), ]; // MA3:REF(MA(CR,M3),M3/2.5+1); const MA3 = [ ...Array.from({ length: Math.ceil(M3 / 2.5 + 1) }).fill(null), ...(0, common_1.funMA)(CR, M3) .slice(Math.ceil((M3 / 2.5) % 1), -Math.floor(M3 / 2.5 + 1)) .map((v) => (0, common_1.funRound)(v, 3)), ]; // MA4:REF(MA(CR,M4),M4/2.5+1); const MA4 = [ ...Array.from({ length: Math.ceil(M4 / 2.5 + 1) }).fill(null), ...(0, common_1.funMA)(CR, M4) .slice(Math.ceil((M4 / 2.5) % 1), -Math.floor(M4 / 2.5 + 1)) .map((v) => (0, common_1.funRound)(v, 3)), ]; return { CR: CR.map((v) => (0, common_1.funRound)(v, 3)), MA1, MA2, MA3, MA4 }; } //# sourceMappingURL=cr.js.map