JForex StopManager 1.0

I am building my real JForex automated trading system one feature at a time. The idea is to automate some of my most fundamental trading techniques on JForex so that I can trade forex semi-automatically on Dukascopy. I am starting off here with a simple stop management strategy. In a nutshell, once the market price moves in your favour equidistant from your original stop loss, this strategy moves the stop to breakeven. For example, if I go long EURUSD at 1.3500 with a stop at 1.3400 (100 pips stop). Then if the price breaks above 1.3600 (100 pips profit), the strategy moves the stop to breakeven. This is a simplistic implementation of the saying that "never let profits turn into losses". You can download the source code here and the executable strategy here. Note that these files are made available through Dropbox. Update: This logic is now integrated into the JFUtil open source project. You can also see a list of my latest JForex articles here. [java] /* 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 { } } [/java]