From ec9bea24778d9b66368de7e3768ed984476ee0c6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 8 Jun 2019 08:20:08 +0200 Subject: [PATCH] Fixing comparison when checking stoploss and take profit --- Commons.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Commons.js b/Commons.js index 1db8ce08e..d98900328 100644 --- a/Commons.js +++ b/Commons.js @@ -732,7 +732,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { /* Stop Loss condition: Here we verify if the Stop Loss was hitted or not. */ - if (candle.max >= stopLoss) { + if ((baseAsset === 'BTC' && candle.max >= stopLoss) || (baseAsset !== 'BTC' && candle.min <= stopLoss)) { if (baseAsset === 'BTC') { balanceAssetA = balanceAssetA + balanceAssetB / stopLoss; @@ -767,7 +767,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { /* Take Profit condition: Here we verify if the Take Profit was filled or not. */ - if (candle.min <= takeProfit) { + if ((baseAsset === 'BTC' && candle.min <= takeProfit) || (baseAsset !== 'BTC' && candle.max >= takeProfit)) { if (baseAsset === 'BTC') { balanceAssetA = balanceAssetA + balanceAssetB / takeProfit; @@ -1174,9 +1174,7 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { currentTrade.lastProfitPercent = lastProfitPercent; currentTrade.stopRate = stopLoss; - - //if (isNaN(ROI)) { ROI = 0; } - + if (lastProfit > 0) { hits++; @@ -1196,9 +1194,15 @@ exports.newCommons = function newCommons(bot, logger, UTILITIES) { } } - ROI = (initialBalanceA + profit) / initialBalanceA - 1; - hitRatio = hits / roundtrips; - anualizedRateOfReturn = ROI / days * 365; + if (baseAsset === 'BTC') { + ROI = (initialBalanceA + profit) / initialBalanceA - 1; + hitRatio = hits / roundtrips; + anualizedRateOfReturn = ROI / days * 365; + } else { + ROI = (initialBalanceB + profit) / initialBalanceB - 1; + hitRatio = hits / roundtrips; + anualizedRateOfReturn = ROI / days * 365; + } if (currentDay !== undefined) { if (positionInstant < currentDay.valueOf()) {