PositionRate pre calculated and BUG FIXED negative balances
This commit is contained in:
1 parent
85c9c74c3b
commit
515d8f2f0b
2 files changed
+20
-12
No files matched your search
+16
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user