diff --git a/LowFrequencyTrading/TradingSimulation.js b/LowFrequencyTrading/TradingSimulation.js index eb70d24ac..89255ae3f 100644 --- a/LowFrequencyTrading/TradingSimulation.js +++ b/LowFrequencyTrading/TradingSimulation.js @@ -121,6 +121,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin } if (checkInitialDatetime() === false) { + if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] runSimulation -> loop -> Candle Before the Initia Date Time @ ' + (new Date(candle.begin)).toLocaleString()) } continue } @@ -155,7 +156,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin had the chance to check for the status of placed orders or even cancel the ones that needed cancellation. */ - checkIfWeNeedToStop() + checkIfWeNeedToStopBetweenCycles() /* Add new records to the process output */ tradingRecordsModule.appendRecords() @@ -172,6 +173,8 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin tradingEngineModule.setCurrentCycle('Second') await runCycle() + checkIfWeNeedToStopAfterBothCycles() + /* Add new records to the process output */ tradingRecordsModule.appendRecords() @@ -186,8 +189,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin await tradingSystemModule.run() } - function checkIfWeNeedToStop() { - /* Checking if we should continue processing this loop or not. */ + function checkIfWeNeedToStopBetweenCycles() { if (bot.STOP_SESSION === 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 session.') } updateEpisode('Session Stopped') @@ -209,12 +211,6 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin return } - if (checkNextCandle() === false) { - updateEpisode('All Available Candles Processed') - breakLoop = true - return - } - if (checkMinimunAndMaximunBalance() === false) { closeEpisode('Min or Max Balance Reached') breakLoop = true @@ -222,6 +218,14 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, tradin return } } + + function checkIfWeNeedToStopAfterBothCycles() { + if (checkNextCandle() === false) { + updateEpisode('All Available Candles Processed') + breakLoop = true + return + } + } } tradingSystemModule.finalize() diff --git a/Session.js b/Session.js index 0e74351ad..135b2cc68 100644 --- a/Session.js +++ b/Session.js @@ -185,7 +185,7 @@ } /* Session Type Forced Values */ - let today = new Date((new Date()).valueOf()) + let today = (new Date()).valueOf() let aYearAgo = today - global.ONE_YEAR_IN_MILISECONDS let aYearFromNow = today + global.ONE_YEAR_IN_MILISECONDS switch (bot.SESSION.type) { @@ -214,7 +214,7 @@ */ /* Initial Datetime */ - if (bot.SESSION.parameters.timeRange.config.initialDatetime === undefined) { + if (bot.SESSION.parameters.timeRange.config.initialDatetime === undefined || bot.SESSION.parameters.timeRange.config.allowStartingFromThePast !== true ) { bot.SESSION.parameters.timeRange.config.initialDatetime = initialDefault } else { bot.SESSION.parameters.timeRange.config.initialDatetime = (new Date(bot.SESSION.parameters.timeRange.config.initialDatetime)).valueOf()