Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Set Trading hours ...
 Post subject: Set Trading hours ... Post rating: 0   New post Posted: Thu 05 Jul, 2012, 13:22 

User rating: 2
Joined: Tue 08 Nov, 2011, 15:23
Posts: 29
Location: Slovenia,
On back testing the following example is used (by using calendar option):
https://www.dukascopy.com/wiki/#Customiz ... e_Calendar

It seem that is not working for time limit. It returne true for day of the week but always false for time ... Is there any special trick to be used for back testing?


 
 Post subject: Re: Set Trading hours ... Post rating: 0   New post Posted: Thu 05 Jul, 2012, 19:57 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
Hi Federro:

If i understand correctly your problem, when backtesting don't get the time by new instance , but convert tick time or bar time to do the checks.
I have a similar problem when backtesting as the time returned by new instance don't is the real time of the backtesting event but your actual time.

I hope that helps.

Trade well and prospers in your way.

JL


 
 Post subject: Re: Set Trading hours ... Post rating: 0   New post Posted: Fri 06 Jul, 2012, 08:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The calendar-related examples have been fixed, the field Calendar.HOUR was replaced with Calendar.HOUR_OF_DAY.


 
 Post subject: Re: Set Trading hours ... Post rating: 0   New post Posted: Fri 06 Jul, 2012, 14:36 

User rating: 2
Joined: Tue 08 Nov, 2011, 15:23
Posts: 29
Location: Slovenia,
Day Trade limitation works. Time Trade limitation on backTesting always return false. Code sampe:
private boolean isValidTime(int fromHour, int fromMin, int toHour, int toMin, int mondayGO, int tuesdayGO, int wednesdayGO, int thursdayGO, int fridayGo) throws JFException {

boolean isTimeOk = false;
boolean isDayOk = false;
boolean result = false ;

int monday = 0;
int tuesday = 0;
int wednesday = 0;
int thurseday = 0;
int friday = 0;

// Data Formating for DATE CHECK
if (mondayGO == 1) {
monday = 1;
}
if (tuesdayGO == 1) {
tuesday = 2;
}
if (wednesdayGO == 1) {
wednesday = 3;
}
if (thursdayGO == 1) {
thurseday = 4;
}
if (fridayGo == 1) {
friday = 5;
}

if ( dayTime_Limit == 0){ // NO Date Time Check Needed
result = true;
print("Day Time Checking OFF");
}

if ( dayTime_Limit == 1){ // YES Date Time Check is Needed
long lastTickTime = history.getLastTick(selectedInstrument).getTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(lastTickTime);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
calendar.set(Calendar.HOUR, fromHour);
calendar.set(Calendar.MINUTE, fromMin);
calendar.set(Calendar.SECOND, 0);
long from = calendar.getTimeInMillis();

calendar.setTimeInMillis(lastTickTime);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
calendar.set(Calendar.HOUR, toHour);
calendar.set(Calendar.MINUTE, toMin);
calendar.set(Calendar.SECOND, 0);
long to = calendar.getTimeInMillis();

print(String.format("calendar: %s - %s last tick: %s", gmtSdf.format(from), gmtSdf.format(to), gmtSdf.format(lastTickTime)));

isTimeOk = (lastTickTime > from && lastTickTime < to);
print("Day Time Checking ON");
print("IsTimeOK: " + isTimeOk);
print("LastTickTime: " + lastTickTime);
print("from: " + from);
print("to: " + to);

//Checking: Is it DAY OK for Trading?
int currentDayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
isDayOk = ((monday == currentDayOfTheWeek) || (tuesday == currentDayOfTheWeek) || (wednesday == currentDayOfTheWeek) || (thurseday == currentDayOfTheWeek) || (friday == currentDayOfTheWeek));
print("isDayOk: " + isDayOk);
print("currentDayOfTheWeek: " + currentDayOfTheWeek);

// FINAL CHECK ***********************************************************************
result = (isDayOk == true && isTimeOk == true) ;
print("result: " + result);

}

return result;


 
 Post subject: Re: Set Trading hours ... Post rating: 0   New post Posted: Fri 06 Jul, 2012, 14:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please make the same adjustment as we mentioned in the post above.


 

Jump to:  

  © 1998-2025 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