Happy New Year for all at Dukascopy Support Team and our community!
I tried to solve this problem for past one week but finally i gave up.
Lets say I have an ArrayList or Map of orders that interest me. I want to get ProfitLoss in total value for those orders combined.
Once printing this I get the right value:
public void onAccount(IAccount account) throws JFException {
for (IOrder o : MainOrders.values()) {
if(o.getState() == IOrder.State.FILLED){
profitLoss += o.getProfitLossInAccountCurrency();
totalAmount += o.getAmount();
}
console.getOut().format("last server equity=%.2f calculated equity=%.2f profit/loss=%.2f balance=%.2f total amount=%.3f",
account.getEquity(), history.getEquity(), profitLoss, account.getCreditLine(), totalAmount).println();
}
But once I add this statement :
I get wrong value of ProfitLoss for those orders in the Map/Array.
Therefore this "if" statement is not or wrongly executed.
if(profitLoss >= minprofitrounded){
console.getOut().println(String.format("ORDERS CLOSED " + minprofitrounded + "and profitloss= " + profitLoss + " || Actual LotSize now =" + lotsizerounded + " || pipvalue= " + pipvalue2 ));
}
Messages : where u see properly displayed value under profit/loss=-160.43 and same variable wrongly via profitloss=34.31.
profitloss represents last order which was iterated.
I know that i use wrong way to string.format this value but testing shows that this is actually the problem. That profitloss variable is showing only the last order and not total orders profitloss summarised.
Quote:
2014.01.03 10:42:24 ORDERS CLOSED 25.8and profitloss= 34.31 || Actual LotSize now 0.04 || pipvalue= 2.58
2014.01.03 10:42:24 last server equity=9833.08 calculated equity=9833.08 profit/loss=-160.43 balance=949039.14 total amount=0.240
I looked closely and seems like under o.getProfitLossInAccountCurrency(); it stores each order value separately and via += it summarise them.
profitLoss += o.getProfitLossInAccountCurrency();
But later I cant use profitLoss variable for anything than printing its values.
I want to compare total profit of orders to close them after reaching some static profit value. Like TakeProfit.
What do I do wrongly, am I missing something?
Please help.