Dukascopy
 
 
Wiki JStore Search Login

APICLIENT-266 order.close(<a number>) closes the postition completely instead of partially
 Post subject: APICLIENT-266 order.close(<a number>) closes the postition completely instead of partially Post rating: 0   New post Posted: Fri 17 Aug, 2012, 10:30 
User avatar

User rating: 0
Joined: Mon 09 Jul, 2012, 14:09
Posts: 17
Location: Ireland,
I have been programming a strategy using the Dukascopy API. The command

order.close(halfPosition);

where halfPosition has been calculated to be 50% of the original trade size, is supposed to take off half the position. This was working fine until I reloaded the system this AM. Now this command closes the position totally, which is a major problem.

I have only been able to test this in the Historical Tester so it looks like the same issue as reported by another poster related to partial closes. Is it known when this will be fixed?

Seamus McKenna


 
 Post subject: Re: APICLIENT-266 order.close(<a number>) closes the postition completely instead of partially Post rating: 0   New post Posted: Tue 21 Aug, 2012, 15:42 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 413
Location: Germany, Munich
I found the same problem. It occurs in Historical Tester of JForex DEMO v2.18 only.
No bug on Historical Tester of current JForex LIVE v2.17.25!

Dear support team,
here is a small program for you, where you can see this bug easily.

Forward output
Message Type: ORDER_CLOSE_OK; Text: ; Related Order: [order1]-FILLED / EUR/USD / 1.24656 / 0.4 / 0.4
Message Type: NOTIFICATION; Text: ORDER_FILLED-Order FILLED at 1.24648 USD (#158463944 SELL 0.1 mil. EUR/USD @ MKT MAX SLIPPAGE 0.0005) - Position #40898618; Related Order: [order1]-FILLED / EUR/USD / 1.24656 / 0.5 / 0.5
Message Type: ORDER_FILL_OK; Text: ; Related Order: [order1]-FILLED / EUR/USD / 1.24656 / 0.5 / 0.5
Message Type: NOTIFICATION; Text: ORDER_FILLED-Order FILLED at 1.24656 USD (#158463881 BUY 0.5 mil. EUR/USD @ MKT MAX SLIPPAGE 0.002) - Position #40898618; Related Order: [order1]-OPENED / EUR/USD / 0.0 / 0.5 / 0.5
Message Type: ORDER_SUBMIT_OK; Text: ; Related Order: [order1]-OPENED / EUR/USD / 0.0 / 0.5 / 0.5

Here everything works nicely.

Historical Tester output
ORDER_CLOSE_OK - Order closed order: CLOSED BUY 0.5 @ 1.22755
ORDER_FILL_OK - Order filled order: FILLED BUY 0.5 @ 1.22755
ORDER_SUBMIT_OK - Order submitted order: OPENED BUY 0.5 @ 0.0
Start

As you can see, 0.5 mio are closed at last message, it should be 0.1 mio



/*     
 * Bug in IOrder class:  close(double amount) does not work properly in historical tester
 *     
 * This is a test programm only, do not use for trading!
 * It openes a trade at default 0.5 million, waits one bar at 10 secs and
 * tries a partial close for 0.1 million.
 * In forward test this works nicely.
 * On historical tester the filled order is completely closed.
 *
 * Bug seen on JForex version 2.18
 *
 * (c) Stash GmbH Muenchen / Germany, August 21st 2012
 *     www.stash.de
 *     Author: Bernhard Schicht
 *     Email: [email protected]
 */

package jforex.orders.merge;

import com.dukascopy.api.*;
import static com.dukascopy.api.IEngine.OrderCommand.*;
import java.util.Vector;

@RequiresFullAccess
public class PartialCloseBug implements IStrategy {

    @Configurable("")
    public Instrument instr = Instrument.EURUSD;
    @Configurable("")
    public Period per = Period.TEN_SECS;
   
    @Configurable("open size")
    public double openSize = 0.5;

    @Configurable("partial close size")
    public double partialCloseSize = 0.1;
   
    private IConsole console;
    private IEngine engine;
    private IHistory history;   
    private Vector<IOrder> mergeOrders = new Vector<IOrder>();
       
    @Override
    public void onStart(IContext context) throws JFException {
        engine = context.getEngine();
        console = context.getConsole();
        history = context.getHistory();
        console.getOut().println("Start");
    }

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

   
    private int counter = 0;
    private double orderAmount = 0.1;
    private IOrder order = null; 
    boolean orderIsLong = false;
    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (instrument != instr) return;
        if (period != per) return;
        counter++;           
        if (counter == 1){                     
            order = engine.submitOrder("order"+counter, instrument, BUY, openSize, 0, 20, 0, 0);
            return;
        }
        if (counter == 2){
            order.close(partialCloseSize);
        }
       
    }

    @Override
    public void onMessage(IMessage message) throws JFException {
        // print all order related messsages
        if (message.getOrder() != null)
            print("<html><font color=\"gray\">"+ message+"</font>");
    }
   
    private void printErr(Object o){
        console.getErr().println(o);
    }

    private void print(Object o) {
        console.getOut().println(o);
    }

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

    @Override
    public void onStop() throws JFException {
        for (IOrder o : engine.getOrders())
            o.close();
    }

}


We need a bug fix asap.


Attachments:
PartialCloseBug.jfx [3.95 KiB]
Downloaded 322 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.
 

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