bhavneesh wrote:
Hi,
I want to reconfigure this strategy to trade only from 8 am-12 pm EST (NY Time). How can the code be rewritten to allow this?
Thanks a lot.
Put the first line in onBar method. This line checks if the period is 5 or 1 min. If it's not, then we exit the method with return command.
if (period == Period.FIVE_MINS || period == Period.ONE_MIN) return; bhavneesh wrote:
Also, if I want to trade on 5 min or 1 min charts only, how do I modify the code.
It's a bit more tricky to do! First of all, note that we use GMT but not EST. So it's better to convert EST time to GMT using a service like this one
https://www.timezoneconverter.com/cgi-bin/tzc.tzcIt will be equal to 13-17 GMT.
Now all you need to do is to retrieve the current time and compare it to 13-17 zone.
long timeInMilliis = bidBar.getTime();
Calendar time = Calendar.getInstance();
time.setTimeZone(TimeZone.getTimeZone("GMT"));
time.setTimeInMillis(timeInMilliis);
int currentHour = time.get(Calendar.HOUR_OF_DAY);
if (currentHour < 13 || currentHour >17) return;We take the current hour from the bidBar and exit the onBar method if the time is not withing the zone.