I'm trying to launch the ITesterClient interface from within a running strategy and am not having much luck. The strategy I'm trying to test is declared with public class MAF implements IStrategy { .. in it's own MAF.java file with package selfopt; as the first line.
I'm getting these error messages:
16:10:01 ----------
16:10:01 MAF cannot be resolved to a type
16:10:01 ^^^
16:10:01 client.startStrategy(new MAF(), new LoadingProgressListener() { //
16:10:01 2. ERROR in C:\Users\Chris\AppData\Local\Temp\jfxide\tmp\mafMain2.java (at line 118)
16:10:01 ----------
16:10:01 DataLoadingMethod cannot be resolved
16:10:01 ^^^^^^^^^^^^^^^^^
16:10:01 client.setDataInterval(DataLoadingMethod.ALL_TICKS, tmFrom , tmTo);
16:10:01 1. ERROR in C:\Users\Chris\AppData\Local\Temp\jfxide\tmp\mafMain2.java (at line 117)
16:10:01 ----------
when compiling this:
package selfopt;
import java.io.File;
import java.util.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.system.ISystemListener;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.TesterFactory;
import selfopt.*;
public class mafMain2 implements IStrategy {
public double ordAmount = 0.001;
@Configurable ("intPer") public int intPer = 15;
@Configurable ("selPer") public Period selectedPeriod = Period.ONE_HOUR ;
@Configurable ("selIns") public Instrument selIns = Instrument.EURGBP;
public Period upperPeriod = Period.WEEKLY;
Set<Instrument> instSet = new HashSet<Instrument>();
private String strParam="";
private int anPeriod = 0;
private long lstWeekTm = 0;
private IEngine engine;
private IConsole console;
private IHistory history;
private IIndicators indicators;
//private IAccount account;
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 {
if (!selIns.equals(instrument)) return;
if ((anPeriod == 0 && period == Period.ONE_HOUR) || period == Period.WEEKLY)
{
long timeTo = history.getBar(instrument, Period.WEEKLY, OfferSide.BID, 0).getTime();
long timeFrom = timeTo - Period.WEEKLY.getInterval()*2;
try {
anHist( timeFrom , timeTo );
} catch (IllegalAccessException e) {
console.getErr().println(e.getMessage());
} catch (InstantiationException e) {
console.getErr().println(e.getMessage());
} catch (Exception e) {
console.getErr().println(e.getMessage());
}
}
}
@Override
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.indicators = context.getIndicators();
instSet.add(selIns);
context.setSubscribedInstruments(instSet);
}
public enum OrderStat {
BUYFILLED, BUYUNFILLED, SELLFILLED, SELLUNFILLED, NONE
}
public void anHist(long tmFrom, long tmTo) throws JFException, Exception, IllegalAccessException, InstantiationException {
final ITesterClient client = TesterFactory.getDefaultInstance();
client.setSystemListener(new ISystemListener() {
@Override
public void onStart(long processId) {
console.getOut().println("Backtest started: " + processId);
}
@Override
public void onStop(long processId) {
console.getOut().println("Backtest stopped: " + processId);
File reportFile = new File("C:\\Temp\\report.html");
try {
client.createReport(processId, reportFile);
} catch (Exception e) {
console.getErr().println(e.getMessage());
}
if (client.getStartedStrategies().size() == 0) {
System.exit(0);
}
}
@Override
public void onConnect() {
console.getOut().println("Connected");
}
@Override
public void onDisconnect() {
//tester doesn't disconnect
}
});
client.setSubscribedInstruments(instSet);
client.setInitialDeposit(Instrument.EURUSD.getSecondaryCurrency(), 5000);
client.setDataInterval(ITesterClient.DataLoadingMethod.ALL_TICKS, tmFrom , tmTo);
client.startStrategy(new MAF(), new LoadingProgressListener() { //
@Override
public void dataLoaded(long startTime, long endTime, long currentTime, String information) {
double num = currentTime - startTime;
double tot = endTime - startTime;
double res = (int) (num/tot*100);
console.getOut().println( Double.toString(res)) ;
}
@Override
public void loadingFinished(boolean allDataLoaded, long startTime, long endTime, long currentTime) {
}
@Override
public boolean stopJob() {
return false;
}
});
}
}