NinjaTrader Support Forum  

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 04-24-2008, 10:08 AM   #1
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default Multitime frequency system

Hi

I developed a system on 1min bars, I want to put a condition on the 5min bars.
I did so:

protected override void Initialize()
{
Add(PeriodType.Minute, 5);

Add(EMA(20));

CalculateOnBarClose = true;
}

// Condition set 1

if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])


{
...
}


Then I run it on 1m data. Is it correct? I'm asking because, when I watch the 1m chart of the back test, I see plotted the two EMAs (but they're supposed to be calculated on 5m!).
Does BarsArray[1] automatically refers to the 5m data only, or I should use another BarsArray[2] for the 1m data (which I don't think makes sense anyway).

Thank you a lot
stefy is offline  
Reply With Quote
Old 04-24-2008, 10:37 AM   #2
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

BarsArray[0] = 1 minute
BarsArray[1] = 5 minute

In C#, indexes are zero based.

You also have to fitler OnBarUpdate() events by BarsInProgress

if (BarsInProgress == 0)
// Process my 1 minute bars
else if (BarsInProgress == 1)
// Process my 5 minute bars
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-24-2008, 02:20 PM   #3
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you, Ray.
I want to use just the 1min bars (using the 5min just to calculate the averages). So I added:
if (BarsInProgress != 0)
return;
as in the SampleMultiframe.

Now it looks like:

protected override void Initialize()
{
Add(PeriodType.Minute, 5);

Add(EMA(20));

CalculateOnBarClose = true;
}

if (BarsInProgress != 0)
return;

// Condition set 1

if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])


{
...
}


Is that correct now?

Thank you
stefy is offline  
Reply With Quote
Old 04-24-2008, 02:56 PM   #4
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

I had some problems with this last year when I was trying to do this.

If memory serves me, there's a basic problem with checking bars on a DataSeries from another timeframe.

The problem stems from the fact that there will be a different number of bars for the 1-Min and 5-Min timeframes, and I don't think the indicators (such as EMA that you're trying to use) are written to take this into account.

Therefore, I don't think the calculations will work correctly when you're running in the 1-Min (primary) timeframe and you try to invoke EMA for the 5-Min timeframe DataSeries.

The solution I used at the time was to re-code the logic of the indicator within my strategy being sure to take this into account.
KBJ is offline  
Reply With Quote
Old 04-24-2008, 03:07 PM   #5
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

Quote:
Originally Posted by stefy View Post
Thank you, Ray.
I want to use just the 1min bars (using the 5min just to calculate the averages). So I added:
if (BarsInProgress != 0)
return;
as in the SampleMultiframe.

Now it looks like:

protected override void Initialize()
{
Add(PeriodType.Minute, 5);

Add(EMA(20));

CalculateOnBarClose = true;
}

if (BarsInProgress != 0)
return;

// Condition set 1

if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])


{
...
}


Is that correct now?

Thank you
Incorrect.

if (BarsInProgress == 1) return;

is what you want.

Now this method is called only on the 1 minute chart.

Then your code

if (EMA(BarsArray[1], 2)[0] > EMA(BarsArray[1], 20)[0])

is saying

if (2 period ema on 5 minute is greater than 20 period ema on 5 minute) do something..
NinjaTrader_Ray 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
Grid Line Frequency neuronicnobody Charting 5 05-07-2012 06:57 AM
BuySellVolume/backfill and change frequency cherriman Charting 2 04-18-2008 11:43 AM
Maximum frequency of order modification allowed? MarkSanDiego Automated Trading 1 02-27-2008 02:15 PM
High Frequency Systems Futures_Shark Automated Trading 7 02-12-2008 02:48 AM
Update frequency of multiple data series in a Strategy ThePatientOne Strategy Development 1 05-02-2007 10:05 AM


All times are GMT -6. The time now is 08:44 AM.