UNPKG

sql-synergy

Version:

Synergy Wave TA

211 lines (210 loc) 8.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WaveCalculatorV2 = void 0; const IConstants_1 = require("./IConstants"); const Wave_1 = require("./Wave"); var fs = require('fs'); const WaveSequence_1 = require("./WaveSequence"); const WaveOrganizerV2_1 = require("./WaveOrganizerV2"); const WaveOrganizer_1 = require("./WaveOrganizer"); const WaveList_1 = require("./WaveList"); const AbstractWaves_1 = require("./AbstractWaves"); const WGenerator_1 = require("./WGenerator"); const MWGenerator_1 = require("./MWGenerator"); class WaveCalculatorV2 { //This is called by the GUI program constructor(oMSQuote) { this.oWS = new WaveSequence_1.WaveSequence(); this.iLevel = 0; this.oWaveList = new WaveList_1.WaveList(); this.iPC = -1; this.iIC = -1; this.oMSQuote = oMSQuote; this.process(); } process() { this.setStockType(this.oMSQuote); let oaIW = this.oWaveList.getWaveList(); let oW = null; let ch = ''; this.oPW = fs.createWriteStream("./data/" + this.oMSQuote.oTickerQuotes.getSymbol() + "/" + "WAVES-V2.json"); this.oPW.write('['); for (var i = 0; i < oaIW.length; i++) { if (oaIW[i] instanceof Wave_1.Wave) { oW = oaIW[i]; oW.print(); this.oPW.write(ch + oW.getJSON()); ch = ','; } } if (oW != null) { let v = oW.getSmallerWaves(); var n = v.length; if (n > 0) console.log("** Currently in Smaller Waves.... "); for (var i = 0; i < n; i++) { let oSWave = v[i]; console.log("********"); oSWave.print(); } this.adjustSmallerWaves(v, this.oMSQuote); } console.log("TOTAL WAVES: ", oaIW.length); this.oPW.write(']'); } adjustSmallerWaves(v, oMSQuote) { let oWSS = new WaveSequence_1.WaveSequence(); oWSS.setPeriods(oMSQuote.getPeriod() + 1, oMSQuote.getPeriod() + 1); let oPC = oMSQuote.getData(oMSQuote.getPeriod() + 1); oWSS.setPriceChart(oPC); let n = v.length; for (var i = 0; i < n; i++) oWSS.add(v[i]); let oWO = new WaveOrganizerV2_1.WaveOrganizerV2(oWSS, this.oMSQuote); oWO.setCheckNeutralization(false); while (oWO.reorganize() == false) { console.log("***Merging & Renaming*******"); oWO.adjustWaves(); oWSS.print(); } console.log("*** Adjust Min MAx ***"); oWO.recomputeMinMax(); oWSS.print(); console.log("***Finished Merging & Renaming****Final Result***"); console.log("***Renaming last Waves** "); while (oWO.consolidateLastImplusiveWave() == false) { oWO.adjustWaves(); oWSS.print(); } console.log("*** Adjust Min MAx ***"); oWO.recomputeMinMax(); oWSS.print(); console.log("***Finished Renaming last Waves** "); oWSS.print(); oWSS.copyInto(this.oWaveList); } getLevel() { return this.iLevel; } setStockType(oMSQuote) { //Treat it as Normal console.error("Normal M+M"); // let oWR: WaveReader = new WaveReader(this.oMSQuote, "Normal"); // let oWS = oWR.getWaveSequence(); let oWS = new WaveSequence_1.WaveSequence(); this.calculateMonthlyWaves(IConstants_1.IConstants.WEEKLY, IConstants_1.IConstants.WEEKLY); return; } getWaveList() { return this.oWaveList; } getWaves(iPC, iIC) { let oWaves = new Array(); let oWLL = this.getWaveList(); let ss = oWLL.getWavesString(); for (var z = 0; z < ss.length; z++) { let oW = oWLL.get(ss[z]); if (oW.getIndicatorChart() != iIC) continue; if (oW.getPriceChart() != iPC) continue; oWaves.push(oW); } return oWaves; } quitApp() { process.exit(1); } calculateMonthlyWaves(iPC, iCS) { let oPC = this.oMSQuote.getData(this.iPC); let oIC = this.oMSQuote.getData(this.iIC); } generateWave(iPCS, iICS) { this.iPC = iPCS; this.iIC = iICS; // console.log(this.iPC, this.iIC) ; let oPC = this.oMSQuote.getData(this.iPC); let oIC = this.oMSQuote.getData(this.iIC); let oMWG = new MWGenerator_1.MWGenerator(this.oMSQuote); oMWG.setWaveSequence(this.oWS); oMWG.generateWave(oPC, oIC); let oMWS = oMWG.getWaveSequence(); console.log(">>*** Monthly Waves "); // oMWS.print ( ) ; this.quitApp(); oMWS.copyInto(this.oWaveList); WaveOrganizer_1.WaveOrganizer.setWaveList(this.oWaveList); let oTWS = oMWS; this.iPC++; this.iIC++; for (var iWaveType = 0; iWaveType < 3; iWaveType++) { this.iPC--; this.iIC--; if ((this.iIC - 1) < IConstants_1.IConstants.HOURLY) continue; if ((this.iPC - 1) < IConstants_1.IConstants.HOURLY) continue; // ListIterator oLI = oTWS.getIterator ( ) ; let oLI = oTWS.oLL.toArray(); // let oW:any = null ; let oBPC = this.oMSQuote.getData(this.iPC); let oSPC = this.oMSQuote.getData(this.iPC - 1); console.log("***Processing SmallerWaves using " + IConstants_1.IConstants.sChart[this.iPC - 1] + "+" + IConstants_1.IConstants.sChart[this.iIC - 1] + "***"); for (var i = 0; i < oLI.length; i++) // while ( oLI.hasNext ( ) ) { let oMW = oLI[i]; console.log(" ***Parent Wave " + IConstants_1.IConstants.sChart[this.iPC] + "+" + IConstants_1.IConstants.sChart[this.iIC] + "*** "); oMW.print(); let iStartIndex = oMW.getStartIndex(); let iEndIndex = oMW.getEndIndex(); let oWWG = new WGenerator_1.WGenerator(this.oMSQuote); oWWG.setParentWave(oMW.getName()); // console.error ( "Debug: " + iStartIndex + " " + iEndIndex ) ; if (iStartIndex > iEndIndex) { // This happens only when A = down console.error("Wave StartIndex > iEndIndex"); continue; } let iSStartIndex = AbstractWaves_1.AbstractWaves.getSmallerChartDateIndex(oBPC, iStartIndex, oSPC); let iSStartIndexP = 0; if (iStartIndex != 0) iSStartIndexP = AbstractWaves_1.AbstractWaves.getSmallerChartDateIndex(oBPC, iStartIndex - 1, oSPC); iSStartIndex++; while (iSStartIndex > iSStartIndexP) { //console.error ( "Checking " + oMW.getLow ( ) + " => " + oSPC.getLow ( ) [ iSStartIndex ] ) ; if (oMW.isUp() && oMW.getLow() == oSPC.getLow()[iSStartIndex]) break; if (oMW.isDown() && oMW.getHigh() == oSPC.getHigh()[iSStartIndex]) break; iSStartIndex--; } let iSEndIndex = oSPC.getLastDay(); if (i + 1 < oLI.length) { iSEndIndex = AbstractWaves_1.AbstractWaves.getSmallerChartDateIndex(oBPC, iEndIndex, oSPC); if (iEndIndex == 0) continue; //console.log ( "Computing EndIndexP [" + oMW.getName() + "]" + iEndIndex ) ; let iSEndIndexP = AbstractWaves_1.AbstractWaves.getSmallerChartDateIndex(oBPC, iEndIndex - 1, oSPC); iSEndIndex++; while (iSEndIndex > iSEndIndexP) { if (oMW.isDown() && oMW.getLow() == oSPC.getLow()[iSEndIndex]) break; if (oMW.isUp() && oMW.getHigh() == oSPC.getHigh()[iSEndIndex]) break; iSEndIndex--; } } oWWG.generateWaves(this.oMSQuote.getData(this.iPC - 1), this.oMSQuote.getData(this.iIC - 1), iStartIndex, iSEndIndex, oMW.getDirection()); let oWWS = oWWG.getWaveSequence(); console.log(" *** Parent Wave Start [" + oBPC.getDate()[iStartIndex] + "] End [" + oBPC.getDate()[iEndIndex] + "]"); oMW.print(); console.log(" *** This Wave Start [" + oSPC.getDate()[iSStartIndex] + "] End [" + oSPC.getDate()[iSEndIndex] + "]"); oWWS.print(); oWWS.copyInto(this.oWaveList); oTWS = oWWS; } } } } exports.WaveCalculatorV2 = WaveCalculatorV2;