Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Data Series

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

    Multiple Data Series

    Hi,
    I am trying to build a Currency Index. Is there a template available that someone can show me?

    Also, i am having problems accessing the correct data from the secondary series with "Open[1][0]"
    > So to get this data, i have resorted to using the "BarsArray[1].GetOpen(0));"
    > But this is returning a different value to "Open[0]" when i have the same instrument as the Primary series (loaded on chart), and also the secondary series (imported)
    > Why am i getting an incorrect value when using BarsArray object?
    Thanks,



    Code:
         else if (State == State.Configure)
                {
                    ClearOutputWindow();
                    AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 1); //BarsInProgress index = 1 | Close[1][0]
                }
            }
            protected override void OnBarUpdate()
            {
                //if (Time[0].Hour == 17 && Time[0].Minute == 00)
                if (BarsInProgress == 0)
                {
                    Print("Time : " + Time[0]);
                    Print("Open Series 0 : " + Open[0]);
                    //Print("Open Series 0 : " + Open[0][0]);//Error : CS0021
                    Print("BarsArray 0 : " + BarsArray[0].GetOpen(0));
                }
                if (BarsInProgress == 1)
                {
                    Print("Time : " + Time[0]);
                    Print("Open Series 1 : " + Open[0]);
                   // Print("Open Series 1 : " + Open[1][0]); //Error : CS0021
                    Print("Open Series 1 : " + BarsArray[1].GetOpen(0));
                }            
            }
        }
    }​
    ​
    Attached Files
    Last edited by yertle; 08-30-2023, 10:06 AM.

    #2
    Hello yertle,

    Opens (plural) is a collection of price series
    Open (singular) is a price series

    You want Opens[0][0] or Opens[1][0].



    Bars.Get methods use absolute bar indexes, not bars ago indexes.
    Bars.GetOpen(0) is the first bar CurrentBar 0.
    Bars.GetOpen(CurrentBar) is the last bar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you :-)

      Also, i get a different value, based on the timeframe that is loaded on the chart.

      For instance;

      the Open Values will match, when the 1minute chart is loaded in the chart.
      > but they will Not Match, when i have a 15minute timeframe loaded.

      So it its getting a different Open price for all timeframes.
      > is there a way to solve this?

      Code:
                  else if (State == State.Configure)
                  {
                      ClearOutputWindow();
                      AddDataSeries("EURUSD", Data.BarsPeriodType.Minute, 1); //BarsInProgress index = 1 | Close[1][0]
                  }
              }
              protected override void OnBarUpdate()
              {
                  if (Time[0].Hour == 17 && Time[0].Minute == 00)
                  {
                      if (BarsInProgress == 0)
                      {
                          Print("Time : " + Time[0]);
                          Print("Open Series 0 : " + Open[0]);
                          Print("Open Series 0 : " + Opens[0][0]);
      
                      }
                      if (BarsInProgress == 1)
                      {
                          Print("Time : " + Time[0]);
                          Print("Open Series 1 : " + Open[0]);
                          Print("Open Series 1 : " + Opens[1][0]);
      
                      }
                  }
              }​
      Attached Files
      Last edited by yertle; 08-30-2023, 10:56 AM.

      Comment


        #4
        Wait.. i think this is okay & wont be a problem, as i wont use Opens[0][0] in the code..
        > i can reference only the imported dataseries, which should be fine.

        This can be closed. Thank you.
        Last edited by yertle; 08-30-2023, 11:00 AM.

        Comment


          #5
          Hello yertle,

          You are stating that the open of the bar of the instrument of the primary series has a different open of the different instrument added with AddDataSeries()?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello yertle,

            You are stating that the open of the bar of the instrument of the primary series has a different open of the different instrument added with AddDataSeries()?
            yes,
            in the above code i take the Open price at 5pm.
            But when using the secondary series, the value changes across timeframes.

            Comment


              #7
              Hello yertle,

              You should simplify to understand what data is being provided by NinjaTrader without custom logic first.

              Use null as the instrument in AddDataSeries if you want the added series instrument to be the same as the primary.
              See tip 4 in the help guide.


              I'm not clear on the issue.

              You are stating: "it is wrong, because the Open is not being reset on any timeframe other than the 1m"

              You are expecting Opens[0][0] of the primary series to change everytime the added series bar updates and not when the primary series is updating?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi ChelseaB, sorry for the mess.

                going back to post #3, where,
                > if i load EURUSD on the chart as the Primary Dataseries.
                > & i then add the 1 minute EURUSD as the secondary Dataseries, using Adddataseries.

                Then if i apply the same OnBarUpdate() method to both. for example, lets assume i apply the SMA(20) to both.
                > When i load these both on the chart, What i find is that;
                > the output of the primary dataseries is correct, on any timeframe that i select on the chart / UI
                > BUT... the output of the secondary dataseries is only correct when the chart /UI is set to the 1 minute timeframe. it gives the wrong output when using a 5minute or 15minute chart.

                My intentions are to apply the OnBarUpdate() method to all Exchange rates. so 28 dataseries.
                > I am using EURUSD as the secondary dataseries, to test if the output is correct.
                (so i dont think "null" is not what im looking for)

                Question:
                For this: AddDataSeries(string instrumentName, BarsPeriodType periodType, int period)
                > Can i make the 'int period' dynamic, so that it matches the timeframe selected in the chart UI ?

                Click image for larger version  Name:	image.png Views:	0 Size:	60.3 KB ID:	1266898

                Thank you​
                Last edited by yertle; 08-31-2023, 06:10 AM.

                Comment


                  #9
                  Hello yertle,

                  It is not supported to call AddDataSeries() dynamically.

                  "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.​"


                  An SMA() using a different data series is expected to have different values.

                  The bar times are marked by the time they close.
                  If the time is 9:00, a 5 minute bar will have opened at 8:55, while a 1 minute bar will have opened at 8:59.
                  It would not be expected that the market price at 8:55 would be exactly the same as at 8:59...
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Ok Thank you,

                    I solved the issue with the BarsPeriods object.

                    Thank you for your help. This can be closed now.

                    P.s. I agree with your SMA statement, my problem was that when i had the chart UI set to 5 minutes, the indicator was still using 1 minute data

                    Click image for larger version  Name:	image.png Views:	0 Size:	113.1 KB ID:	1266925
                    Last edited by yertle; 08-31-2023, 07:45 AM.

                    Comment


                      #11
                      Hello yertle,

                      That code using BarsPeriods[0].Value in AddDataSeries() is not supported. (This will break optimizations and may cause other unexpected behavior)
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        would a better solution for this be to import Tick Data instead? So the SMA can calculate correctly across all timeframes?


                        Comment


                          #13
                          Hello yertle,

                          The source of the data wouldn't change this. It would still be necessary to hard code the values to be using AddDataSeries() in a fully supported way.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            ok, this makes sense now.

                            (timeframes are a period...)

                            Thank you.
                            Last edited by yertle; 09-01-2023, 07:46 AM.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            637 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            366 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            107 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            569 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            571 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X