Modify Orders

One can separate order modification operations in two parts:

  1. Main order modifications (i.e. changing order amount, open price, good till time),
  2. Adding stop loss and/or take profit order to the main order or changing it.

The following article covers the first part, for more on the second one see Stop Loss and Take Profit articles. Also note that the first one exclusively refers to Conditional Orders, since Market Orders are bound to immediate execution.

Conditional Order Modification

The main order can be modified before it has been filled. To be precise, the order can be modified when it is in IOrder.State OPENED - after it has been CREATED and before it has been FILLED. Please refer to the following fragment of the Conditional order states diagram:

Order State Zoom

Example

Consider creating a conditional order and modifying its amount and open price:

ITick tick = history.getLastTick(Instrument.EURUSD);

double openPrice = round(tick.getBid() + Instrument.EURUSD.getPipValue() * 10, Instrument.EURUSD);
double openPrice2 = round(tick.getBid() + Instrument.EURUSD.getPipValue() * 15, Instrument.EURUSD);
double slippage = 1;

order = engine.submitOrder(
    "order1" , Instrument.EURUSD, IEngine.OrderCommand.BUYSTOP, 0.01, openPrice, slippage, 0, 0);        
console.getOut().println(
    String.format("%s, amount=%s, open price=%s",order.getLabel(), order.getAmount(), order.getOpenPrice()));

order.waitForUpdate(2000, IOrder.State.OPENED); //wait for IOrder.State.OPENED

//modify order amount
order.setOpenPrice(openPrice2);
order.waitForUpdate(2000); //wait for modification to take place
console.getOut().println(
    String.format("%s, amount=%s, open price=%s",order.getLabel(), order.getAmount(), order.getOpenPrice()));

Consider a full strategy which also includes logging the order values as soon as the order update arrives from the server.

ModifyLimitOrderWithMessages.java

The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.