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.

Timezone used in strategy on live trading and backtesting
 Post subject: Timezone used in strategy on live trading and backtesting Post rating: 0   New post Posted: Wed 30 Jul, 2014, 19:22 

User rating: 0
Joined: Wed 22 Feb, 2012, 16:22
Posts: 2
Hi everyone!

In the strategy I'm developing now the orders should be sent in the defined time interval between 21 and 23 +0000 UTC.

As I understand, the bars on charts are shown in +0000 UTC, but the as the result of function call
tick.getTime()
I get time in my current timezone (UTC +3). So to get hour is UTC, I use the following code:

   Calendar cal = Calendar.getInstance();
   TimeZone current_tz = cal.getTimeZone();
   Date date = cal.getTime();
   long UTCOffset=current_tz.getOffset(date.getTime());//get local computer timezone shift
   
   Time = curTick.getTime()-UTCOffset;//tick time in +0000 UTC
   
   calendar.setTimeInMillis(Time);
   
   EA_GMTTime = calendar.get(Calendar.HOUR_OF_DAY); //get current hour in +0000 UTC


Can you please check, if this code is correct, and will it work correct on strategy backtesting?

Also I would like to know, in what time zone (local or UTC )order opening and closing time are shown in the html report, that appears after the backtesting is done?


 
 Post subject: Re: Timezone used in strategy on live trading and backtesting Post rating: 0   New post Posted: Thu 31 Jul, 2014, 14:56 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ili4 wrote:
but the as the result of function call
tick.getTime()
I get time in my current timezone (UTC +3).
This is not the case, JForex-API works with UTC+0. You can check that it is the case by simply printing to the console tick.toString() or DateUtils.format(tick.getTime).
See the following examples on how to work with the Timezones and calendar:
https://www.dukascopy.com/wiki/#Customize_trading_hours
If you still don't manage to resolve this, please post full example strategy of yours which would demonstrate the problem. Also please provide the screenshot of the Historical Tester settings that you use.


 
 Post subject: Re: Timezone used in strategy on live trading and backtesting Post rating: 0   New post Posted: Thu 31 Jul, 2014, 18:46 

User rating: 0
Joined: Wed 22 Feb, 2012, 16:22
Posts: 2
Thnaks, looks like I missed in my code a line:

calendar.setTimeZone(TimeZone.getTimeZone("GMT"));


Also thanks for a link, it is exactly that I need.


 

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