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.