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.

HOUR_OF_DAY question
 Post subject: HOUR_OF_DAY question Post rating: 0   New post Posted: Thu 26 Feb, 2009, 02:45 

User rating: 0
Joined: Mon 09 Feb, 2009, 22:35
Posts: 5
Hello all,

I am using (calendar.get(Calendar.HOUR_OF_DAY) to return the current hour, as I am trying to get my system to trade only during certain times. However, this function is returning my time zone, and not the Time Value shown on Duka's charts. This creates problems during backtesting, as I only trade during certain hours. Is there a way to get JForex to get the time value shown by Duka's charts, so that I can make sure my system is only trading when it is supposed to be?

Thanks everyone. :)


 
 Post subject: Re: HOUR_OF_DAY question Post rating: 0   New post Posted: Thu 26 Feb, 2009, 15:30 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,

according to Java Docs:

HOUR_OF_DAY
Field number for get and set indicating the hour of the day. HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.


The JForex platform uses GMT=0, so you need to initialize your calendar instance correctly:
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT 0"));
After creating such an instance it will be in sync with the platform and you cat fetch required time fields using appropriate constants, e.g. HOUR_OF_DAY.

If you are using the backtester you should reset calendar instance time, because you operate with historical data and not with the current time. Each time you get data from historical tester, you should set time to your calendar instance using this method:

public void setTimeInMillis(longВ millis)
Sets this Calendar's current time from the given long value.


and then fetch the appropriate time field.


 
 Post subject: Re: HOUR_OF_DAY question Post rating: 0   New post Posted: Tue 29 Sep, 2009, 16:45 

User rating: 0
Joined: Thu 27 Aug, 2009, 12:09
Posts: 23
I'm having to code for the same issue with backtesting.

My question is though, is it safe to set the calendar time on each tick regardless if it's backtesting or not?

If not how do I detect if it's not backtesting and avoid setting it?

Thanks


 
 Post subject: Re: HOUR_OF_DAY question Post rating: 0   New post Posted: Wed 30 Sep, 2009, 15:43 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
answering on your question - YES it's safe
even if you are running in real time you can set time of the tick in your calendar and it will return correct hour of the latest tick

to detect what is running you can use context.getEngine().getType(), which in case of "backtesting" will return you "TEST". If it's real time execution then it will return DEMO or LIVE depending on what evironment is used


 

Jump to:  

cron
  © 1998-2025 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