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

Absolute current close

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

    Absolute current close

    If upon loading an indicator to a chart, OnBarUpdate() starts iterating from the left-most bar, how can I refer the close price of the right-most bar at that stage of the initial iteration?

    #2
    savekad,

    Unfortunately this wouldn't be advised here. You can try to use negative indices or something like GetCurrentBid() or GetCurrentAsk() however this is sort of like "peeking" into the future at that point.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      OK, so let's say I create a DS object and store all bars close prices. How do I later, address the last value in the DS object?

      Comment


        #4
        savekad,

        Generally an index of 0 is always the last added element to the series. Values[][] is the array of plots.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          But if I didn't use the Add() method to create a DS object, then how do I address its elements?

          Comment


            #6
            savekad,

            You can use something like this :

            SMA(41)[0] to access elements of an indicator for example. There is no need to use the Add() method. If you are wanting to instantiate an indicator you can do this as well.

            IndicatorBase SMA = new SMA(period);

            Here is a sample that works with instantiated indicators : http://www.ninjatrader.com/support/f...d=4&linkid=535
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Oh no, I don't want to access elements of some other indicator. In the indicator I am building, I created a DS object which to it I save some close values from bars on the chart. Later in the code, I want to access the values I saved in the aforementioned DS object. How do I do that?

              Comment


                #8
                savekad,

                It would probably be easier to see how you are creating this object. Do you have a code sample?
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  It isn't finished but it goes something like this:

                  Let's say that I want to draw a ray from all close values that are above the price 1300.00.

                  I create a DataSeries object and code OnBarUpdate() to:

                  if (Close[0] > 1300.00)
                  {
                  dso.Set(Close[0])
                  }

                  I am left with a DS object that holds values above 1300.00 and their corresponding CurrentBar int, correct?

                  How do I later, draw a ray for those prices, a ray that will start from the relevant bar?

                  This example is quite of a nonsense, I know, but it is simple and will do the trick.

                  Comment


                    #10
                    Originally posted by savekad View Post
                    But if I didn't use the Add() method to create a DS object, then how do I address its elements?
                    A DataSeries is an object with properties .It has nothing to do with how it was created. The DataSeries elements are indexed backwards, 0 being the most recent, and increasing monotonically into the past until the number of entries in the DataSeries equals the number of bars on the chart.

                    You may be overthinking this. If you want to access a member of a DataSeries, just use its index to do so.

                    Comment


                      #11
                      So every DSo has access properties? What are they than? And if I have several DS objects that were not created via the Add() method, how do I access their properties? Simply using the full name DataSeriesObject.PropertyName[barsAgo] and it will return the double stored there?

                      Let me know if I got it right.

                      Comment


                        #12
                        OK, I just went over the DataSeries Class page again and noticed I can simply access the values by DataSeriesObject[int barAgo] like you said.

                        I will try continue from here. Thank you both.

                        Comment


                          #13
                          savekad, if you run into the need to expose internal dataseries of other indicators, please keep this reference in mind - http://www.ninjatrader.com/support/f...ead.php?t=4991
                          BertrandNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Spiderbird, Today, 12:15 PM
                          2 responses
                          10 views
                          0 likes
                          Last Post Spiderbird  
                          Started by WHICKED, Today, 12:45 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post WHICKED
                          by WHICKED
                           
                          Started by FrazMann, Today, 11:21 AM
                          2 responses
                          6 views
                          0 likes
                          Last Post NinjaTrader_ChristopherJ  
                          Started by rjbtrade1, 11-30-2023, 04:38 PM
                          2 responses
                          80 views
                          0 likes
                          Last Post DavidHP
                          by DavidHP
                           
                          Started by lorem, Yesterday, 09:18 AM
                          5 responses
                          18 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X