Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to assign dataseries to indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    #2
    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

    Comment


      #3
      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, 04:07 PM.

      Comment


        #4
        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

        Comment


          #5
          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.

          Comment


            #6
            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.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              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 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; 02-14-2016, 08:00 PM. Reason: Corrected instruction.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by SherwoodJP, 06-04-2024, 06:55 AM
              4 responses
              42 views
              0 likes
              Last Post SherwoodJP  
              Started by dibDab, 11-09-2022, 09:04 AM
              13 responses
              119 views
              0 likes
              Last Post MisterTee  
              Started by LordNoah, Today, 06:15 PM
              0 responses
              4 views
              0 likes
              Last Post LordNoah  
              Started by oneybuchi2, Today, 03:48 PM
              2 responses
              19 views
              0 likes
              Last Post oneybuchi2  
              Started by samish18, Today, 04:59 PM
              0 responses
              8 views
              0 likes
              Last Post samish18  
              Working...
              X