Dukascopy Support Board

How to buy and sell at same time, please help.
Page 1 of 1

Author:  NightOwl [ Thu 22 Jul, 2021, 13:44 ]
Post subject:  How to buy and sell at same time, please help.

Hello, I would like to have a code that buys and sells at same time, but this way it is clearly not working. Here is the code.

import com.dukascopy.api.*;

public class flipper implements IStrategy {

    public Instrument instrument = Instrument.EURUSD;
    public double betsize = 0.001;

    @Configurable("Stop Loss")
    public double stoploss = 300;
    @Configurable("Take Profit")
    public double takeprofit = 5;
    public double spreadlimit = 1;

    private IEngine engine;
    private IConsole console;
    private IOrder order;
    public void onStart(IContext context) throws JFException {

         this.engine = context.getEngine();
         this.console = context.getConsole();
        engine = context.getEngine();
        console = context.getConsole();
        context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
    public void onMessage(IMessage message) throws JFException {}
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        order = engine.submitOrder("EURUSD" + System.currentTimeMillis(), Instrument.EURUSD, IEngine.OrderCommand.BUY, betsize ,0, spreadlimit, tick.getAsk() - stoploss  * Instrument.EURUSD.getPipValue(),
                tick.getAsk() + takeprofit * Instrument.EURUSD.getPipValue(), 0, "A: "  + " B: ");
        order = engine.submitOrder("EURUSD" + System.currentTimeMillis(), Instrument.EURUSD, IEngine.OrderCommand.SELL, betsize, 0, spreadlimit, tick.getBid() + stoploss * Instrument.EURUSD.getPipValue(),
                tick.getBid() - takeprofit * Instrument.EURUSD.getPipValue(), 0, "A: " + " B: ");


    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
    public void onAccount(IAccount account) throws JFException {}
    public void onStop() throws JFException {}}

And here is the result Image


as you can see it does not buy and sell every time, even that the code says it should?

Author:  mtnfx [ Wed 28 Jul, 2021, 01:38 ]
Post subject:  Re: How to buy and sell at same time, please help.

JForex API does not allow multiple orders to have same label. In your case SELL will have in 99.99% of cases same label as BUY.

  Page 1 of 1