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 > Indicator Development

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

Reply
 
Thread Tools Display Modes
Old 08-06-2012, 03:45 PM   #1
saturntd
Junior Member
 
Join Date: May 2009
Posts: 26
Thanks: 0
Thanked 1 time in 1 post
Default How to assign dataseries to indicator

I'm trying to assign a dataseries to an indicator, but not able to do it in the way I want to. Please see below code snippets inside of an indicator:
public class xx : Indicator
{
SMA jk_sma;

protected override void Initialize()
{
jk_sma = new SMA();
}
protected override void OnStartUp()
{
jk_sma.Input=BarsArray[0];
}
protected override void OnBarUpdate()
{
//** Indicator is unusuable, not getting any data
if(BarsArray[0].CurrentBar>100)
Print(String.Format("{0}",jk_sma.Value[0]));

}}...

How can I assign the dataseries properly? I know I can use SMA simply as SMA(x).Value[0] but I need to do it the way I've described for other reasons.

Thanks.
saturntd is offline  
Reply With Quote
Old 08-06-2012, 03:50 PM   #2
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 saturntd,

Thanks for the post. Sorry, it is not clear what you're trying to do. Can you please offer a brief English description and we'll have a better idea?
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-06-2012, 04:02 PM   #3
saturntd
Junior Member
 
Join Date: May 2009
Posts: 26
Thanks: 0
Thanked 1 time in 1 post
Default

Hi Ryan,
I just want to be able to instantiate a new instance of an indicator class & assign a dataseries to it for that indicator to use in it's calculations.
This is going on inside of another new indicator I'm writing, or could also be inside of a strategy.

Thanks.
Last edited by saturntd; 08-06-2012 at 04:07 PM.
saturntd is offline  
Reply With Quote
Old 08-06-2012, 07:51 PM   #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

I see -- you can remove the Initialize() line and do something like this in OnStartup()

// Declaring an object type variable using a Simple Moving Average indicator
SMA mySMA = new SMA(Close, 20);

Access its current values with mySMA[0].
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-06-2012, 08:25 PM   #5
saturntd
Junior Member
 
Join Date: May 2009
Posts: 26
Thanks: 0
Thanked 1 time in 1 post
Default

Ryan,
I can't get it to work that way, just get compile error: does not contain a constructor that takes 2 arguments.
Is there a way to see the # of arg's for the constructor? Call the constructor directly?

Thanks.
saturntd is offline  
Reply With Quote
Old 08-07-2012, 02:33 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

You should be able to see parameters required in Intellisense, just type the method followed by the left brace to see it pop up and what's expected for a compile.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-07-2012, 07:23 PM   #7
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,219
Thanks: 24
Thanked 1,231 times in 1,002 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by NinjaTrader_RyanM View Post
I see -- you can remove the Initialize() line and do something like this in OnStartUp()

// Declaring an object type variable using a Simple Moving Average indicator
SMA mySMA = new SMA(Close, 20);

Access its current values with mySMA[0].
That will not work from OnStartup(); you will have a scope issue.

You have to declare the SMA variable as a class variable.
Then you can assign/instantiate it in either Initialize() or OnStartUp().

Because it was defined as a object type (a named instance of the class), you assign it without the "new" keyword.

Code:
private SMA yada_sma;
Code:
protected override void OnStartUp()
{
yada_SMA = SMA(Close, 5);
//etc;
}
Code:
protected override void OnBarUpdate()
{
//here is where you use your named instance;
}
Last edited by koganam; 08-07-2012 at 08:28 PM.
koganam 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
How to assign exit when scaling into a position nepenthean Charting 2 10-23-2011 08:21 PM
Using 'ad hoc' instruments - need to assign exchange DionysusToast Miscellaneous Support 5 03-09-2011 09:30 AM
multiply value of indicator - assign to variable rangerdoc Indicator Development 2 11-23-2010 08:59 AM
Assign template in Strategy JKrider Version 7 Beta General Questions & Bug Reports 3 08-03-2010 06:00 AM
Assign default account Json Suggestions And Feedback 1 10-23-2007 07:46 AM


All times are GMT -6. The time now is 11:58 PM.