NinjaTrader Support Forum  
X

Attention!

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


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-28-2010, 09:53 AM   #1
gg80108
Senior Member
 
Join Date: Dec 2008
Location: Castle Pines, Co
Posts: 621
Thanks: 1
Thanked 2 times in 2 posts
Default Multi Time Frame Trigger

I want to trigger an order if two different TimeFrames agree ie: 5 min shows a buy and 1 min shows a buy then buy..
Can I do this with the BarsInProgress?
gg80108 is offline  
Reply With Quote
Old 04-28-2010, 10:27 AM   #2
pmaglio
Senior Member
 
Join Date: Oct 2007
Location: Argentina
Posts: 175
Thanks: 2
Thanked 19 times in 14 posts
Send a message via Yahoo to pmaglio Send a message via Skype™ to pmaglio
Default

1st : Code your strategy to be placed on the lowest time frame ( 1Min )
2nd : On Initialize() add " Add(PeriodType.Minute,5);
3rd : On OnBarUpdate() is going to run each time a bar closes on both timeframes
You can check that by if (BarsInProgress == 0) then 1Min bar is triggering
Then u can check a condition ( like SMA(50)[0] ) on both timeframes by
SMA(BarsArray[1], 20)[0] // for the 5 Min
SMA(Close, 20)[0] // fro the 1 min
pmaglio is offline  
Reply With Quote
Old 04-28-2010, 10:27 AM   #3
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello gg80108,

Thank you for your post.

You need to use a combination of BarsInProgress, BarsArray, and Closes, Opens, Highs, Lows for this. The snippet below buys when Close is greater than the 14 period SMA for the two different series. The BarsInProgress == 0 check will ensure that this is only performed during updates to the primary series but the BarsArray and Closes properties tell it to look at values in the secondary series.

Code:
 
if (BarsInProgress == 0)
{
if(Close[0] > SMA(Close, 14)[0] && Closes[1][0] > SMA (BarsArray[1], 14)[0])
EnterLong();
}
The following link will take you to the strategy multi-time-frame article of our help guide:
http://www.ninjatrader-support.com/H...struments.html
NinjaTrader_RyanM is offline  
Reply With Quote
Old 04-28-2010, 10:29 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Excellent. Thanks for sharing, pmaglio!
NinjaTrader_RyanM is offline  
Reply With Quote
Old 09-08-2010, 02:00 PM   #5
ssylwester
Senior Member
 
Join Date: Aug 2010
Location: Locust Valley, NY
Posts: 102
Thanks: 0
Thanked 0 times in 0 posts
Default

Interesting thread. I'm still stuck though.
I'm trying to do a two step entry. Run a handful of proprietary indicators on a longer time frame, eg 50 ticks. If those conditions are met (a bunch of them), then run some proprietary indicators on shorter time frame, eg 5 tck bars, but only for about 2 periods of the longer timer frame.
Any assistance would be helpful (v 6.5)
Steve
ssylwester is offline  
Reply With Quote
Old 09-08-2010, 02:18 PM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Steve,

Thank you for your post.

You can see a sample multi time frame strategy by clicking Tools > Edit NinjaScript > Strategy > Sample Multitime frame.

If you only want to evaluate your secondary series after the primary series is true, you can set and check bool values to code the sequence you're looking for.

if (firstSeriesConditions)
evaluateSecondSeriesNow = true;

if (evaluateSecondSeriesNow && secondSeriesConditions)
//place orders here

Someplace later you would reset the bool values - possibly when flat.
NinjaTrader_RyanM 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 Strateg toptrader General Programming 13 01-20-2010 07:08 AM
Multi-Instrument Multi-Time frame strategy Shansen Strategy Development 1 12-28-2009 06:09 AM
Multi-time frame strategy - Longer-term real-time calculations Shansen Strategy Development 1 04-19-2009 06:36 AM
Multi Time Frame/Multi Instrument? GreenTrade Strategy Development 3 01-14-2008 02:24 PM
Multi-time frame scjohn Strategy Development 1 06-06-2007 07:20 PM


All times are GMT -6. The time now is 05:55 PM.