diff --git a/LowFrequencyTrading/TradingProcess.js b/LowFrequencyTrading/TradingProcess.js index b8c971057..5258f1adc 100644 --- a/LowFrequencyTrading/TradingProcess.js +++ b/LowFrequencyTrading/TradingProcess.js @@ -134,7 +134,10 @@ */ if (currentTimeFrame) { /* We are processing Market Files */ - + /* + With all the indicators data files loaded, we will build the chart object + data structure that will be used in user-defied conditions and formulas. + */ buildCharts(chart) await generateOutput(chart) @@ -153,14 +156,26 @@ the date calculated by the Simulation is applied at the Trading Process Level. */ tradingProcessDate = global.REMOVE_TIME(bot.simulationState.tradingEngine.current.episode.processDate.value) - await processDailyFiles() - + /* + With all the indicators data files loaded, we will build the chart object + data structure that will be used in user-defied conditions and formulas. + */ buildCharts(chart) - + /* + The process of generating the output includes the trading simulation. + */ await generateOutput(chart) await writeProcessFiles() - + /* + If for any reason the session was stopped, we will break this loop and exit the process. + */ + if (bot.STOP_SESSION === true) {break} + /* + When we get to the end of the market, we need to break this process loop in order + to let time pass, new information be collected from the exchange, new data built + into indicators, and eventually a new execution of this process. + */ if (checkStopHeadOfTheMarket() === false) {break} } while (true) @@ -654,18 +669,6 @@ Backtests needs only one execution of this process to complete. */ bot.SESSION.stop('Backtesting Session Finished.') - } else { - /* - The natural way for the session to stop is when we reached the - user defined end datetime. - */ - const now = new Date() - if (now.valueOf() >= bot.SESSION.parameters.timeRange.config.finalDatetime) { - const logText = "User Defined End Datetime reached @ " + now.getUTCFullYear() + "/" + (now.getUTCMonth() + 1) + "/" + now.getUTCDate() + "."; - if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] start -> writeProcessFiles -> onMarketStatusReport -> " + logText); } - - bot.SESSION.stop('Final Datetime Reached.') - } } } } diff --git a/LowFrequencyTrading/TradingSimulation.js b/LowFrequencyTrading/TradingSimulation.js index ec2b3d4e6..7937c46f5 100644 --- a/LowFrequencyTrading/TradingSimulation.js +++ b/LowFrequencyTrading/TradingSimulation.js @@ -189,27 +189,34 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> controlLoop -> We are going to stop here bacause we were requested to stop processing this session.') } updateEpisode('Session Stopped') breakLoop = true + return } if (global.STOP_TASK_GRACEFULLY === true) { if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> controlLoop -> We are going to stop here bacause we were requested to stop processing this task.') } updateEpisode('Task Stopped') breakLoop = true + return } if (checkFinalDatetime() === false) { closeEpisode('Final Datetime Reached') breakLoop = true + bot.SESSION.stop('Final Datetime Reached') + return } if (checkNextCandle() === false) { updateEpisode('All Available Candles Processed') breakLoop = true + return } if (checkMinimunAndMaximunBalance() === false) { closeEpisode('Min or Max Balance Reached') breakLoop = true + bot.SESSION.stop('Min or Max Balance Reached') + return } } } diff --git a/Session.js b/Session.js index 79f5cb9b0..0e74351ad 100644 --- a/Session.js +++ b/Session.js @@ -114,7 +114,6 @@ socialBotsModule.finalize() bot.STOP_SESSION = true sessionError(bot.SESSION, commandOrigin) - } function setUpAppSchema() {