![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
|
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. |
|
|
|
|
|
#5 | |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Quote:
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..
Ray
NinjaTrader Customer Service |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |