Hi,
It's been a while since I haven't posted !
My strategy can open up to 16 orders with very low leverage at the same time.
Instead of putting a stoploss on each order, it calculates the total profit/loss in % for all opened orders.
If the total amount of opened order losses is bigger than 2% of the account equity, it is closing all positions.
When I backtest, the problem is that getBaseEquity() returns a number where the price never managed
to go, causing my trades to be stopped out to early.
I tried to retrieve manually getBaseEquity() by using getProfitLossInAccountCurrency(), the same issue.
I tried to replace getBaseEquity() with getBalance(), the same issue.
Maybe the problem is coming from getProfitLossInAccountCurrency() not returning the result
in the account currency of the backtest (EURO) but in USD ?
For an easier understanding please see the screenshot bellow and a part of my code.
If you have an other working solution I'll be glad.
Thanks for helping me.
Best regards
Nicolas.

Here is my code in onBar :
double pctProfitLossTotal = 0;
double pctProfitLossBalance = 0;
double baseAccountEquity = 0;
double currentAccountEquity = 0;
if (period.equals(Period.ONE_MIN) && instrument == Instrument.EURUSD) {
double totalProfitLoss = 0;
baseAccountEquity = account.getBaseEquity();
currentAccountEquity = account.getEquity();
for (IOrder order : engine.getOrders()) {
if (order.getState() == IOrder.State.FILLED) {
totalProfitLoss = totalProfitLoss + order.getProfitLossInAccountCurrency();
}
}
double currentBalance = account.getBalance();
pctProfitLossBalance = roundFloor(((currentAccountEquity - currentBalance) / currentBalance) * 100, 100);
pctProfitLossTotal = roundFloor(((currentAccountEquity - (currentAccountEquity - totalProfitLoss)) / (currentAccountEquity - totalProfitLoss)) * 100, 100);
pctProfitLoss = roundFloor(((currentAccountEquity - baseAccountEquity) / baseAccountEquity) * 100, 100);
if (pctProfitLoss < maxPctEquityLoss) {
for (IOrder order : engine.getOrders()) {
order.close();
}
}
}
if (period.equals(Period.ONE_MIN)) {
commentOnChart(instrument, "currentAccountEquity : " + String.valueOf(currentAccountEquity) + "\n"
+ "baseAccountEquity : " + String.valueOf(baseAccountEquity) + "\n"
+ "Equity P/L : " + String.valueOf(pctProfitLoss) + "%\n"
+ "Balance P/L : " + String.valueOf(pctProfitLossBalance) + "%\n"
+ "Total P/L : " + String.valueOf(pctProfitLossTotal) + "%\n");
}