![]() |
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
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: May 2009
Posts: 26
Thanks: 0
Thanked 1 time in 1 post
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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?
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: May 2009
Posts: 26
Thanks: 0
Thanked 1 time in 1 post
|
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.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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].
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: May 2009
Posts: 26
Thanks: 0
Thanked 1 time in 1 post
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 | |
|
Senior Member
|
Quote:
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.
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |