Conditional Order

There are 3 types of conditional orders one can use in his strategy:

  • Stop Order,
  • Limit Order,
  • Market if Touch Order (MIT).

All of them get submitted by using the same set of IEngine.submitOrder methods, but by passing different IEngine.OrderCommand order commands.

Stop Order

You can submit a Buy Stop Order using the submitOrder method and specifying a command BUYSTOP_BYBID as a parameter. If the current bid price is greater than or equal to a Stop price, the order will be filled:

engine.submitOrder("OrderLabel", Instrument.EURUSD, OrderCommand.BUYSTOP_BYBID, 0.01, price));

Note: If price at the moment of submission is set below the bid price of the last tick, then the command is changed to BUYLIMIT and the price is changed to the last tick's bid price.

For Sell Stop Order by bid price, change the order command to SELLSTOP. To submit Buy Stop Order by ask price, specify a command BUYSTOP:

engine.submitOrder("OrderLabel", Instrument.EURUSD, OrderCommand.BUYSTOP, 0.01, price));

For Sell Stop Order by ask price, change the order command to a SELLSTOP_BYASK

Note: If price at the moment of submission for SELLSTOP_BYASK order is set above the ask price of the last tick, then the command is changed to SELLLIMIT and the price is changed to the last tick's ask price.

Consider creating a buy stop order 2 pips above the current ask price:

double lastAsk = history.getLastTick(Instrument.EURUSD).getAsk();
double price = lastAsk + Instrument.EURUSD.getPipValue() * 2;
order = engine.submitOrder("BuyStopOrder", Instrument.EURUSD, OrderCommand.BUYSTOP, 0.1, price);     

ConditionaOrder.java

Limit Order

You can set a Buy Limit Order by ask price using BUYLIMIT command as a parameter in a submitOrder method. Order will be filled when the current ask price is less or equal than a limit price:

engine.submitOrder("OrderLabel", Instrument.EURUSD, OrderCommand.BUYLIMIT, 0.01, price);

For setting a Sell Limit Order by ask price, specify a command SELLLIMIT_BYASK.

Note: It is not possible to submit a Sell Limit Order by ask price manually in a JForex platform. It is not possible to submit a Buy Limit Order by bid price manually in the JForex platform. It can be done in a strategy only by using a command BUYLIMIT_BYBID:

engine.submitOrder("OrderLabel", Instrument.EURUSD, OrderCommand.BUYLIMIT_BYBID, 0.01, price);

SELLLIMIT command is reserved for submitting a Sell Limit Order by bid price.

Market if Touch Order (MIT)

If you specify a Limit Order with slippage, then the order becomes a MIT order. To set a BUY MIT order:

int slippage = 5;
engine.submitOrder("OrderLabel", Instrument.EURUSD, OrderCommand.BUYLIMIT, 0.01, price, slippage);

For a Sell MIT order, please use a SELLLIMIT order command with slippage.

Note: You can set a MIT Order by ask and by bid price exactly as Limit Orders.

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