Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Stop order never becomes "OPENED"
 Post subject: Stop order never becomes "OPENED" Post rating: 0   New post Posted: Mon 19 Oct, 2015, 18:23 

User rating: 1
Joined: Tue 14 Jan, 2014, 16:13
Posts: 21
Location: United KingdomUnited Kingdom
I want to set a sell stop entry order, then add a stop based on the bid. I understand that I cannot do this until the order is opened, so I attempt to wait using a loop:

order = engine.submitOrder(theLabel, theInstrument, OrderCommand.SELLSTOP, tradeSize, entryPrice);
while(order.getState() == State.CREATED) {
                   Thread.sleep(1000);
                    System.out.print(".");
               }
order.setStopLossPrice(entryPrice + offset, OfferSide.BID);


The problem is that the loop never ends (for several minutes at least). I thought the change of state from CREATED to OPENED should be quick? The trade size is small, no problems with the parameters that I can see. Values are rounded to nearest 0.00001 pips using Math.round.

What is wrong?


 
 Post subject: Re: Stop order never becomes "OPENED" Post rating: 0   New post Posted: Wed 21 Oct, 2015, 13:51 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Here is an example that sets stop loss price after the order has been filled.
Order is checked on each tick.

public void onTick(Instrument instrument, ITick tick) throws JFException {
        if(!instrument.equals(Instrument.EURUSD)){
            return;
        }
        double delta = Instrument.EURUSD.getPipValue();
        if(order != null && order.getState() == IOrder.State.FILLED && order.getStopLossPrice() < delta) {
            order.setStopLossPrice(stopLossPrice);
            console.getOut().println("test");
        }
    }


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com