NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-03-2011, 10:56 AM   #1
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 102
Thanks: 13
Thanked 2 times in 1 post
Default Getting the daily volume MA from within a minute script

I have been trying to do this all day, and seem to just be getting further away and confusing myself further....??!!!

I have a strategy which is on a 5 minute timeframe.

I need an average of the volume over e.g. the last 100 days. Only for today. That is all.

I have tried adding a Add(PeriodType.Daily, 1). However, it doesn't seem to work right. Am I not loading sufficient historic bars? Do I need to overload a dataseries object?

An easier way would be if I could call the VOLMA indicator, but instead of using the DataSeries from which I called it, could I not call the VOLMA indicator specifying a daily timeframe?

Thanks in advance
AntiMatter is offline  
Reply With Quote
Old 02-03-2011, 11:14 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,128
Thanks: 249
Thanked 427 times in 423 posts
Default

Hello antimatter,

You're likely on the right track with making sure you have enough historical bars loaded.

Once you add the series with this:
Add(PeriodType.Day, 1);

Accessing the 100 day volume average is:
double myDouble = SMA(Volumes[1], 100)[0];

You'll have to make sure you load enough days on your chart, and check the log tab for any error messages.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-03-2011, 11:15 AM   #3
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 102
Thanks: 13
Thanked 2 times in 1 post
Default

How about if I want to put it in a strategy, and load that strategy from the control centre?
AntiMatter is offline  
Reply With Quote
Old 02-03-2011, 11:33 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,128
Thanks: 249
Thanked 427 times in 423 posts
Default

These principles work in an indicator or a strategy. There is a sample multiTime frame strategy built into the platform. Click Tools > Edit NinjaScript > Strategy > SampleMultiTimeFrame. Documentation is available here:
http://www.ninjatrader.com/support/h...nstruments.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-03-2011, 03:39 PM   #5
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 102
Thanks: 13
Thanked 2 times in 1 post
Default

OK, so something like this...
Run my strategy with Paramater "Days to Load" = 100

Then:

protected override void Initialize()
{

Add(PeriodType.Day, 1);

.....etc


Later....


protected override void OnBarUpdate()
{

double vol = ( VOLMA(BarsArray[1], 100)[0]);


...etc


Should be the 100 day MA?
AntiMatter is offline  
Reply With Quote
Old 02-03-2011, 03:46 PM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,128
Thanks: 249
Thanked 427 times in 423 posts
Default

Yes, that should work as well. To confirm the value is what you expect, print it.

Print(vol);

View in the Tools > output window. Additional help for debugging is available here:
http://www.ninjatrader-support.com/v...ead.php?t=3418
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-03-2011, 03:51 PM   #7
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 102
Thanks: 13
Thanked 2 times in 1 post
Default

Getting there, thanks for the help....

What I really want to do, is just run this bit of code once at the start of each code.
I want to find the 100 day MA of the volume for the last 100 days, on this day (today).

Then if the volume is below a certain quantity, I can kill the strategy.

At the moment, I am running this on each bar update. Ideally, I just want to do this once, but only on the most current bar. But I want to access the latest bar from the when the script is started..... rather than cycling through all the last 100 days....???!!
AntiMatter is offline  
Reply With Quote
Old 02-03-2011, 05:57 PM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,128
Thanks: 249
Thanked 427 times in 423 posts
Default

You can custom code the conditions for calculating this indicator, but must be objective about what you want to express. If you only wanted the calculated value on historical data (data prior to starting the strategy), you could enclose the calculations in a block like this:

if (Historical)
{
//indicatorCalcs here
}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-04-2011, 02:42 AM   #9
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 102
Thanks: 13
Thanked 2 times in 1 post
Default

How would I know it was the last historical bar? e.g. the most recent data?
AntiMatter is offline  
Reply With Quote
Old 02-04-2011, 12:00 PM   #10
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,128
Thanks: 249
Thanked 427 times in 423 posts
Default

You can store bar values with CurrentBar.

if (Historical)
int myBar = CurrentBar.

That will update myBar with the last historical, CurrentBar value.
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
Daily vs Minute bar mismatch? ErikHR Automated Trading 15 05-06-2011 06:17 AM
Different daily and minute data mpe66 Version 7 Beta General Questions & Bug Reports 7 08-10-2010 08:44 AM
Minute and Daily Historical Data. Scooter1 Charting 1 12-15-2008 09:00 AM
MA Daily Volume not updating realtime TF Angler Market Analyzer 1 10-19-2008 10:17 AM
KAMA and HULL MA - is anybody able to covert to NINJA script? Akros Indicator Development 15 06-21-2007 06:55 AM


All times are GMT -6. The time now is 10:20 AM.