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

How to create an array contain multi data series

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

    How to create an array contain multi data series

    I'm trying to create a three column array that holds certain values from the 5minute, 10minute, 15minute ES chart. How do I begin the process?

    Thanks.

    #2
    Hello AdeptistJune,

    Could you please let me know which NinjaTrader version you're using?

    If possible, please also let me know what kind of values you're looking to record, are you looking to have them in a text-based (e.g. Market Analyzer) or visual (e.g. in a chart) form?

    Thank you in advance, I look forward to your reply!
    Manfred F.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      And I'm using Ninja Trader 8.

      I would like to have 6 columns (for 5, 10, 15, 30, Positive, Negative) with "Positive" holding the sum of positive values of the row, and "Negative" holding the sum of negative values of the row. I would like the array to read: row1/column1 = pos or neg value, row1/column2 = pos or neg value, row1/column3 = pos or neg value, row1/column4 = pos or neg value, row1/column5 = sum of all positive values, row1/column6 = sum of all negative values.

      I'm looking at four different ES time frames; with each column holding a value from each time frame.:

      If ((close > open or close = open)) // this rule applies to all time frames
      {
      PositivechangeES5 = 1 // ES5 is the five minute data series
      }
      else
      {
      PositiveChageES5 = 0;
      }
      If (close < open)
      {
      NegativechangeES5 = 1 // ES5 is the five minute data series
      }
      else
      {
      NegativeChageES5 = 0;
      }

      I hoped this helped. I have no clue how to code this concept. Thanks

      Comment


        #4
        Hello AdeptistJune, thanks for posting.

        The most straight forward way of storing bar-by-bar information is to use a custom Series<T>;. With that, you can store values and the indexing is already taken care of because you are using the Series<T> object, so adding a value on a new bar is as simple as "MySeries[0] = value;". Also, you can look back on bars with indexing e.g. to look back one bar in your series it's exactly like the price series: MySeries[1] would be one bar ago.

        All of the data is already there, its just a matter of accessing it at the proper time. This snippet would print the high value of every bar in the series once the highest time frame has at least one bar.

        Heres a quick example:

        Code:
        protected override void OnBarUpdate()
        {
        if(BarsInProgress == 3)
        {
        if(CurrentBars[3] < 1)
        return;
        
        Print("Highs");
                Print("Primary" + Highs[0][0]);
                Print("10 Min " + Highs[1][0]);
                Print("15 Min" + Highs[2][0]);
                Print("30 Min" + Highs[3][0]);
        
        MySeries[0] = Highs[0][0] + Highs[1][0] + Highs[2][0] + Highs[3][0];
        
        Print(MySeries[0]);
        }
        }
        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks,

          I will work on it shortly.

          Comment


            #6
            Hey Chris,

            I tried writing the sample code you gave me, but it will not compile. The error message says: The name "MySeries" does not exist in the current context.

            I see this error message a lot when I'm attempting to write custom indicators. What does it mean?

            Comment


              #7
              Hello AdeptistJune, thanks for your reply.

              At the class level, add the definition of MySeries. I attached the full script to this post.

              Best regards.
              Attached Files
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Thanks, Chris

                I have a question. What is the purpose of this line of code:
                if(BarsInProgress == 3)
                {
                if(CurrentBars[3] < 1)
                return;

                Thanks.

                Comment


                  #9
                  Hey Chris,

                  I tried adding daily data series to the code you sent me, but I got an error message. So I will just post what I'm attempting to do:

                  Lets say the time is 9:00am. I would like to store the difference between the close and open, of four different data series (close - open of 5minute, close - open of 15minute, close - open of 60minute, close - open of daily) across two different instruments (ES and RTY). That would give me an array with two rows and four columns. What I'm attempting to do is create a 15 minute snap shot, every 15 minutes, of the four different data series.

                  How can I accomplish this? Thanks.

                  Comment


                    #10
                    Hello AdeptistJune, thanks for your reply.

                    I ran the code in BarsInProgress 3 because that is the highest period data series. If you want to capture the prices every 15 minutes run the code in the 15 minute series. Try printing all the timestamps and prices from each series when BarsInProgress is 2 for the 15 minute series.

                    Please also read through this multi time frame guide if you have not already for more information:


                    Kind regards.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Okay,

                      Thanks.

                      Comment


                        #12
                        Hey Chris,

                        I figured everything out. My only question now: is how do I add the ES daily data series to the other data series in the code.

                        And thanks for all the help.

                        Comment


                          #13
                          Hello AdeptistJune, thanks for the follow up.

                          Please check the example I posted. This adds the extra data series with the AddDataSeries() method in State.Configure:



                          e.g. AddDataSeries(BarsPeriodType.Day, 1);

                          If the primary series is not the ES, use the alternate overload:

                          AddDataSeries("ES 12-20", BarsPeriodType.Day, 1);
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks Chris,

                            I got the code to compile (finally). I'm beginning to understand series. But I notice when I use the daily data, instead of giving me the current daily (lets say, the low for example), its giving me the previous daily Low. Is it possible to get the current daily price instead of the previous price? I tried coding it like this: AddDataSeries("ES 12-20", BarsPeriodType.Day, 0). But I got an error message.

                            Thanks.

                            Comment


                              #15
                              Hello AdeptistJune, thanks for your reply.

                              The Daily bar has not closed yet, so it is giving the prior close. To access the current daily values use the CurrentDayOHL indicator rather than adding the Daily series to get around this.

                              Please let me know if I can assist any further.
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by WHICKED, Today, 12:56 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cre8able, Today, 01:16 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post cre8able  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              2 responses
                              47 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by WHICKED, Today, 12:45 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by samish18, Today, 01:01 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Working...
                              X