If you want to know if the New York Session is currently open you have to take in account the time of year
as New York could be on Eastern Standard Time (EST) or Eastern Daylight Time (EDT).

We can easily do this in our Java code using the following constants

private static int USopen = 8, USclose = 17;
private static String UStimezone = "EST5EDT"; // New York SESSION_HOURS

and then in our onBar logic set up a Calendar to obtain the current time in the required timezone, as follows:

Calendar UScal = Calendar.getInstance(TimeZone.getTimeZone(UStimezone));
UScal.setTimeInMillis(bidBar.getTime());
int UShr = UScal.get(Calendar.HOUR_OF_DAY); // local time in NEW YORK regardless of date
boolean NY_isOpen = UShr>=USopen && UShr
Traducir a inglés Mostrar original