From 83da1c32aaf3ba6fb710072e0b5a643fb118093a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 16 Jun 2020 19:21:53 +0200 Subject: [PATCH] hightlights and values working --- LowFrequencyTrading/TradingRecords.js | 29 +++++++++---- LowFrequencyTrading/TradingSimulation.js | 2 +- LowFrequencyTrading/TradingSystem.js | 52 ++++++++++++------------ 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/LowFrequencyTrading/TradingRecords.js b/LowFrequencyTrading/TradingRecords.js index 8865f092c..e74116bbc 100644 --- a/LowFrequencyTrading/TradingRecords.js +++ b/LowFrequencyTrading/TradingRecords.js @@ -106,15 +106,26 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) { */ let value if (targetNode !== undefined) { - value = targetNode.value - } - - value = safeValue(value) - if (recordProperty.config.isString === true) { - value = '"' + value + '"' - } - if (recordProperty.config.decimals !== undefined) { - value = Number(value.toFixed(recordProperty.config.decimals)) + if (targetNode.type !== undefined) { + /* + In this case the Target Node is really a node (since it has a type), so we extract the value + from its value property. + */ + value = targetNode.value + value = safeValue(value) + if (recordProperty.config.isString === true) { + value = '"' + value + '"' + } + if (recordProperty.config.decimals !== undefined) { + value = Number(value.toFixed(recordProperty.config.decimals)) + } + } else { + /* + In this case the Target Node is not really node, but the value itself. Se we return this as the + value of the Record Property. + */ + value = targetNode + } } record.push(value) } diff --git a/LowFrequencyTrading/TradingSimulation.js b/LowFrequencyTrading/TradingSimulation.js index f6aee62d9..da931ff07 100644 --- a/LowFrequencyTrading/TradingSimulation.js +++ b/LowFrequencyTrading/TradingSimulation.js @@ -151,7 +151,7 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT heartBeat() positionChartAtCurrentCandle() - tradingSystemModule.setChart(chart) + tradingSystemModule.reset(chart) tradingEngineModule.updateEpisodeCountersAndStatistics() diff --git a/LowFrequencyTrading/TradingSystem.js b/LowFrequencyTrading/TradingSystem.js index cf066bc8f..4abd7dacc 100644 --- a/LowFrequencyTrading/TradingSystem.js +++ b/LowFrequencyTrading/TradingSystem.js @@ -4,7 +4,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) { const FULL_LOG = true let thisObject = { - setChart: setChart, + reset: reset, evalConditions: evalConditions, evalFormulas: evalFormulas, checkTriggerOn: checkTriggerOn, @@ -34,30 +34,33 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) { function initialize() { tradingSystem = bot.simulationState.tradingSystem tradingEngine = bot.simulationState.tradingEngine - - tradingSystem.highlights = [] - tradingSystem.conditionsErrors = [] - tradingSystem.formulasValues = [] - tradingSystem.formulasErrors = [] } function finalize() { chart = undefined conditions = undefined - tradingSystem.highlights = undefined - tradingSystem.conditionsErrors = undefined - formulas = undefined - tradingSystem.formulasValues = undefined - tradingSystem.formulasErrors = undefined + + tradingSystem.highlights = undefined + tradingSystem.errors = undefined + tradingSystem.values = undefined + tradingSystem.status = undefined + tradingSystem.progress = undefined + tradingSystem.running = undefined tradingSystem = undefined tradingEngine = undefined } - function setChart(pChart) { + function reset(pChart) { chart = pChart // We need chat to be a local object accessible from conditions and formulas. + tradingSystem.highlights = [] + tradingSystem.errors = [] + tradingSystem.values = [] + tradingSystem.status = [] + tradingSystem.progress = [] + tradingSystem.running = [] } function evalConditions() { @@ -143,19 +146,20 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) { */ } else { error = err.message - node.error = error } } conditions.set(node.id, value) if (value === true) { - tradingSystem.highlights.push(1) - } else { - tradingSystem.highlights.push(0) + tradingSystem.highlights.push([node.id, '']) + } + if (error !== undefined) { + tradingSystem.errors.push([node.id, error]) + } + if (value !== undefined) { + tradingSystem.values.push([node.id, value]) } - - tradingSystem.conditionsErrors.push(error) if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] evalCondition -> value = ' + value) } if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] evalCondition -> error = ' + error) } @@ -183,19 +187,17 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) { */ } else { error = err.message - node.error = error } } formulas.set(node.id, value) - if (value === true) { - tradingSystem.formulasValues.push(1) - } else { - tradingSystem.formulasValues.push(0) + if (error !== undefined) { + tradingSystem.errors.push([node.id, error]) + } + if (value !== undefined) { + tradingSystem.values.push([node.id, value]) } - - tradingSystem.formulasErrors.push(error) if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] evalFormula -> value = ' + value) } if (FULL_LOG === true) { logger.write(MODULE_NAME, '[INFO] evalFormula -> error = ' + error) }