thanks API support,
I tried the following code for buying all USD pairs but it gives me errors when compiling.
This is the complete strategy:
package jforex;
import java.util.*;
import com.dukascopy.api.*;
public class USDbuy implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
@Configurable("Amount")
public double amount = 0.002;
@Configurable("Price")
public double price = 0;
@Configurable("Slippage")
public double slippage = 2;
private int counter = 0;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
Set<Instrument> instruments = new HashSet<Instrument>();
instruments.add(Instrument.AUDUSD);
instruments.add(Instrument.EURUSD);
instruments.add(Instrument.GBPUSD);
instruments.add(Instrument.NZDUSD);
instruments.add(Instrument.USDCAD);
instruments.add(Instrument.USDCHF);
instruments.add(Instrument.USDJPY);
context.setSubscribedInstruments(instruments);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
engine.submitOrder("AUDUSD", Instrument.AUDUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("EURUSD", Instrument.EURUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("GBPUSD", Instrument.GBPUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("NZDUSD", Instrument.NZDUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("USDCAD", Instrument.USDCAD, OrderCommand.BUY, amount, price, slippage);
engine.submitOrder("USDCHF", Instrument.USDCHF, OrderCommand.BUY, amount, price, slippage);
engine.submitOrder("USDJPY", Instrument.USDJPY, OrderCommand.BUY, amount, price, slippage);
context.stop();
}
private String getLabel(Instrument instr) {
String label = instr.name();
label = label + (counter++);
label = label.toUpperCase();
return label;
}
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 {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}
the problem seems to be in the following piece of code:
engine.submitOrder("AUDUSD", Instrument.AUDUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("EURUSD", Instrument.EURUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("GBPUSD", Instrument.GBPUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("NZDUSD", Instrument.NZDUSD, OrderCommand.SELL, amount, price, slippage);
engine.submitOrder("USDCAD", Instrument.USDCAD, OrderCommand.BUY, amount, price, slippage);
engine.submitOrder("USDCHF", Instrument.USDCHF, OrderCommand.BUY, amount, price, slippage);
engine.submitOrder("USDJPY", Instrument.USDJPY, OrderCommand.BUY, amount, price, slippage);