From 00c47a74783faae4cbd777c02976fc80d569f706 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 29 Jul 2020 11:16:05 +0200 Subject: [PATCH] Bug Fixes --- LowFrequencyTrading/Announcements.js | 6 +----- LowFrequencyTrading/TradingProcess.js | 2 +- LowFrequencyTrading/TradingSimulation.js | 16 ++++++++++++---- LowFrequencyTrading/TradingSystem.js | 8 ++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/LowFrequencyTrading/Announcements.js b/LowFrequencyTrading/Announcements.js index ec8c25d75..2c63c88d1 100644 --- a/LowFrequencyTrading/Announcements.js +++ b/LowFrequencyTrading/Announcements.js @@ -41,11 +41,7 @@ exports.newAnnouncements = function newAnnouncements(bot, logger) { if (canAnnounce === true) { let text = announcement.config.text if (announcement.formula !== undefined) { - try { - text = eval(announcement.formula.code) - } catch (err) { - tradingSystem.errors.push([announcement.formula.id, err.message]) - } + text = tradingSystem.formulas.get(announcement.formula.id) } if (bot.SESSION.socialBots !== undefined) { diff --git a/LowFrequencyTrading/TradingProcess.js b/LowFrequencyTrading/TradingProcess.js index aee4a0f74..7e66fe1e9 100644 --- a/LowFrequencyTrading/TradingProcess.js +++ b/LowFrequencyTrading/TradingProcess.js @@ -797,7 +797,7 @@ let dataRecord = dataFile[i] let begin = dataRecord[beginIndex] let end = dataRecord[endIndex] - if (end < bot.SESSION.parameters.timeRange.config.initialDatetime) { continue } + if (end < bot.SESSION.parameters.timeRange.config.initialDatetime - 1) { continue } // /1 because we need the previous closed element if (begin > bot.SESSION.parameters.timeRange.config.finalDatetime) { continue } result.push(dataRecord) } diff --git a/LowFrequencyTrading/TradingSimulation.js b/LowFrequencyTrading/TradingSimulation.js index 58470f756..4e8f655b2 100644 --- a/LowFrequencyTrading/TradingSimulation.js +++ b/LowFrequencyTrading/TradingSimulation.js @@ -240,8 +240,12 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT if (dataDependencyNode.referenceParent.config.codeName !== 'Multi-Period-Daily') { continue } let singularVariableName = dataDependencyNode.referenceParent.parentNode.config.singularVariableName let pluralVariableName = dataDependencyNode.referenceParent.parentNode.config.pluralVariableName - let currentElement = getElement(thisChart[pluralVariableName], 'Daily' + '-' + mapKey + '-' + pluralVariableName) - thisChart[singularVariableName] = currentElement + if (thisChart[pluralVariableName] !== undefined) { + let currentElement = getElement(thisChart[pluralVariableName], 'Daily' + '-' + mapKey + '-' + pluralVariableName) + if (currentElement !== undefined) { + thisChart[singularVariableName] = currentElement + } + } } } } @@ -257,8 +261,12 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT if (dataDependencyNode.referenceParent.config.codeName !== 'Multi-Period-Market') { continue } let singularVariableName = dataDependencyNode.referenceParent.parentNode.config.singularVariableName let pluralVariableName = dataDependencyNode.referenceParent.parentNode.config.pluralVariableName - let currentElement = getElement(thisChart[pluralVariableName], 'Market' + '-' + mapKey + '-' + pluralVariableName) - thisChart[singularVariableName] = currentElement + if (thisChart[pluralVariableName] !== undefined) { + let currentElement = getElement(thisChart[pluralVariableName], 'Market' + '-' + mapKey + '-' + pluralVariableName) + if (currentElement !== undefined) { + thisChart[singularVariableName] = currentElement + } + } } } diff --git a/LowFrequencyTrading/TradingSystem.js b/LowFrequencyTrading/TradingSystem.js index 64670330d..a1755803f 100644 --- a/LowFrequencyTrading/TradingSystem.js +++ b/LowFrequencyTrading/TradingSystem.js @@ -656,6 +656,14 @@ exports.newTradingSystem = function newTradingSystem(bot, logger, tradingEngineM evalConditions(manageStage, 'Manage Stage') evalFormulas(manageStage, 'Manage Stage') + if ( + tradingEngine.current.position.stopLoss.stopLossStage.value === 'Open Stage' || + tradingEngine.current.position.takeProfit.takeProfitStage.value === 'Open Stage') { + let stageNode = tradingSystem.tradingStrategies[tradingEngine.current.strategy.index.value].openStage + evalConditions(stageNode, 'Initial Definition') + evalFormulas(stageNode, 'Initial Definition') + } + /* Stop Loss Management */ checkStopPhasesEvents() calculateStopLoss()