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.

check time
 Post subject: check time Post rating: 0   Post Posted: Mon 29 Oct, 2012, 01:55 

User rating: 0
Joined: Thu 03 Nov, 2011, 21:46
Posts: 68
Location: Russian Federation,
hello support,
please help:

in parameters:
 @Configurable("Open hour")
    public int openHour = 0;
    @Configurable("Open min")
    public int openMin = 0;
    @Configurable("Open day")
    public DayOfWeek openDayOfWeek = DayOfWeek.MONDAY;

    @Configurable("Close hour")
    public int closeHour = 24;
    @Configurable("Close min")
    public int closeMin = 0;
    @Configurable("Close day")
    public DayOfWeek closeDayOfWeek = DayOfWeek.FRIDAY;

if (!isInInterval(tick.getTime(), openDayOfWeek.getIdx(), openHour, openMin, closeDayOfWeek.getIdx(), closeHour, closeMin)) {
       return;
       }

How check for every day period ?
example need work time only:
MONDAY from ( 2- 14)
TUESDAY from ( 2-14 )
WEDNESDAY from ( 2-14)
THURSDAY from ( 2 -14 )
FRIDAY from (2 -14 )

Thank You


 
 Post subject: Re: check time Post rating: 0   Post Posted: Mon 29 Oct, 2012, 08:12 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#Customize_trading_hours/Use_Calendar_weekdays


 
 Post subject: Re: check time Post rating: 0   Post Posted: Mon 29 Oct, 2012, 08:36 

User rating: 0
Joined: Thu 03 Nov, 2011, 21:46
Posts: 68
Location: Russian Federation,
I have this,
I have in code:
public void onTick(Instrument instrument, ITick tick) throws JFException {

if (!isInInterval(tick.getTime(), openDayOfWeek.getIdx(), openHour, openMin, closeDayOfWeek.getIdx(), closeHour, closeMin)) {
return;
}

BUT: this code for work full week.

I need work in specific time everyday:

MONDAY from ( 2- 14)
TUESDAY from ( 2-14 )
WEDNESDAY from ( 2-14)
THURSDAY from ( 2 -14 )
FRIDAY from (2 -14 )


how make it here?

if (!isInInterval(tick.getTime(), ???????? ) {
return;
}

this not work:
if (!isInInterval(tick.getTime(), openDayOfWeek.MONDAY.getIdx(), openHour, openMin, closeDayOfWeek.MONDAY.getIdx(),closeHour, closeMin)) {
}
else if (!isInInterval(tick.getTime(), openDayOfWeek.TUESDAY.getIdx(), openHour, openMin, closeDayOfWeek.TUESDAY.getIdx(), closeHour, closeMin)) {
}


 
 Post subject: Re: check time Post rating: 0   Post Posted: Mon 29 Oct, 2012, 11:01 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi maxi:

I have a strategy you can use snipets of it to do what you want.

 /**
     * Controls time paramenters and sets if it's possible to trade at given time paramenters
     * Also close all orders if we are outside time interval
     *
     * @param barTime
     * @param bHour
     * @param eHour
     * @param weekend
     * @return
     */
    private boolean timeAllowsTrades(long barTime, int bHour, int eHour, boolean weekend) throws JFException{
        boolean allowsTrades = false;
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cal.setTimeInMillis(barTime);
        int day = cal.get(Calendar.DAY_OF_WEEK);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
       
        if (hour >= bHour && hour < eHour) allowsTrades = true;
        if (weekend && (day == 1 || day == 7)) allowsTrades = false;
        if (!allowsTrades) closeAllOrders();
        return allowsTrades;
    }// End timeAllowsTrades


You can see complete strategy in strategy contest if you want or here -> viewtopic.php?p=65302#p65302

I hope this helps

Trade well and prospers in your way.

JL


 

Jump to:  

  © 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