diff --git a/TaskServer/LowFrequencyTrading/TradingEngine.js b/TaskServer/LowFrequencyTrading/TradingEngine.js index 865713d7f..c0ed6d7d2 100644 --- a/TaskServer/LowFrequencyTrading/TradingEngine.js +++ b/TaskServer/LowFrequencyTrading/TradingEngine.js @@ -45,7 +45,6 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) { } function mantain() { - updateDistanceToEventsCounters() } function reset() { @@ -212,63 +211,5 @@ exports.newTradingEngine = function newTradingEngine(bot, logger) { } } } - - function updateDistanceToEventsCounters() { - /* Keeping Distance Counters Up-to-date while avoinding counting before the first event happens. */ - if ( - tradingEngine.current.episode.distanceToEvent.triggerOn.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.triggerOn.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.triggerOff.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.triggerOff.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.takePosition.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.takePosition.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.closePosition.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.closePosition.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.nextPhase.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.nextPhase.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.moveToPhase.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.moveToPhase.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.createOrder.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.createOrder.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.cancelOrder.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.cancelOrder.value++ - } - - if ( - tradingEngine.current.episode.distanceToEvent.closeOrder.value > 0 - ) { - tradingEngine.current.episode.distanceToEvent.closeOrder.value++ - } - } - } diff --git a/TaskServer/LowFrequencyTrading/TradingEpisode.js b/TaskServer/LowFrequencyTrading/TradingEpisode.js index b5112fb56..5276ba5bc 100644 --- a/TaskServer/LowFrequencyTrading/TradingEpisode.js +++ b/TaskServer/LowFrequencyTrading/TradingEpisode.js @@ -37,6 +37,7 @@ exports.newTradingEpisode = function newTradingEpisode(bot, logger, tradingEngin updateCounters() updateStatistics() updateEnds() + updateDistanceToEventsCounters() } function reset() { @@ -225,4 +226,61 @@ exports.newTradingEpisode = function newTradingEpisode(bot, logger, tradingEngin tradingEngine.current.episode.episodeQuotedAsset.hitFail.value = 'Fail' } } + + function updateDistanceToEventsCounters() { + /* Keeping Distance Counters Up-to-date while avoinding counting before the first event happens. */ + if ( + tradingEngine.current.episode.distanceToEvent.triggerOn.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.triggerOn.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.triggerOff.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.triggerOff.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.takePosition.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.takePosition.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.closePosition.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.closePosition.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.nextPhase.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.nextPhase.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.moveToPhase.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.moveToPhase.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.createOrder.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.createOrder.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.cancelOrder.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.cancelOrder.value++ + } + + if ( + tradingEngine.current.episode.distanceToEvent.closeOrder.value > 0 + ) { + tradingEngine.current.episode.distanceToEvent.closeOrder.value++ + } + } } \ No newline at end of file diff --git a/TaskServer/LowFrequencyTrading/TradingSimulation.js b/TaskServer/LowFrequencyTrading/TradingSimulation.js index 6a8e98a75..c63f6988e 100644 --- a/TaskServer/LowFrequencyTrading/TradingSimulation.js +++ b/TaskServer/LowFrequencyTrading/TradingSimulation.js @@ -110,6 +110,9 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT 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. + + /* We emit a heart beat so that the UI can now where we are at the overal process.*/ + heartBeat() if (firstLoopExecution === true) { tradingEpisodeModule.openEpisode() @@ -131,7 +134,6 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT return } - heartBeat() positionChartAtCurrentCandle() /* The chart was recalculated based on the current candle. */ diff --git a/TaskServer/LowFrequencyTrading/TradingStages.js b/TaskServer/LowFrequencyTrading/TradingStages.js index 79007509b..063cb977a 100644 --- a/TaskServer/LowFrequencyTrading/TradingStages.js +++ b/TaskServer/LowFrequencyTrading/TradingStages.js @@ -548,6 +548,9 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM tradingPositionModule.updateStopLoss(tradingEngine.current.position.stopLoss.stopLossPhase.value + 1) announcementsModule.makeAnnoucements(nextPhaseEvent) + + /* Reset this counter */ + tradingEngine.current.episode.distanceToEvent.nextPhase.value = 1 return // only one event can pass at the time } } @@ -588,6 +591,9 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM } announcementsModule.makeAnnoucements(moveToPhaseEvent) + + /* Reset this counter */ + tradingEngine.current.episode.distanceToEvent.moveToPhase.value = 1 return // only one event can pass at the time } } @@ -641,6 +647,9 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM tradingPositionModule.updateTakeProfit(tradingEngine.current.position.takeProfit.takeProfitPhase.value + 1) announcementsModule.makeAnnoucements(nextPhaseEvent) + + /* Reset this counter */ + tradingEngine.current.episode.distanceToEvent.nextPhase.value = 1 return // only one event can pass at the time } } @@ -681,6 +690,9 @@ exports.newTradingStages = function newTradingStages(bot, logger, tradingEngineM } announcementsModule.makeAnnoucements(moveToPhaseEvent) + + /* Reset this counter */ + tradingEngine.current.episode.distanceToEvent.moveToPhase.value = 1 return // only one event can pass at the time } }