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 realise work strategy by time
 Post subject: How to realise work strategy by time Post rating: 0   New post Posted: Tue 09 Sep, 2008, 19:38 

User rating: 0
Joined: Tue 09 Sep, 2008, 18:55
Posts: 9
Hello!

Is it any method which can realise work strategy by time( of certain hours or/and certain dates)? If it is possible, help me with sample.


 
 Post subject: Re: How to realise work strategy by time Post rating: 0   New post Posted: Tue 09 Sep, 2008, 21:43 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
Why not use strategyStart/End-parameters and check for the time in onTick() ?

you could use something like:
private Calendar calStart=...
private Calendar calEnd=...

to set specific datetime for the start/end or

private int hourStart=...
private int hourEnd=...

if you only want to set certain trading hours...

and then in onTick() use:

if (tick.getTime() >= calStart.getTime().getTime() &&
tick.getTime() <= calEnd.getTime().getTime() )
{
... do your trades...
}
else
{
... no trading time... --> maybe close trades that are still open, etc.
}

If you have several trading periods you could use arrays for your start/end-parameters.

Hope this helps.
Greetings, R.


 
 Post subject: Re: How to realise work strategy by time Post rating: 0   New post Posted: Wed 10 Sep, 2008, 14:30 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
There is no built in functionality for this. Only as RoadRunner says, you can implement it yourself


 
 Post subject: Re: How to realise work strategy by time Post rating: 0   New post Posted: Thu 18 Sep, 2008, 12:01 

User rating: 0
Joined: Tue 09 Sep, 2008, 18:55
Posts: 9
Thanks for your help. But I don't understand how to translate "long" variables to hours and days.


 
 Post subject: Re: How to realise work strategy by time Post rating: 0   New post Posted: Fri 19 Sep, 2008, 11:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT 0"));
calendar.setTimeInMillis(timeToBeTranslated);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);

If you have another time zone rather than GMT 0, set correct number for this time zone e.g. for Geneva use 1.
The time zone of the incoming data (ticks, candles) is 0.

You can also get other fields from calendar, please see this link for more details: https://java.sun.com/javase/6/docs/api/j ... endar.html

For online conversion this link could be useful: https://www.onlineconversion.com/unix_time.htm


 

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