diff --git a/Commons.js b/Commons.js index ee498e8ab..44f6912e1 100644 --- a/Commons.js +++ b/Commons.js @@ -398,6 +398,14 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { let formulasErrors = []; // Here we store the errors produced by all phase formulas. let formulasValues = []; // Here we store the values produced by all phase formulas. + /* We set some variables that would be nice if they have a value before the formulas are calculated. */ + + if (strategyStage === 'Trigger Stage') { + + positionRate = candle.close; + + } + /* We define and evaluate all conditions to be used later during the simulation loop. */ conditionsArrayRecord.push(candle.begin); @@ -731,7 +739,6 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } - if ( strategyStage === 'No Stage' && currentStrategyIndex === -1 @@ -1214,6 +1221,12 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { positionSize = balanceAssetA; } else { positionSize = balanceAssetB; + } + } else { + if (baseAsset === 'BTC') { + if (positionSize > balanceAssetA) { positionSize = balanceAssetA} + } else { + if (positionSize > balanceAssetB) { positionSize = balanceAssetB} } } } @@ -1221,7 +1234,6 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } marketRate = candle.close; - positionRate = marketRate; calculateStopLoss(); calculateTakeProfit(); @@ -1233,10 +1245,10 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { lastProfitPercent = 0; if (baseAsset === 'BTC') { - balanceAssetB = balanceAssetB + positionSize * marketRate; + balanceAssetB = balanceAssetB + positionSize * positionRate; balanceAssetA = balanceAssetA - positionSize; } else { - balanceAssetA = balanceAssetA + positionSize / marketRate; + balanceAssetA = balanceAssetA + positionSize / positionRate; balanceAssetB = balanceAssetB - positionSize; } diff --git a/this.bot.config.json b/this.bot.config.json index 2f17c31ad..b1043d5d8 100644 --- a/this.bot.config.json +++ b/this.bot.config.json @@ -264,8 +264,7 @@ "devTeam": "AAMasters", "codeName": "PlottersTradingSimulation", "moduleName": "TradingSimulation" - }, - "relatedToTradingEngine": true + } }, { "codeName": "Simulation-Conditions", @@ -304,8 +303,7 @@ "devTeam": "AAMasters", "codeName": "PlottersTradingSimulation", "moduleName": "Conditions" - }, - "relatedToTradingEngine": true + } }, { "codeName": "Simulation-Strategies", @@ -344,8 +342,7 @@ "devTeam": "AAMasters", "codeName": "PlottersTradingSimulation", "moduleName": "Strategies" - }, - "relatedToTradingEngine": true + } }, { "codeName": "Simulation-Trades", @@ -384,8 +381,7 @@ "devTeam": "AAMasters", "codeName": "PlottersTradingSimulation", "moduleName": "Trades" - }, - "relatedToTradingEngine": true + } } ] }