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 copy DataSeries to another DataSeries

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

    How to copy DataSeries to another DataSeries

    I like to find the HighestBar starting from High[1] to High[20].
    Do I have to copy 'High' DataSeries elements (1 to 20) to another DataSeries, then pass the new DataSeries into HighestBar () function.
    How do I do it?

    #2
    That is correct. Or you can just save the value out from the previous bar. In your previous bar just save a variable that does not get reset for when you access HighestBar().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      How do you copy from DataSeries? Would you be able to show the code?

      Comment


        #4


        myDataSeries.Set(High[1]);
        int value = HighestBar(myDataSeries, 20);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          myDataSeries.Set(High[1]);

          Does this automatic copy High[1], High[2], High[3], High[4], High[5], ... High[19], High[20] into myDataSeries?

          I don't really understand how DataSeries works? Would you try to explain further?

          Comment


            #6
            Need a little explain

            I think I got how it works because we try to put the value of the previous bar into the dataseries hence it is always one bar behind the current high.

            And I would need to protect the series by

            if (CurrentBar < 2)
            return;

            inside the OnBarUpdate().


            This is neat. But would it be possible to have an optional parameter int HighestBar () or functions that uses dataSeries to specify the starting index that would be good too.

            Thanks Josh

            Comment


              #7
              Hello,

              You are correct. High[1] always returns the high value of one bar to the left of the current bar.

              if(CurrentBar < 2) return; could be:
              if(CurrentBar < 1) return;

              Because all you need is one bar of history. If there are no bars to the left of the current bar yet, then do nothing.

              I do not understand your last statement regarding HighestBar(). HighestBar() returns the index value of the highest bar within a range:
              DenNinjaTrader Customer Service

              Comment


                #8
                I mean add an optional parameter to HighestBar. Instead of

                HighestBar (IDataSeries ds, int length),

                we can have

                HighestBar (IDataSeries ds, int length, int startIndex),

                where startIndex is 0 by default

                Comment


                  #9
                  Hello,

                  Thank you for your suggestion, I will send it to development for consideration.

                  You may want to use MAX(High, 20)[1] or something like that to return the highest VALUE. However, this does not return the bar INDEX with the highest value. This link will help:
                  DenNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by rhyminkevin, Today, 04:58 PM
                  3 responses
                  47 views
                  0 likes
                  Last Post Anfedport  
                  Started by iceman2018, Today, 05:07 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post iceman2018  
                  Started by lightsun47, Today, 03:51 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post lightsun47  
                  Started by 00nevest, Today, 02:27 PM
                  1 response
                  14 views
                  0 likes
                  Last Post 00nevest  
                  Started by futtrader, 04-21-2024, 01:50 AM
                  4 responses
                  50 views
                  0 likes
                  Last Post futtrader  
                  Working...
                  X