From 970c2e96cc71143a5330d85492151b8884370654 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 19 May 2019 16:53:34 +0200 Subject: [PATCH] Cleaning Records when time Period changes --- Conditions.js | 14 ++++---------- Strategies.js | 12 +++--------- Trades.js | 12 +++--------- TradingSimulation.js | 46 +++++++++++++++----------------------------- 4 files changed, 26 insertions(+), 58 deletions(-) diff --git a/Conditions.js b/Conditions.js index 232ef1059..650401534 100644 --- a/Conditions.js +++ b/Conditions.js @@ -185,21 +185,15 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod !== pTimePeriod) { timePeriod = pTimePeriod; if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimePeriod); - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + recalculate(); } else { @@ -207,7 +201,7 @@ fileCursor = newFileCursor; // In this case, we explicitly want that if there is no valid cursor, we invalidate the data and show nothing. recalculate(); - + } } @@ -265,7 +259,7 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + records = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/Strategies.js b/Strategies.js index de5e91ce3..de045c4bb 100644 --- a/Strategies.js +++ b/Strategies.js @@ -193,21 +193,15 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod !== pTimePeriod) { timePeriod = pTimePeriod; if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimePeriod); - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + recalculate(); } else { @@ -273,7 +267,7 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + records = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/Trades.js b/Trades.js index fc51c9229..0fd53b3c9 100644 --- a/Trades.js +++ b/Trades.js @@ -185,21 +185,15 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod !== pTimePeriod) { timePeriod = pTimePeriod; if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + marketFile = marketFiles.getFile(pTimePeriod); - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + recalculate(); } else { @@ -265,7 +259,7 @@ try { - if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } + records = [] if (timePeriod >= _1_HOUR_IN_MILISECONDS) { diff --git a/TradingSimulation.js b/TradingSimulation.js index c2e883d18..5eb0cb6bd 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -151,27 +151,13 @@ } function getContainer(point) { - - try { - - let container; - - /* First we check if this point is inside this space. */ - - if (this.container.frame.isThisPointHere(point) === true) { - - return this.container; - - } else { - - /* This point does not belong to this space. */ - - return undefined; - } - - } catch (err) { - - if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } + let container; + /* First we check if this point is inside this space. */ + if (this.container.frame.isThisPointHere(point) === true) { + return this.container; + } else { + /* This point does not belong to this space. */ + return undefined; } } @@ -203,14 +189,10 @@ if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - let newMarketFile = marketFiles.getFile(pTimePeriod); - - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; - recalculate(); - } + marketFile = marketFiles.getFile(pTimePeriod); + recalculate(); + } else { let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); @@ -271,6 +253,8 @@ try { + records = [] + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { recalculateUsingMarketFiles(); @@ -631,10 +615,10 @@ let imageOffset = { x: 0, - y: 15 + y: 30 } let imageSize = (recordPoint2.x - recordPoint1.x) / 2; - let recordLabel = record.periods.toString() + let recordLabel = record.periods.toLocaleString() if (imageSize < 8) { if (recordLabel[recordLabel.length - 1] !== '0' || imageSize < 4) recordLabel = '' @@ -818,6 +802,8 @@ + +