NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Strategy Analyzer

Strategy Analyzer Support for automated system backtesting and optimization using the NinjaTrader Strategy Analyzer.

Reply
 
Thread Tools Display Modes
Old 08-25-2008, 12:25 PM   #1
pmn100
Junior Member
 
Join Date: Aug 2008
Posts: 27
Thanks: 0
Thanked 0 times in 0 posts
Default Create Weekly Time Frame from Daily Data

I'm creating a strategy that needs to verify certain conditions exist in both the daily time frame and weekly time frame. I have historical daily data from Yahoo loaded.

Is it possible to create an array of weekly bar data from daily bar data? Similar to what is explained on this page but instead of creating a 1 minute and a 3 minute array of bar data from 1 minute data, I need to create a daily and weekly array from daily data? Obviously the daily array is default, but how do I get the weekly from the daily data?

Thanks.
pmn100 is offline  
Reply With Quote
Old 08-25-2008, 12:51 PM   #2
pmn100
Junior Member
 
Join Date: Aug 2008
Posts: 27
Thanks: 0
Thanked 0 times in 0 posts
Default

Do I put Add(PeriodType.Day); and Add(PeriodType.Week); in the Initialize() function area, and then access the daily array using BarsArray[1] and access the weekly array using BarsArray[2]?


Or do I enter only Add(PeriodType.Week); in the Initialize() function area, and access the daily data using BarsArray[0] and access the weekly array using BarsArray[1]?


Or is that completely wrong?
Last edited by pmn100; 08-25-2008 at 12:57 PM.
pmn100 is offline  
Reply With Quote
Old 08-25-2008, 01:50 PM   #3
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

>> Or do I enter only Add(PeriodType.Week); in the Initialize() function area, and access the daily data using BarsArray[0] and access the weekly array using BarsArray[1]?
correct
NinjaTrader_Dierk is offline  
Reply With Quote
Old 08-25-2008, 02:57 PM   #4
pmn100
Junior Member
 
Join Date: Aug 2008
Posts: 27
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Dierk
pmn100 is offline  
Reply With Quote
Old 08-26-2008, 10:21 AM   #5
pmn100
Junior Member
 
Join Date: Aug 2008
Posts: 27
Thanks: 0
Thanked 0 times in 0 posts
Default

This isn't working for me.



I've put Add(PeriodType.Week, 1); into the initialize() function area. I've then used the following code example to try and access this bar array:
if (SMA(BarsArray[0], 5)[0] > SMA(BarsArray[0], 50)[0] && SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 50)[0])

{
EnterShort(
1000, "Order1");
}

if (BarsSinceEntry() == 4)
{
ExitShort(
"Order1", "");
}


In English, if the 5 period SMA is above the 50 period SMA on the daily bars and the 5 period SMA is above the 50 period SMA on the weekly bars, enter short.

But this is giving me no orders/no results. I've checked the charts and orders should have been activated.
Last edited by pmn100; 08-26-2008 at 10:27 AM.
pmn100 is offline  
Reply With Quote
Old 08-26-2008, 10:22 AM   #6
pmn100
Junior Member
 
Join Date: Aug 2008
Posts: 27
Thanks: 0
Thanked 0 times in 0 posts
Default

If I delete the Add(PeriodType.Week, 1); and use just the following code, I do get results and orders are activated:
if(SMA(BarsArray[0], 5)[0] > SMA(BarsArray[0], 50)[0])

{
EnterShort(
1000, "Order1");
}

if (BarsSinceEntry() == 4)
{
ExitShort(
"Order1", "");
}

So why isn't it recognising the weekly bar array? I've back tested using the DOW 30 from 2005 onwards, with daily bar data from Yahoo Finance. Daily, weekly, monthly charts display no problem.
pmn100 is offline  
Reply With Quote
Old 08-26-2008, 02:00 PM   #7
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

I suggest adding some Print() statements to see what the values of the SMA on the weekly bars are and etc...
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-26-2008, 02:25 PM   #8
pmn100
Junior Member
 
Join Date: Aug 2008
Posts: 27
Thanks: 0
Thanked 0 times in 0 posts
Default

I've simplified the code now to this:

if (SMA(5)[0] > 1 && SMA(BarsArray[1], 5)[0] > 1)
{
EnterShort(1000, "Order1");
}
if (BarsSinceEntry() == 4)
{
ExitShort("Order1", "");
}
And still no orders. That is simply if the 5 bar SMA is above 1 on both daily and weekly charts. Which they all are.

This is what I've got. What am I not doing right?




protectedoverridevoid Initialize()
{
Add(PeriodType.Week, 1);
Add(SMA(5));

CalculateOnBarClose = true;
}

///<summary>
/// Called on each bar update event (incoming tick)
///</summary>

protectedoverridevoid OnBarUpdate()
{
if (SMA(5)[0] > 1 && SMA(BarsArray[1], 5)[0] > 1)
{
EnterShort(1000, "Order1");
}
if (BarsSinceEntry() == 4)
{
ExitShort("Order1", "");
}
}
pmn100 is offline  
Reply With Quote
Old 08-26-2008, 03:11 PM   #9
pmn100
Junior Member
 
Join Date: Aug 2008
Posts: 27
Thanks: 0
Thanked 0 times in 0 posts
Default

I think I've narrowed it down to BarsSinceEntry() That function doesn't seem to want to work in multi time frames.

I'm using daily and weekly time frames. I want the BarsSinceEntry() to apply to the daily time frame. Is this possible using BarsInProgress or something?
pmn100 is offline  
Reply With Quote
Old 08-26-2008, 11:24 PM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

BarsSinceEntry() needs to be used with the multi-time frame syntax. Please see the Help Guide for more information. We are aware of some bugs with it right now which will be addressed in the next update.
NinjaTrader_Josh 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
Multi-Time Frame & Bar Data Reference michaelbb Strategy Development 3 06-11-2008 07:08 AM
Can't veiw my daily, weekly and monthly charts....HELP... amaruenterprise Charting 6 05-28-2008 11:22 PM
How do I create memory efficient Time Series Data LlewS General Programming 2 01-12-2008 03:10 PM
Displaying daily and weekly data from yahoo? mazachan Historical NinjaTrader 6.5 Beta Threads 2 11-30-2007 12:51 PM
Daily and Weekly Pivots don't work! nightowl Charting 4 03-07-2007 01:00 AM


All times are GMT -6. The time now is 09:22 PM.