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.

Stoploss Break Even
 Post subject: Stoploss Break Even Post rating: 0   New post Posted: Tue 06 Dec, 2011, 19:17 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
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.


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Wed 07 Dec, 2011, 09:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See if you can make use of:
viewtopic.php?f=65&t=35365&p=45599
or
viewtopic.php?f=65&t=42122&p=53818


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Wed 07 Dec, 2011, 22:54 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
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 420 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.
 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Wed 07 Dec, 2011, 22:56 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
Image


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Thu 08 Dec, 2011, 09:30 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/index.php ... _in_JForex


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Thu 08 Dec, 2011, 15:25 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
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,


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Thu 08 Dec, 2011, 15:26 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
Thanks for the help.


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Thu 08 Dec, 2011, 15:33 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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.


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Thu 08 Dec, 2011, 15:49 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
ok there's no parameter option, Every time i hit run, it just opens a long position on eurusd and a stoploss order?!!??


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Thu 08 Dec, 2011, 15:55 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Thu 08 Dec, 2011, 16:55 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
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 423 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.
 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Fri 09 Dec, 2011, 15:32 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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?


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Sat 10 Dec, 2011, 21:09 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
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.


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Mon 12 Dec, 2011, 14:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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 415 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.
 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Tue 13 Dec, 2011, 16:07 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
seems to be working pretty, i will keep testing it, thank you!.


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Tue 13 Dec, 2011, 17:16 

User rating: 0
Joined: Wed 30 Nov, 2011, 02:55
Posts: 10
Location: CA
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


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Tue 13 Dec, 2011, 21:15 

User rating: 1
Joined: Mon 23 May, 2011, 07:52
Posts: 57
Location: Bulgaria,
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


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Tue 13 Dec, 2011, 22:39 

User rating: 3
Joined: Tue 17 May, 2011, 16:51
Posts: 38
Location: Sweden, Jonkoping
dreamtheater and uncharted29,

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


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Wed 14 Dec, 2011, 16:25 

User rating: 1
Joined: Mon 23 May, 2011, 07:52
Posts: 57
Location: Bulgaria,
Thanks Cashbone, I've enabled the console but really don't know what to do with that code :?


 
 Post subject: Re: Stoploss Break Even Post rating: 0   New post Posted: Wed 14 Dec, 2011, 22:27 

User rating: 3
Joined: Tue 17 May, 2011, 16:51
Posts: 38
Location: Sweden, Jonkoping
Well I used @RequiresFullAccess so as not to have to deal with that, so I'm of no help there


 

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