Dukascopy
 
 
Wiki JStore Search Login

Code to close all position in Jforex
 Post subject: Code to close all position in Jforex Post rating: 0   New post Posted: Mon 06 Jan, 2014, 03:26 
User avatar

User rating: 0
Joined: Sat 18 Feb, 2012, 04:48
Posts: 5
Location: IndiaIndia
Hello Support,

I wanted to know how can I get total number of orders opened . DO we have anything similar to OrdersTotal() in MT4 code?
Any certain script or something to get that value?
For instance if I want to close all position in my account if number of position reached is 10 then how to do that?


Regards


 
 Post subject: Re: Code to close all position in Jforex Post rating: 0   New post Posted: Thu 09 Jan, 2014, 20:50 
User avatar

User rating: 3
Joined: Mon 05 Mar, 2012, 11:15
Posts: 24
Location: Indonesia, Jakarta
......
// first, count filled position   
     int count = 0;

     List<IOrder> AllPositions  = engine.getOrders(instrument);
     for (IOrder order: AllPositions) {
            if (order.getState().equals(IOrder.State.FILLED)){
                   count = count  + 1;
       }
     }

// then if open positions > 10, close all position
     if ( count >= 10 ){
           // in real life after executing order.close(), AllPositions might point to invalid data
           // so this code below is not recomended, but hope you got the idea
           for (IOrder order: AllPositions) {
                 if (order.getState().equals(IOrder.State.FILLED)){
                   order.close();
                         // should wait some time here
           }
           }
     }
.......


 

Jump to:  

  © 1998-2024 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