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

Syncing custom DataSeries to secondary series

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

    Syncing custom DataSeries to secondary series

    Hi,

    Just trying to get familiar with the way DataSeries objects work. If I need to sync a custom dataseries I can definite by using DataSeries(this). If I add more series to the indicator, how do I sync the custom DataSeries object to the secondary series added using Add().

    Hope i'm clear in what I'm asking.

    thanks

    #2
    Hello buylosellhi,

    Yes, there is a sample dedicated to this here:
    Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan, thanks for your reply. In the example that you provided the secondaryDataSeries is synced using

      secondarySeries = new DataSeries(SMA(BarsArray[1], 50));

      do we need to use an Indicator with the appropriate BarsArray[] to sync it or can it also be synced using

      secondarySeries = new DataSeries(BarsArray[1]);

      thanks again...

      Comment


        #4
        Yes, you can do that, although you might not need a data series. You can access the close series of the secondary time frame with:
        Closes[1]

        Don't include the second bracket [ ] and it's a series, not a double.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Can't synchronize secondary series directly with BarsArray[1]

          Guys, synching the secondary series using an indicator like the SMA appears to work fine, as in the example zip file. But doing it directly via BarsArray[1], as in

          secondarySeries = new DataSeries(BarsArray[1]);

          didn't work for me. Not a big deal... just thought I'd mention it in case others try the same thing.

          Comment


            #6
            Cannot Sync to Closes[1]

            Originally posted by NinjaTrader_RyanM View Post
            Yes, you can do that, although you might not need a data series. You can access the close series of the secondary time frame with:
            Closes[1]

            Don't include the second bracket [ ] and it's a series, not a double.
            It's an old thread, it might work on Ninja 6 , but doesn't work now. An attempt to synchronize to Closes[1] as below :

            Code:
                    protected override void OnStartUp()
                    {
                        if (askTicks == null)
                        {
                            /* Syncs another DataSeries object to the secondary bar object.
                            We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
                            The indicator can be any indicator. The DataSeries will be synced to whatever the
                            BarsArray[] is provided.*/
                            askTicks = new DataSeries(Closes[1]);
                        }
                    }
            fails and creates compilation errors:
            Strategy\MyTest1Stg.cs,The best overloaded method match for 'NinjaTrader.Data.DataSeries.DataSeries(NinjaTrade r.Indicator.IndicatorBase)' has some invalid arguments,CS1502 - click for info,80,16,
            Strategy\MyTest1Stg.cs,Argument '1': cannot convert from 'NinjaTrader.Data.IDataSeries' to 'NinjaTrader.Indicator.IndicatorBase',NT1503 - click for info,80,31,

            Another attempt, trying "to cheat" :
            Code:
            askTicks = new DataSeries((IndicatorBase)(Closes[1]));
            Gives a runtime error:
            Strategy,Error on calling 'OnStartUp' method for strategy 'MyTest1Stg/2c8b4818f5c447f18f7bfa899ae087aa': Unable to cast object of type 'NinjaTrader.Indicator.DataSeriesHelper' to type 'NinjaTrader.Indicator.IndicatorBase'.,

            Of course I can create a dummy indicator just returning Close, but may be have you a better advice?
            Last edited by xTrader1; 09-12-2014, 07:51 AM.

            Comment


              #7
              xTrader1,

              You need to have an indicator base that is using the secondary data series for this.

              It doesn't matter what indicator you use, we just an arbitrary one so that we the data series synced.

              Code:
              /* Only need to sync DataSeries objects once. We couldn't do this sync in the Initialize() method because we
              cannot access the BarsArray property there. */
              	if (secondarySeries == null)
              	{
              		/* Syncs another DataSeries object to the secondary bar object.
              		We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
              		The indicator can be any indicator. The DataSeries will be synced to whatever the
              		BarsArray[] is provided.*/
              		secondarySeries = new DataSeries(SMA(BarsArray[1], 50));
              	}
              You can view the sample we have on how to do this from the thread link below -
              http://www.ninjatrader.com/support/f...ead.php?t=3572

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

              Comment


                #8
                Originally posted by NinjaTrader_Cal View Post
                xTrader1,

                You need to have an indicator base that is using the secondary data series for this.

                It doesn't matter what indicator you use, we just an arbitrary one so that we the data series synced.

                Code:
                /* Only need to sync DataSeries objects once. We couldn't do this sync in the Initialize() method because we
                cannot access the BarsArray property there. */
                    if (secondarySeries == null)
                    {
                        /* Syncs another DataSeries object to the secondary bar object.
                        We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
                        The indicator can be any indicator. The DataSeries will be synced to whatever the
                        BarsArray[] is provided.*/
                        secondarySeries = new DataSeries(SMA(BarsArray[1], 50));
                    }
                You can view the sample we have on how to do this from the thread link below -
                Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for


                Let me know if I can be of further assistance.
                I saw an example, So the only way to synchronize additional data series is via an indicator?

                Comment


                  #9
                  xTrader1,

                  Correct. An indicator base needs to be used for the new DataSeries() however, we only need the bar series for the secondary timeframe which this allows us to do.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    A followup question is (well actually a BIG question):
                    assume 15min is BIP 0, 60m is BIP1, and a DataSeries X60m is created as

                    X60m = new DataSeries(SMA(Closes[1],50));

                    the OBU code is:

                    If (BIP==0)
                    {
                    // Do 15m logic
                    if (X60m[0] < 0.5)
                    Print(CurrentBar + " X60m < 0.5");
                    }
                    else if (BIP ==1)
                    {
                    var x = GetAvgRatio(..); // x is guaranteed to be <=1
                    X60m.Set(x);
                    }

                    If this is run on HSI, currently at 24900, the Print of 15m code will NEVER happen, since it's accessing the 'SMA 50' part of the X60m, which is just a dummy placeholder...

                    Short of adding another 15m to the chart and moving the BIP0 part of the code to BIP2, is there any other way to tell Ninjatrader to execute (certain part of) 15m logic AFTER BIP1 is run, on the same bar.

                    No, I don't want to always use [1] to avoid this problem, and I need to make 15m as primary, and I know a 2-year chart of adding another 15m (even though it's the same as BIP0) would need quite a bit of resources..

                    Comment


                      #11
                      balancenv,

                      Are you checking that you enough data on the two data series before processing your if statements? -
                      Code:
                      if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                      This would need to be placed at the beginning of your OnBarUpdate().

                      Have you tried printing out the values of the x60m and see what it returns? Is it indeed the SMA() values?
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks for the reply.
                        1. All OBU codes for all TFs are guarded by
                        if (CurrentBar < 40) return;

                        2. Yes, every access to X60m[0] by the 1st 15m OBU code is its SMA. This is logical since
                        the 15m code is always executed before the 'setting correct value of X60m[0]' part of the 60m code.

                        I am temporarily solving this by adding another 15m AFTER the 60m and put the accessing X60m[0] logic in its OBU code.

                        Again, my question is, is there a better way to solve this?
                        Last edited by balancenv; 01-27-2015, 08:47 AM.

                        Comment


                          #13
                          Hello balancenv,

                          Thank you for your response.

                          Unfortunately, there is no method or function to force the primary series to wait for the secondary series to update before the primary series updates.

                          Comment


                            #14
                            Thanks for the update.
                            It would be nice to allow users to configure the 'execution sequence' of each instrument added to the chart, independent of the sequence they're added.

                            Please consider this as a new feature request.

                            Comment


                              #15
                              Hello balancenv,

                              Thank you for your response.

                              I have forwarded your request to our development team, however at this time there are no plans for future implementation of this feature.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by gentlebenthebear, Today, 01:30 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post gentlebenthebear  
                              Working...
                              X