Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Stoploss Break Even
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=44322
Page 1 of 2

Author:  uncharted29 [ Tue 06 Dec, 2011, 19:17 ]
Post subject:  Stoploss Break Even

Hey does anyone have a stoploss break even strategy i can use. One that I can set the value for how many pips price mush move forward in order to trigger the SLBE, and a value to adjust the SLBE by a few pips from entry. thanks.

Author:  API Support [ Wed 07 Dec, 2011, 09:20 ]
Post subject:  Re: Stoploss Break Even

See if you can make use of:
viewtopic.php?f=65&t=35365&p=45599
or
viewtopic.php?f=65&t=42122&p=53818

Author:  uncharted29 [ Wed 07 Dec, 2011, 22:54 ]
Post subject:  Re: Stoploss Break Even

I tried taking the code from the links u provided and pasting it into a text and saving it as a jfx file, it doesnt seem to work. Before i setup my pamm account, my IB ( molecule6) had a stragety software that had this feature) but it doesnt work since then. IS there someone who can rip out the SLBE code for me.

Attachments:
Managing_Orders_Basic_Live_1_21_Haym438 - AC.jfx [224.4 KiB]
Downloaded 365 times

Author:  uncharted29 [ Wed 07 Dec, 2011, 22:56 ]
Post subject:  Re: Stoploss Break Even

Image

Author:  API Support [ Thu 08 Dec, 2011, 09:30 ]
Post subject:  Re: Stoploss Break Even

See:
http://www.dukascopy.com/wiki/index.php ... _in_JForex

Author:  uncharted29 [ Thu 08 Dec, 2011, 15:25 ]
Post subject:  Re: Stoploss Break Even

Ok when i saved it, it has to be the specific name provided. So i compiled it , and when i hit run, it looks like its executing it, but then just locks jforex,

Author:  uncharted29 [ Thu 08 Dec, 2011, 15:26 ]
Post subject:  Re: Stoploss Break Even

Thanks for the help.

Author:  API Support [ Thu 08 Dec, 2011, 15:33 ]
Post subject:  Re: Stoploss Break Even

The exception tells what needs to be changed:
OneOrderBreakEvenSLThreads class should be saved in a file called OneOrderBreakEvenSLThreads.java.
Or alternatively rename the class to SLBE.

Author:  uncharted29 [ Thu 08 Dec, 2011, 15:49 ]
Post subject:  Re: Stoploss Break Even

ok there's no parameter option, Every time i hit run, it just opens a long position on eurusd and a stoploss order?!!??

Author:  API Support [ Thu 08 Dec, 2011, 15:55 ]
Post subject:  Re: Stoploss Break Even

This is as designed. Consider using the strategy in Historical Tester to see the stop loss updates. For the historical period, please refer to the post where the strategy was originally posted.
If you have any other particular Break Even algorithm in mind, consider making a strategy request in the following forum section:
viewforum.php?f=112

Author:  uncharted29 [ Thu 08 Dec, 2011, 16:55 ]
Post subject:  Re: Stoploss Break Even

I came across this piece of coding, close to what i want. Only problem is moves the stoploss to break even after 25 pips, I tried looking at the code to see if i can change that value, but cant seem to see where it is. would u know?

thanks.


Quote:
/*

StopManager.java
version 1.0
Copyright 2010 Quantisan.com

Move stops to breakeven when equidistance to original stop loss

*/

package jforex;

import com.dukascopy.api.*;

public class StopManager implements IStrategy {
private IEngine engine;
private IConsole console;
private IContext context;

@Configurable("Lock-in Pips for Breakeven")
public int lockPip = 3;

@Configurable("Move stop to breakeven?")
public boolean moveBE = true;

public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.context = context;
}

public void onAccount(IAccount account) throws JFException {
}

public void onMessage(IMessage message) throws JFException {
}

public void onStop() throws JFException {
}

public void onTick(Instrument instrument, ITick tick) throws JFException {
for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() == IOrder.State.FILLED) {
boolean isLong;
double open, stop, diff, newStop;
String label = order.getLabel();
IChart chart;

isLong = order.isLong();
open = order.getOpenPrice();
stop = order.getStopLossPrice();
diff = open - stop; // stop loss distance

if (isLong) { // long side order
if (moveBE && diff > 0 && tick.getBid() > (open + diff)) {
// make it breakeven trade + lock in a few pips
newStop = open + instrument.getPipValue() * lockPip;
order.setStopLossPrice(newStop);
console.getOut().println(label + ": Moved stop to breakeven");

chart = this.context.getChart(instrument);
chart.draw(label + "_BE", IChart.Type.SIGNAL_UP, tick.getTime(), newStop);
}
}
else { // short side order
// Move to breakeven
if (moveBE && diff < 0 && tick.getAsk() < (open + diff)) { // diff is negative
// make it breakeven trade + lock in a few pips
newStop = open - (instrument.getPipValue() * lockPip);
order.setStopLossPrice(newStop);
console.getOut().println(label + ": Moved stop to breakeven");

chart = this.context.getChart(instrument);
chart.draw(label + "_BE", IChart.Type.SIGNAL_DOWN, tick.getTime(), newStop);
}
}
}
}
}

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}


Attachments:
StopManager.java [2.43 KiB]
Downloaded 365 times

Author:  API Support [ Fri 09 Dec, 2011, 15:32 ]
Post subject:  Re: Stoploss Break Even

There is nothing in the source code suggesting such behavior. Could you please provide in detail how the Break even should be implemented in a strategy?

Author:  uncharted29 [ Sat 10 Dec, 2011, 21:09 ]
Post subject:  Re: Stoploss Break Even

thats what i dont get, ive tried it in the demo and it works.

Well like in my old strategy. there needs to be 2 values

1. Stoploss Break Even Trigger (SLBET)
2. Stoploss Break Even (SLBE)

So lets say i place a long trade at 1.0000, stoploss is 0.9980. the value of SLBET=40pips and SLBE=1pip. So if price moved to 1.0040, it will tell the strategy to move the stoploss from .9980 to 1.0001.

Author:  API Support [ Mon 12 Dec, 2011, 14:21 ]
Post subject:  Re: Stoploss Break Even

Consider the following code:
package jforex.strategies;

import com.dukascopy.api.*;

public class StopManager implements IStrategy {

    private IEngine engine;
    private IConsole console;
    private IContext context;
    @Configurable("Lock-in Pips for Breakeven (SLBE)")
    public int lockPip = 3;
    @Configurable("Stoploss Break Even Trigger (SLBET)")
    public int triggerPips = 40;
    @Configurable("Move stop to breakeven?")
    public boolean moveBE = true;

    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.context = context;
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
       
        for (IOrder order : engine.getOrders(instrument)) {
            if (order.getState() == IOrder.State.FILLED) {
                boolean isLong;
                double open, newStop;
                String label = order.getLabel();
                IChart chart;

                isLong = order.isLong();
                open = order.getOpenPrice();

                if (isLong) { // long side order
                    if (moveBE && tick.getBid() > (open + toPrice(instrument, triggerPips))) {
                        // make it breakeven trade + lock in a few pips
                        newStop = open + toPrice(instrument, lockPip);
                        order.setStopLossPrice(newStop);
                        console.getOut().println(label + ": Moved stop to breakeven");

                        chart = this.context.getChart(instrument);
                        chart.draw(label + "_BE", IChart.Type.SIGNAL_UP, tick.getTime(), newStop);
                    }
                } else { // short side order
                    // Move to breakeven
                    if (moveBE && tick.getAsk() < (open - toPrice(instrument, triggerPips))) { // diff is negative
                        // make it breakeven trade + lock in a few pips
                        newStop = open - toPrice(instrument, lockPip);
                        order.setStopLossPrice(newStop);
                        console.getOut().println(label + ": Moved stop to breakeven");

                        chart = this.context.getChart(instrument);
                        chart.draw(label + "_BE", IChart.Type.SIGNAL_DOWN, tick.getTime(), newStop);
                    }
                }
            }
        }
    }
   
    private double toPrice(Instrument instr, int pips) {
        return instr.getPipValue() * pips;
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


Attachments:
StopManager.java [2.79 KiB]
Downloaded 362 times

Author:  uncharted29 [ Tue 13 Dec, 2011, 16:07 ]
Post subject:  Re: Stoploss Break Even

seems to be working pretty, i will keep testing it, thank you!.

Author:  uncharted29 [ Tue 13 Dec, 2011, 17:16 ]
Post subject:  Re: Stoploss Break Even

Hey, it working fine, only problem i notice, is on the strategy's first attempt to move the stoploss to breakeven, this message pops up and it will not move the stoploss until you click OK. after that it runs fine, itll trigger the stoploss automatically. Anyways to get rid of this message box?
thanks.

Image

Author:  dreamtheater [ Tue 13 Dec, 2011, 21:15 ]
Post subject:  Re: Stoploss Break Even

I get the same message like you and every time my platform freezes and needs force close. Totally no response by clicking any button and needs restart

Author:  Cashbone [ Tue 13 Dec, 2011, 22:39 ]
Post subject:  Re: Stoploss Break Even

dreamtheater and uncharted29,

have a look at this thread: http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=43153

Author:  dreamtheater [ Wed 14 Dec, 2011, 16:25 ]
Post subject:  Re: Stoploss Break Even

Thanks Cashbone, I've enabled the console but really don't know what to do with that code :?

Author:  Cashbone [ Wed 14 Dec, 2011, 22:27 ]
Post subject:  Re: Stoploss Break Even

Well I used @RequiresFullAccess so as not to have to deal with that, so I'm of no help there

  Page 1 of 2