NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 03-04-2009, 11:31 AM   #1
darckeen
Senior Member
 
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
Default Better way to check for weekend/data integrity?

I'm looking for a way to exit positions prior to the weekend and then resume the strategy at the begining of the next week after BarsRequired has been seen on the new week. The idea is to eliminate the gaps over the weekend but maintain positions during the week. Additionally I'd like to be able to foresee data gaps that occur in the series that also produce gaps, say when the data series on 10 min data jumps 4 hours between bars. I put together some code to try to accomplish these goals but i was wondering if there might be a better way to go about this.
darckeen is offline  
Reply With Quote
Old 03-04-2009, 11:34 AM   #2
darckeen
Senior Member
 
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
Default

Code:
privatebool isWeekend = false;
privateint sundayOpen = -1;
 
DateTime date = Time[0];
if (CurrentBar == 1) {
Print("Setting initial date");
switch (date.DayOfWeek) {
case DayOfWeek.Friday:
if(date.Hour >= 16) { isWeekend = true; }
break;
case DayOfWeek.Saturday:
isWeekend = true;
break;
case DayOfWeek.Sunday:
if(date.Hour < 20) { isWeekend = true; }
break;
}
}
darckeen is offline  
Reply With Quote
Old 03-04-2009, 11:35 AM   #3
darckeen
Senior Member
 
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
Default

Code:
switch (date.DayOfWeek) {
case DayOfWeek.Friday:
if(date.Hour >= 16 || (date.Hour == 15 && date.Minute == 59)) {
if (Position.MarketPosition == MarketPosition.Long) { ExitLong(); }
if (Position.MarketPosition == MarketPosition.Short) { ExitShort(); }
isWeekend = true;
sundayOpen = -1;
}
break;
case DayOfWeek.Sunday:
if (date.Hour == 20 && date.Minute == 0) { 
sundayOpen = CurrentBar; 
Print("Japan open " + Time[0].ToString() + " " + sundayOpen);
}
if (isWeekend && sundayOpen != -1 && CurrentBar >= sundayOpen + BarsRequired) { 
isWeekend = false; 
Print("Enough bars " + Time[0].ToString() + " " + sundayOpen);
}
break;
case DayOfWeek.Monday:
if (isWeekend) {
if (sundayOpen == -1) {
sundayOpen = CurrentBar;
} elseif (CurrentBar >= sundayOpen + BarsRequired) {
isWeekend = false;
}
}
break;
}
darckeen is offline  
Reply With Quote
Old 03-04-2009, 11:37 AM   #4
darckeen
Senior Member
 
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
Default

Code:

// Known data gaps
if (date == new DateTime(2007,3,2,16,0,0) ||
date == new DateTime(2007,4,5,3,3,0))
) 
{
if (Position.MarketPosition == MarketPosition.Long) { ExitLong(); }
if (Position.MarketPosition == MarketPosition.Short) { ExitShort(); }
isWeekend = true;
sundayOpen = -1;
}
if (isWeekend) { return; }
#endregion
darckeen is offline  
Reply With Quote
Old 03-04-2009, 01:06 PM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

Hi darckeen, thanks for your post and your code. You're on the right track with your approach and use of the DateTime object.
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data minutes shifted 1 day and weekend issue WhoKnows Strategy Analyzer 11 12-16-2008 06:17 AM
Weekend stock data TraderGreg Charting 13 07-24-2008 11:16 PM
Weekend data moon_rainz Charting 4 07-20-2008 09:40 PM
New 6.5 version-Weekend Data not showing up stevebong Charting 7 04-14-2008 11:13 PM
Weekend data not triggering on secondary time series gert74 Strategy Development 12 08-28-2007 08:12 PM


All times are GMT -6. The time now is 01:11 PM.