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
[quantisan]
Post subject: Re: Partial takeprofit
Post rating: 0
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)); } }