Backtest at the middle of each candle.

This commit is contained in:
Luis Fernando Molina committed 2018-05-30 12:25:56 +02:00
1 parent 031add278f
commit d4c840cfcf
1 file changed
+21 -12
+21 -12
View File
@@ -156,6 +156,18 @@
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> Backtesting Mode detected."); }
let timePeriod;
if (UI_COMMANDS.timePeriod !== undefined) {
timePeriod = UI_COMMANDS.timePeriod;
} else {
timePeriod = processConfig.timePeriod;
}
if (bot.hasTheBotJustStarted === true) {
if (FULL_LOG === true) { logger.write("[INFO] run -> loop -> Setting initial datetime."); }
@@ -170,20 +182,17 @@
}
/*
We will standarize the backtesting execution time, setting the exact time at the middle of the candle or timePeriod.
*/
let totalMiliseconds = bot.processDatetime.valueOf();
totalMiliseconds = Math.trunc(totalMiliseconds / timePeriod) * timePeriod + timePeriod / 2;
bot.processDatetime = new Date(totalMiliseconds);
} else {
let timePeriod;
if (UI_COMMANDS.timePeriod !== undefined) {
timePeriod = UI_COMMANDS.timePeriod;
} else {
timePeriod = processConfig.normalWaitTime;
}
bot.processDatetime = new Date(bot.processDatetime.valueOf() + timePeriod); // We advance time here.