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 yertle, Yesterday, 08:38 AM
          7 responses
          28 views
          0 likes
          Last Post yertle
          by yertle
           
          Started by bmartz, 03-12-2024, 06:12 AM
          2 responses
          21 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by funk10101, Today, 12:02 AM
          0 responses
          5 views
          0 likes
          Last Post funk10101  
          Started by gravdigaz6, Yesterday, 11:40 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by MarianApalaghiei, Yesterday, 10:49 PM
          3 responses
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X