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.

Number of buy orders
 Post subject: Number of buy orders Post rating: 0   New post Posted: Thu 29 Dec, 2011, 07:15 

User rating: 0
Joined: Sun 22 May, 2011, 23:05
Posts: 12
Location: BR
Hi,
I have some questions:
How can i get the total of orders still opened on buy side only and on sell side only?
How do I set a stoploss with trail to a specific order since I have many opened?
Thanks! And happy new year!


 
 Post subject: Re: Number of buy orders Post rating: 0   New post Posted: Thu 29 Dec, 2011, 12:25 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
marceizi wrote:
How can i get the total of orders still opened on buy side only and on sell side only?

Consider the following example strategy:
package jforex.orders;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;

@RequiresFullAccess
public class OrderManagement implements IStrategy {
   
   private IConsole console;
   private IEngine engine;

   @Override
   public void onStart(IContext context) throws JFException {
      
      console = context.getConsole();
      engine = context.getEngine();
      
      engine.submitOrder("Order1", Instrument.EURUSD, OrderCommand.BUY, 0.1);
      engine.submitOrder("Order2", Instrument.EURUSD, OrderCommand.BUYLIMIT, 0.12, 1.5);
      engine.submitOrder("Order3", Instrument.EURUSD, OrderCommand.SELL, 0.123);
      
      print("long orders");
      for(IOrder order : engine.getOrders()){
         if(order.isLong()){
            print(order);
         }
      }
      
      print("BUY orders");
      for(IOrder order : engine.getOrders()){
         if(order.getOrderCommand() == OrderCommand.BUY){
            print(order);
         }
      }
   }
   
   private void print(Object o){
      console.getOut().println(o);
   }
   
   public void onTick(Instrument instrument, ITick tick) throws JFException {}
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onAccount(IAccount account) throws JFException {}

   @Override
   public void onStop() throws JFException {
      //close all orders on strategy stop
      for(IOrder o : engine.getOrders()){
         o.close();
      }
   }

}

marceizi wrote:
How do I set a stoploss with trail to a specific order since I have many opened?
See JForex wiki https://www.dukascopy.com/wiki/ section Strategy API/Orders/Set Stop Loss price


 

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