• 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 Steve L, Today, 05:01 PM
    0 responses
    5 views
    0 likes
    Last Post Steve L
    by Steve L
     
    Started by Trader-Joe, Today, 04:06 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Started by vantojo, Today, 04:06 PM
    0 responses
    4 views
    0 likes
    Last Post vantojo
    by vantojo
     
    Started by tonynt, Today, 02:39 PM
    2 responses
    12 views
    0 likes
    Last Post tonynt
    by tonynt
     
    Started by StevenNelson, Today, 12:23 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Working...
    X