From aabf49dccb4643935a2113df78edffdb64e5e6e6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 12 Jun 2020 10:25:40 +0200 Subject: [PATCH] fixes --- LowFrequencyTrading/TradingSimulation.js | 10 +++++----- Session.js | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/LowFrequencyTrading/TradingSimulation.js b/LowFrequencyTrading/TradingSimulation.js index b3e79419f..39e8f5cb7 100644 --- a/LowFrequencyTrading/TradingSimulation.js +++ b/LowFrequencyTrading/TradingSimulation.js @@ -138,6 +138,8 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> loop -> Candle Begin @ ' + (new Date(candle.begin)).toLocaleString()) } if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> loop -> Candle End @ ' + (new Date(candle.end)).toLocaleString()) } + tradingEngineModule.setCurrentCandle(candle) // We move the current candle we are standing at, to the trading engine data structure to make it available to anyone, including conditions and formulas. + if (checkIfWeAreAtTheHeadOfTheMarket() === false) { afterLoop() return @@ -154,8 +156,6 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT } heartBeat() - - tradingEngineModule.setCurrentCandle(candle) // We move the current candle we are standing at, to the trading engine data structure to make it available to anyone, including conditions and formulas. positionChartAtCurrentCandle() tradingEngineModule.updateEpisodeCountersAndStatistics() @@ -422,11 +422,11 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT function checkInitialAndFinalDatetime() { /* Here we check that the current candle is not outside of user-defined time range at the session parameters.*/ - if (candle.end < sessionParameters.timeRange.config.initialDatetime.valueOf()) { + if (tradingEngine.current.candle.end.value < sessionParameters.timeRange.config.initialDatetime.valueOf()) { if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> checkInitialAndFinalDatetime -> Skipping Candle before the sessionParameters.timeRange.config.initialDatetime.') } return false } - if (candle.begin > sessionParameters.timeRange.config.finalDatetime.valueOf()) { + if (tradingEngine.current.candle.begin.value > sessionParameters.timeRange.config.finalDatetime.valueOf()) { if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> checkInitialAndFinalDatetime -> Skipping Candle after the sessionParameters.timeRange.config.finalDatetime.') } return false } @@ -457,7 +457,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT maximumBalance = sessionParameters.sessionQuotedAsset.config.maximumBalance } - let stopRunningDate = new Date(candle.begin) + let stopRunningDate = new Date(tradingEngine.current.candle.begin.value) if (balance <= minimumBalance) { tradingSystem.error = 'Min Balance @ ' + stopRunningDate.toLocaleString() if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> checkMinimunAndMaximunBalance -> ' + tradingSystem.error) } diff --git a/Session.js b/Session.js index 0a928a0cf..0297863f1 100644 --- a/Session.js +++ b/Session.js @@ -213,6 +213,7 @@ bot.sessionError(bot.SESSION.parameters.timeFrame, errorMessage) return false } + bot.SESSION.parameters.timeFrame.config.value = getTimeFrameFromLabel(bot.SESSION.parameters.timeFrame.config.label) /* Session Base Asset */ if (bot.SESSION.parameters.sessionBaseAsset === undefined) { @@ -314,7 +315,7 @@ bot.resumeExecution = false; bot.tradingProcessDate = new Date(bot.SESSION.parameters.timeRange.config.initialDatetime.valueOf()) bot.hasTheBotJustStarted = true - pProcessConfig.liveWaitTime = getTimeFrameFromLabel(bot.SESSION.parameters.timeFrame.config.label) + pProcessConfig.liveWaitTime = sessionParameters.timeFrame.config.value return true } @@ -347,7 +348,7 @@ bot.SESSION.parameters.sessionBaseAsset.config.maximumBalance = bot.SESSION.parameters.sessionBaseAsset.config.maximumBalance * balancePercentage / 100 bot.SESSION.parameters.sessionQuotedAsset.config.maximumBalance = bot.SESSION.parameters.sessionQuotedAsset.config.maximumBalance * balancePercentage / 100 - pProcessConfig.normalWaitTime = getTimeFrameFromLabel(bot.SESSION.parameters.timeFrame.config.label) + pProcessConfig.normalWaitTime = sessionParameters.timeFrame.config.value return true } @@ -357,7 +358,7 @@ bot.resumeExecution = false; bot.hasTheBotJustStarted = true bot.tradingProcessDate = new Date(bot.SESSION.parameters.timeRange.config.initialDatetime.valueOf()) - pProcessConfig.normalWaitTime = getTimeFrameFromLabel(bot.SESSION.parameters.timeFrame.label) + pProcessConfig.normalWaitTime = sessionParameters.timeFrame.config.value return true }