![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
|
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;
}
}
|
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
|
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;
}
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Feb 2009
Posts: 177
Thanks: 0
Thanked 0 times in 0 posts
|
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
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Hi darckeen, thanks for your post and your code. You're on the right track with your approach and use of the DateTime object.
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |