Hello everyone,
I'n trying to send pending orders, a long order and a short order at the same time. Sometimes both orders go through, other times only one of the two orders go through. I need to find a fix for this not sure what is wrong. See for some example code below.
I'm sending both stop and limit orders, for if the one fails the other one will fill. It also doesn't solve my problem. Any help will be appreciated!
double PipVal = instrument.getPipValue();
double LongPrice = askPrice + 30*PipVal;
double LongSL = LongPrice - 20*PipVal;
double LongTP = LongPrice + 20*PipVal;
double ShortPrice = bidPrice - 30*PipVal;
double ShortSL = ShortPrice + 20*PipVal;
double ShortTP = ShortPrice - 20*PipVal;
sendorder(instrument, engine, ShortTP , ShortSL, volume,ShortPrice,IEngine.OrderCommand.SELLSTOP);
sendorder(instrument, engine, LongTP , LongSL, volume,LongPrice,IEngine.OrderCommand.BUYSTOP);
sendorder(instrument, engine, ShortTP , ShortSL, volume,ShortPrice,IEngine.OrderCommand.SELLLIMIT);
sendorder(instrument, engine, LongTP , LongSL, volume,LongPrice,IEngine.OrderCommand.BUYLIMIT);
//+------------------------------------------------------------------+
//| Send Orders Function |
//+------------------------------------------------------------------+
public void sendorder(Instrument instrument, IEngine engine, double TakeProfit, double StopLoss, double volumeParam,double price,IEngine.OrderCommand OrderType) throws JFException
{
IOrder pendingOrder = engine.submitOrder(getLabel(instrument),instrument,OrderType,volumeParam,price,10,StopLoss,TakeProfit);
pendingOrder.waitForUpdate(30000);
}