Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get a Bar by index

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

    Get a Bar by index

    I had this super handy extension method that I use EVERYWHERE that no longer works. I can't figure out how to make it work.

    public static Bar GetBarAtIndex(this Indicator.Indicator indicator, int index, int barsArrayIdx)
    {
    return indicator.BarsArray[barsArrayIdx].Get(index);
    }

    usage: this.GetBarAtIndex(0, 23)

    Its supposed to return me the bar object for an index - not "bars ago" the actual left-to-right index that doesn't ever change.

    How do I achieve this now?

    #2
    Hello reach4thelasers,

    To make sure I understand, could you please confirm what is happening in your NT8 version of this code? Is it throwing an error, or is it returning the bar from the barsAgo index?

    Also, in your NT7 version, you are passing it the regular (not barsAgo) index? So in your example, it is returning the very first bar of the 24th data series?

    Thank you for clarifying.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      The NT8 code doesn't compile. There is no Get method. And from what I can see no methods return a Bar object just individual HLOCVT values

      And yes it's a regular index not bars ago.

      Comment


        #4
        Hello reach4thelasers,

        The method has been deprecated in NinjaTrader 8. From a performance standpoint, you can see why having a full Bar object containing the Open, High, Low, Close, Time, and Volume is significantly slower than only requesting the parts of that Bar that are being used. I recommend thinking about this moving forward with your NT8 code to make sure it is as efficient as is now possible in the new platform.

        As a temporary solution or for any circumstances where you may actually require the full Bar object, please see the following:
        Code:
        public Bar GetBarAtIndex(this Indicator indicator, int index, int barsArrayIdx)
        {
            return new Bar
            { 
                Open = indicator.BarsArray[barsArrayIdx].GetOpen(index),
                High = indicator.BarsArray[barsArrayIdx].GetHigh(index),
                Low = indicator.BarsArray[barsArrayIdx].GetLow(index),
                Close = indicator.BarsArray[barsArrayIdx].GetClose(index),
                Time = indicator.BarsArray[barsArrayIdx].GetTime(index),
                Volume = indicator.BarsArray[barsArrayIdx].GetVolume(index)
            };
        }
        Please let me know if you have any questions or if I may be of further assistance.
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          Thanks Michael. That's a similar approach to what I ended up with. Unfortunately my process requires analyzing each and every bar individually based on HLOCV so I need to grab all the values every time and for every bar. The individual numbers don't tell me very much by themselves unfortunately.

          I can't imagine how you must be storing this data internally such that it is perceived that to retrieve just the close value of a bar is somehow slower than grabbing the whole bar! You can't actually be storing the HLOC values in different places, surely?

          Cheers for your help

          Comment


            #6
            Hello reach4thelasers,

            I can't imagine how you must be storing this data internally such that it is perceived that to retrieve just the close value of a bar is somehow slower than grabbing the whole bar!
            I apologize if my post wasn't clear. I was saying just the opposite: Grabbing the whole bar as an object is much slower than grabbing just the close value at an index in the BarsArray. I was just noting the differences in how this was handled in NT7 vs how it is now in NT8.

            I am glad to hear I was able to be of assistance. Please let me know if you have any further questions.
            Michael M.NinjaTrader Quality Assurance

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,611 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            22 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X