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 {
@Configurable("Instrument")
public Instrument instrument = Instrument.EURUSD;
@Configurable("Amount")
public double betsize = 0.001;
@Configurable("Stop Loss")
public double stoploss = 300;
@Configurable("Take Profit")
public double takeprofit = 5;
@Configurable("Spread")
public double spreadlimit = 1;
private IEngine engine;
private IConsole console;
private IOrder order;
@Override
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
https://imgur.com/a/ceNVpZOas you can see it does not buy and sell every time, even that the code says it should?