• 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 Adfra, Today, 10:18 PM
    0 responses
    2 views
    0 likes
    Last Post Adfra
    by Adfra
     
    Started by jeronymite, Today, 09:01 PM
    0 responses
    4 views
    0 likes
    Last Post jeronymite  
    Started by Brillo, Today, 07:04 PM
    0 responses
    9 views
    0 likes
    Last Post Brillo
    by Brillo
     
    Started by ttodua, Today, 01:12 AM
    2 responses
    20 views
    0 likes
    Last Post ttodua
    by ttodua
     
    Started by kujista, Today, 02:57 PM
    1 response
    25 views
    0 likes
    Last Post NinjaTrader_Kate  
    Working...
    X