Hi.
Sometimes I get following error message and my strategy stops:
-----------------------------------------------------------------------------------------------------------
02:05:50 com.dukascopy.api.JFException: Label not unique. (Order already exists) @ jforex.bttrader_v106.sendorder(bttrader_v106.java:118)
-----------------------------------------------------------------------------------------------------------
In my code I count all the positions that are open:
protected int positionsTotal(Instrument currentInstrument) throws JFException {
int counter = 0;
for (IOrder order : engine.getOrders(currentInstrument)) {
if (order.getState() == IOrder.State.FILLED) {
counter++;
}
}
return counter;
}
...and
if (positionsTotal(currentInstrument)==0 && /*some other trade conditions here....*/)
I allow sending orders:
engine.submitOrder("LONG", currentInstrument, IEngine.OrderCommand.BUY,lot,0, 0, tick.getBid() - values_get("Pip") * stopLoss, tick.getBid()+values_get("Pip") * takeProfit);
As I said, it only happens sometimes. I assume the following is happening:
1.) An order is sent, but not yet filled.
2.) The quotes change quickly, but order is still not filled.
3.) The "positionsTotal(currentInstrument)" still returns the value "0".
4.) Another order is sent, of course with the same label.
5.) Error message. Strategy stops.
How do I prevent the strategy from stopping?
Thanks for your help.
-Fuzzy