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.

setTakProfit - how to use
 Post subject: setTakProfit - how to use Post rating: 0   New post Posted: Fri 16 Nov, 2012, 15:23 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
I have X orders which are at FILL state.

I would like to set the take profit to all of them to a new level.

please advice how to do that (code example).

calling setTakeProfit on each order (iterating) causes a REJECT message on the orders which I'm trying to update.

Please advice.


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Fri 16 Nov, 2012, 22:50 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
cb888trader:

You need to set all of them individualy, but you need to leave some space time between each set take profit because the system only allow one change by each second or so i think...

One ideia that came to my mind is to use onBar() method with filter for ONE_SECOND or TWO_SECONDS... at each of this bars, set the TP for each of the open orders one by one.

Other way is with a timer...

I hope this helps...

Trade well and prosper in your way

JL


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Sat 17 Nov, 2012, 10:42 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
are u sure about the one second limitation?

As far as I recall this limitation only exist for a specific order.

It doesn't make sense that setting the take profit for a list of orders would be so cumbersome.

Can someone from dukas suggest a sample code on how to do that?


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Mon 19 Nov, 2012, 08:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
cb888trader wrote:
are u sure about the one second limitation?

As far as I recall this limitation only exist for a specific order.
Yes, the limitation is only per order basis.

cb888trader wrote:
calling setTakeProfit on each order (iterating) causes a REJECT message on the orders which I'm trying to update.
The approach that you mentioned, is the right way to do it, please provide the example strategy which replicates the issue and also the messages that you receive. Please also provide details on the launch scenario.


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Mon 19 Nov, 2012, 08:57 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
I will send an example.

I'm running in stand alone mode (latest API)

Just a quick guess:

Is it required to first cancel the previous takeprofit using setTakeProfit(0) and only after waitForUpdate I should set the new take profit?

If so - can you please advice a code example how to do that because it is not documented in the javadocs NOR in the Wiki.


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Mon 19 Nov, 2012, 10:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
cb888trader wrote:
Just a quick guess:

Is it required to first cancel the previous takeprofit using setTakeProfit(0) and only after waitForUpdate I should set the new take profit?

If so - can you please advice a code example how to do that because it is not documented in the javadocs NOR in the Wiki.
It's rather straightforward to check that this is not the case:
package jforex.orders;

import com.dukascopy.api.*;

/**
 * The strategy creates a market order on its start with TP at 5 pips.
 * Every 10 seconds it increases the TP by 1 pip
 *
 */
public class TpModify implements IStrategy {

    private IOrder order;
    private Instrument instrument = Instrument.EURUSD;
    @Override
    public void onStart(IContext context) throws JFException {
        double lastBid = context.getHistory().getLastTick(instrument).getBid();
        order = context.getEngine().submitOrder(
                "order", instrument, IEngine.OrderCommand.BUY, 0.1, 0, 10, 0, lastBid + instrument.getPipValue() * 5);
    }
   
    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if(this.instrument == instrument && period == Period.TEN_SECS && order.getState() == IOrder.State.FILLED){
            order.setTakeProfitPrice(order.getTakeProfitPrice() + instrument.getPipValue());
        }
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}
    @Override
    public void onMessage(IMessage message) throws JFException {}
    @Override
    public void onAccount(IAccount account) throws JFException {}
    @Override
    public void onStop() throws JFException {}
}


Attachments:
TpModify.java [1.28 KiB]
Downloaded 293 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.
 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Tue 20 Nov, 2012, 08:44 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
Just to let you know - I am running in stand alone mode. using the singlejartest in eclipse. I'm using the latest: JForex Client Library 2.17.1

I have tried running you example. It is behaving exactly as I expected. The setTakeProfit is rejected.

As a workaround I modified you example to work like this:

        if(this.instrument == instrument && period == Period.TEN_SECS && order.getState() == IOrder.State.FILLED){
           double newTP = order.getTakeProfitPrice() + 10 * instrument.getPipValue();
           
           //first we need to cancel the existing TP
           order.setTakeProfitPrice(0);
           //wait for acknowledge message coming back from the server
           order.waitForUpdate(2000);
           //another wait is required in order to fill the restriction of 1 second minimum delay between consecutive order change requests
           order.waitForUpdate(1000); 
 
                order.setTakeProfitPrice(newTP);
        }


Why do I need this workaround? Please advice what to do instead and why a simple setTakeProfit is Rejected?? The Server returns a very ambiguous message - more details are required.

also - very strange, but the strategy will not go to each and every 10 sec bars at the begin of the run (I'm using JForex UI to observe the 10 sec bars). In the stand alone it takes a few minutes before the onbar starts getting called. From that moment it is in sync with the UI why is that and how to overcome the initial GAP?


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Tue 20 Nov, 2012, 09:12 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
cb888trader wrote:
Just to let you know - I am running in stand alone mode. using the singlejartest in eclipse. I'm using the latest: JForex Client Library 2.17.1
The latest JForex-SDK version is 2.21, see:
https://publicrepo.site.dukascopy.com/jf ... Forex-SDK/
Consider using the Maven configuration either in Eclipse:
https://www.dukascopy.com/wiki/#Use_with_Maven
or in NetBeans:
https://www.dukascopy.com/wiki/#Use_with ... n_NetBeans


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Tue 20 Nov, 2012, 09:48 

User rating: 0
Joined: Tue 22 Nov, 2011, 12:47
Posts: 130
Location: United States,
OK - I can confirm that updating to the latest jars indeed solved the issue. setTakeProfit now works as expected.

Please advice on the other issue - why is 10 sec bars do not get send to onBar in the first 5 minutes?? what should I do to overcome this issue?


 
 Post subject: Re: setTakProfit - how to use Post rating: 0   New post Posted: Tue 20 Nov, 2012, 09:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
cb888trader wrote:
Please advice on the other issue - why is 10 sec bars do not get send to onBar in the first 5 minutes??
Could you please provide an example program and strategy which replicate the issue?


 

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