From 85211ab486feff002690a83e9abb1a896677d4ac Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 2 Feb 2021 18:44:15 +0100 Subject: [PATCH] Bug Fixed, almost all debuged --- .../Low-Frequency-Trading/Snapshots.js | 16 +++++++++++- .../Low-Frequency-Trading/TradingOutput.js | 4 +-- .../Low-Frequency-Trading/TradingProcess.js | 26 ++++++++++--------- .../TradingSimulation.js | 12 ++++++--- .../Low-Frequency-Trading/TradingStages.js | 4 +-- .../Low-Frequency-Trading/TradingSystem.js | 2 +- 6 files changed, 43 insertions(+), 21 deletions(-) diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js index 4af1bcfbd..031eab5d9 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/Snapshots.js @@ -38,7 +38,13 @@ exports.newSuperalgosBotModulesSnapshots = function (processIndex) { let positionValues let addToPositionValues + /* + These 3 are the main data structures available to users + when writing conditions and formulas. + */ let chart + let exchange + let market return thisObject @@ -58,10 +64,18 @@ exports.newSuperalgosBotModulesSnapshots = function (processIndex) { strategyKeys = undefined chart = undefined + exchange = undefined + market = undefined } - function updateChart(pChart) { + function updateChart(pChart, pExchange, pMarket) { + /* + We need these 3 data structures to be a local objects + accessible while evaluating conditions and formulas. + */ chart = pChart + exchange = pExchange + market = pMarket } function strategyEntry() { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js index fb3c06aa4..d0a799b9a 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingOutput.js @@ -28,8 +28,8 @@ exports.newSuperalgosBotModulesTradingOutput = function (processIndex) { async function start( chart, - exchange, market, + exchange, timeFrame, timeFrameLabel, tradingProcessDate @@ -80,8 +80,8 @@ exports.newSuperalgosBotModulesTradingOutput = function (processIndex) { await tradingSimulationModuleObject.runSimulation( chart, - exchange, market, + exchange, outputDatasetsMap, writeFiles ) diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js index c8cf63784..613f41d2f 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingProcess.js @@ -341,7 +341,7 @@ continue } - if (dataDependenciesModule.filters.exchange.timeFrames.get(datasetModule.exchange, datasetModule.market, datasetModule.product, 'atAnyTimeFrame') !== true) { + if (dataDependenciesModule.filters.exchange.timeFrames.get(datasetModule.exchange + '-' + datasetModule.market + '-' + datasetModule.product + '-' + 'atAnyTimeFrame') !== true) { /* If we can not find the current data set is used at the current time frame we will skip this file. @@ -405,7 +405,7 @@ continue } - if (dataDependenciesModule.filters.exchange.timeFrames.get(datasetModule.exchange, datasetModule.market, datasetModule.product, timeFrameLabel) !== true) { + if (dataDependenciesModule.filters.exchange.timeFrames.get(datasetModule.exchange + '-' + datasetModule.market + '-' + datasetModule.product + '-' + timeFrameLabel) !== true) { /* If we can not find the current data set is used at the current time frame we will skip this file, unless we are in the only special @@ -520,7 +520,7 @@ continue } - if (dataDependenciesModule.filters.exchange.timeFrames.get(datasetModule.exchange, datasetModule.market, datasetModule.product, timeFrameLabel) !== true) { + if (dataDependenciesModule.filters.exchange.timeFrames.get(datasetModule.exchange + '-' + datasetModule.market + '-' + datasetModule.product + '-' + timeFrameLabel) !== true) { /* If we can not find the current data set is used at the current time frame we will skip this file, unless we are in the only special @@ -662,7 +662,7 @@ TS.projects.superalgos.functionLibraries.singleMarketFunctions.inflateDatafiles(processIndex, dataFiles, dataDependencies, products, mainDependency, currentTimeFrame) let propertyName = 'at' + timeFrameLabel.replace('-', '') - addProducs(propertyName) + addProducs(propertyName, products) } } @@ -676,22 +676,24 @@ TS.projects.superalgos.functionLibraries.singleMarketFunctions.inflateDatafiles(processIndex, dataFiles, dataDependencies, products, mainDependency, currentTimeFrame) let propertyName = 'at' + timeFrameLabel.replace('-', '') - addProducs(propertyName) + addProducs(propertyName, products) } } /* Single Files */ - let dataFiles = multiTimeFrameDataFiles.get('Single Files') - let products = {} + { + let dataFiles = multiTimeFrameDataFiles.get('Single Files') + let products = {} - if (dataFiles !== undefined && dataFiles.size > 0) { - TS.projects.superalgos.functionLibraries.singleMarketFunctions.inflateDatafiles(processIndex, dataFiles, dataDependencies, products, mainDependency, currentTimeFrame) + if (dataFiles !== undefined && dataFiles.size > 0) { + TS.projects.superalgos.functionLibraries.singleMarketFunctions.inflateDatafiles(processIndex, dataFiles, dataDependencies, products, mainDependency, currentTimeFrame) - let propertyName = 'atAnyTimeFrame' - addProducs(propertyName) + let propertyName = 'atAnyTimeFrame' + addProducs(propertyName, products) + } } - function addProducs(propertyName) { + function addProducs(propertyName, products) { /* The chart data structure allow users to simplify the syntax when they are using the default exchange and the default market. diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js index a4c95762f..4bab96ff7 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSimulation.js @@ -17,8 +17,8 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex) { async function runSimulation( chart, - exchange, market, + exchange, outputDatasetsMap, writeFiles, ) { @@ -152,7 +152,7 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex) { chart, exchange, market - ) + ) /* Do the stuff needed previous to the run like @@ -220,7 +220,7 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex) { type: 'TS LF Trading Bot Info - Candle And Cycle', placeholder: {} } - + contextInfo = { candleIndex: tradingEngine.current.episode.candle.index.value, cycle: tradingEngine.current.episode.cycle.value @@ -368,6 +368,8 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex) { let propertyName = 'at' + mapKey.replace('-', '') let thisChart = chart[propertyName] + if (thisChart === undefined) { continue } + for (let k = 0; k < dataDependencies.length; k++) { let dataDependencyNode = dataDependencies[k] if (dataDependencyNode.referenceParent.config.codeName !== 'Multi-Period-Daily') { continue } @@ -389,6 +391,8 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex) { let propertyName = 'at' + mapKey.replace('-', '') let thisChart = chart[propertyName] + if (thisChart === undefined) { continue } + for (let k = 0; k < dataDependencies.length; k++) { let dataDependencyNode = dataDependencies[k] if (dataDependencyNode.referenceParent.config.codeName !== 'Multi-Period-Market') { continue } @@ -407,6 +411,8 @@ exports.newSuperalgosBotModulesTradingSimulation = function (processIndex) { let propertyName = 'atAnyTimeFrame' let thisChart = chart[propertyName] + if (thisChart === undefined) { return } + for (let k = 0; k < dataDependencies.length; k++) { let dataDependencyNode = dataDependencies[k] if (dataDependencyNode.referenceParent.config.codeName !== 'Single-File') { continue } diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js index 7dbdd2c5e..ef55ba96c 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingStages.js @@ -71,8 +71,8 @@ exports.newSuperalgosBotModulesTradingStages = function (processIndex) { tradingEpisodeModuleObject = undefined } - function updateChart(pChart) { - snapshotsModuleObject.updateChart(pChart) + function updateChart(pChart, pExchange, pMarket) { + snapshotsModuleObject.updateChart(pChart, pExchange, pMarket) } function mantain() { diff --git a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js index baff85703..e784c7e28 100644 --- a/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js +++ b/Projects/Superalgos/TS/Bot-Modules/Trading-Bot/Low-Frequency-Trading/TradingSystem.js @@ -169,7 +169,7 @@ exports.newSuperalgosBotModulesTradingSystem = function (processIndex) { exchange = pExchange market = pMarket - tradingStagesModuleObject.updateChart(pChart) + tradingStagesModuleObject.updateChart(pChart, pExchange, pMarket) } function buildDynamicIndicators() {