• 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

  • Herrwolf1
    started a topic Get Bar By Index

    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,

  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by racehit, Today, 12:50 AM
0 responses
3 views
0 likes
Last Post racehit
by racehit
 
Started by cmarkb, Today, 12:04 AM
0 responses
2 views
0 likes
Last Post cmarkb
by cmarkb
 
Started by supernova0219, Yesterday, 07:48 PM
0 responses
6 views
0 likes
Last Post supernova0219  
Started by qwfxny, Yesterday, 07:20 PM
0 responses
7 views
0 likes
Last Post qwfxny
by qwfxny
 
Started by bouncetherubble, Yesterday, 04:48 PM
0 responses
5 views
0 likes
Last Post bouncetherubble  
Working...
X