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.

Historical Ticks
 Post subject: Historical Ticks Post rating: 0   New post Posted: Wed 28 Dec, 2011, 22:53 

User rating: 0
Joined: Tue 01 Nov, 2011, 00:44
Posts: 29
Location: United Kingdom,
Hello,

I would like to download historical tick data, but I am unable to find an example in the Wiki or Forum. Please can you point me in the right direction.

Regards.


 
 Post subject: Re: Historical Ticks Post rating: 0   New post Posted: Thu 29 Dec, 2011, 12:09 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
There are multiple ways:
  1. From Historical Tester in JForex client by selecting Save Data.
  2. From dukascopy website https://www.dukascopy.com/swiss/english/ ... istorical/
  3. By using a strategy, for instance: viewtopic.php?f=31&t=466


 
 Post subject: Re: Historical Ticks Post rating: 0   New post Posted: Thu 29 Dec, 2011, 13:08 

User rating: 0
Joined: Tue 01 Nov, 2011, 00:44
Posts: 29
Location: United Kingdom,
I am interested in using the strategy. Here is the code I use to get historical bar data which works fine for bars. But the problem is that when I use periods.add(Period.TICK) then the history.getBarStart complains.
public void onStart(IContext context) throws JFException {   
   
        long startTime = 0;
        long endTime = 0;
        long startDate = 0;
       
        DateTimeFormatter fmt = DateTimeFormat.forPattern("dd/MM/Y - k:mm");
        DecimalFormat twoDForm = new DecimalFormat("#.00000");
                       
   console = context.getConsole();   
   this.history = context.getHistory();
      
   gcSqlclient.connect();
       
   gmtSdfShort.setTimeZone(TimeZone.getTimeZone("GMT"));
        gmtSdfLong.setTimeZone(TimeZone.getTimeZone("GMT"));
       
        Set<Instrument> instruments = new HashSet<Instrument>();
        instruments.add(Instrument.EURUSD);     
     
        Enumeration<Instrument> eInstruments = Collections.enumeration(instruments);

        Set<Period> periods = new HashSet<Period>();
        //!!!!
        periods.add(Period.TICK);
        //periods.add(Period.ONE_MIN); 
       
        Enumeration<Period> ePeriods;

        while (eInstruments.hasMoreElements()) {
           
           Instrument iCurrent = eInstruments.nextElement();
           
           ePeriods = Collections.enumeration(periods);
           
           while (ePeriods.hasMoreElements()) {
              
              Period pCurrent = ePeriods.nextElement();
              
              //console.getErr().println(iCurrent.toString() + "\t" + pCurrent.toString());

              // Here is where I set the number of days to go back.
                 DateTime jDateTime = new DateTime().minusDays(7);
                 //DateTime jDateTime = new DateTime("2010-02-28T22:00:00");
              startDateStr = jDateTime.toString();
             
              day = Days.daysBetween(DateTime.parse(startDateStr), DateTime.now()); 
              days = day.getDays();
             
              try {
               startDate = gmtSdfShort.parse(startDateStr).getTime();
              } catch (ParseException e) {
                  //stop strategy
               LOGGER.warn(e.toString());
                  context.stop();
                  return;
              }

              for (int day = 0; day < days; day++ ) {
      
                 startTime = startDate + Period.DAILY.getInterval() * day;
                 //endTime = startTime + Period.DAILY.getInterval();
                 endTime = new DateTime().getMillis() - 1;
                 
                  LOGGER.info("\t" + fmt.print(startTime) + "\t" + fmt.print(endTime));
                         
                  [color=#FF0080] long startBarTime = history.getBarStart(pCurrent, startTime);[/color]
                  long endBarTime = history.getBarStart(pCurrent, endTime);
                  List<IBar> bars = history.getBars(iCurrent, pCurrent, OfferSide.BID, startBarTime, endBarTime);
                 
                  for(IBar bar : bars) {
                     
                     LOGGER.info("\t" + iCurrent.toString() + "\t\t" + pCurrent.toString() + "\t" + fmt.print(bar.getTime()) + "\t" + twoDForm.format(bar.getLow()) + "\t" + twoDForm.format(bar.getHigh()));

                     brains.saveData(iCurrent.toString(), pCurrent.toString(), bar.getTime(), bar.getLow(), bar.getHigh(), bar.getClose());
                 
                  }
              } 
       
          }

        }
       
      LOGGER.info("onStop");
      gcSqlclient.disconnect();   
      brains.disconnect();       
       
        System.exit(0);
   }


 
 Post subject: Re: Historical Ticks Post rating: 0   New post Posted: Thu 29 Dec, 2011, 14:07 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Techniques that are applied for retrieving historical candle stick bars can not be applied to retrieving ticks. Please consider using IHistory.getTicks().


 
 Post subject: Re: Historical Ticks Post rating: 0   New post Posted: Thu 29 Dec, 2011, 15:47 

User rating: 0
Joined: Tue 01 Nov, 2011, 00:44
Posts: 29
Location: United Kingdom,
Its working. Thanks alot.


 
 Post subject: Re: Historical Ticks Post rating: 0   New post Posted: Thu 26 Apr, 2012, 14:46 

User rating: 0
Joined: Thu 26 Apr, 2012, 14:41
Posts: 7
I'm new to JForex and just starting to learn to code in Java.

Can you post the whole code for the historical bars? I'd like to use it to find a way to store 1 minute, 5 minute, 1 hour, and 4 hour OHLC data in MySQL. There is info. and code on how to store ticks, but not bar data.

Thanks!


 
 Post subject: Re: Historical Ticks Post rating: 0   New post Posted: Thu 26 Apr, 2012, 15:45 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please read Wiki before asking a question.
Off topics are strictly forbidden.


 

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