Hi, support.
I try to test my strategy in some intervals at one time by using Eclipse.
If I test two intervals, I'll get two result reports.
I modified TesterMain class code in JForexClientLibrary, and created a new class to input interval information.
package singlejartest;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.LoadingProgressListener;
import com.dukascopy.api.system.ISystemListener;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.TesterFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Future;
/**
* This small program demonstrates how to initialize Dukascopy tester and start a strategy
*/
public class TesterMain {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
//url of the DEMO jnlp
private static String jnlpUrl = "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";
//user name
private static String userName = "username";
//password
private static String password = "password";
/* my settings */
// cache directory
private static String cacheDir = "D:\\JForex\\.cache\\";
// report file
private static String reportRoot = "D:\\Test\\P1_Lv1_Single\\";
public static void main(String[] args) throws Exception {
ArrayList<TestInterval> intervalList = new ArrayList<TestInterval>();
intervalList.add(new TestInterval("2011_1Q", "2010/12/31 22:00", "2011/03/31 21:00"));
intervalList.add(new TestInterval("2011_2Q", "2011/03/31 21:00", "2011/06/30 21:00"));
for (TestInterval testInterval : intervalList)
{
String reportPath = reportRoot +
testInterval.getName() + ".html";
final File reportFile = new File(reportPath);
File reportDir = reportFile.getParentFile();
if (!reportDir.exists())
{
reportDir.mkdirs();
}
//get the instance of the IClient interface
final ITesterClient client = TesterFactory.getDefaultInstance();
//set the listener that will receive system events
// cache directory
client.setCacheDirectory(new File(cacheDir));
client.setSystemListener(new ISystemListener() {
@Override
public void onStart(long processId) {
LOGGER.info("Strategy started: " + processId);
}
@Override
public void onStop(long processId) {
LOGGER.info("Strategy stopped: " + processId);
//File reportFile = new File("C:\\report.html");
try {
client.createReport(processId, reportFile);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
// if (client.getStartedStrategies().size() == 0) {
// System.exit(0);
// }
}
@Override
public void onConnect() {
LOGGER.info("Connected");
}
@Override
public void onDisconnect() {
//tester doesn't disconnect
}
});
LOGGER.info("Connecting...");
//connect to the server using jnlp, user name and password
//connection is needed for data downloading
client.connect(jnlpUrl, userName, password);
//wait for it to connect
int i = 10; //wait max ten seconds
while (i > 0 && !client.isConnected()) {
Thread.sleep(1000);
i--;
}
if (!client.isConnected()) {
LOGGER.error("Failed to connect Dukascopy servers");
System.exit(1);
}
//set instruments that will be used in testing
Set<Instrument> instruments = new HashSet<Instrument>();
instruments.add(Instrument.EURUSD);
LOGGER.info("Subscribing instruments...");
client.setSubscribedInstruments(instruments);
//setting initial deposit
client.setInitialDeposit(Instrument.EURUSD.getSecondaryCurrency(), 50000);
//load data
LOGGER.info("Downloading data");
long startDate = testInterval.getStartTime();
long endDate = testInterval.getEndTime();
client.setDataInterval(ITesterClient.DataLoadingMethod.ALL_TICKS, startDate, endDate);
Future<?> future = client.downloadData(null);
//wait for downloading to complete
future.get();
//start the strategy
LOGGER.info("Starting strategy");
client.startStrategy(new MA_Play(), new LoadingProgressListener() {
@Override
public void dataLoaded(long startTime, long endTime, long currentTime, String information) {
LOGGER.info(information);
}
@Override
public void loadingFinished(boolean allDataLoaded, long startTime, long endTime, long currentTime) {
}
@Override
public boolean stopJob() {
return false;
}
});
//now it's running
}
}
}
package singlejartest;
import java.util.*;
import java.text.SimpleDateFormat;
import java.text.ParseException;
public class TestInterval {
private String name;
private String startTimeStr;
private String endTimeStr;
private SimpleDateFormat dateFmt;
private static final String DATE_PATTERN = "yyyy/MM/dd HH:mm";
public TestInterval(String name, String startTimeStr, String endTimeStr)
{
this.name = name;
this.startTimeStr = startTimeStr;
this.endTimeStr = endTimeStr;
this.dateFmt = new SimpleDateFormat(DATE_PATTERN);
this.dateFmt.setTimeZone(TimeZone.getTimeZone("GMT"));
}
public String getName()
{
return this.name;
}
public long getStartTime() throws ParseException
{
return this.dateFmt.parse(this.startTimeStr).getTime();
}
public long getEndTime() throws ParseException
{
return this.dateFmt.parse(this.endTimeStr).getTime();
}
}
I tested MA_Play strategy in the two intervals, but I got only one result report on the last interval.
What is wrong? Isn't there any good way?
Thank you in advance for your help
tnaka36