Hi everyone,
I don't know how to synchronize time in historical tester to EET time zone. I tried to do this in a different ways, but nothing works:
1) get a bars with filter weekend
2) change settings platform tester.setDataInterval() in code
3) stop print data in console when context time is lower bar time --> if ( d.getDay() > e.getDay()) { return; } else { /* do sth */ }
and other what you see in code below
Always I get data from UTC time zone. Even when I change UTC to EET in platform time zone and chart settings it does not solve the problem.
I want to use EET time zone in historical tester but I don't know how...
Those picture shows testing results my strategy code in UTC and EET time zone and it's no difference between this settings, because I get always data in UTC time zone.
This is UTC time zone in platform and chart settingsThis is EET time zone in platform and chart settingspackage jforex;
import com.dukascopy.api.*;
import com.dukascopy.api.system.IClient;
import java.util.*;
import java.util.Collections;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.ITesterClient.DataLoadingMethod;
import java.text.ParseException;
public class strategy_synchronize_time implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
private IChart chart;
private ITesterClient tester;
private IClient client;
private SimpleDateFormat sdf;
private SimpleDateFormat sdf2;
ITick lastTick;
public Instrument selectedInstrument = Instrument.EURUSD;
Date dateFrom;
Date dateTo;
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();
this.chart = context.getChart(selectedInstrument);
// ================
final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
//Date dateFrom;
//Date dateTo;
try {
dateFrom = dateFormat.parse("05/25/2018 12:00:00");
dateTo = dateFormat.parse("05/26/2018 00:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
//tester.setDataInterval(DataLoadingMethod.ALL_TICKS, dateFrom.getTime(), dateTo.getTime());
// ================
// ================
//print( client.getAvailableInstruments() );
//context.stop();
// ================
sdf = new SimpleDateFormat("dd");
sdf.setTimeZone(TimeZone.getTimeZone("EET"));
sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
sdf2.setTimeZone(TimeZone.getTimeZone("EET"));
}
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 {
lastTick = tick;
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
//print( sdf.format( context.getTime() ) );
//
long prevBarTime = history.getPreviousBarStart(Period.DAILY, history.getLastTick(Instrument.EURUSD).getTime());
List<IBar> bars = history.getBars(Instrument.EURUSD, Period.DAILY, OfferSide.BID, Filter.WEEKENDS, 1, prevBarTime, 0);
//
//print( " >> " + bars );
//
IBar dailyLastBar = history.getBar(instrument, Period.DAILY, OfferSide.BID, 0);
print( sdf.format( dailyLastBar.getTime() ) );
Date d = new Date();
d.setTime(context.getTime());
Date e = new Date();
e.setTime(dailyLastBar.getTime());
// !!!
// This code result we see in the pictures
if ( d.getDay() > e.getDay()) {
print( 1 + " | " + sdf2.format(dailyLastBar.getTime()) + " " + sdf2.format(context.getTime()) );
print( dailyLastBar );
} else {
print( 2 + " | " + sdf2.format(dailyLastBar.getTime()) + " " + sdf2.format(context.getTime()) );
print( " ----> " + dailyLastBar );
}
/*
IBar dailyLastBar = history.getBar(instrument, Period.DAILY, OfferSide.BID, 0);
Date d = new Date();
d.setTime(context.getTime());
Date e = new Date();
e.setTime(dailyLastBar.getTime());
if ( d.getDay() > e.getDay()) {
//return;
print( 1 + " | " + sdf2.format(dailyLastBar.getTime()) + " " + sdf2.format(context.getTime()) );
} else {
print( 2 + " | " + sdf2.format(dailyLastBar.getTime()) + " " + sdf2.format(context.getTime()) );
print( dailyLastBar );
}
*/
}
public void print(Object obj) {
console.getOut().println(obj);
}
}
=====================
So, the problem is - how to set default time zone and start day time UTC to other time zone like EET. I get always only UTC data in historical tester. Maybe I'm doing something wrong... How to set default time zone in historical tester ?
Regards.