When I set a new stoploss price to order by the "Add Stop Loss" menu of JForex Platform, comes the something wrong message.
When I did Add Stop Loss:
Then receive messages as below.
I think, "ORDER_CHANGED_OK: Reason =
ORDER_CHANGED_TP, SL = 1.08144, TP = 0.0" is wrong.
It should be like this, "ORDER_CHANGED_OK: R
eason = ORDER_CHANGED_SL, SL = 1.08144, TP = 0.0".
FYI, "Add Take Profit" menu was good.
Sample Strategy for test
package jforex;
import com.dukascopy.api.Configurable;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IOrder;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
public class MessageGetTest implements IStrategy {
@Configurable(value="Check Side:", options = {"StopLoss", "TakeProfit"})
public String checkSide = "StopLoss";
private IContext context;
private final Instrument INSTRUMENT = Instrument.EURUSD;
private final double SLTP = 100 * INSTRUMENT.getPipValue();
private IOrder testOrder;
@Override
public void onStart(IContext context) throws JFException {
IEngine engine = context.getEngine();
if(engine.getType() == IEngine.Type.LIVE){
context.getConsole().getErr().println("Don't try to this strategy on IEngine.Type.LIVE");
context.stop();
return;
}
ITick t = context.getHistory().getLastTick(Instrument.EURUSD);
double ask = t.getAsk();
double sl = 0;
double tp = 0;
if(checkSide.equals("StopLoss")) tp = ask + SLTP;
else sl = ask - SLTP;
testOrder = engine.submitOrder("test", INSTRUMENT, IEngine.OrderCommand.BUY, 0.001, 0, 5, sl, tp);
this.context = context;
}
@Override
public void onMessage(IMessage message) throws JFException {
IMessage.Type type = message.getType();
if(type == IMessage.Type.ORDER_CHANGED_OK){
StringBuilder buf = new StringBuilder(type.toString());
buf.append(": Reason = ");
for(IMessage.Reason reason: message.getReasons()){
buf.append(reason.toString());
buf.append(", ");
}
IOrder order = message.getOrder();
buf.append("SL = ");
buf.append(order.getStopLossPrice());
buf.append(", TP = ");
buf.append(order.getTakeProfitPrice());
context.getConsole().getInfo().println(buf.toString());
}
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar,
IBar bidBar) throws JFException {
}
@Override
public void onAccount(IAccount account) throws JFException {
}
@Override
public void onStop() throws JFException {
if(testOrder.getCloseTime() == 0) testOrder.close();
}
}