UNPKG

sql-synergy

Version:

Synergy Wave TA

135 lines (130 loc) 5.25 kB
"use strict"; /* Stochastics The right way to use stochastics. a) IDENTIFY the underlying Major Trend. If you are thinking of going long you would want the weekly chart to be trending UP or atleast Hooking UP. b) Switch to Daily Chart to IDENTIFY the Intermediate Trend When the weekly trend is UP, you would want to take all upturns of the daily stochastics as BUY ( LONG ) signals. Having identified a weekly uptrend, you would want to IGNORE all the sell signals from the daily stochastics. c) Finally, use the hourly stochastics as a "further buy" signal ONLY when the daily & weekly stochastics are UP. It is the crossing between %K line and %D line that produce buy or sell signals. Crossovers are also called "hook-ups" or "hook-downs". Hourly Daily Weekly Short-term Medium-term Stochastics Stochastics Stochastics Day Trader Position Traders ------------------------------------------------------------------------ Hook UP Hook UP Hook UP Long Signal Long Signal Hook Down Hook UP Hook UP Stay Out Long Signal Hook Down Hook Down Hook UP Short Signal Hold On to Longs Hook Up Hook Down Hook Up Stay Out Hold On to Longs Hook Up Hook Down Hook Down Stay Out Short Signal Hook Up Hook Up Hook Down Long Signal Hold On to Shorts Hook Down Hook Up Hook Down Stay out Hold On to Shorts Hook Down Hook Down Hook Down Short Signal Short Signal */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Stochastics = void 0; const Technicals_1 = require("./Technicals"); class Stochastics { // public hasJustCrossedForSell ( iDay:number ) // { // if ( iDay < ( this.nDays + this.nDDays + this.nMA - 2 ) ) // return 0 ; // if ( this.fK [ iDay ] < this.fD [ iDay ] && // this.fK [ iDay - 1 ] >= this.fD [ iDay - 1 ] ) // return iDay ; // if ( this.fK [ iDay ] <= this.fD [ iDay ] && // this.fK [ iDay - 1 ] > this.fD [ iDay - 1 ] ) // return iDay ; // return 0 ; // } // public hasCrossedForSell ( iDay:number ) // { // if ( iDay < ( this.nDays + this.nDDays + this.nMA - 2 ) ) // return 0 ; // if ( ( this.fK [ iDay ] < this.fD [ iDay ] ) == false ) // return 0 ; // while ( --iDay > ( this.nDays + this.nDDays + this.nMA - 2 ) ) // { // if ( this.fK [ iDay ] > this.fD [ iDay ] ) // return iDay + 1 ; // } // return 0 ; // } // public hasJustCrossedForBuy ( iDay:number ) // { // if ( iDay < ( this.nDays + this.nDDays + this.nMA - 2 ) ) // return 0 ; // if ( this.fK [ iDay ] > this.fD [ iDay ] && // this.fK [ iDay - 1 ] <= this.fD [ iDay - 1 ] ) // return iDay ; // if ( this.fK [ iDay ] >= this.fD [ iDay ] && // this.fK [ iDay - 1 ] < this.fD [ iDay - 1 ] ) // return iDay ; // return 0 ; // } // public hasCrossedForBuy ( iDay:number ) // { // if ( iDay < ( this.nDays + this.nDDays + this.nMA - 2 ) ) // return 0 ; // if ( ( this.fK [ iDay ] > this.fD [ iDay ] ) == false ) // return 0 ; // while ( --iDay > ( this.nDays + this.nDDays + this.nMA - 2 ) ) // { // if ( this.fK [ iDay ] < this.fD [ iDay ] ) // return iDay + 1 ; // } // return 0 ; // } //Tested according to MetaStock constructor(oPD, nK, nD, nMA) { this.nDays = 5; this.nDDays = 3; // %D Parameter this.nMA = 3; this.nDays = nK; this.nDDays = nD; this.nMA = nMA; let fHigh = oPD.getHigh(); let fLow = oPD.getLow(); let fClose = oPD.getClose(); let n = fHigh.length; this.fK = new Array(n); this.fD = new Array(n); let fRawK = new Array(n); let fH_L = new Array(n); let fC_L = new Array(n); for (var i = 0; i < n; i++) { let fH = Technicals_1.Technicals.getHighest(fHigh, this.nDays, i); let fL = Technicals_1.Technicals.getLowest(fLow, this.nDays, i); fH_L[i] = fH - fL; fC_L[i] = fClose[i] - fL; if (fH_L[i] != 0) fRawK[i] = fC_L[i] * 100 / fH_L[i]; else fRawK[i] = Number.MIN_VALUE; let f = Technicals_1.Technicals.getSum(fH_L, this.nDDays, i); if (i > this.nDays) this.fK[i] = Technicals_1.Technicals.getSum(fC_L, this.nDDays, i) * 100 / f; else this.fK[i] = Number.MIN_VALUE; if (i > this.nDDays + nMA + 1) this.fD[i] = Technicals_1.Technicals.getMA(this.fK, nMA, i); else this.fD[i] = Number.MIN_VALUE; // System.out.println ( fKK [ i ] + "," + fK [ i ] + "," + fD [ i ] ) ; } } getD() { return this.fD; } getK() { return this.fK; } } exports.Stochastics = Stochastics; //70 - 30 RSI //25 - 75 Stochastics //