Hi everybody!,
I have this problem. I'm trying to find a way to store the values of some indicators in an external file so i can feed them to a learning algorithm.
I would use a java strategy file ran from the jforex terminal that would recover the data over a period of time and then write to a file.
I just cannot get it to work, it doesn't seem that the interface allows it. anybody have any idea how i could do that?
here's a simplified strategy... compiling this give me an Unhandled exception type IOException error.
package jforex;
import java.util.*;
import com.dukascopy.api.*;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.util.Date;
import java.text.ParseException;
import com.dukascopy.api.Filter;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IIndicators.MaType;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import com.dukascopy.api.RequiresFullAccess;
import java.io.*;
public class Test2 implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
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();
Date dateFrom = new Date(), dateTo = new Date();
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
dateFrom = format.parse("2015-04-22 21:00:00");
dateTo = format.parse("2015-04-23 07:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
long from = dateFrom.getTime(), to = dateTo.getTime();
double[][] stochFive = indicators.stoch(Instrument.EURUSD, Period.FIVE_MINS, OfferSide.ASK, 5, 3, MaType.SMA, 3, MaType.SMA, from, to);
createFile("bla.dat", stochFive, stochFive.length);
}
static void createFile(String name, double[][] foo, int n)throws IOException{
boolean problem = false;
FileWriter fw = null;
try{
fw = new FileWriter(name);
}catch (IOException error){
problem = true;
}
if (!problem){
PrintWriter writer = new PrintWriter(fw);
for(int i = 0; i < n; i++){
writer.printf("%d %f %f\n", i, foo[1][i], foo[0][i]);
}
writer.close();
}
}
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 {
}
}