Dukascopy Support Board

How to get dailyBar in different time zones?
Page 1 of 1

Author:  grosskt [ Mon 14 May, 2018, 16:36 ]
Post subject:  How to get dailyBar in different time zones?

I am bothered about the different time zones,
the opening price and closing price of the K line are different,
because these basic data are not correct, resulting in very different results of the strategy operation

I learned from Wikipedia that all API data is based on the UTC time zone,

but the K line displayed by the platform is based on the UTC+2 time zone.

I would like to ask, how do I obtain the K line data shown in the figure???

 IBar preDailyBar;
        List<IBar> bars;
             long lastTickTime = history.getLastTick(SpecInstru).getTime();
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR_OF_DAY, baseHour );
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
           long endDays = calendar.getTimeInMillis();
           long beforeDay= endDays -3*24*60*60*1000;
           bars = history.getBars(SpecInstru, Specperiod, OfferSide.ASK, Filter.WEEKENDS, 3, endDays, 0);

com.dukascopy.api.JFException: Interval from [2018.05.10 21:00:00 400] to [2018.05.13 21:00:00 400] GMT is not valid for period [Daily]
at com.dukascopy.api.impl.o.b(L:1386)
at com.dukascopy.api.impl.o.getBars(L:2885)
at COM.Mystrategies.TradeTool.CheckThreeUpDown(TradeTool.java:1044)
at COM.Mystrategies.TradeTool.InitActiveInstruIndicator(TradeTool.java:1007)
at COM.Mystrategies.TradeTool.InitAllStatuse(TradeTool.java:436)
at COM.Mystrategies.TradeTool.onStart(TradeTool.java:281)
at com.dukascopy.api.impl.execution.s.call(L:27)
at com.dukascopy.api.impl.execution.s.call(L:13)
at com.dukascopy.api.impl.connect.as.a(L:140)
at com.dukascopy.api.impl.connect.cl.call(L:709)
at com.dukascopy.api.impl.connect.cl.call(L:670)
at com.dukascopy.api.impl.execution.j.call(L:34)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.dukascopy.api.impl.execution.f$a.e(L:904)
at com.dukascopy.api.impl.execution.f$a.run(L:926)
at java.lang.Thread.run(Unknown Source)


getdailybar.jpg [328.02 KiB]
Downloaded 337 times

Author:  API Support [ Thu 24 May, 2018, 13:18 ]
Post subject:  Re: How to get dailyBar in different time zones?

Here best solution would be creation of custom period and make request for bar based on it.

        JFTimeZone myTimeZone = JFTimeZone.EET;//Here you specify your timeZone, for example - EET
        Period myPeriod = Period.createCustomPeriod(Unit.Day, 1, myTimeZone);
        IBar previousDailyBarBasedOnMyTimeZone = history.getBar(Curinstrument, myPeriod, OfferSide.ASK, 1);

Author:  grosskt [ Fri 01 Jun, 2018, 10:38 ]
Post subject:  Re: How to get dailyBar in different time zones?

          JFTimeZone myTimeZone = JFTimeZone.EET;//Here you specify your timeZone, for example - EET
        Period myPeriod =   Period myPeriod = Period.createCustomPeriod(Unit.Minute,30, myTimeZone);( my want to   Period.THIRTY_MINS)
        dukCur_FiveSMA = myIdicator.sma(SpecInstru, myPeriod, OfferSide.ASK, AppliedPrice.CLOSE, 5, 0);

but show exception is:

java.lang.IllegalArgumentException: JFTimeZone is not appropriate for this unit. Received Unit = Minute, numOfUnits = 30, JFTimeZone = EET with standard offset -7200000(milliseconds) and daylight offset -10800000(milliseconds). Offsets cannot be other than 0 for periods with Unit smaller than Unit.Day.
at com.dukascopy.api.Period.createCustomPeriod(Period.java:380)

how to do?

Author:  API Support [ Mon 04 Jun, 2018, 15:17 ]
Post subject:  Re: How to get dailyBar in different time zones?

Custom period creation with time zone different from UTC is supported only for Units greater than 1-hour. For smaller periods this is meaningless, since their filling will be same regardless of time zone.

In your example for the current 30-minutes candle you need just use Period.THIRTY_MINS instead of custom period.

  Page 1 of 1