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.

Close all positions
 Post subject: Close all positions Post rating: 0   New post Posted: Sat 18 Sep, 2010, 14:07 

User rating: 0
Joined: Wed 08 Sep, 2010, 13:36
Posts: 5
Hi, support
I write a simple strategy. But it doesn't work.
Would you please tell me where is the problem?
package jforex;

import java.util.*;

import com.dukascopy.api.*;

public class MyCloseAll implements IStrategy
{
    private IContext context = null;
    private IEngine engine = null;

    public void onStart(IContext context) throws JFException
    {
        this.context = context;
        engine = context.getEngine();
    }

    public void onStop() throws JFException
    {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException
    {
        if (positionsTotal(instrument) > 0)
        {
            engine.closeOrders();
        }
    }
     
    protected int positionsTotal(Instrument instrument) throws JFException
    {
        int counter = 0;
        for (IOrder order : engine.getOrders(instrument))
        {
            if (order.getState() == IOrder.State.FILLED)
            {
                counter++;
            }
        }
        return counter;
    }

    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
    {
    }
}

//+////////////////////////////////////////////////////////////////////+


 
 Post subject: Re: Close all positions Post rating: 0   New post Posted: Sun 19 Sep, 2010, 13:29 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
Hi dmgysy,

you are missing to pass the orders-argument: void closeOrders(IOrder... orders)

      List<IOrder> orders = engine.getOrders();
      engine.closeOrders(orders.toArray(new IOrder[orders.size()]));


see this post:
viewtopic.php?f=5&t=474&p=1416&hilit=.closeOrders#p1416

Best, RR.


 

Jump to:  

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