• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dataseries containing selected members of another dataseries

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

    Dataseries containing selected members of another dataseries

    Hello,

    I'm using NT7.

    I have a function producing binary signals on each bar. This is converted to a data series, say ds1, which works well.
    I wish to have another data series that holds only the positive values, i.e. if (ds1[index] == 1) ds2.Set(ds1), as well as another data series that holds the Close values when ds1(index) == 1.

    please advice, tnx, bkool

    #2
    Hello bkool,

    Thank you for your post.

    To clarify, is this a strategy or indicator you are creating? The values for ds1 would be either 0 or 1, is that correct? Or are you creating the data series with price information as well?

    Would you be able to provide me an example of a reduced version of your script? Remove all code that is not necessary for understanding the logic you're trying to achieve.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks Kate W.

      This is a tiny part of an quite large indicator, and indeed the ds1 data series values are either 1 or 0 reflecting some other indicator conditions (resembling a simple ma-cross).
      I have tried: if (ds1[0] == 1) cl = Close[0]; clds.Set(cl);
      using these, I'm able to print out clds[0] & clds[1] correctly, but no further.

      bkool

      Comment


        #4
        Hello bkool,

        Thank you for your reply.

        I've created a small example script that illustrates adding the close to a custom data series based on whether your binary data series was 1 or 0.

        Your line if (ds1[0] == 1) cl = Close[0]; clds.Set(cl); works just fine in this test script - I've set it up to show you can access bar data further back than the previous bar.

        When you try to access your clds data series, does anything print if you try to access a bar further back than clds[1]? Do you receive any errors in the Log tab of the control center?

        Thanks in advance; I look forward to assisting you further.
        Attached Files
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks so much Kate W., for the effort

          This one works but not the way I need it.
          I wish to have data series that holds only the positive values.
          There must be a way to populate and array or data series with selected items.

          Best...

          Comment


            #6
            Hello bkool,

            Thank you for your reply.

            Would you be able to clarify exactly what behavior you wish to see? What is the purpose of this data series and what would you expect to see as data in it?

            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hi Kate W.,

              Thanks for your question. I will try to clarify.

              I have two types of signals, say sig1 & sig2, generated by distinct functions, and both are presented as double and/or dataseries.
              I wish to have them in a single data series while ignoring all cases where both equal zero.
              This may described as follows for the positive cases:

              time; sig1[0]; Close;
              time, sig1[1]; Close;
              time, sig2[0]; Close;
              time, sig1[2]; Close;
              time, sig1[3]; Close;
              time, sig2[2]; Close;
              time, sig2[3]; Close;
              etc...

              Hope this is doable,

              Many thanks, bkool.
              Last edited by bkool; 07-02-2019, 04:47 AM.

              Comment


                #8
                Hello bkool,

                Thank you for your reply.

                We'll need some further clarification, actually. It would be redundant to save the time and the close values to a single series with the signal values, as those are accessible by their bar index (Close[0], Time[0]), although possible to do.

                I am confused about the sig1 and sig2. Are you wanting to save only one of these values per bar, depending on which is positive? And there would be bars on which you wouldn't want either value saved, correct?

                Any further detail you can provide as to how these values are to be used would be helpful. If you can provide any code snippets that better illustrate what you're trying to achieve, that would be helpful as well.

                Thanks in advance; I look forward to assisting you further.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Kate,

                  You've got it correct. I essence, I wish to reduce the amount of information of a time series by ignoring all non-signal containing bars, but yet have the positive signals in order (and time) along with their Close[x] values, which I need for further calculations.
                  Sig1 & sig2 are two distinct data series holding signals of the same time series & bars.
                  It would be great to have it working ....!

                  Thank you much... bkool.
                  Last edited by bkool; 07-03-2019, 01:24 PM.

                  Comment


                    #10
                    Hello bkool,

                    Thank you for your reply.

                    I think we can simplify this a bit. Since you can access the Time, Close, and Sig1 and Sig2 values via a bars ago value, all you really need to save is the bar index of each bar for which sig1 or sig2 is true.

                    Here's an example:.

                    Code:
                    using System.Collections.Generic;
                    namespace NinjaTrader.Indicator
                    {
                        /// <summary>
                        /// Enter the description of your new custom indicator here
                        /// </summary>
                        [Description("Enter the description of your new custom indicator here")]
                        public class MyCustomIndicator : Indicator
                        {
                            #region Variables
                            List<int> trueBarIndexes;
                            private int myBarsAgoValue;
                            #endregion
                    
                            /// <summary>
                            /// This method is used to configure the indicator and is called once before any bar data is loaded.
                            /// </summary>
                            protected override void Initialize()
                            {
                                //Print(BarsArray[0].BarsType.Name);
                                trueBarIndexes = new List<int>();
                            }
                    
                            /// <summary>
                            /// Called on each bar update event (incoming tick)
                            /// </summary>
                            protected override void OnBarUpdate()
                            {
                                if (/* condition that would normally set sig1[0] to 1 here || condition that would normally set sig2[0] to 1 here*/true)
                                {
                                    trueBarIndexes.Add(CurrentBar);
                                }
                    
                                foreach (int barIndex in trueBarIndexes)
                                {
                                    myBarsAgoValue = CurrentBar - barIndex;
                                    Print(string.Format("{0} | sig1[{1}]: {2}, Close[{1}]: {3}", Time[myBarsAgoValue], myBarsAgoValue, /*sig1[myBarsAgoValue], (note this is commented out since I don't have this in my code)*/ Close[myBarsAgoValue]));
                                }
                            }
                    
                            #region Properties
                            #endregion
                        }
                    }
                    What this would do is take the bar index of a bar on which either Sig1 or Sig2 is true and add that to a list, which we can then use to loop through and find the necessary time, close, and sig1 and sig2 values (though this code would only print the sig1 value, you'd have to add sig2.

                    Since we saved the bar index, we can use it to access all those values on each bar for which sig1 or sig2 were positive. You don't need to have a separate data series containing all this information as that would be redundant.

                    Please let us know if we may be of further assistance to you.
                    Last edited by NinjaTrader_Kate; 07-04-2019, 08:33 AM. Reason: Updated code for NT7.
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Kate w., is this compatible with NT7?

                      Comment


                        #12
                        Hello bkool,

                        Thank you for your reply.

                        I've updated the code in my previous post for NT7. I do apologize for any confusion. Note that in order to use Lists, you'll need to make sure you include the using System.Collections.Generic; line at the very beginning as lists are not supported natively in NinjaTrader 7 as they are in NinjaTrader 8.

                        Please let us know if we may be of further assistance to you.
                        Kate W.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks Kate W., looks good, I will test this out...

                          Comment


                            #14
                            Hello Kate W.,
                            Thanks much for your effort.
                            I have tested the above script and it work fine in getting the bars as well as sig1, sig2 & Close values in the correct order.
                            Since my ultimate goal is to compare current & previous Close values of sig1 & sig2, I need a good indexing to reference those values.
                            However, It seems that indexing is not available in the for-each loop system.
                            I have managed to convert your approach to the "for-loop, but my C# skills are not there yet in terms of the indexing issue...



                            Your advice please...

                            best, bkool.
                            Last edited by bkool; 07-07-2019, 04:03 AM.

                            Comment


                              #15
                              Please find attached some printout results - trueBarIndexes file
                              and the data chart.
                              Clearly, the printout values of the CurrentBars are not inline with the rest, which are correct.
                              Printing CurrentBars before the loop gives correct values.
                              Attached Files
                              Last edited by bkool; 07-07-2019, 05:43 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Mykro, Today, 04:58 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Mykro
                              by Mykro
                               
                              Started by edunwa, Today, 04:11 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post edunwa
                              by edunwa
                               
                              Started by yeshujbp, Today, 02:40 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post yeshujbp  
                              Started by Venom, Today, 01:05 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post Venom
                              by Venom
                               
                              Started by Dert66, Today, 12:11 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post Dert66
                              by Dert66
                               
                              Working...
                              X