Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

How to realise work strategy by time
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=169
Page 1 of 1

Author:  [fxprogrammer] [ Tue 09 Sep, 2008, 19:38 ]
Post subject:  How to realise work strategy by time

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.

Author:  RoadRunner [ Tue 09 Sep, 2008, 21:43 ]
Post subject:  Re: How to realise work strategy by time

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.

Author:  API Support [ Wed 10 Sep, 2008, 14:30 ]
Post subject:  Re: How to realise work strategy by time

There is no built in functionality for this. Only as RoadRunner says, you can implement it yourself

Author:  [fxprogrammer] [ Thu 18 Sep, 2008, 12:01 ]
Post subject:  Re: How to realise work strategy by time

Thanks for your help. But I don't understand how to translate "long" variables to hours and days.

Author:  API Support [ Fri 19 Sep, 2008, 11:22 ]
Post subject:  Re: How to realise work strategy by time

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

  Page 1 of 1