Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Additional messages for ORDER_CHANGED_OK
 Post subject: Additional messages for ORDER_CHANGED_OK Post rating: 0   Post Posted: Fri 01 Jun, 2012, 06:23 

User rating: 0
Joined: Sun 27 May, 2012, 11:48
Posts: 13
Hello APISupport,

is it possible to add an extra messages for order closed by strategy in addition to TP and SL?

e.g ORDER_CLOSED_BY_Strategy


 
 Post subject: Re: Additional messages for ORDER_CHANGED_OK Post rating: 0   Post Posted: Fri 01 Jun, 2012, 08:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
zhao wrote:
is it possible to add an extra messages for order closed by strategy in addition to TP and SL?

e.g ORDER_CLOSED_BY_Strategy
There is no necessity to do that, as the strategy itself can keep track on its actions, i.e., when it closes orders.


 
 Post subject: Re: Additional messages for ORDER_CHANGED_OK Post rating: 0   Post Posted: Fri 01 Jun, 2012, 08:49 

User rating: 0
Joined: Sun 27 May, 2012, 11:48
Posts: 13
Hello APISupport,

can you show me how do i know if an order is closed by strategy? I want to know when an order is being closed so that my strategy can check the order's comment field and based on the comment field, do something.


 
 Post subject: Re: Additional messages for ORDER_CHANGED_OK Post rating: 0   Post Posted: Fri 01 Jun, 2012, 09:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Also do some manual trading while running the strategy:
package jforex.orders;

import java.util.ArrayList;
import java.util.List;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.*;

/**
 * The strategy demonstrates how to detect if an order got
 * closed by the strategy itself or the close was done manually
 * or from another strategy.
 *
 * Test its work by doing some manual trading in parallel.
 *
 */
public class OrderClosedByStrategy implements IStrategy {
   
    private IConsole console;
    private IEngine engine;
    private int counter;
   
    List<IOrder> ordersClosedByStrategy = new ArrayList<IOrder>();
       
    @Override
    public void onStart(IContext context) throws JFException {
        console = context.getConsole();
        engine = context.getEngine();
     
    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if(instrument != Instrument.EURUSD || period != Period.TEN_SECS){
            return;
        }
       
        IOrder order = engine.submitOrder("myOrder"+counter++, Instrument.EURUSD, OrderCommand.BUY, 0.1, 0, 20, 0, 0, 0, this.getClass().getSimpleName() + " order");
        order.waitForUpdate(2000, IOrder.State.FILLED); //wait for fill to close it
        close(order);
       
    }
   
    private void close(IOrder order) throws JFException{
        order.close();
        ordersClosedByStrategy.add(order);
    }
   
    private void print(Object o){
        console.getOut().println(o);
    }

    @Override
    public void onMessage(IMessage message) throws JFException {
        IOrder order = message.getOrder();
        if(order == null || message.getType() != IMessage.Type.ORDER_CLOSE_OK){
            return;
        }
        if(ordersClosedByStrategy.contains(order)){
            print(String.format("order %s with comment \"%s\" was closed by strategy!", order, order.getComment()));   
            ordersClosedByStrategy.remove(order);
        } else {
            print(String.format("order %s was either closed manually or by another strategy!", order)); 
        }
    }   


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

    @Override
    public void onAccount(IAccount account) throws JFException {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void onStop() throws JFException {
        // TODO Auto-generated method stub
       
    }

}
See more on closing orders:
https://www.dukascopy.com/wiki/#Close_Orders
Managing orders:
https://www.dukascopy.com/wiki/#Order_Management
And managing order state:
https://www.dukascopy.com/wiki/#Manage_Order_State


 

Jump to:  

  © 1998-2025 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