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.

Partial takeprofit
 Post subject: Partial takeprofit Post rating: 0   New post Posted: Thu 08 Jul, 2010, 16:09 

User rating: 0
Joined: Thu 08 Jul, 2010, 15:55
Posts: 3
Hello
I am wondering if anyone knows how to build a strategy that will allow me to take partial takeprofits. So for example close 50% at +50 pips, 30% at +80pips and 20% at +100 pips. Also would be nice to have another feature like moving the stoploss to breakeven after the position is in your favour by certain amount of pips.
Any input is appreciated.

thanks


 
 Post subject: Re: Partial takeprofit Post rating: 0   New post Posted: Fri 09 Jul, 2010, 02:49 

User rating: 1
Joined: Fri 26 Mar, 2010, 19:19
Posts: 116
Location: Canada
Here's the gist of the code. I assume you know how to finish it. Note that roundLot() is not in the API.

Put this in your onTick to monitor the position.

for (IOrder order : engine.getOrders(instrument)) {
   if (order.getState() == IOrder.State.FILLED) {
      if (order.getProfitLossInPips() > threshold)
         order.close(roundLot(order.getAmount() * portion));
   }
}


 

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