Hello support,
I am lost in programming my fist chunks of code... I've tried to programme simplest order logic. The engine should open an order if Heikin Ashi indicator gives signal for that. When already a sell order is filled no further sell order should be submitted. After closing the order manually another sell order should be opened regarding signals. The open of the order works - sometimes for one sell order and sometimes for some more. But sooner or later I get the following error code after the filling of the sell order and the strategie aborts:
07:27:08 com.dukascopy.api.JFException: Label not unique(code 1). (Order already exists) [Verkauf]:label=Verkauf;getId()=null;groupId=null;openingOrderId=null;pendingOrderId=null;parentOrderId=null;tpOrderId=null;slOrderId=null;state=CREATED;instrument=EUR/USD;openPrice=0.0;requestedAmount=0.0010;amount=0.0010;lastServerRequest=SUBMIT;awaitingResubmit=false;localCreationTime=1336721228765; @ jforex.strategies.indicators.HeikinAshiSet.onTick(HeikinAshiSet.java:72)
My source code:
package jforex.strategies.indicators;
import java.util.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IIndicators.*;
import com.dukascopy.api.IOrder;
import com.dukascopy.api.Instrument.*;
public class HeikinAshiSet implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IOrder order;
@Configurable ("Instrument")
public Instrument selectedInstrument = Instrument.EURUSD;
@Configurable ("Period")
public Period selectedPeriod = Period.ONE_MIN;
@Override
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
}
@Override
public void onAccount(IAccount account) throws JFException {
}
@Override
public void onMessage(IMessage message) throws JFException {
}
@Override
public void onStop() throws JFException {
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
boolean heikini_2 = false;
boolean i = true;
int candlesBefore = 10;
int candlesAfter = 0;
long currBarTime = history.getBar (selectedInstrument, selectedPeriod, OfferSide.BID, 0).getTime();
double[][] heikin = indicators.heikinAshi(selectedInstrument, selectedPeriod, OfferSide.BID, Filter.WEEKENDS, candlesBefore, currBarTime,
candlesAfter);
for (IOrder order : engine.getOrders()) {
if (order.getState() == IOrder.State.FILLED && order.getLabel().equals("Verkauf")) {
i =false;
}}
if(heikin[8][0] >= heikin [8][1] && heikin[7][0] >= heikin [7][1] && heikin [9][0] >= heikin [9][1]) {
heikini_2 = true;}
if (i == true && heikini_2 == true ) {
order = engine.submitOrder("Verkauf", selectedInstrument, OrderCommand.SELL, 0.001);
heikini_2 = false;
i = false;
}}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}
What is most confusing for me is the fact, that when I change OrderCommand.SELL to OrderCommand.BUY (and change the HA indicator signals to <=) the strategy runs without a problem and I get no error code. How could this be? I can't understand that.
Could you please show me, what I did wrong in code programming, where my bug is or if there is another way to get the strategy run.
Thank you in advance
Cheers
Lars