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.

Stopping the strategy processing further when the markets are closed?
 Post subject: Stopping the strategy processing further when the markets are closed? Post rating: 0   New post Posted: Mon 12 Feb, 2018, 14:07 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
Hi,

How can I stop the strategy processing furrther when the markets are closed? And when are the markets closed? I know weekends but what about Christmas, NYE, Easter, Japanese holidays etc? I need it to return once the markets are closed and VOLUME = 0. Is it valid to just code as directly below or must I also use askBar.getVolume()?
double inVolume = bidBar.getVolume();
        if (inVolume <= 0.0)
            return;


I have these 2 snippets of code. I know the 2nd one (green) works, but I'm not sure the 1st one does. If the strategy encounters volume = 0.0 and O=C=H=L, e.g. 2/02/2018 22:00 87.237 87.237 87.237 87.237 0, it stops due to caught exception.

1.
long timeOfLastTick = myHistory.getLastTick(instrument).getTime();
        if (myIDataService.isOfflineTime(timeOfLastTick))
            return;


2.
        if (!timeAllowsTrades(instrument, bidBar.getTime(), myBeginTime, myEndTime))
            return;
...
private boolean timeAllowsTrades(Instrument instrument, long barTime, int beginHour, int endHour) throws JFException{
        boolean allowsTrades = false;
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cal.setTimeInMillis(barTime);
        int sysDay  = cal.get(Calendar.DAY_OF_WEEK);
        int sysHour = cal.get(Calendar.HOUR_OF_DAY);
       
        if (sysHour >= beginHour && sysHour < endHour) 
            allowsTrades = true;
       
        if ((sysDay == 6 && sysHour >= 20) || sysDay == 7 || sysDay == 1) // Saturday == 7 || Sunday == 1
            allowsTrades = false;

        return allowsTrades;
    }


I tried searching wiki, but got no definitive answer.

Thanks,
Chrysos.


 
 Post subject: Re: Stopping the strategy processing further when the markets are closed? Post rating: 0   New post Posted: Tue 13 Feb, 2018, 12:30 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Each instrument can have different market hours. They can also change dynamically.
The methods that you described are valid.
JForex has also a separate method that tells if an istrument is currently tradable - IEngine.isTradable


 
 Post subject: Re: Stopping the strategy processing further when the markets are closed? Post rating: 0   New post Posted: Tue 13 Feb, 2018, 21:09 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
Chrysos, in addition to the IEngine.isTradable method linked by API Support above, you might also consider the following sections of the wiki for additional information and context:

Home > Development > Strategy API > Instruments > Instrument tradability
Home > Development > Strategy API > Instruments > Market Hours


 
 Post subject: Re: Stopping the strategy processing further when the markets are closed? Post rating: 0   New post Posted: Wed 14 Feb, 2018, 06:59 

User rating: 1
Joined: Mon 01 Sep, 2014, 13:39
Posts: 34
Location: AustraliaAustralia
Thanks API Support and CriticalSection,

I'm almost thinking to go with
double inVolume = bidBar.getVolume();
        if (inVolume <= 0.0)
            return;


This is because I've noticed some pairs have a low volume when others do not during holiday periods. Also, I've used some methods like isTradable and I get the error
Reason: Strategy <EMT_TEST> is going to be stopped - Max overload period exceeded : 60 seconds


My strategy trades 16 instruments on the 4HR and I had this error a lot, but I changed the code to sleep after subscribing and submitting orders etc.

I suppose I should trade less instruments but that means more than 1 strategy.

Regards,
Chrysos.


 

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