UNPKG

sql-synergy

Version:

Synergy Wave TA

390 lines (389 loc) 17.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WaveOrganizerV2 = void 0; const WaveOrganizer_1 = require("./WaveOrganizer"); //import { WaveList } from './WaveList' ; const Wave_1 = require("./Wave"); //import { LinkedList } from 'linked-list-typescript'; const Step1Neutralized_1 = require("./Step1Neutralized"); // import { IWave } from './IWave' ; // import { LinkedList } from 'linked-list-typescript'; class WaveOrganizerV2 extends WaveOrganizer_1.WaveOrganizer { constructor(oWS, oMSQuote) { super(oWS); this.bCheckNeutralization = true; this.oMSQuote = oMSQuote; } consolidateLastImplusiveWave() { let oWave0 = null, oWave1 = null, oWave2 = null; let oWaves = this.oWS.oLL.toArray(); let n = oWaves.length; for (var c = 0; c < n; c++) { oWave2 = oWave1; oWave1 = oWave0; oWave0 = oWaves[c]; if (oWave2 == null || oWave1 == null) continue; if (oWave1.isImpulsive() && oWave1.getName().endsWith("5")) { if (c > 0) return this.renameToSmallerWaves(oWave1, c - 1, oWaves); } } return true; } setCheckNeutralization(b) { this.bCheckNeutralization = b; } setMinMax(oWave0, oWave1, oWave2) { super.setMinMax(oWave0, oWave1, oWave2); if (oWave0.wasBiggerChannelBroken()) oWave0.step1Neutralized(true); else { if (this.bCheckNeutralization) { let oS1N = new Step1Neutralized_1.Step1Neutralized(this.oMSQuote, oWave0, this.oWS.oPC); oWave0.step1Neutralized(oS1N.wasNeutralized(oWave0.get5StepsDateIndex(), oWave0.getEndIndex())); } } } reorganize() { console.log("IN REORGANIZE"); let oWave0 = null, oWave1 = null, oWave2 = null; let oWaves = this.oWS.oLL.toArray(); for (var z = 0; z < oWaves.length; z++) { oWave2 = oWave1; oWave1 = oWave0; oWave0 = oWaves[z]; this.setMinMax(oWave0, oWave1, oWave2); console.log("***Reorganizing " + oWave0.getName()); if (oWave1 == null) { //Step1 Neutralization Policy //Waves that ends with 1 Step1 need not be met provided they can be neutralized //Waves that ends with 2 & 4 Step1 need not be met they can be neutralized if (oWave0.wasStep1Met() == false && oWave0.wasStep1Neutralized() == false) { //Step1 Not Met and couldn't be neutralized return this.renameToSmallerWaves(oWave0, z, oWaves); } } if (oWave2 == null) { continue; } // if ( oWave1.wasStep1Met ( ) ) // continue ; if (oWave1.isCorrective() && oWave1.wasStep1Met() == false) { //Corrective Waves //Waves that ends with 2 & 4, Step1 need not be met they can be neutralized if (oWave1.wasStep1Neutralized() == false) { if (oWave0.isUp() && oWave1.getHigh() < oWave0.getHigh()) { // Wave2 resumes return this.renameToSmallerWaves(oWave2, z - 2, oWaves); } if (oWave0.isDown() && oWave1.getLow() > oWave0.getLow()) { // Wave2 resumes return this.renameToSmallerWaves(oWave2, z - 2, oWaves); } // if ( bCheckNeutralization == false ) // { // //Final Smaller waves // } // else { return this.renameToSmallerWaves(oWave1, z - 1, oWaves); } } } if (oWave1.isImpulsive() && oWave1.wasStep1Met() == false) { return this.renameToSmallerWaves(oWave1, z - 1, oWaves); // //Impulsive Waves // // We are here provided the Previous Wave was Neutralized for Step1 // // Additional requirement for Implusive wave is it should have gone // // higher than the previous impluse wave ( oWave2 ) // if ( oWave0.getHigh ( ) > oWave1.getHigh ( ) ) // continue ; // Perfect. // if ( oLI.hasNext ( ) == false ) // continue ; // Last Wave... lets wait until this wave terminates // //Subsequent Wave exists so rename to smaller wave // Vector vSmallerWaves = new Vector ( ) ; // Wave oNextWave = null ; // boolean bFound = false ; // while ( oLI.hasNext ( ) ) // { // oNextWave = ( Wave ) oLI.next ( ) ; // vSmallerWaves.push (oNextWave ) ; // if ( oNextWave.isDown ( ) && oNextWave.getLow ( ) < oWave0.getLow ( ) ) // { // bFound = true ; // break ; // } // if ( oNextWave.isUp ( ) && oNextWave.getHigh ( ) > oWave0.getHigh ( ) ) // { // bFound = true ; // break ; // } // } // if ( bFound ) // { // if ( oNextWave.isDown ( ) ) // { // oWave1.vSmallerWaves.clear ( ) ; // oWave1.addSmallerWave ( Wave.copy ( oWave1 ) ) ; // oWave1.addSmallerWave ( oWave0 ) ; // this.vRemove.push ( oWave0 ) ; // for ( int z = 0 ; z < vSmallerWaves.length ; z++ ) // { // Wave vW = ( Wave ) vSmallerWaves.elementAt ( z ) ; // oWave1.addSmallerWave ( vW ) ; // this.vRemove.push ( vW ) ; // } // oWave1.setLowest ( oNextWave.getLowIndex ( ), oNextWave.getLow ( ) ) ; // this.oWaveChanged = oWave1 ; // return false ; // } // //Up wave // oWave0.vSmallerWaves.clear ( ) ; // oWave0.addSmallerWave ( Wave.copy ( oWave0 ) ) ; // for ( int z = 0 ; z < vSmallerWaves.length ; z++ ) // { // Wave vW = ( Wave ) vSmallerWaves.elementAt ( z ) ; // oWave0.addSmallerWave ( vW ) ; // this.vRemove.push ( vW ) ; // } // oWave0.setHighest ( oNextWave.getHighIndex ( ), oNextWave.getHigh ( ) ) ; // this.oWaveChanged = oWave0 ; // return false ; // } // //Last waves zigzag //// oWave0.vSmallerWaves.clear ( ) ; //// oWave0.addSmallerWave ( Wave.copy ( oWave0 ) ) ; //// oWave0.bZigZag = true ; //// for ( int z = 0 ; z < vSmallerWaves.length ; z++ ) //// { //// Wave vW = ( Wave ) vSmallerWaves.elementAt ( z ) ; //// oWave0.addSmallerWave ( vW ) ; //// this.vRemove.push ( vW ) ; //// } //// this.oWaveChanged = oWave0 ; // // //New Last Wave Starts // Wave oNewWave = null ; // for ( int z = 0 ; z < vSmallerWaves.length ; z++ ) // { // Wave vW = ( Wave ) vSmallerWaves.elementAt ( z ) ; // if ( oNewWave == null ) // { // oNewWave = Wave.copy ( vW ) ; //// setMinMax ( oNewWave, oWave0, oWave1 ) ; // this.oWaveChanged = oNewWave ; // } // else // { // if ( z == vSmallerWaves.length - 1 && oNextWave.getDirection() != vW.getDirection ( ) ) // { // return false ; // } // oNewWave.addSmallerWave ( vW ) ; // this.vRemove.push ( vW ) ; // } // } // return true ; // Done. no more waves } if (oWave0.isDown() && oWave0.isImpulsive()) { // Down Implusive wave. No Neutralization of Step1 Possible // Rename to smaller waves if (z + 1 >= oWaves.length) continue; // This wave not ended //Subsequent Wave exists so rename to smaller wave let vSmallerWaves = new Array(); let oNextWave = null; let bFound = false; while (++z < oWaves.length) { oNextWave = oWaves[z]; vSmallerWaves.push(oNextWave); if (oNextWave.isDown() && oNextWave.getLow() < oWave0.getLow()) { bFound = true; break; } if (oNextWave.isUp() && oNextWave.getHigh() > oWave0.getHigh()) { bFound = true; break; } } if (bFound) { if (oNextWave.isDown()) { oWave0.vSmallerWaves = []; oWave0.addSmallerWave(Wave_1.Wave.copy(oWave0)); for (var z = 0; z < vSmallerWaves.length; z++) { let vW = vSmallerWaves[z]; oWave0.addSmallerWave(vW); this.vRemove.push(vW); } oWave0.setLowest(oNextWave.getLowIndex(), oNextWave.getLow()); this.oWaveChanged = oWave0; return false; } //Up wave oWave1.vSmallerWaves = []; oWave1.addSmallerWave(Wave_1.Wave.copy(oWave1)); oWave1.addSmallerWave(oWave0); this.vRemove.push(oWave0); for (var z = 0; z < vSmallerWaves.length; z++) { let vW = vSmallerWaves[z]; oWave1.addSmallerWave(vW); this.vRemove.push(vW); } oWave1.setHighest(oNextWave.getHighIndex(), oNextWave.getHigh()); this.oWaveChanged = oWave1; return false; } //Last waves zigzag oWave0.vSmallerWaves = []; //New Last Wave Starts // oWave0.addSmallerWave ( Wave.copy ( oWave0 ) ) ; // oWave0.bZigZag = true ; // for ( int z = 0 ; z < vSmallerWaves.length ; z++ ) // { // Wave vW = ( Wave ) vSmallerWaves.elementAt ( z ) ; // oWave0.addSmallerWave ( vW ) ; // this.vRemove.push ( vW ) ; // } // this.oWaveChanged = oWave0 ; let oNewWave = null; for (var z = 0; z < vSmallerWaves.length; z++) { let vW = vSmallerWaves[z]; if (oNewWave == null) { oNewWave = Wave_1.Wave.copy(vW); // setMinMax ( oNewWave, oWave0, oWave1 ) ; this.oWaveChanged = oNewWave; } else { if (z == vSmallerWaves.length - 1 && oNextWave.getDirection() != vW.getDirection()) { return false; } oNewWave.addSmallerWave(vW); this.vRemove.push(vW); } } return true; // Done. no more waves } //Implusive Wave if (oWave0.isUp() && oWave0.isImpulsive()) { // We are here provided the Previous Wave was Neutralized for Step1 // Additional requirement for Implusive wave is it should have gone // higher than the previous impluse wave ( oWave2 ) if (oWave0.getHigh() > oWave1.getHigh()) continue; // Perfect. if (z + 1 >= oWaves.length) continue; // Last Wave... lets wait until this wave terminates //Subsequent Wave exists so rename to smaller wave let vSmallerWaves = new Array(); let oNextWave = null; let bFound = false; while (++z < oWaves.length) { oNextWave = oWaves[z]; vSmallerWaves.push(oNextWave); if (oNextWave?.isDown() && oNextWave.getLow() < oWave0.getLow()) { bFound = true; break; } if (oNextWave?.isUp() && oNextWave.getHigh() > oWave0.getHigh()) { bFound = true; break; } } if (bFound) { if (oNextWave?.isDown()) { oWave1.vSmallerWaves = []; oWave1.addSmallerWave(Wave_1.Wave.copy(oWave1)); oWave1.addSmallerWave(oWave0); this.vRemove.push(oWave0); for (var s = 0; s < vSmallerWaves.length; s++) { let vW = vSmallerWaves[s]; oWave1.addSmallerWave(vW); this.vRemove.push(vW); } oWave1.setLowest(oNextWave.getLowIndex(), oNextWave.getLow()); this.oWaveChanged = oWave1; return false; } //Up wave oWave0.vSmallerWaves = []; oWave0.addSmallerWave(Wave_1.Wave.copy(oWave0)); for (var z = 0; z < vSmallerWaves.length; z++) { let vW = vSmallerWaves[z]; oWave0.addSmallerWave(vW); this.vRemove.push(vW); } oWave0.setHighest(oNextWave.getHighIndex(), oNextWave.getHigh()); this.oWaveChanged = oWave0; return false; } //Last waves zigzag oWave0.vSmallerWaves = []; oWave0.addSmallerWave(Wave_1.Wave.copy(oWave0)); oWave0.bZigZag = true; for (var z = 0; z < vSmallerWaves.length; z++) { let vW = vSmallerWaves[z]; oWave0.addSmallerWave(vW); this.vRemove.push(vW); } this.oWaveChanged = oWave0; return false; // //New Last Wave Starts // Wave oNewWave = null ; // for ( int z = 0 ; z < vSmallerWaves.length ; z++ ) // { // Wave vW = ( Wave ) vSmallerWaves.elementAt ( z ) ; // if ( oNewWave == null ) // { // oNewWave = Wave.copy ( vW ) ; //// setMinMax ( oNewWave, oWave0, oWave1 ) ; // this.oWaveChanged = oNewWave ; // } // else // { // if ( z == vSmallerWaves.length - 1 && oNextWave.getDirection() != vW.getDirection ( ) ) // { // return false ; // } // oNewWave.addSmallerWave ( vW ) ; // this.vRemove.push ( vW ) ; // } // } // return true ; // Done. no more waves } } return true; } renameToSmallerWaves(oWave0, c, oWaves) { let n = oWaves.length; if (c < n) // if ( oLI.hasNext ( ) ) { oWave0.vSmallerWaves = []; oWave0.addSmallerWave(Wave_1.Wave.copy(oWave0)); c++; let oTWave = oWaves[c]; oWave0.addSmallerWave(oTWave); this.vRemove.push(oTWave); } if (c < n) // if ( oLI.hasNext ( ) ) { c++; let oTWave = oWaves[c]; oWave0.addSmallerWave(oTWave); if (oWave0.isUp()) { if (oWave0.getHigh() < oTWave.getHigh()) oWave0.setHighest(oTWave.getHighIndex(), oTWave.getHigh()); } else { if (oWave0.getLow() > oTWave.getLow()) oWave0.setLowest(oTWave.getLowIndex(), oTWave.getLow()); } this.vRemove.push(oTWave); oWave0.set5StepsDateIndex(oTWave.get5StepsDateIndex()); oWave0.setBiggerChannelBroken(oTWave.wasBiggerChannelBroken()); } if (this.vRemove.length == 0) return true; this.oWaveChanged = oWave0; return false; } } exports.WaveOrganizerV2 = WaveOrganizerV2;