Go Back   NinjaTrader Support Forum > NinjaTrader 7 > 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: 114
Thanks: 15
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_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 434 times in 427 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_RyanM1 is offline  
Reply With Quote
Old 02-03-2011, 11:15 AM   #3
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 114
Thanks: 15
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_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 434 times in 427 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_RyanM1 is offline  
Reply With Quote
Old 02-03-2011, 03:39 PM   #5
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 114
Thanks: 15
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_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 434 times in 427 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_RyanM1 is offline  
Reply With Quote
Old 02-03-2011, 03:51 PM   #7
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 114
Thanks: 15
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_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 434 times in 427 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_RyanM1 is offline  
Reply With Quote
Old 02-04-2011, 02:42 AM   #9
AntiMatter
Senior Member
 
Join Date: Dec 2010
Posts: 114
Thanks: 15
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_RyanM1
NinjaTrader Customer Service
 
NinjaTrader_RyanM1's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,127
Thanks: 249
Thanked 434 times in 427 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_RyanM1 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 Platform Technical Support 15 05-06-2011 06:17 AM
Minute and Daily Historical Data. Scooter1 Platform Technical Support 1 12-15-2008 09:00 AM
MA Daily Volume not updating realtime TF Angler Platform Technical Support 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 04:03 PM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.