There you GO, I made this little strategy for you!
import com.dukascopy.api.Configurable;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IOrder;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
public class Order_BS_STAT_X1 implements IStrategy {
private IEngine engine;
private IConsole console;
private int counter = 0;
private IHistory history;
private String string = "";
@Configurable("Instrument")
public Instrument instrument = Instrument.EURUSD;
@Configurable("Slippage")
public double slippage = 2;
@Configurable("Amount")
public double amount = 0.1;
@Configurable("Take Profit Pips")
public int takeProfitPips = 20;
@Configurable("Stop Loss Pips")
public int slPips = 20;
@Configurable("Start Buing")
public boolean startBuing = true;
@Configurable("Start Buing")
public boolean startSelling = false;
@Configurable("Nr of Orders B/S")
public int ordNR= 1;
@Override
public void onStart(IContext context) throws JFException {
this.console = context.getConsole();
this.engine = context.getEngine();
this.setHistory(context.getHistory());
if(startSelling){
if (tradesTotalSELL(instrument) < ordNR) {
string = "SELL@Market"+counter;
submitOrder(OrderCommand.SELL, instrument);
context.stop();
}}
if(startBuing){
if (tradesTotalBUY(instrument) < ordNR) {
string = "BUY@Market"+counter;
submitOrder(OrderCommand.BUY, instrument);
context.stop();
}}
}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (instrument != this.instrument) {
return;
}
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (instrument != this.instrument) {
return;
}
}
private double getPipPrice(double pips) {
return pips * this.instrument.getPipValue();
}
private String getLabel(Instrument instrument) {
String label = instrument.name();
label = label + (counter++) + System.currentTimeMillis();
label = label.toUpperCase();
return label;
}
public void onMessage(IMessage message) throws JFException {
print(message);
}
public void onStop() throws JFException {
}
private void print(Object o) {
console.getOut().println(o);
}
public IHistory getHistory() {
return history;
}
public void setHistory(IHistory history) {
this.history = history;
}
private IOrder submitOrder(OrderCommand orderCmd, Instrument instrument) throws JFException {
double stopLossPrice = 0.0, takeProfitPrice = 0.0;
if (orderCmd == OrderCommand.BUY) {
if (slPips > 0) {
stopLossPrice = history.getLastTick(instrument).getBid() - getPipPrice(slPips);
}
if (takeProfitPips > 0) {
takeProfitPrice = history.getLastTick(instrument).getBid() + getPipPrice(takeProfitPips);
}
} else if (orderCmd == OrderCommand.SELL) {
if (slPips > 0) {
stopLossPrice = history.getLastTick(instrument).getBid() + getPipPrice(slPips);
}
if (takeProfitPips > 0) {
takeProfitPrice = history.getLastTick(instrument).getBid() - getPipPrice(takeProfitPips);
}
}
return engine.submitOrder(getLabel(instrument), instrument, orderCmd, amount, 0, slippage, stopLossPrice,takeProfitPrice,0,string);
}
public void onAccount(IAccount account) throws JFException {
}
public int tradesTotalBUY(Instrument INS) throws JFException {
int counter1 = 0;
for (IOrder ORD : engine.getOrders(INS)) {
if (ORD.getState() == IOrder.State.FILLED && ORD.isLong()) {
counter1++;
}
}
return counter1;
}
public int tradesTotalSELL(Instrument INS) throws JFException {
int counter2 = 0;
for (IOrder ORD : engine.getOrders(INS)) {
if (ORD.getState() == IOrder.State.FILLED && !ORD.isLong()) {
counter2++;
}
}
return counter2;
}
}