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.

why " setTakeProfitPrice" get error?
 Post subject: why " setTakeProfitPrice" get error? Post rating: 0   New post Posted: Mon 01 Jun, 2009, 06:46 

User rating: 0
Joined: Tue 09 Dec, 2008, 05:20
Posts: 4
the errer says: the order is immutable
code is following:

for(int i=0;i<allPositions.size();i++)
{
if(Math.abs(allPositions.get(i).getTakeProfitPrice()-allPositions.get(i).getOpenPrice())<0.0004 )
{
if(allPositions.get(i).isLong()==true)
{
allPositions.get(i).setTakeProfitPrice(allPositions.get(i).getOpenPrice()+0.0008);
}
else
{
allPositions.get(i).setTakeProfitPrice(allPositions.get(i).getOpenPrice()-0.0008) ;
}
}
}


 
 Post subject: Re: why " setTakeProfitPrice" get error? Post rating: 0   New post Posted: Fri 25 Sep, 2009, 10:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
before you use methods like IOrder.setStopLossPrice or IOrder.setTakeProfitPrice you should verify that server has been submitted this order. If submission was successful server gives you message IMessage.Type.ORDER_SUBMIT_OK, after which order comes available for previusly mentioned methods.
Here is sample:
package jforex;
import com.dukascopy.api.*;
/**
 * This sample strategy, which demostrates usage of IOrder.setTakeProfitPrice
 * */
public class TakeProfitSampleStrategy implements IStrategy {
    private IEngine engine;
    private IOrder myOrder;
    private IConsole console;
   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();       
        this.console = context.getConsole();
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
        //Check if this is our created order and that its successful submitted
        if(message.getOrder() == myOrder && message.getType()== IMessage.Type.ORDER_SUBMIT_OK){
            myOrder.setTakeProfitPrice(1.55455);                       
        }       
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {       
        if (myOrder == null) {
            myOrder = engine.submitOrder("myOrder", Instrument.EURUSD, IEngine.OrderCommand.BUY, 2);    //Placing our order
        }       
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


Attachments:
TakeProfitSampleStrategy.java [1.08 KiB]
Downloaded 542 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:  

  © 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