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

Is it best to sync new Series on BarsArray[1] or on SMA(BarsArray[1], 50)?

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

    Is it best to sync new Series on BarsArray[1] or on SMA(BarsArray[1], 50)?

    Hello,

    The "Creating Series<T> Objects" section of the official "Multi-Time Frame & Instruments" NT8 help doc ( https://ninjatrader.com/support/help...gSeriesObjects ) shows two different ways to sync a Series<T> on a secondary data series so that the number of slots in the Series<T> will be the same as the secondary data series, but it doesn't say which method is better or when you would use one over the other.

    The first way shown is to sync on BarsArray[1] directly:
    Code:
    myEmptyIndexedSeries = new Series<double>(BarsArray[1]);
    The second way shown is to sync on a dummy indicator that is synced on BarsArray[1]:
    Code:
    secondarySeries = new Series<double>(SMA(BarsArray[1], 50));
    Which of the two methods above is the the best, most bug-free way to sync a new Series<T> on a secondary data series?

    On one hand, the first method is more direct and has one less moving part. One might say "Why use a dummy indicator on BarsArray[1] instead of using BarsArray[1] directly?"

    On the other hand:
    1. Intellisense for the first method says it is "[Deprecated]", so maybe the dummy indicator way is the best approach?
    2. Also, the example that of syncing that I've seen NinjaTrader technical support link to the most is https://ninjatrader.com/support/help...series_obj.htm , which uses the dummy indicator method.
    If the dummy indicator method is better, would using a 1-period SMA instead of a 50-period SMA (as is done in the example) provide any advantages or disadvantages?

    I also would like to suggest that the NT8 help doc in my first link above be updated to say which method is better or when you would use one over the other.

    Thanks in advance!

    EquityTrader

    #2
    Hello EquityTrader,

    Thank you for the post.

    Which of the two methods above is the the best, most bug-free way to sync a new Series<T> on a secondary data series?
    Either, it would not matter because they achieve the same goal. The Indicator approach could be used if you are also using Indicators with the same secondary series or AddChartIndicator. You can then chain these items together by using the same variable instead of re-coding the same details over again which may be more error prone.

    For the indicator way the period would not make a difference, the series is synced to the bar series and not the period. The indicator will specify the number of bars needed to define the series when passed into the constructor based on the BarsArray the indicator was using.

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, Jesse!

      Based on your response, I will use the second method, but syncing on a 1-Period SMA instead of a 50-Period SMA, since you are confident that it doesn't make a difference whether I use method 1 or method 2 and the indicator period makes no difference either.

      So I will sync my Series<T> on the secondary Data Series like this:

      Code:
      secondarySeries = new Series<double>(SMA(BarsArray[1], 1));
      Please respond if you can think of anything wrong with the code above. If I don't hear from you, I will assume that it is good as written.

      Thanks again!

      EquityTrader

      Comment


        #4
        Hello EquityTrader,

        Nothing looks off there and that would work. You are passing BarsArray 1 as the series to be synced with. You could also not use an indicator there to achieve the same goal. The purpose of that sample is to show that Indicators can also be used for syncing if you wanted and that the passed in BarsArray will be used.

        A simple scenario where you would use the indicator use case would be the following:
        1. Generate a strategy using the builder and use any indicator in a condition.
        2. This generates a variable for the indicator.
        3. You want to now manually code the script and unlock it, then use a synced secondary series that matches the indicator.
        4. You pass the indicator variable to the series to sync it using the same series/data as the indicator.

        The reason to use the variable is that this prevents you from typing in the wrong index or if you change what series the indicator uses the other custom series still matches it after making that change.




        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks, Jesse!

          I appreciate the real example of when using an indicator to sync might be a better option and your explanation of it.

          I think I am leaning toward using an indicator to sync, both because you are confident it works as well as syncing on BarsArray[1] and also because as I mentioned above, Intellisense for the Series<T> constructor that takes BarsArray[1] directly instead of an indicator says it is deprecated (i.e. the prefix of the tooltip in the NinjaScript Editor says "[Deprecated]") which suggests to me that maybe I should avoid that constructor if there are no other reasons why it would be better to use the deprecated constructor, and based on your responses there is no real benefit to syncing on BarsArray[1] directly instead of syncing on an indicator.

          Thanks again!

          EquityTrader

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by MarianApalaghiei, Today, 10:49 PM
          3 responses
          9 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by XXtrader, Today, 11:30 PM
          0 responses
          3 views
          0 likes
          Last Post XXtrader  
          Started by love2code2trade, Yesterday, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          9 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Working...
          X