From e552d6fd4e373ad83b76bd139471460cbbec3495 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 4 Jun 2019 21:19:20 +0200 Subject: [PATCH] Reorganizing Code and dividing in stages --- Commons.js | 91 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/Commons.js b/Commons.js index 34baf42ab..5701c3071 100644 --- a/Commons.js +++ b/Commons.js @@ -320,20 +320,23 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { evaluateConditions(tradingSystem, conditions); - if (currentStrategyNumber === 0 && - balanceAssetA > minimunBalanceA) { + if ( + strategyStage === 'No Stage' && + currentStrategyNumber === 0 && + balanceAssetA > minimunBalanceA + ) { /* Trigger On Conditions */ /* Here we need to pick a strategy, or if there is not suitable strategy for the current market conditions, we pass until the next period. - + To pick a new strategy we will evaluate what we call the trigger on. Once we enter into one strategy, we will ignore market conditions for others. However there is also a strategy trigger off which can be hit before taking a position. If hit, we would be outside a strategy again and looking for the condition to enter all over again. - + */ checkTriggerOn(); @@ -413,6 +416,46 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } + /* Take Position Condition */ + + if (strategyStage === 'Trigger Stage') { + + checkTakePosition(); + + function checkTakePosition() { + + let strategy = tradingSystem.strategies[currentStrategyNumber - 1]; + + for (let k = 0; k < strategy.takePosition.situations.length; k++) { + + let situation = strategy.takePosition.situations[k]; + let passed = true; + + for (let m = 0; m < situation.conditions.length; m++) { + + let condition = situation.conditions[m]; + let key = strategy.name + '-' + situation.name + '-' + condition.name + + let value = conditions.get(key).value; + + if (value === false) { passed = false; } + } + + if (passed) { + + type = '"Sell"'; + + strategyStage = 'Open Stage'; + stopLossPhase = 1; + takeProfitPhase = 1; + currentTrade.begin = candle.begin; + currentTrade.beginRate = candle.close; + return; + } + } + } + } + /* Checking if Stop or Take Profit were hit */ if (strategyStage === 'Manage Stage') { @@ -478,46 +521,6 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } - /* Trade Enter Condition */ - - if (strategyStage === 'Trigger Stage') { - - checkTakePosition(); - - function checkTakePosition() { - - let strategy = tradingSystem.strategies[currentStrategyNumber - 1]; - - for (let k = 0; k < strategy.takePosition.situations.length; k++) { - - let situation = strategy.takePosition.situations[k]; - let passed = true; - - for (let m = 0; m < situation.conditions.length; m++) { - - let condition = situation.conditions[m]; - let key = strategy.name + '-' + situation.name + '-' + condition.name - - let value = conditions.get(key).value; - - if (value === false) { passed = false; } - } - - if (passed) { - - type = '"Sell"'; - - strategyStage = 'Open Stage'; - stopLossPhase = 1; - takeProfitPhase = 1; - currentTrade.begin = candle.begin; - currentTrade.beginRate = candle.close; - return; - } - } - } - } - /* Stop Loss Management */ if (strategyStage === 'Manage Stage') {