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.

How to delete pendings orders (STOP and LIMIT)
 Post subject: How to delete pendings orders (STOP and LIMIT) Post rating: 0   Post Posted: Wed 10 Aug, 2011, 17:06 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
Hellow eweryone!

How to delete pendings orders (STOP and LIMIT) in JForex.

This code dont work:

for (IOrder order : engine.getOrders()) {

if (order.getLabel().equals(label)) {

if (order.getOrderCommand() == OrderCommand.BUYLIMIT) {

order.close();

}
}
}

Thanks for help!


 
 Post subject: Re: How to delete pendings orders (STOP and LIMIT) Post rating: 0   Post Posted: Thu 11 Aug, 2011, 09:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
IOrder.close() does close pending LIMIT and STOP orders. Consider the following strategy which makes a BUYSTOP order and closes it on the next 10 SEC bar:
package jforex.strategies.oneorder;

import com.dukascopy.api.*;

/**
 * The strategy tries to make a BUYSTOP order in every 10 seconds - it does so
 * if all previous orders have been closed or canceled
 *
 */
public class OneOrderStopOrder implements IStrategy {

   private IConsole console;
   private IEngine engine;
   
   private Instrument instrument = Instrument.EURUSD;
   private Period period = Period.TEN_SECS;
   
   private int counter;
   
   //user defined
   private final double buyStopPriceStep = 0.0005;
   private double slippage = 1;
   private IOrder order;
   
   @Override
   public void onStart(IContext context) throws JFException {
      engine = context.getEngine();
      console = context.getConsole();
      print("Start");
   }

   @Override
   public void onTick(Instrument instrument, ITick tick) throws JFException {}

   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
      if(!instrument.equals(this.instrument) || ! period.equals(this.period))
         return;
      double stopLossPrice = askBar.getClose() - 0.0010;
      double takeProfitPrice = askBar.getClose()  + 0.0010;
      //make a new order if there are no orders or the previous orders have been either closed or cancelled
      if(engine.getOrders().size() == 0){
         order = engine.submitOrder("order" + counter++, this.instrument, IEngine.OrderCommand.BUYSTOP, 0.01,
            askBar.getClose() + buyStopPriceStep, slippage, stopLossPrice, takeProfitPrice);
      } else {
      //close the order otherwise
         order.close();
      }

   }

   @Override
   public void onMessage(IMessage message) throws JFException {}

   @Override
   public void onAccount(IAccount account) throws JFException {}

   @Override
   public void onStop() throws JFException {
      for(IOrder o : engine.getOrders())
         o.close();
   }
   
   private void print(Object o){
      console.getOut().println(o);
   }

}


 
 Post subject: Re: How to delete pendings orders (STOP and LIMIT) Post rating: 0   Post Posted: Thu 11 Aug, 2011, 18:19 

User rating: 0
Joined: Sat 06 Aug, 2011, 23:17
Posts: 27
Location: Russian Federation,
Thanks for help


 

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