Bug fixes

This commit is contained in:
Luis Fernando Molina committed 2020-08-15 09:10:07 +02:00
1 parent 593e53fea3
commit aee420e01e
4 files changed
+73 -60

No files matched your search

@@ -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++
}
}
}
@@ -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++
}
}
}
@@ -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. */
@@ -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
}
}