NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 07-21-2009, 02:49 PM   #1
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default ATR - calculate the ATR ticks for the last 7 days

I wish to calculat the Avearge - ATR for the last 7 days from inside a strategy.

it is mulitframe, the primary bars are intraday - 89 tick

so i would:
Add(PeriodType.Minute,
60);

Then i want to get the average value for the ATR for the last 7 days -

convet it into ticks and use it to set my targets dynamically...

tomleeson is offline  
Reply With Quote
Old 07-21-2009, 02:58 PM   #2
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

This can be done through custom programming. There are several threads discussing using ATR for trailing stops and things like that. Please take a look at them and see if they help you.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-21-2009, 03:03 PM   #3
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

I have had a look at quite a few and inspected the code -and drew a blank - as they are mostly indicators and the such like - all i want is a pattern/ method to obtain the ATR for the last 7 days... as a tick value.
I will keep looking
tomleeson is offline  
Reply With Quote
Old 07-21-2009, 03:08 PM   #4
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

Not sure what you mean "tick value". ATR will come out as some range value as determined by the high - low calculation for the various days.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-21-2009, 03:16 PM   #5
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

essentially i wish to get the number of ticks an instrument moves per day - using the last 7 days as the period - but calculate it from a intraday period (so it can achieved in a intrady stratefy)...
Eg.
last 7 day ES was 20 points per day or 80 ticks

i can use the 80 ticks as the basic tradeable oppurtunity.
i thought ATR migh assist in this - maybe i need to look at another pattern
Last edited by tomleeson; 07-21-2009 at 03:20 PM.
tomleeson is offline  
Reply With Quote
Old 07-21-2009, 03:26 PM   #6
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

i found this:
http://www.ninjatrader-support2.com/...e+Range&page=2

somevalue= (ATR(
14)[1] * 0.25) * 100);
i believe the * 100 is there to convert it to to a number versus degrees?
what is the 0.25 (ticks?)
tomleeson is offline  
Reply With Quote
Old 07-21-2009, 03:30 PM   #7
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

Tom, what you outlined in your first post would work, but the larger timeframe must be the primary instrument.
NinjaTrader_Austin is offline  
Reply With Quote
Old 07-21-2009, 03:38 PM   #8
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

Quote:
Originally Posted by tomleeson View Post

somevalue= (ATR(
14)[1] * 0.25) * 100);
i believe the * 100 is there to convert it to to a number versus degrees?
what is the 0.25 (ticks?)
Not sure what the * 100 and the *0.25 mean... If I remember my basic math properties, multiplication is associative so (ATR(14) * 0.25) * 100 = ATR(14) * 25.

In addition, there is a helpful function in NinjaTrader that rounds a value to the nearest tick size. Here is the reference page for Round2TickSize.
NinjaTrader_Austin is offline  
Reply With Quote
Old 07-22-2009, 05:57 AM   #9
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks for your replies:

The smaller time has to be the primary.
The system has been tested with a weekly atr average value.
NT strategy wotn allow me to mix intrady series with weekly series - so i guess i will have to count evrery bar and take an average for each 7 day period.. or create it on another chart and then commuicate this to the running strategy module..:-) through a common static class, a data cache, or maybe even post via a windowsmessage...:-)
tomleeson is offline  
Reply With Quote
Old 07-22-2009, 07:13 AM   #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

tomlesson,

NT for sure does allow you to mix intraday with weekly. You just need to ensure you reach the min. bars required requirement on all bar series. By default this means you need 20 bars which would be a lot of time to achieve 20 weekly bars.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-22-2009, 07:36 AM   #11
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

Tom, I wasn't sure of your programming skills, so I didn't suggest anything too complicated from the start.

You can try this: run your ATR calculations from a daily chart, and then have your strategy communicate with that daily chart to retrieve the values. Here is a reference sample that demonstrates how to expose indicator values. The sample includes a strategy and an indicator--they work together and are a great example.
NinjaTrader_Austin is offline  
Reply With Quote
Old 07-22-2009, 12:59 PM   #12
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
tomlesson,

NT for sure does allow you to mix intraday with weekly. You just need to ensure you reach the min. bars required requirement on all bar series. By default this means you need 20 bars which would be a lot of time to achieve 20 weekly bars.
yes i think i can see how that would work :-)
tomleeson is offline  
Reply With Quote
Old 07-22-2009, 02:23 PM   #13
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Austin View Post
Tom, I wasn't sure of your programming skills, so I didn't suggest anything too complicated from the start.

You can try this: run your ATR calculations from a daily chart, and then have your strategy communicate with that daily chart to retrieve the values. Here is a reference sample that demonstrates how to expose indicator values. The sample includes a strategy and an indicator--they work together and are a great example.
I am checking this out.
thank you!
tomleeson is offline  
Reply With Quote
Old 07-22-2009, 02:25 PM   #14
tomleeson
Member
 
Join Date: Apr 2009
Posts: 45
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
tomlesson,

NT for sure does allow you to mix intraday with weekly. You just need to ensure you reach the min. bars required requirement on all bar series. By default this means you need 20 bars which would be a lot of time to achieve 20 weekly bars.
the default of 20 - can i change that programmatically? is that set when the strategy is added to a chart?
tomleeson is offline  
Reply With Quote
Old 07-22-2009, 02:25 PM   #15
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

BarsRequired = 20;

It can also be set via the UI when you add a strategy.
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
Atr Stop Anthero2000 Strategy Development 3 06-01-2009 11:03 AM
Weighted ATR badasan Indicator Development 1 03-28-2009 12:02 PM
ATR Indicator playafh69 Indicator Development 1 01-01-2009 10:28 PM
ATR plot cptrader Indicator Development 3 12-29-2008 09:28 AM
ATR Stop ATI user Strategy Development 8 09-29-2008 10:12 AM


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