UNPKG

sql-synergy

Version:

Synergy Wave TA

299 lines (298 loc) 14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractWaves = void 0; const IConstants_1 = require("./IConstants"); const WaveLines_1 = require("./WaveLines"); const Wave_1 = require("./Wave"); const Step2_1 = require("./Step2"); const Step2N_1 = require("./Step2N"); const Step3_1 = require("./Step3"); const Step4N_1 = require("./Step4N"); const Step5N_1 = require("./Step5N"); const Step6N_1 = require("./Step6N"); const Technicals_1 = require("./Technicals"); const Step1D1_1 = require("./Step1D1"); class AbstractWaves { constructor(oMSQuote, oPC, oIC) { this.iPC = 0; this.iIC = 0; this.iSmallerChartDate = 0; //List vWaveLines = new Vector ( ) ; this.oWBLines = null; this.oWSLines = null; this.vWL = new Array(); this.iPStart = 0; // int iPPStart = 0 ; this.fL = []; this.fH = []; // oSignals:Map = new HashMap ( ) ; this.oSignals = new Map(); this.bTillEnd = false; this.bPerfect = false; this.bWasBiggerChannelBroken = false; this.oMSQuote = oMSQuote; this.oPC = oPC; this.oIC = oIC; this.iPC = oPC.getPeriod(); this.iIC = oIC.getPeriod(); this.oStep2N = new Step2N_1.Step2N(oMSQuote, oPC); // this.oIC = this.oStep2N.oIndicatorChart.oPC; // this.oPC = this.oStep2N.oIndicatorChart.oPC; this.oStep3 = new Step3_1.Step3(this.oPC); this.oStep4N = new Step4N_1.Step4N(oMSQuote, oPC, oIC); this.oStep5N = new Step5N_1.Step5N(oMSQuote, oPC, oIC); this.oStep6N = new Step6N_1.Step6N(oMSQuote, oPC, oIC); if (this.iIC == IConstants_1.IConstants.HOURLY) { this.oStep1D1 = new Step1D1_1.Step1D1(oIC); this.oStep2 = new Step2_1.Step2(oPC); } } getSignals() { return this.oSignals; } getWaves(iStartIndex, iEndIndex) { let iDir = IConstants_1.IConstants.UP; this.fL = this.oPC.getLow(); this.fH = this.oPC.getHigh(); var i = Math.max(iStartIndex, 10); for (; i < iEndIndex; i++) { try { this.iSmallerChartDate = AbstractWaves.getSmallerChartDateIndex(this.oPC, i, this.oIC); } catch (error) { console.error(error); break; } let iSignal = this.hasAllSteps(i); if (iSignal == IConstants_1.IConstants.BUY_SIGNAL) { // console.log ( "Has Buy Signal: " + oPC.getDate ( ) [ i ] ) ; iDir = IConstants_1.IConstants.UP; let iL = Technicals_1.Technicals.getLowIndex(this.fL, 0, i); // console.log ( ">>Low: " + oPC.getDate ( ) [ iL ] ) ; this.vWL.push(this.oWBLines = new WaveLines_1.WaveLines(iL, Wave_1.Wave.UP)); this.oWBLines.set5StepsDateIndex(i); this.oWBLines.setPerfect(this.bPerfect); this.oWBLines.setBiggerChannelBroken(this.bWasBiggerChannelBroken); this.oWBLines.setTechnicals(this.oPC); console.log(this.oWBLines); this.iPStart = iL; // iPPStart = iL ; this.oSignals.set("" + i, "B"); break; } if (iSignal == IConstants_1.IConstants.SELL_SIGNAL) { // console.log ( "Has Sell Signal: " + oPC.getDate ( ) [ i ] ) ; iDir = IConstants_1.IConstants.DOWN; let iH = Technicals_1.Technicals.getHighIndex(this.fH, 0, i); this.vWL.push(this.oWSLines = new WaveLines_1.WaveLines(iH, Wave_1.Wave.DN)); this.oWSLines.set5StepsDateIndex(i); this.oWSLines.setPerfect(this.bPerfect); this.oWSLines.setBiggerChannelBroken(this.bWasBiggerChannelBroken); this.oWSLines.setTechnicals(this.oPC); // System.err.println ( oWSLines ) ; this.iPStart = iH; // iPPStart = iH ; this.oSignals.set("" + i, "S"); break; } } return this.getWavesOpposite(i, iEndIndex, iDir == IConstants_1.IConstants.DOWN ? IConstants_1.IConstants.UP : IConstants_1.IConstants.DOWN); } setPPStart(i) { this.iPStart = i; this.oWSLines = null; this.oWBLines = null; this.vWL = new Array(); } setFirstWave(iDir) { if (iDir == IConstants_1.IConstants.DN) { this.oWBLines = new WaveLines_1.WaveLines(this.iPStart, iDir); this.oWBLines.set5StepsDateIndex(this.iPStart); this.oWBLines.setPerfect(false); this.oWBLines.setBiggerChannelBroken(false); this.oWBLines.setTechnicals(this.oPC); } else { this.oWSLines = new WaveLines_1.WaveLines(this.iPStart, iDir); this.oWSLines.set5StepsDateIndex(this.iPStart); this.oWSLines.setPerfect(false); this.oWSLines.setBiggerChannelBroken(false); this.oWSLines.setTechnicals(this.oPC); } } getWavesOpposite(iStartIndex, iEndIndex, iDir) { this.fL = this.oPC.getLow(); this.fH = this.oPC.getHigh(); let iStart = Math.max(Math.max(this.oStep3.nCHDays, this.oStep3.nCLDays), iStartIndex); i = iStart; let iLookFor = (iDir == IConstants_1.IConstants.DOWN) ? IConstants_1.IConstants.BUY_SIGNAL : IConstants_1.IConstants.SELL_SIGNAL; let bUpDown = true; let bDebug = true; if (i >= iEndIndex) { return this.vWL; } for (var i = iStart; i <= iEndIndex; i++) { try { this.iSmallerChartDate = AbstractWaves.getSmallerChartDateIndex(this.oPC, i, this.oIC); } catch (err) { console.error(err); break; } let iSignal = this.hasAllSteps(i); // if ( bUpDown && iSignal != iLookFor ) // continue ; bUpDown = false; if (iSignal == IConstants_1.IConstants.BUY_SIGNAL) { // console.log ( ( oWBLines == null ? "**" : " " ) + "Has Buy Signal: " + oPC.getDate ( ) [ i ] ) ; if (this.oWBLines == null) // First Time Change of Signal { let iL = Technicals_1.Technicals.getLowIndex(this.fL, this.iPStart, i); if (this.oWSLines != null) { this.oWSLines.setEnd(iL); this.oWSLines = null; } this.vWL.push(this.oWBLines = new WaveLines_1.WaveLines(iL, Wave_1.Wave.UP)); this.oWBLines.set5StepsDateIndex(i); this.oWBLines.setPerfect(this.bPerfect); this.oWBLines.setBiggerChannelBroken(this.bWasBiggerChannelBroken); this.oWBLines.setTechnicals(this.oPC); // if ( bDebug ) // { // System.err.println ( "Lowest " + oPC.getDate ( ) [ iL ] ) ; // } // iPPStart = iL ; this.iPStart = iL; this.oSignals.set("" + i, "B"); } // else // { //console.log ( "Buy Signal Update: " + oPC.getDate ( ) [ i ] ) ; // oWBLines.setEnd ( i ) ; // } } else if (iSignal == IConstants_1.IConstants.SELL_SIGNAL) { // console.log ( ( oWSLines == null ? "**" : " " ) + "Has Sell Signal: " + oPC.getDate ( ) [ i ] ) ; if (this.oWSLines == null) { let iH = Technicals_1.Technicals.getHighIndex(this.fH, this.iPStart, i); if (this.oWBLines != null) { this.oWBLines.setEnd(iH); this.oWBLines = null; } this.vWL.push(this.oWSLines = new WaveLines_1.WaveLines(iH, Wave_1.Wave.DN)); this.oWSLines.set5StepsDateIndex(i); this.oWSLines.setPerfect(this.bPerfect); this.oWSLines.setBiggerChannelBroken(this.bWasBiggerChannelBroken); this.oWSLines.setTechnicals(this.oPC); // if ( bDebug ) // { // System.err.println ( "Highest " + oPC.getDate ( ) [ iH ] ) ; // } // iPPStart = iH ; this.iPStart = iH; this.oSignals.set("" + i, "S"); } // else // { //console.log ( "Buy Signal Update: " + oPC.getDate ( ) [ i ] ) ; // oWBLines.setEnd ( i ) ; // } } } // if ( oWSLines == null && oWBLines == null ) // { // WaveLines oWL = new WaveLines ( iStartIndex, iDir == UP ? DOWN : UP ) ; //// WaveLines oWL = new WaveLines ( iStartIndex, iDir ) ; // oWL.set5StepsDateIndex ( iStartIndex ) ; // oWL.setEnd ( iEndIndex ) ; // oWL.setTechnicals ( oPC ) ; // console.log ( oWL ) ; // vWL.add ( oWL ) ; // System.err.println ( "Only 1 Wave " + oWL ) ; // } if (this.oWSLines != null) { // if ( i != iEndIndex || i == oPC.getLastDay ( ) ) { let iL = Technicals_1.Technicals.getLowIndex(this.fL, this.iPStart, iEndIndex); this.oWSLines.setEnd(iL); // if ( iL != oPC.getLastDay ( ) ) if (this.bTillEnd) { this.vWL.push(this.oWBLines = new WaveLines_1.WaveLines(iL, IConstants_1.IConstants.UP)); this.oWBLines.setTechnicals(this.oPC); this.oWBLines.set5StepsDateIndex(iL); this.oWBLines.setEnd(this.oStep3.oPC.getLastDay()); this.oWBLines = null; } } } else if (this.oWBLines != null) { // if ( i != iEndIndex || i == oPC.getLastDay ( ) ) { let iH = Technicals_1.Technicals.getHighIndex(this.fH, this.iPStart, iEndIndex); this.oWBLines.setEnd(iH); // if ( iH != oPC.getLastDay ( ) ) if (this.bTillEnd) { this.vWL.push(this.oWSLines = new WaveLines_1.WaveLines(iH, IConstants_1.IConstants.DOWN)); this.oWSLines.setTechnicals(this.oPC); this.oWSLines.set5StepsDateIndex(iH); this.oWSLines.setEnd(this.oStep3.oPC.getLastDay()); } } } return this.vWL; } hasAllSteps(iDay) { this.bPerfect = false; // console.log ( iDay + " " + oStep3.oPC.getDate ( ) [ iDay ] ) ; // console.log ( iSmallerChartDate + " " + oStep4N.oIndicatorChart.oPC.getDate ( ) [ iSmallerChartDate ] ) ; if (this.iIC == IConstants_1.IConstants.HOURLY) { if (this.oStep3.hasBuySignal(iDay) && this.oStep2.hasBuySignal(iDay) && this.oStep1D1.hasBuySignal(iDay)) { this.bPerfect = true; this.bWasBiggerChannelBroken = (this.oStep2N.wasBiggerChannelBroken()); return IConstants_1.IConstants.BUY_SIGNAL; } if (this.oStep3.hasSellSignal(iDay) && this.oStep2.hasSellSignal(iDay) && this.oStep1D1.hasSellSignal(iDay)) { this.bPerfect = true; this.bWasBiggerChannelBroken = (this.oStep2N.wasBiggerChannelBroken()); return IConstants_1.IConstants.SELL_SIGNAL; } return IConstants_1.IConstants.NO_SIGNAL; } if (this.oStep3.hasBuySignal(iDay) && this.oStep2N.hasBuySignal(iDay) && this.oStep4N.hasBuySignal(this.iSmallerChartDate) && this.oStep5N.hasBuySignal(this.iSmallerChartDate) && this.oStep6N.hasBuySignal(this.iSmallerChartDate)) { this.bPerfect = this.oStep2N.isPerfect() && this.oStep4N.isPerfect() && this.oStep5N.isPerfect() && this.oStep6N.isPerfect(); this.bWasBiggerChannelBroken = (this.oStep2N.wasBiggerChannelBroken() || this.oStep4N.wasBiggerChannelBroken() || this.oStep5N.wasBiggerChannelBroken() || this.oStep6N.wasBiggerChannelBroken()); return IConstants_1.IConstants.BUY_SIGNAL; } if (this.oStep3.hasSellSignal(iDay) && this.oStep2N.hasSellSignal(iDay) && this.oStep4N.hasSellSignal(this.iSmallerChartDate) && this.oStep5N.hasSellSignal(this.iSmallerChartDate) && this.oStep6N.hasSellSignal(this.iSmallerChartDate)) { this.bPerfect = this.oStep2N.isPerfect() && this.oStep4N.isPerfect() && this.oStep5N.isPerfect() && this.oStep6N.isPerfect(); this.bWasBiggerChannelBroken = (this.oStep2N.wasBiggerChannelBroken() || this.oStep4N.wasBiggerChannelBroken() || this.oStep5N.wasBiggerChannelBroken() || this.oStep6N.wasBiggerChannelBroken()); return IConstants_1.IConstants.SELL_SIGNAL; } return IConstants_1.IConstants.NO_SIGNAL; } static getSmallerChartDateIndex(oPC, iBigChartIndex, oSC) { try { return oSC.getSmallerChartDate(oPC.getDate()[iBigChartIndex]); } catch (err) { console.error(err); } return -1; } static getBigChartIndex(oPC, iSmallChartIndex, oBPC) { return oBPC.getChartDate(oPC.getDate()[iSmallChartIndex]); } } exports.AbstractWaves = AbstractWaves;