sql-synergy
Version:
Synergy Wave TA
300 lines (299 loc) • 10.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Wave = void 0;
const IConstants_1 = require("./IConstants");
class Wave {
//sChart = "UnSet" ;
constructor() {
this.biggerChannel = 0;
this.i5StepsDateIndex = -1;
this.iSingalDate = -1;
this.bStep1Met = false;
this.bBiggerChannelBroken = false;
this.sName = 'UnSet';
this.bPerfect = false;
this.bNeutralized = false;
this.iHighIndex = 0;
this.iLowIndex = 0;
this.iStartDate = 0;
this.iEndDate = 0;
this.fMinimum = 0.0;
this.fMaximum = 0.0;
this.fLowest = 0.0;
this.fHighest = 0.0;
this.iDir = 0;
this.iNumber = 0;
this.bZigZag = false; // When the wave is renamed to a smaller wave then it is considered as ZigZag.
// No trading signal if ZigZag is true.
this.bManual = false;
this.vSmallerWaves = new Array();
this.iPC = -1;
this.iIC = -1;
}
getSignalDate() {
return this.iSingalDate;
}
setSignalDate(iDate) {
this.iSingalDate = iDate;
}
set5StepsDateIndex(iDayIndex) {
this.i5StepsDateIndex = iDayIndex;
}
get5StepsDateIndex() {
return this.i5StepsDateIndex;
}
setBiggerChannelBroken(bBiggerChannelBroken) {
this.bBiggerChannelBroken = bBiggerChannelBroken;
}
wasBiggerChannelBroken() {
return this.bBiggerChannelBroken;
}
step1Neutralized(b) {
this.bNeutralized = b;
}
wasStep1Neutralized() {
return this.bNeutralized;
}
//Perfect 5 Steps
setPerfect(bPerfect) {
this.bPerfect = bPerfect;
}
isPerfect() {
return this.bPerfect;
}
addSmallerWave(oWave) {
this.vSmallerWaves.push(oWave);
}
getSmallerWaves() {
let v = new Array();
let n = this.vSmallerWaves.length;
for (var i = 0; i < n; i++) {
let oSW = Wave.copy(this.vSmallerWaves[i]);
oSW.setName("" + this.sName + (i + 1));
v.push(oSW);
}
return v;
}
hasSmallerWaves() {
return this.vSmallerWaves.length != 0;
}
getParent() {
if (this.sName.length > 1)
return this.sName.substring(0, this.sName.length - 1);
return "";
}
getWaveType() {
return (this.isImpulsive() ? "I" : "C");
}
getName() {
return this.sName;
}
getWaveStartEnd() {
if (this.iDir == Wave.UP) {
return this.fLowest + "," + this.fHighest;
}
return this.fHighest + "," + this.fLowest;
}
getStartIndex() {
if (this.iDir == Wave.UP)
return this.iLowIndex;
return this.iHighIndex;
}
getEndIndex() {
if (this.iDir == Wave.UP)
return this.iHighIndex;
return this.iLowIndex;
}
getPriceChart() {
return this.iPC;
}
getIndicatorChart() {
return this.iIC;
}
getChart() {
return IConstants_1.IConstants.sChart[this.iPC] + IConstants_1.IConstants.sChart[this.iIC];
}
getCSV() {
let sWaveStartEnd = "";
if (this.iDir == Wave.UP) {
sWaveStartEnd += this.fLowest + "," + this.fHighest;
}
else
sWaveStartEnd += this.fHighest + "," + this.fLowest;
return IConstants_1.IConstants.sChart[this.iPC] + IConstants_1.IConstants.sChart[this.iIC] + "," + this.getName() + "-" + (this.isUp() ? "Up" : "Dn") + "," + (this.isImpulsive() ? "I" : "C") + "," + sWaveStartEnd + "," + this.fMinimum + "," + this.fMaximum;
}
getJSON() {
let s = "" + this.getStartDate(this.oPC);
s += ',' + this.getEndDate(this.oPC);
s += ',"' + this.getName() + "-" + (this.isUp() ? "Up" : "Dn") + '"';
s += ',' + (this.isUp() ? this.fLowest : this.fHighest);
s += ',' + (this.isDown() ? this.fLowest : this.fHighest);
s += ',"' + (this.isImpulsive() ? "I" : "C") + '"';
s += ',"' + (this.isPerfect() ? "P" : "N") + '"';
s += "," + this.fMinimum.toFixed(4);
s += "," + this.fMaximum.toFixed(4);
s += "," + this.getDirection();
s += ',"' + IConstants_1.IConstants.sChart[this.iPC] + '"';
s += ',"' + IConstants_1.IConstants.sChart[this.iIC] + '"';
s += ',' + this.oPC.fD[this.get5StepsDateIndex()]; // Signal Day
s += ',"' + (this.bStep1Met ? "M" : "N") + '"';
s += ',' + (this.biggerChannel);
return '[' + s + ']';
}
print(oPC = undefined) {
if (oPC === undefined)
console.log("**" + this.getChart() + (this.isImpulsive() ? "Imp" : "Cor") + " " + this.sName + "-" + (this.iDir == Wave.UP ? "Up" : "Dn") + " " + this.getWaveStartEnd() + " Min: " + this.fMinimum + " Max: " + this.fMaximum + " Start: " + this.getStartIndex() + " End: " + this.getEndIndex());
else
console.log("**" + this.getChart() + (this.isImpulsive() ? "Imp" : "Cor") + " " + this.sName + "-" + (this.iDir == Wave.UP ? "Up" : "Dn") + " " + this.getWaveStartEnd() + " Min: " + this.fMinimum + " Max: " + this.fMaximum + " Start:" + oPC.getDate(this.getStartIndex()) + " End:" + oPC.getDate(this.getEndIndex()));
}
setName(sName) {
// console.log("*** Setting Name: ', sName) ;
this.sName = sName;
}
wasStep1Met() {
if (this.fMinimum == 0 && this.fMaximum == 0)
return true;
if (this.iDir == Wave.UP)
return this.fHighest > this.fMinimum;
return this.fLowest < this.fMinimum;
}
setDirection(iDir) {
this.iDir = iDir;
}
getLength() {
return this.getHigh() - this.getLow();
}
getLowIndex() {
return this.iLowIndex;
}
getHighIndex() {
return this.iHighIndex;
}
setLowest(iIndex, f) {
this.iLowIndex = iIndex;
this.fLowest = f;
}
setHighest(iIndex, f) {
this.iHighIndex = iIndex;
this.fHighest = f;
}
setMinimum(f) {
this.fMinimum = f;
this.bStep1Met = false;
if (this.isUp() && f < this.fHighest)
this.bStep1Met = true;
if (this.isDown() && f > this.fLowest)
this.bStep1Met = true;
}
setMaximum(f) {
this.fMaximum = f;
}
getMaximum() {
return this.fMaximum;
}
getMinimum() {
return this.fMinimum;
}
minimumMet() {
// if ( bNeutralized )
// return true ;
if (this.fMinimum == 0 && this.fMaximum == 0) // TODO: Remove this if we have handled calculation of the Min/Max for 1st waves
return true;
if (this.isUp() && this.getHigh() > this.fMinimum)
return true;
if (this.isDown() && this.getLow() < this.fMinimum)
return true;
return false;
}
getHigh() {
return this.fHighest;
}
getLow() {
return this.fLowest;
}
isDown() {
return this.iDir == Wave.DN;
}
isUp() {
return this.iDir == Wave.UP;
}
getDirection() {
return this.iDir;
}
getStartDate(oPC) {
return oPC.fD[this.getStartIndex()];
}
getEndDate(oPC) {
return oPC.fD[this.getEndIndex()];
}
static copy(oWave) {
let oW = new Wave();
oW.setDirection(oWave.getDirection());
oW.setLowest(oWave.getLowIndex(), oWave.getLow());
oW.setHighest(oWave.getHighIndex(), oWave.getHigh());
oW.setMinimum(oWave.getMinimum());
oW.setMaximum(oWave.getMaximum());
oW.setPerfect(oWave.isPerfect());
oW.setName(oWave.getName());
oW.set5StepsDateIndex(oWave.get5StepsDateIndex());
oW.setBiggerChannelBroken(oWave.bBiggerChannelBroken);
oW.setCharts(oWave.oPC, oWave.oIC);
return oW;
}
setCharts(oPC, oIC) {
this.oPC = oPC;
this.oIC = oIC;
this.iPC = oPC.getPeriod();
this.iIC = oIC.getPeriod();
}
isImpulsive() {
return this.isCorrective() == false;
}
ascii(a) { return a.charCodeAt(0); }
isCorrective() {
return true;
// let ch = this.sName.charAt(this.sName.length - 1);
// if (this.sName.length == 1)
// return (ch == 'B' || ch == 'D');
// return (this.ascii(ch) % 2 == 0);
}
// reduceWaveNumber ( )
// {
// let ch = this.sName.charAt ( this.sName.length ( ) - 1 ) ;
// if ( this.sName.length == 1 )
// {
// this.sName = "" + ( this.ascii(ch) - 1 ) ;
// return ;
// }
// var i = parseInt ( this.sName.substring ( 1 ) ) ;
// i-- ;
// this.setName ( this.sName.substring ( 0, 1 ) + i ) ;
// }
reduceWaveNumber(iWaveNameLength = 1) {
var ch = this.sName.charAt(this.sName.length - 1);
if (this.sName.length == 1) {
// this.sName = "" + (this.ascii(this.sName) - 1);
this.sName = this.getWaveChar(ch, -1);
return this.sName;
}
var i = parseInt(this.sName.substring(iWaveNameLength));
// console.log("ReduceWaveNumber: ", this.sName.substring(iWaveNameLength), " i ", i)
i--;
this.setName(this.sName.substring(0, iWaveNameLength) + i);
return this.sName;
// this.setName(this.getWaveChar(this.sName, -1));
// console.log("ReduceWaveNumber: ", (this.sName.substring(iWaveNameLength) + i), " i ", i)
}
getWaveChar(str, inc) {
var n = str.charCodeAt(0);
// console.log(str, n, (n+inc), String.fromCharCode(n+inc)) ;
return String.fromCharCode(n + inc);
}
toString() {
return "Wave: (" + this.iPC + "," + this.iIC + ") " + this.sName + "," + this.getStartDate(this.oPC) + "," + this.getEndDate(this.oPC) + "," + this.iDir + "," + this.getWaveStartEnd();
;
}
}
exports.Wave = Wave;
Wave.UP = IConstants_1.IConstants.BUY_SIGNAL;
Wave.DN = IConstants_1.IConstants.SELL_SIGNAL;