Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

JFException: Label not unique for some (but not all) sell orders?!
 Post subject: JFException: Label not unique for some (but not all) sell orders?! Post rating: 0   New post Posted: Fri 11 May, 2012, 08:48 

User rating: 0
Joined: Wed 09 May, 2012, 19:19
Posts: 1
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


 
 Post subject: Re: JFException: Label not unique for some (but not all) sell orders?! Post rating: 0   New post Posted: Fri 11 May, 2012, 08:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider using a new method that gives each order a unique name:
    int counter = 1;
    private String getLabel(String label) {
        label = label + (counter++);
        return label;
    }


Consider this modified strategy
package jforex.strategies;

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().startsWith("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(getLabel("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 {
    }
   
   
    int counter = 1;
    private String getLabel(String label) {
        label = label + (counter++);
        return label;
    }
}


Attachments:
HeikinAshiSet.java [2.47 KiB]
Downloaded 269 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com