Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Writing chart information in file
 Post subject: Writing chart information in file Post rating: 0   New post Posted: Wed 22 Aug, 2012, 18:12 

User rating: 0
Joined: Mon 25 Jun, 2012, 15:55
Posts: 13
Hello Support-Team,

I wanted to collect pieces of information about different charts, which were written in a File. This worked for the last few months. But when I tried it today and no File was written anymore.
Thank you
Jimmy Knoppers
here is the code:
package jforex;

import com.dukascopy.api.*;
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.OrderCommand;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.INewsFilter.Currency;
import com.dukascopy.api.IOrder;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.IUserInterface;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import java.io.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.util.Date;


public class GetTime implements IStrategy {
 
private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
   
    private Instrument Currency=Instrument.EURUSD;
    private String path="C:\\Users\\Jimmy\\Documents\\JForex\\files\\";
   
   
   
    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();
    }

    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 {

   Period Periods;
   
    Periods=Period.ONE_SEC;
    if (instrument == Currency && period == Periods{
    IBar Bar= history.getBar(Currency, Periods, OfferSide.BID, 1);
   
 
    long Time = Bar.getTime();    // Time
    double Volume=Bar.getVolume();//volume
    String Dataname= "CVSNAME";
   
    WriteFile(Time,Dataname);
    }

}

    public void WriteFile(long time, String Dataname)throws JFException{
   
    String FILE_NAME=path+Dataname+".csv";
    File file = new File(FILE_NAME);
     
                   try {
                       if(file.exists()==true){
                           console.getNotif().println("exsists");
                                FileWriter fstream = new FileWriter(FILE_NAME, true);
                                BufferedWriter out = new BufferedWriter(fstream);
                                out.append( time+";"+"\n");
                                out.close();
                        }else{
                            console.getNotif().println("doesn't exsist");
                                FileWriter fstream = new FileWriter(FILE_NAME, true);
                                BufferedWriter out = new BufferedWriter(fstream);
                                out.append( "time" + "\n");
                                out.append( time+ "\n");
                                out.close();
                               
                                }} catch (Exception e) {
                                console.getNotif().println("error");
                                console.getOut().print("File access error: " + e.getMessage());
                        }}


    }


 
 Post subject: Re: Writing chart information in file Post rating: 0   New post Posted: Mon 27 Aug, 2012, 08:26 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See if you receive any messages in java console:
viewtopic.php?f=81&t=39073


 

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