From 7eb3ce7d09c711497aa5ebff308e7a58e6cfc109 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 28 Mar 2020 12:47:30 +0100 Subject: [PATCH] new properties --- BollingerBands.js | 22 ++++++++++++++++++---- BollingerBandsPanel.js | 21 +++++++++++++++------ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/BollingerBands.js b/BollingerBands.js index 684bd9688..6a7b974ce 100644 --- a/BollingerBands.js +++ b/BollingerBands.js @@ -331,6 +331,7 @@ let currentDate = new Date(farLeftDate.valueOf()); bands = []; + let lastBand while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { @@ -356,6 +357,14 @@ band.standardDeviation = dailyFile[i][3]; band.deviation = dailyFile[i][4]; + if (lastBand !== undefined) { + if (lastBand.movingAverage > band.movingAverage) { band.direction = "Down" } + if (lastBand.movingAverage < band.movingAverage) { band.direction = "Up" } + if (lastBand.movingAverage === band.movingAverage) { band.direction = "Side" } + } + + lastBand = band + if ( (band.begin >= farLeftDate.valueOf() && band.end <= farRightDate.valueOf()) && (band.begin >= coordinateSystem.min.x && band.end <= coordinateSystem.max.x) @@ -386,13 +395,9 @@ if (bands[0].begin > lowerEnd || bands[bands.length - 1].end < upperEnd) { setTimeout(recalculate, 2000); - - //console.log("File missing while calculating bands, scheduling a recalculation in 2 seconds."); - } } - //console.log("Olivia > recalculateUsingDailyFiles > total bands generated : " + bands.length); } catch (err) { @@ -417,6 +422,7 @@ rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); bands = []; + let lastBand for (let i = 0; i < marketFile.length; i++) { @@ -434,6 +440,14 @@ band.standardDeviation = marketFile[i][3]; band.deviation = marketFile[i][4]; + if (lastBand !== undefined) { + if (lastBand.movingAverage > band.movingAverage) { band.direction = "Down" } + if (lastBand.movingAverage < band.movingAverage) { band.direction = "Up" } + if (lastBand.movingAverage === band.movingAverage) { band.direction = "Side" } + } + + lastBand = band + if ( (band.begin >= leftDate.valueOf() && band.end <= rightDate.valueOf()) && (band.begin >= coordinateSystem.min.x && band.end <= coordinateSystem.max.x) diff --git a/BollingerBandsPanel.js b/BollingerBandsPanel.js index cf23bada6..a01b74e1d 100644 --- a/BollingerBandsPanel.js +++ b/BollingerBandsPanel.js @@ -120,8 +120,8 @@ function newMastersPlottersBollingerBandsBollingerBandsBollingerBandsPanel () { /* Extra bounderies due to constrained space */ - const upperLimit = frameTitleHeight + frameBodyHeight * 0.15; - const downLimit = frameTitleHeight + frameBodyHeight * 0.85; + const upperLimit = frameTitleHeight + frameBodyHeight * 0.25; + const downLimit = frameTitleHeight + frameBodyHeight * 0.75; if (bandPoint1.y > downLimit) { bandPoint1.y = downLimit; } if (bandPoint4.y > downLimit) { bandPoint4.y = downLimit; } @@ -201,11 +201,20 @@ function newMastersPlottersBollingerBandsBollingerBandsBollingerBandsPanel () { let y; - printLabel('Moving Average', X_AXIS, frameTitleHeight + frameBodyHeight * 0.05, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - printLabel(currentBand.innerBand.movingAverage, X_AXIS, frameTitleHeight + frameBodyHeight * 0.10, '1.00', 15, undefined, true, thisObject.container, thisObject.fitFunction); - printLabel('Deviation', X_AXIS, frameTitleHeight + frameBodyHeight * 0.95, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); - printLabel(currentBand.innerBand.deviation, X_AXIS, frameTitleHeight + frameBodyHeight * 0.90, '1.00', 15, undefined, true, thisObject.container, thisObject.fitFunction); + if (currentBand.innerBand.direction !== undefined) { + printLabel('Direction', X_AXIS, frameTitleHeight + frameBodyHeight * 0.05, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(currentBand.innerBand.direction, X_AXIS, frameTitleHeight + frameBodyHeight * 0.10, '1.00', 15, undefined, true, thisObject.container, thisObject.fitFunction); + } + + printLabel('Moving Average', X_AXIS, frameTitleHeight + frameBodyHeight * 0.15, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(currentBand.innerBand.movingAverage, X_AXIS, frameTitleHeight + frameBodyHeight * 0.20, '1.00', 15, undefined, true, thisObject.container, thisObject.fitFunction); + + printLabel('Deviation', X_AXIS, frameTitleHeight + frameBodyHeight * 0.85, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(currentBand.innerBand.deviation, X_AXIS, frameTitleHeight + frameBodyHeight * 0.80, '1.00', 15, undefined, true, thisObject.container, thisObject.fitFunction); + + printLabel('Standard Deviation', X_AXIS, frameTitleHeight + frameBodyHeight * 0.95, '0.60', undefined, undefined, true, thisObject.container, thisObject.fitFunction); + printLabel(currentBand.innerBand.standardDeviation, X_AXIS, frameTitleHeight + frameBodyHeight * 0.90, '1.00', 15, undefined, true, thisObject.container, thisObject.fitFunction); } }