There is a bug in function IHistory.getBars(Instrument instrument, Period period, OfferSide side, Filter filter, int numberOfCandlesBefore, long time, int numberOfCandlesAfter)
and the new DEMO Dukascopy ver. 2.14.24.3
If I need 10 bars from now back on EURUSD, Period.TEN_SECS I get different results on DEMO and on LIVE:
Here comes an example printout:
DEMO Dukascopy ver. 2.14.24.3
2012-02-20 11:18:46 8: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:18:50 GMT
2012-02-20 11:18:46 7: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:18:30 GMT
2012-02-20 11:18:46 6: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:18:20 GMT
2012-02-20 11:18:46 5: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:18:10 GMT
2012-02-20 11:18:46 4: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:18:00 GMT
2012-02-20 11:18:46 3: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:17:50 GMT
2012-02-20 11:18:46 2: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:17:40 GMT
2012-02-20 11:18:46 1: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:17:30 GMT
2012-02-20 11:18:46 0: EUR/USD : barsList.size() = 9, barsBack = 10, bartime = 20 Feb 2012 11:17:20 GMT
2012-02-20 11:18:46 currentbartime = 20 Feb 2012 11:18:50 GMT
LIVE Dukascopy ver. 2.12.30
2012-02-20 11:18:32 9: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:18:50 GMT
2012-02-20 11:18:32 8: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:18:40 GMT2012-02-20 11:18:32 7: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:18:30 GMT
2012-02-20 11:18:32 6: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:18:20 GMT
2012-02-20 11:18:32 5: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:18:10 GMT
2012-02-20 11:18:32 4: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:18:00 GMT
2012-02-20 11:18:32 3: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:17:50 GMT
2012-02-20 11:18:32 2: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:17:40 GMT
2012-02-20 11:18:32 1: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:17:30 GMT
2012-02-20 11:18:32 0: EUR/USD : barsList.size() = 10, barsBack = 10, bartime = 20 Feb 2012 11:17:20 GMT
2012-02-20 11:18:32 currentbartime = 20 Feb 2012 11:18:50 GMT
The second line with
bartime = 20 Feb 2012 11:18:40 GMT is missing in DEMO!
Please also try different barsBack (=3 gives only 1 line in DEMO and 3 lines in LIVE !!) and periods.
Here is the code
/*
* This is a test programm only, do not use for trading!
* It checks the IHistory.getBars(Instrument instrument, Period period, OfferSide side, Filter filter, int numberOfCandlesBefore, long time, int numberOfCandlesAfter) bug
*
* (c) Stash GmbH München
* www.stash.de
* Author: Bernhard Schicht
* Email: [email protected]
*/
package jforex;
import com.dukascopy.api.*;
import com.dukascopy.api.Filter;
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;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
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.util.*;
import java.util.Calendar;
import java.util.TimeZone;
public class StrategyTestBasicPeriod implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
@Configurable("Instrument") public Instrument instr = Instrument.EURUSD;
@Configurable("Bars back") public int barsBack = 10;
@Configurable("Period") public Period checkPeriod = Period.TEN_SECS;
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 {
if (period != checkPeriod) return;
if (instr != instr) return;
List<IBar> barsList = null;
long currentbartime = 0L;
OfferSide os= OfferSide.BID;
try{
long time = history.getLastTick(instr).getTime();
currentbartime = history.getBarStart(period, time);
barsList = history.getBars(instr, period, os, Filter.NO_FILTER, barsBack, currentbartime, 0);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.setTimeInMillis(currentbartime);
p("currentbartime = "+cal.getTime().toGMTString());
for (int t = 0 ; t < barsList.size() ; t++){
cal.setTimeInMillis(barsList.get(t).getTime());
p(t+": "+instr.toString()+" : barsList.size() = "+barsList.size()+", barsBack = "+barsBack+", bartime = "+cal.getTime().toGMTString());
}
}
catch (Exception e){
e.printStackTrace(console.getErr());
}
}
public void p(String text){
console.getOut().println(text);
}
public void pErr(String text){
console.getErr().println(text);
}
}
Please correct asap!