Dukascopy
 
 
Wiki JStore Search Login

APICLIENT-206 IHistory method getBars returns wrong bars on custom periods
 Post subject: APICLIENT-206 IHistory method getBars returns wrong bars on custom periods Post rating: 0   New post Posted: Mon 23 Jul, 2012, 11:31 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 413
Location: Germany, Munich
If you take 2 min custom bars and you use
getBars(Instrument instrument,
Period period,
OfferSide side,
Filter filter,
int numberOfCandlesBefore,
long time,
int numberOfCandlesAfter)
of the current IHisory API you will get wrong results.

Please see this example.
1) A custom period of 2 mins is set
2) BARSAMOUNT = 3 are requested by the above mentioned method
3) the bars are not always in 2 min time differences! See the following output
bar2: 01-05-2012 00:54:00.000 GMT
bar1: 01-05-2012 00:52:00.000 GMT
bar0: 01-05-2012 00:48:00.000 GMT

It should be like this
bar2: 01-05-2012 00:54:00.000 GMT
bar1: 01-05-2012 00:52:00.000 GMT
bar0: 01-05-2012 00:50:00.000 GMT

Seen on JForex DEMO, current version of July 23rd 2012.
Please correct asap.

/*     
 * This is a test programm only, do not use for trading!
 * It checks getBars(Instrument instrument,
 *                            Period period,
 *                            OfferSide side,
 *                            Filter filter,
 *                            int numberOfCandlesBefore,
 *                            long time,
 *                            int numberOfCandlesAfter)
 * method of IHistory
 * At current JForex version it give wrong results!
 *
 * (c) Stash GmbH Muenchen / Germany, July 23rd 2012
 *     www.stash.de
 *     Author: Bernhard Schicht
 *     Email: [email protected]
 */
package jforex;

import java.util.*;
import java.text.SimpleDateFormat;
import com.dukascopy.api.*;

public class CustomPeriodBug implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    private Period twoMin = null;
   
    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();
        twoMin = Period.createCustomPeriod(Unit.Minute, 2);
    }

    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 {
        int BARSAMOUNT = 3;
        long time = history.getBarStart(twoMin,  history.getLastTick(instrument).getTime());
        long bartime = history.getBarStart(twoMin,  time);
        List<IBar> barsList = history.getBars(instrument, twoMin,  OfferSide.ASK, Filter.WEEKENDS,BARSAMOUNT, bartime, 0);
       
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        for (int t = 0 ; t < barsList.size() ; t++){
            cal.setTimeInMillis(barsList.get(t).getTime());
            console.getOut().println("bar"+t+": "+getGMTString(cal.getTime()));           
        }

    }
   
    public static String getGMTString(long milis){
      Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
      cal.setTimeInMillis(milis);
      return getGMTString(cal.getTime());
    }
    public static String getGMTString(Date date){     
      //     Festlegung des Formats:
      SimpleDateFormat df = new SimpleDateFormat( "dd-MM-yyyy HH:mm:ss.SSS z" );
      df.setTimeZone(TimeZone.getTimeZone("GMT"));           
      return df.format(date);     
    }
}


Attachments:
CustomPeriodBug.java [2.83 KiB]
Downloaded 354 times
CustomPeriodBug.jfx [3.92 KiB]
Downloaded 332 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

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