Create a Strategy
Create new/open existing strategy
To open a new strategy right-click on Strategies in Navigator panel
Once a "New strategy" is selected, the system creates a new strategy file in "~\AppData\Local\JForex\Strategies" directory. The Strategy by itself is a java file, which can be edited in any Java compatible editor.
The following example is a typical strategy file with minimal implementation methods needed for a successful compilation:
package jforex;
import com.dukascopy.api.*;
public class Strategy1 implements IStrategy {
public void onStart(IContext context) throws JFException {}
public void onAccount(IAccount account) throws JFException {}
public void onMessage(IMessage message) throws JFException {}
public void onStop() throws JFException {}
public void onTick(Instrument instr, ITick tick) throws JFException {}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
}
A strategy can be compiled by pressing the compilation button in your strategy editor toolbar:
Compilation results can be viewed in the "Messages" tab. A "Compiling... OK" message is displayed, if compilation was successful. Otherwise, you get detailed error messages.
Run the Program
To bring a sense into our example let's adjust onStart and onTick methods to make it print incoming ticks:
package jforex;
import com.dukascopy.api.*;
public class Strategy1 implements IStrategy {
private IConsole con = null;
public void onStart(IContext context) throws JFException {
//here we remember the IConsole needed for printing messages
//on to "Messages" tab
this.con = context.getConsole();
}
public void onAccount(IAccount account) throws JFException {}
public void onMessage(IMessage message) throws JFException {}
public void onStop() throws JFException {}
public void onTick(Instrument instr, ITick tick) throws JFException {
con.getOut().println(instr+" "+tick.getAsk()+"/"+tick.getBid());
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
}
Once the strategy is compiled, one can run it by left-clicking on it in the Navigator pane and selecting Local run.
For more on strategy development and usage examples see Strategy API