Dukascopy
 
 
Wiki JStore Search Login

writing data to an external file?
 Post subject: writing data to an external file? Post rating: 0   New post Posted: Fri 01 May, 2015, 03:59 
User avatar

User rating: 0
Joined: Fri 01 May, 2015, 03:44
Posts: 1
Location: Canada,
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 {
    }
}


 
 Post subject: Re: writing data to an external file? Post rating: 0   New post Posted: Thu 07 May, 2015, 13:21 
User avatar

User rating: 0
Joined: Fri 01 May, 2015, 21:51
Posts: 2
Your method createFile(...) can throw an exception of type IOException, if you call that method (which you do on line 55) you have to write code to handle such an exception.

try {
   method call
} catch (IOException ioE) {
   oh my god, my code threw an exception
}


 
 Post subject: Re: writing data to an external file? Post rating: 0   New post Posted: Fri 08 May, 2015, 08:28 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi,

There are plenty of examples in the wiki how to write to a file from a strategy. Take a look in these:
https://www.dukascopy.com/wiki/#Write_in_File
https://www.dukascopy.com/wiki/#Write_variables_in_file
https://www.dukascopy.com/wiki/#Write_bars_in_File


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com