sql-synergy
Version:
Synergy Wave TA
239 lines (238 loc) • 10.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WaveCalculator = 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 WaveReader_1 = require("./WaveReader");
const WaveList_1 = require("./WaveList");
const SynergySystem_1 = require("./SynergySystem");
const AbstractWaves_1 = require("./AbstractWaves");
const WGenerator_1 = require("./WGenerator");
const MWGenerator_1 = require("./MWGenerator");
class WaveCalculator {
//This is called by the GUI program
constructor(oMSQuote) {
this.bReOrg = true;
this.oWS = new WaveSequence_1.WaveSequence();
this.iLevel = 0;
this.oWaveList = new WaveList_1.WaveList();
this.iPC = -1;
this.iIC = -1;
this.oMSQuote = oMSQuote;
// oMSQuote.oTickerQuotes.setSymbol ( sSymbol ) ;
// oPW = new PrintWriter ( new FileWriter ( sFileName ) ) ;
// oPW.println ( "Symbol,Chart,Wave,Type,!F!Start,!F!End,!F!Min,!F!Max" ) ;
this.process();
// oPW.close ( ) ;
}
process() {
this.setStockType(this.oMSQuote);
// oWaveList.print();
let oaIW = this.oWaveList.getWaveList();
let oW = null;
let ch = '';
this.oPW = fs.createWriteStream("./data/" + this.oMSQuote.oTickerQuotes.getSymbol()
+ "/" + "WAVES.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 ( this.oMSQuote.oTickerQuotes.getSymbol ( ) ) ;
// this.oPW.write ( "," + oW.getCSV ( ) ) ;
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]);
if (!this.bReOrg)
return;
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) {
try {
let oSS = new SynergySystem_1.SynergySystem(oMSQuote);
if (oSS.isLevelII()) {
console.log("Level II Y+M");
this.generateWave(IConstants_1.IConstants.YEARLY, IConstants_1.IConstants.MONTHLY);
let oWR = new WaveReader_1.WaveReader(this.oMSQuote, "LevelII");
this.oWS = oWR.getWaveSequence();
this.iLevel = 2;
return;
}
if (oSS.isLevelI()) {
console.error("Level I Q+M");
this.generateWave(IConstants_1.IConstants.QUARTERLY, IConstants_1.IConstants.MONTHLY);
let oWR = new WaveReader_1.WaveReader(this.oMSQuote, "LevelI");
this.oWS = oWR.getWaveSequence();
this.iLevel = 1;
return;
}
//Normal
console.error("Normal M+M");
let oWR = new WaveReader_1.WaveReader(this.oMSQuote, "Normal");
let oWS = oWR.getWaveSequence();
// this.generateWave ( IConstants.HOURLY, IConstants.HOURLY ) ;
// this.generateWave ( IConstants.DAILY, IConstants.DAILY ) ;
this.generateWave(IConstants_1.IConstants.WEEKLY, IConstants_1.IConstants.WEEKLY);
// this.generateWave ( IConstants.MONTHLY, IConstants.MONTHLY ) ;
return;
}
catch (err) {
console.error(err);
}
}
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;
}
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 ( ) ;
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.WaveCalculator = WaveCalculator;