I won't do the work for you, but I'll give you a description of what I did to give you a nudge in my direction at least, if not the 'right' direction.
What I did originally was something like the following:
import java.util.*;
public class SomeClass {
//...
public GregorianCalendar currentDate = new GregorianCalendar();
// constructor
public void SomeClass () {
currentDate.setTimeZone ( TimeZone.getTimeZone ( "UTC" ) );
}
public void onBar ( Instrument instrument,
Period period,
IBar askBar,
IBar bidBar )
throws JFException,
IllegalStateException {
if ( period == Period.TEN_SECS ) { // or whatever period you're working in
currentDate.setTimeInMillis ( bidBar.getTime() );
int hourOfDay = currentDate.get ( Calendar.HOUR_OF_DAY );
if ( hourOfDay >= 6 && hourOfDay <= 18 ) {
// continue with strategy execution
}
}
}
//...
}
This is not a bad approach to solving the problem, but it can be pretty limited. It can also lead to spaghetti code because you could end up adding conditions all over the place to test things: if this time, then this, else if this time do that, etc etc.
Depending on how complex you want your strategy to be, you might consider adding a state machine. You'd still have date/time checks in there, but if you follow that design strategy correctly you'll only be checking date/time stuff under certain states, analyzing data in another, closing/opening orders in yet another, etc. It helps keep your code separate, reduces complexity, and generally makes your life simpler.
-Brian