Strategies Objects being saved

This commit is contained in:
Luis Fernando Molina committed 2020-06-20 20:14:42 +02:00
1 parent 2aef400f50
commit 7dc1aa648f
3 files changed
+63 -29

No files matched your search

+29 -17
View File
@@ -41,6 +41,10 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
let product = dataset.parentNode
let outputDatasetArray = outputDatasetsMap.get(product.config.codeName)
if (product.config.codeName === 'Strategy-Objects') {
let a = 1
}
if (bot.processingDailyFiles === true && dataset.config.type === 'Daily Files') {
persistRecord()
}
@@ -53,28 +57,36 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
let record = scanRecordDefinition(product)
if (product.config.saveAsObjects === true) {
/*
We check that the existing file does not contain at the end a record that
does not signal that the object is closed.
If it does, we replace it with the new one until at some point it will signal
does the object is closed.
*/
let lastRecord = outputDatasetArray[outputDatasetArray.length - 1]
if (lastRecord !== undefined) {
for (let j = 0; j < product.record.properties.length; j++) {
let recordProperty = product.record.properties[j]
if (recordProperty.config.codeName === product.config.propertyNameThatDefinesObject) {
let propertyValue = record[j]
if (propertyValue !== product.config.propertyValueThatClosesObject) {
for (let j = 0; j < product.record.properties.length; j++) {
let recordProperty = product.record.properties[j]
if (recordProperty.config.codeName === product.config.propertyNameThatDefinesObject) {
let propertyValue = record[j]
/*
We check that the existing file does not contain at the end a record that
does not signal that the object is closed.
If it does, we replace it with the new one until at some point it will signal
does the object is closed.
*/
let lastRecord = outputDatasetArray[outputDatasetArray.length - 1]
if (lastRecord !== undefined) {
let lastRecordValue = lastRecord[j]
if (lastRecordValue !== product.config.propertyValueThatClosesObject) {
outputDatasetArray.splice(outputDatasetArray.length - 1, 1)
}
}
/*
We will add a record everytime that proeprty value does not match this
*/
if (propertyValue !== product.config.propertyValueThatPreventsSavingObject) {
outputDatasetArray.push(record)
}
break
}
}
} else {
/* We add every record to the existing file. */
outputDatasetArray.push(record)
}
/* We add every record to the existing file. */
outputDatasetArray.push(record)
}
}
@@ -151,7 +163,7 @@ exports.newTradingRecords = function newTradingRecords(bot, logger) {
value = targetNode
}
}
if (recordProperty.config.isString !== true) {
if (recordProperty.config.isString !== true && Array.isArray(value) !== true) {
value = safeNumericValue(value)
}
record.push(value)
+2
View File
@@ -158,6 +158,8 @@ exports.newTradingSimulation = function newTradingSimulation(bot, logger, UTILIT
heartBeat()
positionChartAtCurrentCandle()
tradingSystemModule.reset(chart)
tradingSystemModule.mantainStrategies()
tradingSystemModule.mantainPositions()
tradingEngineModule.updateEpisodeCountersAndStatistics()
/*
+32 -12
View File
@@ -6,6 +6,8 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
const MODULE_NAME = 'Trading System'
let thisObject = {
reset: reset,
mantainStrategies: mantainStrategies,
mantainPositions: mantainPositions,
evalConditions: evalConditions,
evalFormulas: evalFormulas,
checkTriggerOn: checkTriggerOn,
@@ -72,6 +74,16 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
tradingSystem.running = []
}
function mantainStrategies() {
if (tradingEngine.current.strategy.status.value === 'Closed') {
resetStrategy()
}
}
function mantainPositions() {
}
function evalConditions() {
evalNode(bot.simulationState.tradingSystem, 'Conditions')
}
@@ -264,12 +276,8 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
tradingSystem.highlights.push(triggerStage.id)
tradingEngine.current.strategy.stageType.value = 'Trigger Stage'
tradingEngine.current.strategy.status.value = 'Open'
openStrategy()
tradingEngine.current.strategy.index.value = j
tradingEngine.current.strategy.begin.value = tradingEngine.current.candle.begin.value
tradingEngine.current.strategy.end.value = tradingEngine.current.candle.end.value // TODO: overrride with the node Formula
tradingEngine.current.strategy.beginRate.value = tradingEngine.current.candle.min.value
tradingEngine.current.strategy.endRate.value = tradingEngine.current.candle.min.value // TODO: overrride with the node Formula
tradingEngine.current.strategy.situationName.value = situation.name
tradingEngine.current.strategy.strategyName.value = strategy.name
@@ -321,9 +329,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
tradingSystem.highlights.push(triggerStage.triggerOff.id)
tradingSystem.highlights.push(triggerStage.id)
tradingEngine.current.strategy.end.value = tradingEngine.current.candle.end.value
tradingEngine.current.strategy.endRate.value = tradingEngine.current.candle.min.value
tradingEngine.current.strategy.status.value = 'Closed'
closeTrateggy()
tradingEngine.current.strategy.stageType.value = 'No Stage'
tradingEngine.current.strategy.index.value = tradingEngine.current.strategy.index.config.initialValue
@@ -982,10 +988,7 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
function exitStrategyAfterPosition() {
if (tradingEngine.current.strategy.stageType.value === 'Close Stage') {
tradingEngine.current.strategy.end.value = tradingEngine.current.candle.end.value
tradingEngine.current.strategy.endRate.value = tradingEngine.current.candle.min.value
tradingEngine.current.strategy.status.value = 'Closed'
closeTrateggy()
tradingEngine.current.strategy.index.value = tradingEngine.current.strategy.index.config.initialValue
tradingEngine.current.strategy.stageType.value = 'No Stage'
@@ -1039,5 +1042,22 @@ exports.newTradingSystem = function newTradingSystem(bot, logger) {
}
}
function closeTrateggy() {
tradingEngine.current.strategy.status.value = 'Closed'
tradingEngine.current.strategy.end.value = tradingEngine.current.candle.end.value
tradingEngine.current.strategy.endRate.value = tradingEngine.current.candle.min.value
}
function openStrategy() {
tradingEngine.current.strategy.status.value = 'Open'
tradingEngine.current.strategy.begin.value = tradingEngine.current.candle.begin.value
tradingEngine.current.strategy.end.value = tradingEngine.current.candle.end.value // TODO: overrride with the node Formula
tradingEngine.current.strategy.beginRate.value = tradingEngine.current.candle.min.value
tradingEngine.current.strategy.endRate.value = tradingEngine.current.candle.min.value // TODO: overrride with the node Formula
}
function resetStrategy() {
tradingEngine.current.strategy.status.value = tradingEngine.current.strategy.status.config.initialValue
}
}