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 fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,404 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by Shai Samuel, 07-02-2022, 02:46 PM
              4 responses
              95 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by DJ888, Yesterday, 10:57 PM
              0 responses
              8 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by MacDad, 02-25-2024, 11:48 PM
              7 responses
              159 views
              0 likes
              Last Post loganjarosz123  
              Started by Belfortbucks, Yesterday, 09:29 PM
              0 responses
              8 views
              0 likes
              Last Post Belfortbucks  
              Working...
              X