Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DataSeries at different timeframe?

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

    DataSeries at different timeframe?

    I would like to set up dataseries object at different timeseries which could be used as input to indicators? What's problem with below approach, it set ups it at first and set the values if barsinprogress == 1.
    An example SMA(secondarySeries, 2)[0] shows some weird values but those
    secondarySeries[0] are ok ?

    (Some context missing?)


    protected override void OnBarUpdate()
    {

    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], 5));
    }

    if (BarsInProgress == 1){
    secondarySeries.Set(Close[0]);
    return;
    }

    PrintWithTimeStamp(SMA(BarsArray[1], 2)[0] + " " + SMA(secondarySeries, 2)[0] + " " + secondarySeries[0] + " " + secondarySeries[1] );

    }

    #2
    It seems to be some context thing as it is OK to call SMA(secondarySeries, ...) if BarsInProgress == 1... But how to call it from other timeframe? SMA(context2, secondarySeries, ....)

    Comment


      #3
      Hi Raffu,

      Thanks, I could set this up here and look into what may be happening. Can you please answer these additional details:
      What are the instruments? What is primary and secondary series interval? What is CalculateOnBarClose setting? Are you having trouble with historical or real time value (or both)? Any clues as to what is weird exactly about the SMA calculation?
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        Ryan,


        Primary 1 minute
        Secondary 5 minute

        Any instrument like ES,
        that SMA(secondarySeries, 2)[0] shows some huge minus value number

        (forget my second post, I actually was looking a solution, where I input values to dataseries from both timeframes and access that from primary)

        Comment


          #5
          Thanks for the reply. We are currently looking into this. Unfortunately we will not have a response until Monday as our main development contact is at the expo in Las Vegas currently.

          For now, a work around would be to set your SMA within BIP1.
          if (BarsInProgress == 1)
          {
          secondarySeries.Set(SMA(Close, 2)[0]);
          }
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            No problem,

            Or even more simpler? q, what is the best way to get results from an indicator if I manage a simple array of double values by myself and that should be calculated by an indicator?

            something like that:
            double[] array = {1.0, 2.0, 3.0, 4.0, 5.0}; // max 256 items
            // between this lines do something with values at any timeframe....
            convertArayToIDataSeries(array, convertedArray, 5); // should I write this or any way to use array without conversion?
            SMA (convertedArray, 5);

            Comment


              #7
              Indicators will only accept DataSeries as input. If you create an array, unfortunately would not be able to pass in as input for an indicator. Any calculations would have to done manually. In the case of SMA, the following tutorial could help with what could be used for manual calculations.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                And even more simplified example, still some confusion with my thinking? ( no more multiple timeframes):

                protected override void Initialize()
                {
                tmpSeries = new DataSeries(this);
                }

                protected override void OnBarUpdate()
                {
                if (CurrentBar < 256) return;
                for (int i = 0; i < 256; i++) // set the values every time!
                tmpSeries[i] = (double) i;

                Print("SMA: " + SMA(tmpSeries, 10)[0] + " " + MIN(tmpSeries, 10)[0] + " " + MAX(tmpSeries, 10)[0]);

                return;
                }

                Now, first time when this is called, output is what I expect: 4,5 but next time 3,5 and 2,5 and so on...

                Probably something to do with CurrentBar but I can't figure how...?

                Comment


                  #9
                  Hi raffu, I will have Ryan get back to you tomorrow.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    raffu,

                    I am responding on behalf of Ryan.

                    In your example from post 8, I fixed this issue by using the DataSeries.Set() method instead of assigning it like an array.

                    DataSeries are classes, so they are a bit more complicated than an array.

                    I replaced : tmpSeries[i] = (double) i;

                    With : tmpSeries.Set(255-i, (double) i);

                    And it appears to be working as expected.

                    Please let me know if I may assist further.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Adam,

                      Unfortunately it does not seem to work like it.

                      Let's make another and actually same example:

                      protected override void Initialize()
                      {
                      tmpSeries = new DataSeries(this);
                      }

                      protected override void OnBarUpdate()
                      {
                      if (CurrentBar < 256) return;

                      for (int i = 0; i < 256; i++) // set the values every time, actually no need more than once
                      tmpSeries[i] = (double) i; // OR tmpSeries.Set(i, (double) i); work same way (as it should)

                      But You can get correct values (not all the big ones but that's not problem ) if you use it with CurentBar like:

                      for (int i = 0; i < 256; i++)
                      Print("SMA :" + i + " " + SMA(tmpSeries, 10)[CurrentBar - 256 + i]); // OK

                      // That CurrentBar is essential and that minus 256 if you wait this run multiple bars since 256 ... I had some test with multitimeframe and then 256 was something else like 253 and 251 but that's not tested enough and I don't remember the setup (either add(5 min or 3 min additional bars) (and if (BarsInProgress == 1) return;

                      return;
                      }

                      Comment


                        #12
                        But still, somehow almost found the solution to the original q: " I actually was looking a solution, where to input values to dataseries from both timeframes (mainly from secondary series) and access that from primary with standard indicators" but not so sure about that constant (CurrentBar - 256 (251 or even 191 with some range bars)) ...

                        Comment


                          #13
                          Hello,

                          Reviewing this tread you would not want to set the same Data Series from the same BarInProgress. Simply will not work as you expect, you would need to sync the data series object to the secondary series as I believe we showed you how to do in another post if not please let me know I will post the instructions again.

                          If this is not the core item please clarify the code you are using and what exactly is not working as you expect. As its not clear to me from your post.

                          -Brett
                          BrettNinjaTrader Product Management

                          Comment


                            #14
                            Maybe too many post already and lost the point but some clarifications:
                            This is a pseudo code and not tested;

                            Two timeframe:

                            if ( BarsInProgress == 1) return; /actually no need to do anything...

                            if (BarsInProgress == 0){

                            ..
                            myDataSeries.Set(myindex, Closes[1][myindex]); // multiple of those or other ways to the data from second timeframe to the primary one, (myindex is newer bigger than 255)
                            and some values are set from primary values to myDataSeries as well
                            ..
                            value = standardindicator(myDataSeries, xx)[0]; // this value is looked after
                            ^----- this index here does not seem to match, at least not to zero (CurrentBar - 256) seems to be ok? if i have understood that correctly or not...

                            }





                            }

                            Comment


                              #15
                              Hello,

                              Thanks for bringing that back up.

                              I have been working with development on this.

                              Currently there is a limitation here that this unfortunately this is not possible. Development is reviewing this limitation with MTF and custom secondary DataSeries objects for our next major release of the software.

                              This however would be sometime down the road for our next major release and no release date yet for this major release. Therefor in NinjaTrader 7 this type of action would be unsupported unfortunately.

                              -Brett
                              BrettNinjaTrader Product Management

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              607 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              353 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              560 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              561 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X