Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Code to close all position in Jforex
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=21&t=50614
Page 1 of 1

Author:  nikunj0580 [ Mon 06 Jan, 2014, 03:26 ]
Post subject:  Code to close all position in Jforex

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

Author:  popopo [ Thu 09 Jan, 2014, 20:50 ]
Post subject:  Re: Code to close all position in Jforex

......
// 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
           }
           }
     }
.......

  Page 1 of 1