UNPKG

sql-synergy

Version:

Synergy Wave TA

200 lines (199 loc) 7.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Step2 = void 0; const Analyzer_1 = require("./Analyzer"); class Step2 extends Analyzer_1.Analyzer { // iCSFormations: Array<number> = new Array(0); constructor(oPC) { super(oPC); this.calculateSignals(); // this.iCSFormations = this.getFormations(); } // public hasBRF(iDay: number): boolean { // while (iDay >= 0) { // if (this.iCSFormations[iDay] < 0) // return false; // if (this.iCSFormations[iDay] > 0) { // this.iReferenceDay = this.iCSFormations[iDay]; // this.iSignalDay = iDay; // return true; // } // iDay--; // } // return false; // } // public getRecentTCR(): number { // let iDay = this.oPC.getLastDay(); // while (iDay >= 0) { // let iD = this.getTCRChange(iDay); // if (iD != 0) // return iDay; // iDay--; // } // return 0; // } // public getTCRChange(iDay: number): number { // if (this.hasBRFCS(iDay)) // return 1; // if (this.hasTRFCS(iDay)) // return -1; // return 0; // } // public hasBRFCS(iDay: number): boolean { // if (iDay >= 0) { // if (this.iCSFormations[iDay] < 0) // return false; // if (this.iCSFormations[iDay] > 0) { // this.iReferenceDay = this.iCSFormations[iDay]; // this.iSignalDay = iDay; // return this.hasTRF(iDay - 1); // } // } // return false; // } // public hasTRF(iDay: number): boolean { // while (iDay >= 0) { // if (this.iCSFormations[iDay] < 0) { // this.iReferenceDay = -this.iCSFormations[iDay]; // this.iSignalDay = iDay; // return true; // } // if (this.iCSFormations[iDay] > 0) // return false; // iDay--; // } // return false; // } // public hasTRFCS(iDay: number): boolean { // if (iDay >= 0) { // if (this.iCSFormations[iDay] < 0) { // this.iReferenceDay = -this.iCSFormations[iDay]; // this.iSignalDay = iDay; // return this.hasBRF(iDay - 1); // } // if (this.iCSFormations[iDay] > 0) // return false; // } // return false; // } calculateSignals() { // this.fAction = this.getFormations() ; // } // public getFormations(): Array<number> { // console.log(this.oPC) ; var n = this.oPC.size(); var iRefCS = 0; // var iCS: Array<number> = new Array(n); for (var i = 1; i < n; i++) { let iNewRefCS = this.isTCR(iRefCS, i); if (iNewRefCS >= 0 && iRefCS >= 0) this.fAction[i] = 0; else if (iNewRefCS <= 0 && iRefCS <= 0) this.fAction[i] = 0; else this.fAction[i] = iNewRefCS; iRefCS = iNewRefCS; } // return this.fAction; } // public iReferenceDay: number = 0; //, iNewReferenceDay = 0 ; // public getReferenceDay(): number { // return this.iReferenceDay; // } // public hasBuySignal(iDay: number = 0): boolean { // if (iDay == 0) // iDay = this.oPC.getLastDay(); // return this.hasBRF(iDay); // } // public hasSellSignal(iDay: number = 0): boolean { // if (iDay == 0) // iDay = this.oPC.getLastDay(); // return this.hasTRF(iDay); // } isTCR(iRefCS, iDay) { var iNewRefCS = Math.abs(iRefCS); if (!this.oPC.isNonReversal(iNewRefCS)) { var i = iNewRefCS + 1; for (; i < iDay; i++) { if (this.oPC.isNonReversal(i)) { iRefCS = this.oPC.isBlackCandle(i) ? -i : i; iNewRefCS = i; return iRefCS; } } if (i == iDay) { return iNewRefCS; } } var bBRF = false; var bTRF = false; var i = iNewRefCS; while (++i <= iDay) { iNewRefCS = Math.abs(iRefCS); if (iRefCS < 0 && this.oPC.isBlackAndNonReversal(iNewRefCS)) { var bInsideBar = false; for (; i <= iDay; i++) { if (this.oPC.isBlackAndNonReversal(i)) { if (this.oPC.getBody(iNewRefCS) < 2 * this.oPC.getBody(i)) { iRefCS = -i; iNewRefCS = i; break; } } if (this.oPC.isWhiteAndNonReversal(i)) { if (bInsideBar == false && this.oPC.fC[i] > (this.oPC.fO[iNewRefCS] + this.oPC.fC[iNewRefCS]) / 2) { bBRF = true; bTRF = false; iRefCS = i; iNewRefCS = i; break; } if (bInsideBar == true && this.oPC.fC[i] > this.oPC.fO[iNewRefCS]) { bBRF = true; bTRF = false; iRefCS = i; iNewRefCS = i; break; } } bInsideBar = (this.oPC.fC[iNewRefCS] < this.oPC.fO[i] || this.oPC.fC[iNewRefCS] < this.oPC.fC[i]); } } if (iRefCS > 0 && this.oPC.isWhiteAndNonReversal(iNewRefCS)) { var bInsideBar = false; for (; i <= iDay; i++) { if (this.oPC.isWhiteAndNonReversal(i)) { if (this.oPC.getBody(iNewRefCS) < 2 * this.oPC.getBody(i)) { iRefCS = i; iNewRefCS = i; break; } } if (this.oPC.isBlackAndNonReversal(i)) { if (bInsideBar == false && this.oPC.fC[i] < (this.oPC.fO[iNewRefCS] + this.oPC.fC[iNewRefCS]) / 2) { bBRF = false; bTRF = true; iRefCS = -i; iNewRefCS = i; break; } if (bInsideBar == true && this.oPC.fC[i] < this.oPC.fO[iNewRefCS]) { bBRF = false; bTRF = true; iRefCS = -i; iNewRefCS = i; break; } } bInsideBar = (this.oPC.fO[iNewRefCS] > this.oPC.fO[i] || this.oPC.fC[iNewRefCS] > this.oPC.fC[i]); } } } // if (bTRF || bBRF) // console.log(" TCR => TRF, BRF => ", this.oPC.getDateToString(iNewRefCS), iRefCS, iDay, bTRF, this.hasTRF(iDay), bBRF, this.hasBRF(iDay)) return iRefCS; } } exports.Step2 = Step2;