• 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

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:
    https://ninjatrader.com/support/help...sub=GetValueAt

    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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ntbone, 07-13-2019, 11:37 PM
    9 responses
    27 views
    0 likes
    Last Post Spaggetti Ninjja  
    Started by nicknamed, Today, 05:10 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_EricB  
    Started by pstrusi, Today, 04:57 PM
    0 responses
    6 views
    0 likes
    Last Post pstrusi
    by pstrusi
     
    Started by williamzz, Today, 04:18 PM
    0 responses
    6 views
    0 likes
    Last Post williamzz  
    Started by ct, Today, 01:57 PM
    2 responses
    14 views
    0 likes
    Last Post ct
    by ct
     
    Working...
    X