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.

What does this error means?
 Post subject: What does this error means? Post rating: 0   New post Posted: Sat 24 Mar, 2012, 10:00 

User rating: 0
Joined: Sat 24 Mar, 2012, 09:54
Posts: 13
08:50:49 at com.dukascopy.api.impl.h.getBars(Unknown Source)
08:50:49 com.dukascopy.api.JFException: "to" parameter can't be greater than the time of the last formed bar for this instrument
08:50:49 "to" parameter can't be greater than the time of the last formed bar for this instrument


package jforex;
import java.util.*;
import java.io.*;
import java.text.*;
import com.dukascopy.api.*;

@RequiresFullAccess
public class DownloadtoC implements IStrategy {
    @Configurable("Period")
    public Period period=Period.ONE_HOUR;
    @Configurable("Instrument")
    public Instrument instrument=Instrument.EURUSD;
    @Configurable("OfferSide")
    public OfferSide offerSide=OfferSide.BID;


    private DecimalFormat priceFormat;
    private SimpleDateFormat gmtsdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private String startDateStr="2012-03-21 00:00:00";
    private int days=3;
   
    private IEngine engine;
    private IConsole console; // use
    private IHistory history; // use
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
   
    //@Override
    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();
       
        gmtsdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        priceFormat=new DecimalFormat("0.#####");
        long startDate=0;
        try{
            startDate=gmtsdf.parse(startDateStr).getTime();
        }catch(ParseException el){
            //stop strategy
            console.getErr().println(el);
            context.stop();
            return;
        }
        int k=1;
        for(int day=0; day<days; day++){
            long startTime=0;
            long endTime=0;
            startTime=startDate+Period.DAILY.getInterval()*day;
            endTime=startTime+Period.DAILY.getInterval()-1; // minus 1 milli to be in the same day
            long startBarTime=history.getBarStart(period, startTime);
            long endBarTime=history.getBarStart(period, endTime);
           
           
            try{
                 List<IBar> bars=history.getBars(instrument,period,OfferSide.BID,startBarTime,endBarTime);
                 for(IBar bar:bars){
                     print(k+","+priceFormat.format(bar.getOpen())+","+priceFormat.format(bar.getHigh())+","+priceFormat.format(bar.getLow())+","+
                     //out.write(priceFormat.format(bar.getOpen())+","+priceFormat.format(bar.getHigh())+","+priceFormat.format(bar.getLow())+","+
                     priceFormat.format(bar.getClose())+","+priceFormat.format(bar.getVolume())+"\r\n");
                     k=k+1;
                 }
            }catch(Exception e){
                console.getErr().println(e.getMessage());
                e.printStackTrace(console.getErr());
                context.stop();
            }
        }
     
    }
    @Override
    public void onAccount(IAccount account) throws JFException {}
    @Override
    public void onMessage(IMessage message) throws JFException {}
    @Override
    public void onStop() throws JFException {}
    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}
    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
    private void print(Object o){
        console.getOut().println(o);
    }
}


 
 Post subject: Re: What does this error means? Post rating: 0   New post Posted: Mon 26 Mar, 2012, 08:06 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
make sure that startBarTime <= endBarTime.


 

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