Dukascopy
 
 
Wiki JStore Search Login

Stop and limit orders
 Post subject: Stop and limit orders Post rating: 0   New post Posted: Mon 23 Apr, 2012, 09:10 
User avatar

User rating: 0
Joined: Mon 23 Apr, 2012, 08:48
Posts: 3
Location: Czech RepublicCzech Republic
Hi everyone, I'd like to know if there's any way to automatically delete one pending order after filling another pending order. I give example I have sell limit order at 1,3150 and second order at 1,3130 and I want cancel first order if the second order will be filled and I'd like to cancel second if the first will be filled. I mean something like OCO but the orders are in the same direction for example two shorts on E/U. Thanks


 
 Post subject: Re: Stop and limit orders Post rating: 0   New post Posted: Tue 01 May, 2012, 21:39 
User avatar

User rating: 0
Joined: Mon 23 Apr, 2012, 08:48
Posts: 3
Location: Czech RepublicCzech Republic
So, is here somebody who can program this? If it's possbile. I just need modified OCO order to be able apply it on 2 orders in the same direction.


 
 Post subject: Re: Stop and limit orders Post rating: 0   New post Posted: Fri 11 May, 2012, 08:09 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
This a code sample that opens two orders, BUYLIMIT and BUYSTOP and closes an order if the other one is filled.
package jforex.strategies;


import com.dukascopy.api.*;

public class Strategy4 implements IStrategy {
    private IEngine engine;
    private IConsole console;
   
    IOrder order1;
    IOrder order2;
   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        ITick tick = context.getHistory().getLastTick(Instrument.EURUSD);
       
        order1 = engine.submitOrder("oneBuy", Instrument.EURUSD, IEngine.OrderCommand.BUYLIMIT, 0.2, tick.getBid() - Instrument.EURUSD.getPipValue());
        order2 = engine.submitOrder("twoBuy", Instrument.EURUSD, IEngine.OrderCommand.BUYSTOP, 0.2, tick.getBid() + Instrument.EURUSD.getPipValue());
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
        console.getOut().println(message);
       
        if( message.getType().equals(IMessage.Type.ORDER_FILL_OK) ) {
            if( message.getOrder().equals(order1) ) {
                concelOrder(order2);
               
            } else if( message.getOrder().equals(order2) ) {
                concelOrder(order1);
            }
        }
    }
   
    private void concelOrder(IOrder order) throws JFException {
        if(order == null) {
            return;
        }
        if(order.getState() == IOrder.State.CREATED) {
            order.waitForUpdate();
        }
        if (order.getState() == IOrder.State.OPENED) {
            order.close();
        }
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


Attachments:
Strategy4.java [1.79 KiB]
Downloaded 399 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Stop and limit orders Post rating: 0   New post Posted: Fri 11 May, 2012, 10:19 
User avatar

User rating: 0
Joined: Mon 23 Apr, 2012, 08:48
Posts: 3
Location: Czech RepublicCzech Republic
Thank you, I understand that code but it probably won't solve my problem. The best would be if the OCO order was allowed to group two pending entries in one direction. It can be grouped only one short and one long and this is that problem. The easiest way would be edit this requirement in next patch if it's possible.


 

Jump to:  

  © 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