Hi,
before you use methods like IOrder.setStopLossPrice or IOrder.setTakeProfitPrice you should verify that server has been submitted this order. If submission was successful server gives you message IMessage.Type.ORDER_SUBMIT_OK, after which order comes available for previusly mentioned methods.
Here is sample:
package jforex;
import com.dukascopy.api.*;
/**
* This sample strategy, which demostrates usage of IOrder.setTakeProfitPrice
* */
public class TakeProfitSampleStrategy implements IStrategy {
private IEngine engine;
private IOrder myOrder;
private IConsole console;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
//Check if this is our created order and that its successful submitted
if(message.getOrder() == myOrder && message.getType()== IMessage.Type.ORDER_SUBMIT_OK){
myOrder.setTakeProfitPrice(1.55455);
}
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (myOrder == null) {
myOrder = engine.submitOrder("myOrder", Instrument.EURUSD, IEngine.OrderCommand.BUY, 2); //Placing our order
}
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}