|
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.
breakeven stop with trigger price |
timokrates
|
Post subject: breakeven stop with trigger price |
Post rating: 0
|
Posted: Tue 16 Aug, 2011, 23:55
|
|
User rating: 0
Joined: Wed 25 May, 2011, 12:46 Posts: 10 Location: DE
|
Hi,
I'm new to the JForex platform and looking for a strategy that moves the stop to breakeven if a predefined trigger price is hit. I used this feature on Ibs TWS a lot and miss it here.
Thanks!
|
|
|
|
 |
API Support
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Thu 18 Aug, 2011, 08:37
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
timokrates
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Fri 19 Aug, 2011, 08:23
|
|
User rating: 0
Joined: Wed 25 May, 2011, 12:46 Posts: 10 Location: DE
|
Thanks for your help, I saw this thread, but as far as I can see, it updates the stop at a certain time. What I'm looking for is a stop which updates when a certain price is triggered. I would like to mention that I'm new to JForex and also have no idea in regards to coding. In my opinion this feature of a breakeven stop is really needed - at least it is essential for me 
|
|
|
|
 |
iulian
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Fri 19 Aug, 2011, 13:01
|
|
User rating: 1
Joined: Wed 06 Jul, 2011, 23:12 Posts: 42 Location: Romania, Bucharest
|
You could use a trainling stop, but this one will update only if the current price goes in your favour for at leas xx pips (where xx is minimum 10, maximum whatever you want).
For that, in a strategy you could use the methods in com.dukascopy.api IOrder interface, especially the setStopLossPrice() method.
void setStopLossPrice(double price, OfferSide side, double trailingStep) throws JFException Sets stop loss price. If price is 0, then stop loss condition will be removed. If trailingStep is bigger than 10, then trailing step logic will be applied for stop loss price. This method will send command to the server, getStopLossPrice() method will still return old value until server will accept this changes Parameters: price - price to set side - side that will be used to check stop loss condition trailingStep - if < 0 then adds stop loss order without trailing step. Should be 0 or >= 10
Throws: JFException - trailingStep is > 0 and < 10 or when method fails for some reason
|
|
|
|
 |
API Support
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Fri 19 Aug, 2011, 15:09
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
timokrates wrote: What I'm looking for is a stop which updates when a certain price is triggered. Consider checking the break-even condition on every every tick. This can be done by modifying the strategy in the linked topic in the following way: package jforex.strategies.oneorder;
import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.TimeZone;
import com.dukascopy.api.*; import com.dukascopy.api.IEngine.OrderCommand;
/** * The strategy on start creates one order and on price improvement * adjusts its stop loss by using break even approach * * To fire the price adjustment, try manually lowering the SL by a significant amount */ public class OneOrderBreakEvenSLonTick implements IStrategy {
@Configurable("Initial stop loss") public double initialStopLoss = 0.0002; @Configurable("Log values") public boolean logValues = true; private IConsole console; private IEngine engine; private IHistory history; private IOrder order; private Instrument instrument = Instrument.EURUSD;
private final String label = "OneOrder"; private double initStopLossPrice; private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private DecimalFormat df = new DecimalFormat("0.00000");
@Override public void onStart(IContext context) throws JFException { engine = context.getEngine(); console = context.getConsole(); history = context.getHistory(); sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
initStopLossPrice = history.getLastTick(instrument).getBid() - initialStopLoss; print("Start, initStopLossPrice: " + initStopLossPrice);
order = engine.submitOrder(label, instrument, OrderCommand.BUY, 0.01, 0, 20, initStopLossPrice, 0); }
@Override public void onTick(Instrument instrument, ITick tick) throws JFException {
if (!instrument.equals(this.instrument)) return;
double risk = order.getOpenPrice() - initStopLossPrice; double newStopLossPrice = tick.getBid() - risk;
if(logValues){ print(sdf.format(tick.getTime()) + " getStopLossPrice()=" + df.format(order.getStopLossPrice()) + " getOpenPrice()=" + df.format(order.getOpenPrice()) + " newStopLossPrice=" + df.format(newStopLossPrice) + " order.getStopLossPrice() < order.getOpenPrice()=" + (order.getStopLossPrice() < order.getOpenPrice()) + " newStopLossPrice > order.getOpenPrice()=" + (newStopLossPrice > order.getOpenPrice()) ); }
if (order.getStopLossPrice() < order.getOpenPrice() && newStopLossPrice > order.getOpenPrice()) { order.setStopLossPrice(newStopLossPrice); print("___________STOP LOSS UPDATED_____________"); }
}
@Override public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
@Override public void onMessage(IMessage message) throws JFException { }
@Override public void onAccount(IAccount account) throws JFException { }
@Override public void onStop() throws JFException { for (IOrder o : engine.getOrders()) o.close(); }
private void print(Object o) { console.getOut().println(o); }
}
|
|
|
|
 |
timokrates
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Fri 19 Aug, 2011, 22:03
|
|
User rating: 0
Joined: Wed 25 May, 2011, 12:46 Posts: 10 Location: DE
|
Thanks for your help guys, but I without any coding knowlegde I simply can't handle this - and trust it...
But, I tried the code and it opened a new position. This is not what I need, I need an implemented breakeven stop - and after a bit of research I think I'm not the only one.
Don't get me wrong, but this is an essential ingredient, the platform needs. A trailing stop is not the same and does not offer the same possibilities to let a position run.
So please make it possible that a "real" implemented breakeven stop will be part of the JForex platform soon, as it is in many others.
Thanks in advance!
|
|
|
|
 |
API Support
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Mon 22 Aug, 2011, 07:34
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
timokrates wrote: But, I tried the code and it opened a new position. The position gets opened in order to show how the algorithm works. timokrates wrote: I need an implemented breakeven stop The previous strategy follows the interpretation of the user. Trailing step is an option provided by the platform. Could you then describe more precisely yours?
|
|
|
|
 |
timokrates
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Tue 23 Aug, 2011, 21:02
|
|
User rating: 0
Joined: Wed 25 May, 2011, 12:46 Posts: 10 Location: DE
|
API Support wrote: The previous strategy follows the interpretation of the user. Trailing step is an option provided by the platform. Could you then describe more precisely yours? A perfect breakeven stop in my opinion would be if one would be able to define a trigger price that if hit would move the stop to the entry pice of the trade. So the difference to a trailing stop would be that you don't define steps the stop is trailing, instead define a trigger for only one movement to breakeven. One thing I would like to add. This all has a lot to do with trust. Even if it's great that there are smart guys which are coders and develop their own solutions, for me it would be far better if this would be implemented in the platform itself. Thanks!
|
|
|
|
 |
API Support
|
Post subject: Re: breakeven stop with trigger price |
Post rating: 0
|
Posted: Wed 24 Aug, 2011, 08:08
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Please post your request in the Feature Request section in the Desktop Platform forum.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|