Consider the following little strategy, which prints out orders from the last week:
package jforex.orders;
import java.util.List;
import com.dukascopy.api.*;
public class OrderHistoryLastWeek implements IStrategy {
private IConsole console;
public void onStart(IContext context) throws JFException {
console = context.getConsole();
long time = System.currentTimeMillis();
List<IOrder> orders = context.getHistory().getOrdersHistory(Instrument.EURUSD, time - Period.WEEKLY.getInterval(), time);
if (orders != null) {
for (IOrder order : orders) {
console.getOut().println("history order: " + order + ", SL: " + order.getStopLossPrice() + ", TP: " + order.getTakeProfitPrice() );
}
}
context.stop();
}
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 {}
public void onStop() throws JFException {}
}
The output of this, is something like:
Quote:
22:44:25 history order: [jfw8oss18]-Instrument: EUR/USD, order command: BUY, amount: 0.031, fill time: 2013-03-20 14:27:32:052, fill price 1.29566, close time: 2013-03-20 18:02:06:238, close price 1.29776, SL: 0.0, TP: 1.29764
If the order was closed due to TP, the TP price is proper, but the SP value is 0.0.
If the order was closed due to SL, the TP price is 0.0, and the SP price is proper.
How can I get in both cases the correct TP/SL prices? Every order was filled with SP and TP.