Dukascopy
 
 
Wiki JStore Search Login

Bug? about IMessage.Reason
 Post subject: Bug? about IMessage.Reason Post rating: 0   New post Posted: Fri 24 Apr, 2015, 13:56 
User avatar

User rating: 7
Joined: Tue 28 Feb, 2012, 09:45
Posts: 45
Location: JapanJapan
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:
Image

Then receive messages as below.
Image

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: Reason = ORDER_CHANGED_SL, SL = 1.08144, TP = 0.0".

FYI, "Add Take Profit" menu was good.
Image
Image

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();
    }

}


Attachments:
tpResult.png [6.58 KiB]
Downloaded 267 times
tp.png [25.25 KiB]
Downloaded 234 times
slResult.png [6.87 KiB]
Downloaded 339 times
sl.png [25.26 KiB]
Downloaded 296 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:  

cron
  © 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