Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get Bar By Index

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

    Get Bar By Index

    Is it possible to obtain a bar object by index from the "Bars" array? I'm wanting to compare a bar classified as a "CandlestickPattern" to a value. I've made a function to so, but I'm having a hard time obtaining the correct bar object. I could pass in the OCHL values but that seems ignorant when the Bar object contains all those values.

    Thanks,

    #2
    Hello Herrwolf1,

    Welcome to the NinjaTrader support forum.

    Yes this is certainly possible to retrieve values from a specific index.

    In NinjaScript you have two methods of retrieving information about a bar depending on the scope of where you are accessing that data. From OnBarUpdate you generally use the BarsAgo system to retrieve data from a number of Bars from now or the processing bar. When outside the OnBarUpdate context you instead deal with direct bar indexes so both systems are supported in NinjaScript.

    When using a price series, indicator, or any Series<T> you will have the GetValueAt method which allows to get a value from a specific index:


    for example:
    Code:
    Close.GetValueAt(123);

    This would return the Close price for that index. Rather than gathering a bar, you would use the series to retrieve the value.

    If you are getting a BarsAgo returned from something you are doing, you can also convert that to an index by subtracting the BarsAgo from the CurrentBar:

    Code:
    CurrentBar - BarsAgo = index of bar
    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    23 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    120 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    63 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    45 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X