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

Using Multiple Data Series In One Indicator

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

    Using Multiple Data Series In One Indicator

    Hi there,

    I'm trying to create a custom indicator that consists of 4 EMA's using different data series/tick charts for each EMA.

    For example:

    1. 21 EMA (377 Tick chart input series)
    2. 50 EMA (377 Tick chart input series)
    3. 50 EMA (610 Tick chart input series)
    4. 50 EMA (987 Tick chart input series)

    Is it possible to combine these EMA's - using different tick charts as their input series - into one single indicator?

    If so, what code would I use to do this?

    Any help would be much appreciated

    #2
    Hello RoswellTrader,

    Thank you for your post.

    Yes, this would be possible from one single indicator. You could call AddDataSeries() to add any additional series that you would like, such as 377 tick, 610 tick, and 987 tick. Then, you could specify the BarsArray to be used as the input for the EMA methods in your script. For more information, please see the following links:Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hi Emily,

      Thanks so much for your help.

      I've managed to implement the AddDataSeries() + BarsArray into my code successfully to use multiple data series!

      The only thing that's strange is that the EMA's using the slower tick chart data series (610, 987) have a jagged appearance to them.

      When I manually combine these EMA's by stacking them into one indicator panel - without coding - the slower EMA's are smooth.

      I'm guessing it must have something to do with the code?

      Please let me know if you have any ideas. Thanks in advance.
      Last edited by RoswellTrader; 09-20-2023, 12:52 PM.

      Comment


        #4
        Hello RoswellTrader,

        Thank you for your reply.

        This could happen if you have a plot based on a slower added series compared to a higher primary series The plot will line up with the bar indexes of the slower series rather than the higher series. This would be expected as there aren't data points assigned to the plot "in-between" the bars for 610 tick or 987 tick. You could programmatically smooth them out for visual purposes if you'd like. There are similar discussions throughout the forum, such as the following thread:


        Please feel free to reach out with any additional questions or concerns.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hi Emily,

          Over the past month, I've been experimenting with smoothing using various moving averages and filters.

          What I've discovered is that the key to removing the jaggedness is to let the plots (using higher tick chart data series) update independently, rather than forcing them to update simultaneously with the plots that use the lower tick chart.

          Here are my EMA configurations:
          1. 21 EMA (377 Tick chart input series)
          2. 50 EMA (377 Tick chart input series)
          3. 50 EMA (610 Tick chart input series)
          4. 50 EMA (987 Tick chart input series)

          In the code, is there a way to specify that the EMA's using the 610 and 987 input series should only update when their respective data series bars close? This way, they won't be compelled to update in sync with the 377 data series.

          Visually, this would mean that the EMA based on the 610 data series would lag one or two bars behind the EMA's based on the 377 data series. The EMA using the 987 data series would be even further behind.

          I raise this issue because, when I manually incorporate multiple data series into one chart and introduce each EMA separately into a single indicator panel, each plot updates independently according to its input data series. This eliminates the need to sync with the 377 tick chart and, in turn, resolves the jagged plot problem.

          Any guidance or help on this matter would be greatly appreciated.

          Comment


            #6
            Hello RoswellTrader,

            Thank you for your reply.

            OnBarUpdate() is called for each added data series. If you would like to specify your logic so, for example, one EMA plot is only updated for the first added data series, you could add a condition that checks for the BarsInProgress calling OnBarUpdate(). If you want an action to only occur on the close of a bar, you could check if IsFirstTickOfBar is true. Combining these would look like the following:
            Code:
            // check if the BIP (BarsInProgress) is the first added series and if it is the close of the bar
            if (BarsInProgress == 1 && IsFirstTickOfBar)
            {
            // set the value for the EMA plot associated with BIP 1
            EMAPlot[0] = 21ema[0];
            }
            For more more information regarding BarsInProgress and IsFirstTickOfBar:



            Please let us know if we may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Hi Emily, thanks so much for your help, I'm learning a lot here.

              I tried coding the OnBarUpdate section like this:

              protected override void OnBarUpdate()
              {
              if (BarsInProgress == 1 && IsFirstTickOfBar)
              {
              Values[0][0] = slow[0];
              }
              else if (BarsInProgress == 2 && IsFirstTickOfBar)
              {
              Values[1][0] = med[0];
              }
              else if (BarsInProgress == 3 && IsFirstTickOfBar)
              {
              Values[2][0] = fast1[0];
              }
              else if (BarsInProgress == 4 && IsFirstTickOfBar)
              {
              Values[3][0] = fast2[0];
              }
              }


              But for some reason it's not working.

              All the EMA's have equally spaced data points, and the EMA's using the higher tick data series (610, 987) should have wider data points.

              Also for some reason my slowest EMA (987) isn't being plotted at all, and the medium EMA (610) has multiple gaps in the line.

              In the manual version, the two fastest lines have equally distant data points, but the 610's data points are wider, and the 987's even wider.

              I'm really hoping there is a way I could replicate this logic in the coded version.

              Any ideas for what I could be doing wrong? Your help is much appreciated!​
              Last edited by RoswellTrader; 10-24-2023, 01:55 PM.

              Comment


                #8
                Hello RoswellTrader,

                Thank you for your reply.

                What is the primary series you are using on the chart? For a multi-series script, plots are synched to the primary series of the NinjaScript object and this may be the effect that you are seeing. Ultimately, it may be difficult to get completely smooth plots for all EMAs. You could see the differences if you add the indicator to a smaller interval data series vs. a larger interval data series.

                When you were manually adding the EMAs to a chart, I suspect you had added a data series for the desired tick series as the input for each EMA. This would allow for each EMA instance to be synched with the bars of the input series that were physically loaded on the chart. In the case of the script, the plot values are in synch with the bars slots of the primary series.

                Please let us know if we may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  My primary data series is a 377 tick chat.

                  Thanks for the detailed response. So I'm guessing there's no work around for plots being synched to the primary series?

                  This is just the limitation of the code? I was hoping there would be some piece of code that would allow the slower plots to update independently like in the manual version.

                  And yes, I loaded multiple data series onto one chart for the manual version, using them as the input for each EMA.

                  Comment


                    #10
                    Originally posted by RoswellTrader View Post
                    My primary data series is a 377 tick chat.

                    Thanks for the detailed response. So I'm guessing there's no work around for plots being synched to the primary series?

                    This is just the limitation of the code? I was hoping there would be some piece of code that would allow the slower plots to update independently like in the manual version.

                    And yes, I loaded multiple data series onto one chart for the manual version, using them as the input for each EMA.
                    Yes, this is a limitation of AddPlot() and how plots are synched. Per the Tip Uncategorized Groups on this page, plots are synched to the primary series:


                    The manual version you are referring to requires you to create separate indicator instances, one for each series you would like them to sync to. For a custom script, additional series may be added programmatically but the plots will still only be synced to the input series in the same way that they are when you are manually creating separate instances.

                    Thank you for using NinjaTrader.
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      Is there a limit as to how many additional data series could be added to an indicator? I'm building a COT indicator trying to reference 10 instruments. Will trying to access so many cause any issues?

                      Comment


                        #12
                        Hello Lance El Camino,

                        There is no limit imposed by the NinjaTrader Desktop platform.

                        The number of series that can be added will be limited by the computer hardware and the number of simultaneous subscriptions allowed by the connected provider.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DJ888, Yesterday, 10:57 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by MacDad, 02-25-2024, 11:48 PM
                        7 responses
                        158 views
                        0 likes
                        Last Post loganjarosz123  
                        Started by Belfortbucks, Yesterday, 09:29 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post Belfortbucks  
                        Started by zstheorist, Yesterday, 07:52 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post zstheorist  
                        Started by pmachiraju, 11-01-2023, 04:46 AM
                        8 responses
                        151 views
                        0 likes
                        Last Post rehmans
                        by rehmans
                         
                        Working...
                        X