sql-synergy
Version:
Synergy Wave TA
138 lines (137 loc) • 4.93 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NeutralizeIndicators = void 0;
const IConstants_1 = require("./IConstants");
const Neutralization_1 = require("./Neutralization");
class NeutralizeIndicators {
constructor(oMSQuote, oPC) {
this.i3P = 0;
// public hasBuySignal ( ):number
// {
// return hasBuySignal ( this.getSmallChartEndDate ( ) ) ;
// }
// public hasSellSignal ( ):boolean
// {
// return hasSellSignal ( this.getSmallChartEndDate ( ) ) ;
// }
this.bNeutralized = false;
this.iSignalDay = 0;
this.iNeutralizedOn = 0;
this.oMSQuote = oMSQuote;
this.i3P = oPC.getPeriod();
this.oN = new Neutralization_1.Neutralization(oMSQuote, oPC);
}
getSmallChartEndDate() {
return this.oIndicatorChart.getLastDay();
}
getSmallerChartDateIndex(iBigChartIndex) {
try {
return this.oIndicatorChart.getSmallerChartDate(this.oMSQuote.getData(this.i3P).getDate(iBigChartIndex));
}
catch (err) {
console.error(err);
}
return -1;
}
getBigChartIndex(iSmallChartIndex) {
return this.oBiggerIndicatorChart.oPC.getChartDate(this.oIndicatorChart.oPC.getDate()[iSmallChartIndex]);
}
hasBiggerIndicatorSignal() {
return this.wasNeutralized();
}
//@deprecated
wasNeutralized() {
return this.bNeutralized;
}
getSignalDay() {
return this.iSignalDay;
}
isPerfect() {
if (this.bNeutralized || this.wasBiggerChannelBroken())
return false;
return true;
}
hasBuySignal(iDay) {
if (iDay == -1)
return false;
if (iDay == 0)
iDay = this.getSmallChartEndDate();
this.iSignalDay = this.iNeutralizedOn = 0;
this.bNeutralized = false;
if (this.oIndicatorChart.hasBuySignal(iDay)) {
this.iSignalDay = this.oIndicatorChart.getSignalDay();
return true;
}
if (this.oBiggerIndicatorChart != null && this.oBiggerIndicatorChart.hasBuySignal(this.getBigChartIndex(iDay))) {
this.bNeutralized = true;
this.iSignalDay = this.oBiggerIndicatorChart.getSignalDay();
return true;
}
return this.canNeutralize(iDay, IConstants_1.IConstants.DN);
}
hasSellSignal(iDay) {
if (iDay == -1)
return false;
if (iDay == 0)
iDay = this.getSmallChartEndDate();
this.iSignalDay = this.iNeutralizedOn = 0;
this.bNeutralized = false;
if (this.oIndicatorChart.hasSellSignal(iDay)) {
this.iSignalDay = this.oIndicatorChart.getSignalDay();
return true;
}
if (this.oBiggerIndicatorChart != null && this.oBiggerIndicatorChart.hasSellSignal(this.getBigChartIndex(iDay))) {
this.bNeutralized = true;
this.iSignalDay = this.oBiggerIndicatorChart.getSignalDay();
return true;
}
return this.canNeutralize(iDay, IConstants_1.IConstants.UP);
}
wasBiggerChannelBroken() {
if (this.oN == null)
return false;
return this.iNeutralizedOn != 0;
}
canNeutralize(iDay, iDir) {
let iPC = this.oIndicatorChart.oPC.getChart();
let iCD = iDay;
let oSPC = this.oIndicatorChart.oPC;
while (iPC < IConstants_1.IConstants.YEARLY && iPC < (this.i3P)) {
iPC++;
try {
// System.out.println ( "Date [" + oSPC.getDate ( ) [ iCD ] + "]" ) ;
let oNBPC = this.oMSQuote.getData(iPC);
iCD = oNBPC.getChartDate(oSPC.getDate()[iCD]);
oSPC = oNBPC;
// iCD = getBigChartIndex ( iCD ) ;
}
catch (err) {
console.error(err);
return false;
}
}
if (iPC != (this.i3P)) {
console.error("FATAL: Impossible Situation");
return false;
}
if (iDir == IConstants_1.IConstants.UP)
this.iNeutralizedOn = this.oN.isUpWaveNeutralized(iCD);
else
this.iNeutralizedOn = this.oN.isDownWaveNeutralized(iCD);
return this.iNeutralizedOn != 0;
}
getSignalDate() {
if (this.wasBiggerChannelBroken()) {
let oPC = this.oN.getBiggerChart();
return "(B)" + oPC.getDate()[this.iSignalDay];
}
if (this.wasNeutralized()) {
return "(" + IConstants_1.IConstants.sChart[this.oBiggerIndicatorChart.oPC.getChart()] + ")" + this.oBiggerIndicatorChart.getSignalDate();
}
return this.oIndicatorChart.getSignalDate();
}
toString() {
return typeof (this);
}
}
exports.NeutralizeIndicators = NeutralizeIndicators;