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.

How to determine time of earliest and latest historical tick or bar?
 Post subject: How to determine time of earliest and latest historical tick or bar? Post rating: 0   New post Posted: Thu 18 Feb, 2016, 06:01 
User avatar

User rating: 0
Joined: Thu 18 Feb, 2016, 05:57
Posts: 1
Location: Canada,
Does anyone know how to determine the earliest and most recent available date/time of a bar?

For example if I use getBars() for one minute period data, I would like to use the earliest and most recent date available.

The most recent date appears to be about 2 days prior to the current date, but I don't know how to determine this easily.


 
 Post subject: Re: How to determine time of earliest and latest historical tick or bar? Post rating: 0   New post Posted: Thu 07 Apr, 2016, 15:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

Yes you can archive this by following this:

package yourpackage.test;

import com.dukascopy.api.*;

import java.util.List;

public class MyStrategy implements IStrategy {

    IContext context;
    IHistory history;
    IConsole console;

    ITick tick;
    long tickTime;      // get the time of last tick
    long barStartTime;

    private Instrument instrument = Instrument.EURUSD;

    @Override
    public void onStart(IContext context) throws JFException {
        this.context = context;
        this.history = context.getHistory();
        this.console = context.getConsole();
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        tick = history.getLastTick(instrument);
        tickTime = tick.getTime();
        barStartTime = history.getBarStart(Period.ONE_MIN, tickTime);

        List<IBar> resultbars = history.getBars(instrument, Period.ONE_MIN, OfferSide.BID, Filter.NO_FILTER, 1, barStartTime, 0);
        IBar bar = resultbars.get(0);
    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {

    }

    @Override
    public void onMessage(IMessage message) throws JFException {

    }

    @Override
    public void onAccount(IAccount account) throws JFException {

    }

    @Override
    public void onStop() throws JFException {

    }
}


For more details: Click Here
Good luck and have a nice day!


 

Jump to:  

cron
  © 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