Dukascopy
 
 
Wiki JStore Search Login

Order expiration after X minutes
 Post subject: Order expiration after X minutes Post rating: 0   New post Posted: Tue 04 Oct, 2011, 14:47 

User rating: -
Hello,

how to close a filled order after X minutes?

I'm using something like this, but is not working

for (IOrder order: engine.getOrders())
{
IOrder.State myStateOrder = order.getState();
if (myStateOrder == IOrder.State.FILLED)
{
if (order.getProfitLossInAccountCurrency() > -stopLossAmount) {
order.close();
}
long creationTime = order.getCreationTime();
long expiremilis = 60000l; // 1 minute
long expirationTime = creationTime + expiremilis * 30;
if (order.getCreationTime() <= expirationTime) {
order.close();
}
}
}

Thanks in advance
Gaetano


 
 Post subject: Re: Order expiration after X minutes Post rating: 0   New post Posted: Thu 06 Oct, 2011, 05:13 

User rating: -
Here you go.
        for (IOrder orderInMarket : engine.getOrders()) {

        if (order.getFillTime() + millisec < tick.getTime()) {
            order.close();
        }
    }


Think I found the mistake in yours though:
In the second-last line your code says
if (order.getCreationTime() <= expirationTime) {

Upon creation the creation time will be less than the expiration time. Had the exact same problem with mine, which i posted above... took me hours. :/


 

Jump to:  

  © 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