IOrder documentation states:
"trailingStep - if < 0 then adds stop loss order without trailing step. Should be 0 or >= 10".
Passing trailingStep = 0 does nothing, passing trailingStep = -1 throws following exception:
"com.dukascopy.api.JFException: Trailing step must be >= 10 or equals to 0 (cancel) @ com.dukascopy.api.impl.connect.c.c.a(Unknown Source)"
It seems that passing trailingStep = 0 should cancel it, but it doesn't happen.
package jforex;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IOrder;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import java.util.Date;
public class CancelTrailingStepTest implements IStrategy {
private IContext context;
private IEngine engine;
private IConsole console;
@Override
public void onStart(IContext context) throws JFException {
this.context = context;
this.engine = context.getEngine();
this.console = context.getConsole();
try {
Instrument instrument = Instrument.EURUSD;
long waitTimeout = 2000;
long sleepTimeout = 2000;
IOrder order = engine.submitOrder("label_" + (new Date()).getTime(), instrument, IEngine.OrderCommand.BUY, 0.001, 0, 10, 0, 0);
order.waitForUpdate(waitTimeout, IOrder.State.FILLED);
Thread.sleep(sleepTimeout);
if (order.getState() == IOrder.State.FILLED) {
double sl = order.getOpenPrice() - 10 * instrument.getPipValue();
order.setStopLossPrice(sl, OfferSide.BID, 10);
order.waitForUpdate(waitTimeout);
Thread.sleep(sleepTimeout);
console.getOut().println("Stop loss: " + order.getStopLossPrice() + ", trailing step: " + order.getTrailingStep());
order.setStopLossPrice(sl, OfferSide.BID, 0);
order.waitForUpdate(waitTimeout);
console.getOut().println("Stop loss: " + order.getStopLossPrice() + ", trailing step: " + order.getTrailingStep());
} else {
console.getOut().println("Order was not filled.");
}
} catch (InterruptedException ex) {
console.getOut().println("Interrupted.");
}
}
@Override
public void onStop() throws JFException {
}
@Override
public void onAccount(IAccount account) throws JFException {
}
@Override
public void onMessage(IMessage message) throws JFException {
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}