sql-synergy
Version:
Synergy Wave TA
128 lines (127 loc) • 4.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Step6 = void 0;
const Analyzer_1 = require("./Analyzer");
const Technicals_1 = require("./Technicals");
class Step6 extends Analyzer_1.Analyzer {
constructor(oPC, nD1 = 10, nD2 = 30, nMA = 10) {
super(oPC);
this.nD1 = 10;
this.nD2 = 30;
this.nMA = 10;
// fAction:Array<number> = [] ;
this.nDays = 0;
this.nD1 = nD1;
this.nD2 = nD2;
this.nMA = nMA;
this.nDays = Math.max(nD1, nD2) + nMA - 1;
this.calculateSignals();
}
calculateSignals() {
let fS = this.getMACDSignal();
let n = fS.length;
let iDir = 0;
this.fAction[0] = 0;
for (var i = 1; i < n; i++) {
if (iDir != 1 && fS[i] > 0.0 && fS[i - 1] < 0.0) {
iDir = 1;
this.fAction[i] = 1;
continue;
}
if (iDir != -1 && fS[i] < 0.0 && fS[i - 1] > 0.0) {
iDir = -1;
this.fAction[i] = -1;
continue;
}
// this.fAction[i] = 0 ;
}
// console.log(this.fAction) ;
}
// hasBuySignal(iDay:number):boolean {
// this.iSignalDay = 0 ;
// if ( this.hasEnoughData ( iDay ) == false )
// return false ;
// var n = iDay + 1 ;
// while ( --n > this.nDays )
// {
// if ( this.fAction[n] > 0 )
// {
// this.iSignalDay = n ;
// return true ;
// }
// if ( this.fAction[n] < 0 ) return false ;
// }
// return false ;
// }
// hasSellSignal(iDay:number):boolean {
// this.iSignalDay = 0 ;
// if ( this.hasEnoughData ( iDay ) == false )
// return false ;
// var n = iDay + 1 ;
// while ( --n > this.nDays )
// {
// if ( this.fAction[n] < 0 )
// {
// this.iSignalDay = n ;
// return true ;
// }
// if ( this.fAction[n] > 0 ) return false ;
// }
// return false ;
// }
// public boolean hasBuySignal ( int iDay )
// {
// iSignalDay = 0 ;
// if ( hasEnoughData ( iDay ) == false )
// return false ;
// float fPrice [ ] = new float [ iDay + 1 ] ;
// System.arraycopy ( oPC.getClose ( ), 0, fPrice, 0, fPrice.length ) ;
// return hasSynergyBuySignal ( fPrice ) ;
// // return hasBuySignal ( fPrice ) ;
// // return hasBuySignalIntersection ( fPrice ) && hasSynergyBuySignal ( fPrice ) ;
// }
// public boolean hasBuySignalIntersection ( int iDay )
// {
// iSignalDay = 0 ;
// if ( hasEnoughData ( iDay ) == false )
// return false ;
// float fPrice [ ] = new float [ iDay + 1 ] ;
// System.arraycopy ( oPC.getClose ( ), 0, fPrice, 0, fPrice.length ) ;
// return hasBuySignalIntersection ( fPrice ) ;
// }
//
// public boolean hasSellSignal ( int iDay )
// {
// iSignalDay = 0 ;
// if ( hasEnoughData ( iDay ) == false )
// return false ;
// float fPrice [ ] = new float [ iDay + 1 ] ;
// System.arraycopy ( oPC.getClose ( ), 0, fPrice, 0, fPrice.length ) ;
// // return hasSellSignalIntersection ( fPrice ) && hasSynergySellSignal ( fPrice ) ;
// return hasSynergySellSignal ( fPrice ) ;
// }
// public boolean hasSellSignalIntersection ( int iDay )
// {
// iSignalDay = 0 ;
// if ( hasEnoughData ( iDay ) == false )
// return false ;
// float fPrice [ ] = new float [ iDay + 1 ] ;
// System.arraycopy ( oPC.getClose ( ), 0, fPrice, 0, fPrice.length ) ;
// return hasSellSignalIntersection ( fPrice ) ;
// }
// public hasEnoughData(iDay: number = 0): boolean {
// if (iDay == 0)
// iDay = this.oPC.getLastDay();
// return (iDay >= this.nDays);
// }
getMACDSignal() {
let fEMA1 = Technicals_1.Technicals.MOV(this.oPC.fC, this.nD1, 'E');
let fEMA2 = Technicals_1.Technicals.MOV(this.oPC.fC, this.nD2, 'E');
let vMACD = [];
for (var i = 0; i < fEMA1.length; i++) {
vMACD.push(fEMA1[i] - fEMA2[i]);
}
return Technicals_1.Technicals.MOV(vMACD, this.nMA, 'E');
}
}
exports.Step6 = Step6;