PDA

View Full Version : Strategy - different time frames


tonynt
04-16-2010, 03:11 PM
Hello,

I have a problem to write a condition in a strategy that refers to 2 different timeframes. Iīve seen in the supportpage the information to this matter but as the example there is different I donīt understand how to do it. I would like to say eg: "if RSI in a 5-Range-chart crosses itīs average and in the 15-Range-chart is Rising(EMA(14)) == true then go long."

I donīt understand what is to add in the Initialize-section and what in the conditions.:confused:

Thanks in advance for any info how to write this.

Best regards
Tony:)

NinjaTrader_RyanM
04-16-2010, 03:49 PM
Hello Tonynt,

There will be an underlying series and this is referenced with index [0] or BarsInProgress 0. This is the chart or the instrument selected that you apply the strategy to.

Any further series are added to the Initialize method. You then use BarsInProgress (http://www.ninjatrader-support.com/HelpGuideV6/CurrentBarSeries.html) checks to define which series you're working with. Secondary objects are accessed with BarsArray (http://www.ninjatrader-support.com/HelpGuideV6/BarSeries.html)

Let's say that the 5 range chart is your underlying instrument and your 15-range chart is secondary.

You add the statement below to the Initialize() method to add your secondary range series.
Add(PeriodType.Range, 15);

For your first condition you need to specify BarsArray = 0 to refer to the first object.
(CrossAbove(RSI(BarsArray[0], 3,1), SMA(RSI(BarsArray[0], 3,1), 14), 1))


For your second condition, you refer to BarsArray = 1 for the secondary series. Combining them together will look like this:


if (BarsInProgress == 0)
{
if (CrossAbove(RSI(BarsArray[0], 3,1), SMA(RSI(BarsArray[0], 3,1), 14), 1) && Rising(EMA(BarsArray[1], 14)))
{
placeYourOrdersHere;
}
}

tonynt
04-16-2010, 04:28 PM
Thanks for your help. Have a great day!
Tony