Dukascopy
 
 
Wiki JStore Search Login

Timed strategy trading
 Post subject: Timed strategy trading Post rating: 0   New post Posted: Fri 12 Nov, 2010, 04:00 

User rating: -
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? Also, if I want to trade on 5 min or 1 min charts only, how do I modify the code.

Thanks a lot.


 
 Post subject: Re: Timed strategy trading Post rating: 0   New post Posted: Fri 12 Nov, 2010, 15:45 
User avatar

User rating: 8
Joined: Wed 21 Apr, 2010, 10:42
Posts: 1167
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.tzc
It 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.


 

Jump to:  

  © 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