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

Trying to add input series to indicator after indicator creation

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

    Trying to add input series to indicator after indicator creation

    I am working on a multi-time frame strategy. Because of the way my data structures are created, I need to add the data series to indicator objects that have already been created.

    To associate an indicator with another time series I Add()'ed in Initialize(), I know that I could do something like this:

    Code:
    SMA sma = SMA(BarsArray[1],14);
    However, what I want to be able to do is this.... First create the indicator object:

    Code:
    SMA sma = SMA(14);
    And then later associate the input series with it. Something like this:

    Code:
    sma.BarsArray = BarsArray[1];
    That obviously does not work, but illustrates the point. How would I accomplish this?

    #2
    Hello Risingfire,

    Thank you for your post.

    There is not a way to add the BarsArray to the indicator object dynamically.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Cal View Post
      Hello Risingfire,

      Thank you for your post.

      There is not a way to add the BarsArray to the indicator object dynamically.

      Let me know if I can be of further assistance.
      To clarify, I don't think it is the BarsArray that needs to be added, but the IDataSeries input stream. BarsArray is of type Bars[] and Bars[] inherits IDataSeries.

      In the example I used, the calling convention for an indicator, such as SMA, is:

      SMA( Data.IDataSeries input, int period )

      So what I want to do is add the input series (i.e., an IDataSeries) to the indicator after it has been created.

      Looking at the question that way, Is this possible?

      Comment


        #4
        Risingfire,

        What you will want to do is just declare the object in the variables first
        Code:
        private SMA sma;
        You can then set the sma to the SMA() in the OnStartUp() method
        Code:
        protected override void OnStartUp()
        {
             sma = SMA(BarsArray[1], 14);
        }
        Let me know if this helps
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          I already have the object created using the short form Indicator( param1, param2, etc.). It's difficult to explain the reasons as to why I cannot call it as you advise in OnStartUp(). It is because of the class structure of my project and other indicators.

          However, I dug a little deeper and found that I could do this:

          Code:
          SMA sma = SMA(14);
          // (many lines of code later....)
          sma.Input = BarsArray[1];
          It works and gives me exactly what I need -- the ability to associate an input series after the actual object creation.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by frankthearm, Today, 09:08 AM
          8 responses
          31 views
          0 likes
          Last Post frankthearm  
          Started by NRITV, Today, 01:15 PM
          2 responses
          9 views
          0 likes
          Last Post NRITV
          by NRITV
           
          Started by maybeimnotrader, Yesterday, 05:46 PM
          5 responses
          26 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by quantismo, Yesterday, 05:13 PM
          2 responses
          20 views
          0 likes
          Last Post quantismo  
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X