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.

How to get dailyBar in different time zones?
 Post subject: How to get dailyBar in different time zones? Post rating: 0   New post Posted: Mon 14 May, 2018, 16:36 

User rating: 0
Joined: Mon 11 Dec, 2017, 03:30
Posts: 26
Location: China,
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;
       
        if(Specperiod.equals(Period.DAILY))
        {
             long lastTickTime = history.getLastTick(SpecInstru).getTime();
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeZone(TimeZone.getTimeZone("GMT+2"));
            calendar.setTimeInMillis(lastTickTime);
            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);
        }

.................................................................
exception
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)




Image


Attachments:
getdailybar.jpg [328.02 KiB]
Downloaded 510 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.
 
 Post subject: Re: How to get dailyBar in different time zones? Post rating: 0   New post Posted: Thu 24 May, 2018, 13:18 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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);
        console.getOut().println(previousDailyBarBasedOnMyTimeZone);


 
 Post subject: Re: How to get dailyBar in different time zones? Post rating: 0   New post Posted: Fri 01 Jun, 2018, 10:38 

User rating: 0
Joined: Mon 11 Dec, 2017, 03:30
Posts: 26
Location: China,
*/
          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)

why?
how to do?


 
 Post subject: Re: How to get dailyBar in different time zones? Post rating: 0   New post Posted: Mon 04 Jun, 2018, 15:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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.


 

Jump to:  

  © 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